|
1 | | -///* |
2 | | -// * Copyright 2022 Apollo Authors |
3 | | -// * |
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 |
7 | | -// * |
8 | | -// * http://www.apache.org/licenses/LICENSE-2.0 |
9 | | -// * |
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. |
15 | | -// * |
16 | | -// */ |
17 | | -//package com.ctrip.framework.apollo.core.utils; |
18 | | -// |
19 | | -//import com.ctrip.framework.test.tools.AloneRunner; |
20 | | -//import com.ctrip.framework.test.tools.AloneWith; |
21 | | -//import org.junit.Assert; |
22 | | -//import org.junit.jupiter.api.Test; |
23 | | -//import org.junit.runner.RunWith; |
24 | | -//import org.junit.runners.JUnit4; |
25 | | -//import org.slf4j.Logger; |
26 | | -//import org.slf4j.LoggerFactory; |
27 | | -// |
28 | | -///** |
29 | | -// * @author kl (http://kailing.pub) |
30 | | -// * @since 2021/5/20 |
31 | | -// */ |
32 | | -//@RunWith(AloneRunner.class) |
33 | | -//@AloneWith(JUnit4.class) |
34 | | -//public class DeferredLogCacheTest { |
35 | | -// |
36 | | -// private final Logger logger = LoggerFactory.getLogger(getClass()); |
37 | | -// private static final String logMsg = "hello kl"; |
38 | | -// |
39 | | -// @Test |
40 | | -// public void testDeferredLogCacheMaxLogSize() { |
41 | | -// for (int i = 0; i < 20000; i++) { |
42 | | -// DeferredLogCache.info(logger, "DeferredLogUtilTest"); |
43 | | -// } |
44 | | -// Assert.assertEquals(DeferredLogCache.logSize(), DeferredLogCache.MAX_LOG_SIZE); |
45 | | -// } |
46 | | -// |
47 | | -// @Test |
48 | | -// public void testDisableDeferred() { |
49 | | -// DeferredLogCache.clear(); |
50 | | -// DeferredLogger.disable(); |
51 | | -// final Logger defaultLogger = DeferredLoggerFactory.getLogger(DeferredLoggerTest.class); |
52 | | -// defaultLogger.info(logMsg); |
53 | | -// defaultLogger.debug(logMsg); |
54 | | -// defaultLogger.warn(logMsg); |
55 | | -// Assert.assertEquals(0, DeferredLogCache.logSize()); |
56 | | -// |
57 | | -// } |
58 | | -// |
59 | | -// @Test |
60 | | -// public void testEnableDeferred() { |
61 | | -// final Logger defaultLogger = DeferredLoggerFactory.getLogger(DeferredLoggerTest.class); |
62 | | -// DeferredLogger.enable(); |
63 | | -// |
64 | | -// defaultLogger.info(logMsg); |
65 | | -// defaultLogger.debug(logMsg); |
66 | | -// defaultLogger.warn(logMsg); |
67 | | -// Assert.assertEquals(3, DeferredLogCache.logSize()); |
68 | | -// } |
69 | | -//} |
| 1 | +/* |
| 2 | + * Copyright 2022 Apollo Authors |
| 3 | + * |
| 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 |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 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. |
| 15 | + * |
| 16 | + */ |
| 17 | +package com.ctrip.framework.apollo.core.utils; |
| 18 | + |
| 19 | +import com.ctrip.framework.test.tools.AloneExtension; |
| 20 | +import org.junit.Assert; |
| 21 | +import org.junit.jupiter.api.Test; |
| 22 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 23 | +import org.slf4j.Logger; |
| 24 | +import org.slf4j.LoggerFactory; |
| 25 | + |
| 26 | +/** |
| 27 | + * @author kl (http://kailing.pub) |
| 28 | + * @since 2021/5/20 |
| 29 | + */ |
| 30 | +@ExtendWith(AloneExtension.class) |
| 31 | +public class DeferredLogCacheTest { |
| 32 | + |
| 33 | + private final Logger logger = LoggerFactory.getLogger(getClass()); |
| 34 | + private static final String logMsg = "hello kl"; |
| 35 | + |
| 36 | + @Test |
| 37 | + public void testDeferredLogCacheMaxLogSize() { |
| 38 | + for (int i = 0; i < 20000; i++) { |
| 39 | + DeferredLogCache.info(logger, "DeferredLogUtilTest"); |
| 40 | + } |
| 41 | + Assert.assertEquals(DeferredLogCache.logSize(), DeferredLogCache.MAX_LOG_SIZE); |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + public void testDisableDeferred() { |
| 46 | + DeferredLogCache.clear(); |
| 47 | + DeferredLogger.disable(); |
| 48 | + final Logger defaultLogger = DeferredLoggerFactory.getLogger(DeferredLoggerTest.class); |
| 49 | + defaultLogger.info(logMsg); |
| 50 | + defaultLogger.debug(logMsg); |
| 51 | + defaultLogger.warn(logMsg); |
| 52 | + Assert.assertEquals(0, DeferredLogCache.logSize()); |
| 53 | + |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + public void testEnableDeferred() { |
| 58 | + final Logger defaultLogger = DeferredLoggerFactory.getLogger(DeferredLoggerTest.class); |
| 59 | + DeferredLogger.enable(); |
| 60 | + |
| 61 | + defaultLogger.info(logMsg); |
| 62 | + defaultLogger.debug(logMsg); |
| 63 | + defaultLogger.warn(logMsg); |
| 64 | + Assert.assertEquals(3, DeferredLogCache.logSize()); |
| 65 | + } |
| 66 | +} |
0 commit comments