Skip to content

Commit a6ad914

Browse files
committed
fix tests
1 parent f44889e commit a6ad914

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

sdk-platform-java/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcLoggingInterceptorTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,16 @@ class GrpcLoggingInterceptorTest {
6060
@Mock private ClientCall<String, Integer> call;
6161

6262
private static final MethodDescriptor<String, Integer> method = FakeMethodDescriptor.create();
63+
private boolean originalLoggingEnabled;
64+
65+
@org.junit.jupiter.api.BeforeEach
66+
void setUpLoggingState() throws Exception {
67+
originalLoggingEnabled = isLoggingEnabled();
68+
}
6369

6470
@AfterEach
6571
void tearDown() throws Exception {
66-
setLoggingEnabled(false);
72+
setLoggingEnabled(originalLoggingEnabled);
6773
}
6874

6975
@Test
@@ -141,4 +147,11 @@ private static void setLoggingEnabled(boolean enabled) throws Exception {
141147
method.setAccessible(true);
142148
method.invoke(null, enabled);
143149
}
150+
151+
private static boolean isLoggingEnabled() throws Exception {
152+
Class<?> loggingUtils = Class.forName("com.google.api.gax.logging.LoggingUtils");
153+
Method method = loggingUtils.getDeclaredMethod("isLoggingEnabled");
154+
method.setAccessible(true);
155+
return (boolean) method.invoke(null);
156+
}
144157
}

sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/logging/Slf4jUtils.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@
4747
class Slf4jUtils {
4848

4949
private static final Logger NO_OP_LOGGER = org.slf4j.helpers.NOPLogger.NOP_LOGGER;
50-
private static final boolean loggingEnabled = LoggingUtils.isLoggingEnabled();
51-
5250
private static final boolean isSLF4J2x;
5351

5452
static {
@@ -70,7 +68,7 @@ static Logger getLogger(Class<?> clazz) {
7068

7169
// constructor with LoggerFactoryProvider to make testing easier
7270
static Logger getLogger(Class<?> clazz, LoggerFactoryProvider factoryProvider) {
73-
if (loggingEnabled) {
71+
if (LoggingUtils.isLoggingEnabled()) {
7472
ILoggerFactory loggerFactory = factoryProvider.getLoggerFactory();
7573
return loggerFactory.getLogger(clazz.getName());
7674
} else {

0 commit comments

Comments
 (0)