20
20
import static org .apache .logging .log4j .layout .template .json .TestHelpers .writeJson ;
21
21
import static org .assertj .core .api .Assertions .assertThat ;
22
22
23
- import java .io .*;
23
+ import java .io .BufferedReader ;
24
+ import java .io .FileInputStream ;
25
+ import java .io .IOException ;
26
+ import java .io .InputStream ;
27
+ import java .io .InputStreamReader ;
28
+ import java .io .Reader ;
24
29
import java .nio .charset .StandardCharsets ;
25
30
import java .nio .file .Files ;
26
31
import java .nio .file .Path ;
38
43
import org .apache .logging .log4j .core .config .builder .api .ConfigurationBuilderFactory ;
39
44
import org .apache .logging .log4j .core .layout .ByteBufferDestination ;
40
45
import org .apache .logging .log4j .core .layout .StringBuilderEncoder ;
46
+ import org .junit .jupiter .api .Test ;
41
47
import org .junit .jupiter .api .parallel .Execution ;
42
48
import org .junit .jupiter .api .parallel .ExecutionMode ;
43
- import org .junit .jupiter .params .ParameterizedTest ;
44
- import org .junit .jupiter .params .provider .ValueSource ;
45
49
46
50
/**
47
51
* Tests {@link JsonTemplateLayout} doesn't exhibit unexpected behavior when accessed concurrently.
58
62
@ Execution (ExecutionMode .SAME_THREAD )
59
63
class JsonTemplateLayoutConcurrentEncodeTest {
60
64
61
- @ ParameterizedTest
62
- @ ValueSource (
63
- strings = {
64
- "dummy" ,
65
- "threadLocal" ,
66
- "queue:supplier=java.util.concurrent.ArrayBlockingQueue.new" ,
67
- "queue:supplier=org.jctools.queues.MpmcArrayQueue.new"
68
- })
69
- void test_concurrent_encode (final String recyclerFactory ) throws IOException {
70
- final Path appenderFilepath = createAppenderFilepath (recyclerFactory );
65
+ @ Test
66
+ void test_concurrent_encode () throws IOException {
67
+ final Path appenderFilepath = createAppenderFilepath ();
71
68
final int workerCount = 10 ;
72
69
final int messageLength = 1_000 ;
73
70
final int messageCount = 1_000 ;
74
71
try {
75
- withContextFromTemplate (appenderFilepath , recyclerFactory , loggerContext -> {
72
+ withContextFromTemplate (appenderFilepath , loggerContext -> {
76
73
final Logger logger = loggerContext .getLogger (JsonTemplateLayoutConcurrentEncodeTest .class );
77
74
runWorkers (workerCount , messageLength , messageCount , logger );
78
75
});
@@ -84,24 +81,16 @@ void test_concurrent_encode(final String recyclerFactory) throws IOException {
84
81
Files .delete (appenderFilepath );
85
82
}
86
83
87
- private static Path createAppenderFilepath (final String recyclerFactory ) {
88
- final String appenderFilename = String .format (
89
- "%s-%s.log" ,
90
- JsonTemplateLayoutConcurrentEncodeTest .class .getSimpleName (),
91
- recyclerFactory .replaceAll ("[^A-Za-z0-9]+" , "" ));
84
+ private static Path createAppenderFilepath () {
85
+ final String appenderFilename = JsonTemplateLayoutConcurrentEncodeTest .class .getSimpleName () + ".log" ;
92
86
return Paths .get (System .getProperty ("java.io.tmpdir" ), appenderFilename );
93
87
}
94
88
95
89
private static void withContextFromTemplate (
96
- final Path appenderFilepath ,
97
- final String recyclerFactory ,
98
- final Consumer <LoggerContext > loggerContextConsumer ) {
90
+ final Path appenderFilepath , final Consumer <LoggerContext > loggerContextConsumer ) {
99
91
100
92
// Create the configuration builder.
101
- final String configName = String .format (
102
- "%s-%s" ,
103
- JsonTemplateLayoutConcurrentEncodeTest .class .getSimpleName (),
104
- recyclerFactory .replaceAll ("[^A-Za-z0-9]+" , "" ));
93
+ final String configName = JsonTemplateLayoutConcurrentEncodeTest .class .getSimpleName ();
105
94
final ConfigurationBuilder <?> configBuilder = ConfigurationBuilderFactory .newConfigurationBuilder ()
106
95
.setStatusLevel (Level .ERROR )
107
96
.setConfigurationName (configName );
@@ -120,8 +109,7 @@ private static void withContextFromTemplate(
120
109
.addAttribute ("ignoreExceptions" , false )
121
110
.add (configBuilder
122
111
.newLayout ("JsonTemplateLayout" )
123
- .addAttribute ("eventTemplate" , eventTemplateJson )
124
- .addAttribute ("recyclerFactory" , recyclerFactory )))
112
+ .addAttribute ("eventTemplate" , eventTemplateJson )))
125
113
.add (configBuilder .newRootLogger (Level .ALL ).add (configBuilder .newAppenderRef (appenderName )))
126
114
.build (false );
127
115
0 commit comments