diff options
author | 2018-03-23 23:10:30 +0300 | |
---|---|---|
committer | 2018-03-23 23:10:30 +0300 | |
commit | 6eceb46537df31756446760484ad1925a997205a (patch) | |
tree | e6a9675ca1c80d55cf5a884a5868491a7d648814 /openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/ContextPropagationTestHelper.java | |
parent | 79550d5dc1c5bcb79123128aa37b381a368e38d9 (diff) |
Logging refactoring and global context
Implemented global context (instance ID, host address).
Refactored the logging context API for clarity and
separation of concerns. Added unit tests. Fixed Javadoc.
Change-Id: I6e29b7b3613aebf23112dc017490ad2828e0fb91
Issue-ID: SDC-772
Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/ContextPropagationTestHelper.java')
-rw-r--r-- | openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/ContextPropagationTestHelper.java | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/ContextPropagationTestHelper.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/ContextPropagationTestHelper.java index 5112d37ac5..fccc6ba59a 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/ContextPropagationTestHelper.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/ContextPropagationTestHelper.java @@ -17,39 +17,44 @@ package org.openecomp.sdc.logging.slf4j; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; -import java.util.Collections; import java.util.EnumMap; import java.util.Map; import java.util.UUID; -import org.openecomp.sdc.logging.slf4j.SLF4JLoggingServiceProvider.ContextField; -import org.openecomp.sdc.logging.spi.LoggingContextService; import org.slf4j.MDC; -/** - * @author evitaliy - * @since 08 Mar 18 - */ class ContextPropagationTestHelper { - private static final Map<ContextField, String> EMPTY_CONTEXT = - Collections.unmodifiableMap(new EnumMap<>(ContextField.class)); + // Set to "false" if an old version of logback implementation is being used. + // Explicit context propagation should be used when the context is not propagated to child threads. + // See https://jira.qos.ch/browse/LOGBACK-422 and https://jira.qos.ch/browse/LOGBACK-624 + static final boolean IS_SUITABLE_LOGBACK_VERSION = true; - static Map<ContextField, String> putUniqueValues(LoggingContextService ctx) { + static final String EXPECT_PROPAGATED_TO_CHILD = "Expected the data to be propagated to the child thread's context"; + static final String EXPECT_RETAINED_IN_CURRENT = "Expected the data to be retained in this thread"; + static final String EXPECT_REPLACED_WITH_STORED = "Expected context data to be replaced with stored data"; + static final String EXPECT_INNER_RUN = "Expected the inner thread to run"; + static final String EXPECT_OUTER_RUN = "Expected the outer thread to run"; + static final String EXPECT_NOT_COPIED = "Expected context data not to be copied to this thread"; + static final String EXPECT_RETAINED_IN_PARENT = "Expected context data to be retained in parent thread"; + static final String EXPECT_POPULATED = "Expected context data to be populated in this thread"; + static final String EXPECT_EMPTY = "Expected context data to be empty"; + static final String EXPECT_REMAIN_EMPTY = "Expected context data to remain empty in this thread"; + static final String EXPECT_REVERTED_ON_EXCEPTION = "Expected context data to be reverted even in case of exception"; + static final String EXPECT_EXCEPTION_FROM_INNER = "Expected the inner class to throw exception"; - Map<ContextField, String> values = new EnumMap<>(ContextField.class); + static Map<ContextField, String> putUniqueValues() { - String service = UUID.randomUUID().toString(); - ctx.putServiceName(service); - values.put(ContextField.SERVICE_NAME, service); + Map<ContextField, String> values = new EnumMap<>(ContextField.class); - String partner = UUID.randomUUID().toString(); - ctx.putPartnerName(partner); - values.put(ContextField.PARTNER_NAME, partner); + String random = UUID.randomUUID().toString(); - String request = UUID.randomUUID().toString(); - ctx.putRequestId(request); - values.put(ContextField.REQUEST_ID, request); + for (ContextField key : ContextField.values()) { + String value = random + "-" + key.name(); + values.put(key, value); + MDC.put(key.asKey(), value); + } return values; } @@ -62,6 +67,9 @@ class ContextPropagationTestHelper { } static void assertContextEmpty(String error) { - assertContextFields(EMPTY_CONTEXT, error); + + for (ContextField key : ContextField.values()) { + assertNull(MDC.get(key.asKey()), error); + } } } |