|
16 | 16 | * under the License. |
17 | 17 | */ |
18 | 18 |
|
| 19 | +import java.io.ByteArrayInputStream; |
19 | 20 | import java.io.IOException; |
20 | | -import java.io.OutputStream; |
21 | | -import java.net.InetSocketAddress; |
| 21 | +import java.util.HashMap; |
| 22 | +import java.util.List; |
| 23 | +import java.util.logging.LogManager; |
22 | 24 |
|
23 | | -import com.splunk.logging.HttpEventCollectorErrorHandler; |
24 | | -import com.splunk.logging.HttpEventCollectorEventInfo; |
| 25 | +import org.apache.logging.log4j.Level; |
25 | 26 | import org.junit.Assert; |
26 | 27 | import org.junit.Test; |
27 | | -import sun.rmi.runtime.Log; |
28 | 28 |
|
29 | | -import java.io.ByteArrayInputStream; |
30 | | -import java.util.Date; |
31 | | -import java.util.HashMap; |
32 | | -import java.util.List; |
33 | | -import java.util.logging.LogManager; |
34 | | -import java.util.logging.Logger; |
| 29 | +import com.splunk.logging.HttpEventCollectorErrorHandler; |
| 30 | +import com.splunk.logging.HttpEventCollectorEventInfo; |
| 31 | +import com.splunk.logging.Log4jTestMiddleware; |
35 | 32 |
|
36 | 33 | public class HttpEventCollectorUnitTest { |
37 | 34 | @Test |
@@ -66,6 +63,35 @@ public void input(List<HttpEventCollectorEventInfo> events) { |
66 | 63 | Assert.assertTrue(HttpEventCollectorUnitTestMiddleware.eventsReceived == 3); |
67 | 64 | } |
68 | 65 |
|
| 66 | + @Test |
| 67 | + public void log4j_subcomponents() throws Exception { |
| 68 | + final Level[] levels = { Level.WARN, Level.INFO, Level.DEBUG }; |
| 69 | + final long[] expectedCounts = { 1, 2, 3 }; |
| 70 | + for (int i = 0; i < levels.length; i++) { |
| 71 | + HashMap<String, String> userInputs = new HashMap<>(); |
| 72 | + String loggerName = "splunk.log4jSubcomponents"; |
| 73 | + userInputs.put("user_logger_name", loggerName); |
| 74 | + userInputs.put("user_httpEventCollector_token", "11111111-2222-3333-4444-555555555555"); |
| 75 | + userInputs.put("user_middleware", "HttpEventCollectorUnitTestMiddleware"); |
| 76 | + userInputs.put("user_batch_size_count", "1"); |
| 77 | + userInputs.put("user_batch_size_bytes", "0"); |
| 78 | + userInputs.put("user_eventBodySerializer", "DoesNotExistButShouldNotCrashTest"); |
| 79 | + userInputs.put("user_eventHeaderSerializer", "DoesNotExistButShouldNotCrashTest"); |
| 80 | + userInputs.put("user_eventLevel", levels[i].toString()); |
| 81 | + TestUtil.resetLog4j2Configuration("log4j2_subcomponents_template.xml", "log4j2.xml", userInputs); |
| 82 | + org.apache.logging.log4j.Logger LOG4J = org.apache.logging.log4j.LogManager.getLogger(loggerName); |
| 83 | + |
| 84 | + HttpEventCollectorUnitTestMiddleware.eventsReceived = 0; |
| 85 | + // send 3 events |
| 86 | + LOG4J.warn("hello log4j"); |
| 87 | + LOG4J.info("hello log4j"); |
| 88 | + LOG4J.debug("hello log4j"); |
| 89 | + if (HttpEventCollectorUnitTestMiddleware.eventsReceived == 0) |
| 90 | + sleep(1000); |
| 91 | + Assert.assertEquals(expectedCounts[i], Log4jTestMiddleware.eventsReceived); |
| 92 | + } |
| 93 | + } |
| 94 | + |
69 | 95 | @Test |
70 | 96 | public void logback_simple() throws Exception { |
71 | 97 | HashMap<String, String> userInputs = new HashMap<String, String>(); |
|
0 commit comments