2 * Copyright © 2016-2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdc.logging.slf4j;
19 import org.openecomp.sdc.logging.api.LoggingContext;
20 import org.openecomp.sdc.logging.spi.LoggingContextService;
21 import org.testng.annotations.DataProvider;
23 import java.util.concurrent.Callable;
29 public abstract class BaseContextPropagationTest {
31 // Disable if an old version of logback implementation is being used.
32 // Context propagation should be used when ctx is not propagated to child threads.
33 // See https://jira.qos.ch/browse/LOGBACK-422 and https://jira.qos.ch/browse/LOGBACK-624
34 static final boolean ENABLED = false;
36 static final String PROVIDER = "context";
38 static final String EXPECT_PROPAGATED_TO_CHILD = "Expected the data to be propagated to the child thread's context";
39 static final String EXPECT_RETAINED_IN_CURRENT = "Expected the data to be retained in this thread";
40 static final String EXPECT_REPLACED_WITH_STORED = "Expected context data to be replaced with stored data";
41 static final String EXPECT_INNER_RUN = "Expected the inner thread to run";
42 static final String EXPECT_OUTER_RUN = "Expected the outer thread to run";
43 static final String EXPECT_NOT_COPIED = "Expected context data not to be copied to this thread";
44 static final String EXPECT_RETAINED_IN_PARENT = "Expected context data to be retained in parent thread";
45 static final String EXPECT_POPULATED = "Expected context data to be populated in this thread";
46 static final String EXPECT_EMPTY = "Expected context data to be empty";
47 static final String EXPECT_REMAIN_EMPTY = "Expected context data to remain empty in this thread";
48 static final String EXPECT_REVERTED_ON_EXCEPTION = "Expected context data to be reverted even in case of exception";
49 static final String EXPECT_EXCEPTION_FROM_INNER = "Expected the inner class to throw exception";
51 @DataProvider(name = PROVIDER)
52 public static Object[][] contextServices() {
53 // try both directly call the implementation and get it via the binding
54 return new Object[][]{
55 {new SLF4JLoggingServiceProvider()},
56 {new LoggingContextAdaptor()}
60 private static class LoggingContextAdaptor implements LoggingContextService {
63 public void putRequestId(String requestId) {
64 LoggingContext.putRequestId(requestId);
68 public void putServiceName(String serviceName) {
69 LoggingContext.putServiceName(serviceName);
73 public void putPartnerName(String partnerName) {
74 LoggingContext.putPartnerName(partnerName);
79 LoggingContext.clear();
83 public Runnable copyToRunnable(Runnable runnable) {
84 return LoggingContext.copyToRunnable(runnable);
88 public <V> Callable<V> copyToCallable(Callable<V> callable) {
89 return LoggingContext.copyToCallable(callable);
93 public String toString() {
94 return this.getClass().getName();