|
8 | 8 | import static org.mockito.Mockito.never; |
9 | 9 | import static org.mockito.Mockito.times; |
10 | 10 |
|
| 11 | +import ch.qos.logback.classic.LoggerContext; |
| 12 | +import ch.qos.logback.classic.util.ContextInitializer; |
| 13 | +import ch.qos.logback.core.joran.spi.JoranException; |
11 | 14 | import com.typesafe.config.Config; |
12 | 15 | import com.typesafe.config.ConfigFactory; |
13 | 16 | import com.typesafe.config.ConfigObject; |
|
27 | 30 | import org.mockito.MockedStatic; |
28 | 31 | import org.mockito.Mockito; |
29 | 32 | import org.mockito.junit.MockitoJUnitRunner; |
| 33 | +import org.slf4j.LoggerFactory; |
30 | 34 | import org.tron.common.arch.Arch; |
31 | 35 | import org.tron.common.log.LogService; |
32 | 36 | import org.tron.common.parameter.RateLimiterInitialization; |
|
38 | 42 | import org.tron.core.services.http.RateLimiterServlet; |
39 | 43 | import org.tron.core.zen.ZksnarkInitService; |
40 | 44 |
|
| 45 | + |
41 | 46 | @RunWith(MockitoJUnitRunner.class) |
42 | 47 | public class TronErrorTest { |
43 | 48 |
|
@@ -85,10 +90,22 @@ public void ZksnarkInitTest() throws IllegalAccessException, NoSuchFieldExceptio |
85 | 90 |
|
86 | 91 | @Test |
87 | 92 | public void LogLoadTest() throws IOException { |
88 | | - LogService.load("non-existent.xml"); |
89 | | - Path path = temporaryFolder.newFile("logback.xml").toPath(); |
90 | | - TronError thrown = assertThrows(TronError.class, () -> LogService.load(path.toString())); |
91 | | - assertEquals(TronError.ErrCode.LOG_LOAD, thrown.getErrCode()); |
| 93 | + LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); |
| 94 | + |
| 95 | + try { |
| 96 | + LogService.load("non-existent.xml"); |
| 97 | + Path path = temporaryFolder.newFile("logback.xml").toPath(); |
| 98 | + TronError thrown = assertThrows(TronError.class, () -> LogService.load(path.toString())); |
| 99 | + assertEquals(TronError.ErrCode.LOG_LOAD, thrown.getErrCode()); |
| 100 | + } finally { |
| 101 | + try { |
| 102 | + context.reset(); |
| 103 | + ContextInitializer ci = new ContextInitializer(context); |
| 104 | + ci.autoConfig(); |
| 105 | + } catch (JoranException e) { |
| 106 | + Assert.fail(e.getMessage()); |
| 107 | + } |
| 108 | + } |
92 | 109 | } |
93 | 110 |
|
94 | 111 | @Test |
|
0 commit comments