11package org .reactivecommons .async .impl .utils .matcher ;
22
3- import org . databene .contiperf .PerfTest ;
4- import org . databene .contiperf .Required ;
5- import org . databene .contiperf .junit .ContiPerfRule ;
3+ import com . github . javatlacati .contiperf .PerfTest ;
4+ import com . github . javatlacati .contiperf .Required ;
5+ import com . github . javatlacati .contiperf .junit .ContiPerfRule ;
66import org .junit .Before ;
7- import org .junit .BeforeClass ;
87import org .junit .Rule ;
98import org .junit .Test ;
9+ import org .junit .jupiter .api .BeforeAll ;
1010import org .junit .runner .RunWith ;
1111import org .springframework .test .context .ContextConfiguration ;
1212import org .springframework .test .context .junit4 .SpringJUnit4ClassRunner ;
1313
1414import java .io .File ;
1515import java .io .IOException ;
16+ import java .net .URI ;
17+ import java .net .URISyntaxException ;
1618import java .nio .file .Files ;
1719import java .nio .file .Paths ;
18- import java .util .HashMap ;
19- import java .util .HashSet ;
20- import java .util .Map ;
21- import java .util .Set ;
20+ import java .util .*;
21+ import java .util .concurrent .atomic .AtomicBoolean ;
22+ import java .util .concurrent .atomic .AtomicReference ;
2223import java .util .stream .Collectors ;
2324
24- @ ContextConfiguration (classes = KeyMatcher .class )
25- @ RunWith (SpringJUnit4ClassRunner .class )
2625public class KeyMatcherPerformanceTest {
27-
2826 @ Rule
2927 public ContiPerfRule contiPerfRule = new ContiPerfRule ();
30- static Map <String , String > candidates = new HashMap <>();
31-
28+ public static AtomicReference < Map <String , String >> candidates = new AtomicReference <>();
29+ public static AtomicBoolean initialized = new AtomicBoolean ( false );
3230 private KeyMatcher keyMatcher = new KeyMatcher ();
31+ private String DATASET_FILENAME = "candidateNamesForMatching.txt" ;
3332
34-
35- @ BeforeClass
36- public static void init () {
37- ClassLoader classLoader = KeyMatcherPerformanceTest .class .getClassLoader ();
38- File file = new File (classLoader .getResource ("candidateNamesForMatching.txt" ).getFile ());
39- try {
40- Set <String > names = new HashSet <>(Files
41- .readAllLines (Paths .get (file .getAbsolutePath ())));
42- candidates = names .stream ()
43- .collect (Collectors .toMap (name -> name , name -> name ));
44- } catch (IOException e ) {
45- e .printStackTrace ();
33+ @ Before
34+ public void init () {
35+ if (!initialized .get ()) {
36+ initialized .set (true );
37+ try {
38+ ClassLoader classLoader = KeyMatcherPerformanceTest .class .getClassLoader ();
39+ File file = new File (Objects .requireNonNull (classLoader .getResource (DATASET_FILENAME ))
40+ .getFile ());
41+ Set <String > names = new HashSet <>(Files
42+ .readAllLines (Paths .get (file .getAbsolutePath ())));
43+ candidates .set (names .stream ()
44+ .collect (Collectors .toMap (name -> name , name -> name )));
45+ } catch (IOException e ) {
46+ e .printStackTrace ();
47+ candidates .set (new HashMap <>());
48+ }
4649 }
4750 }
4851
@@ -51,14 +54,13 @@ public static void init() {
5154 @ Required (average = 200 , max = 10000 , throughput = 200 )
5255 public void getFromMapTest () {
5356 String existentKey = "System.segment.3073.event.action" ;
54- candidates .get (existentKey );
57+ candidates .get (). get ( existentKey );
5558 }
5659
57-
5860 @ Test
5961 @ PerfTest (threads = 4 , duration = 4000 )
6062 @ Required (average = 200 , max = 10000 , throughput = 200 )
6163 public void matchNameBeforeTest () {
62- keyMatcher .match (candidates .keySet (), "System.segment.1.event.action" );
64+ keyMatcher .match (candidates .get (). keySet (), "System.segment.1.event.action" );
6365 }
6466}
0 commit comments