Skip to content

Commit 19c98bf

Browse files
author
Daniel Bustamante Ospina
authored
Merge pull request #43 from kwah07/feature/listeners-matching
updates contiperf version, fixes performance test
2 parents 9c4d930 + bb2e7f9 commit 19c98bf

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed

async/async-commons/async-commons.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,5 @@ dependencies {
7979
api "io.projectreactor.rabbitmq:reactor-rabbitmq"
8080
api 'com.fasterxml.jackson.core:jackson-databind'
8181
testImplementation 'io.projectreactor:reactor-test'
82-
testCompile group: 'org.databene', name: 'contiperf', version: '2.3.4'
83-
82+
testCompile group: 'com.github.javatlacati', name: 'contiperf', version: '2.4.3'
8483
}
Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,51 @@
11
package 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;
66
import org.junit.Before;
77
import org.junit.Rule;
88
import org.junit.Test;
9+
import org.junit.jupiter.api.BeforeAll;
910
import org.junit.runner.RunWith;
1011
import org.springframework.test.context.ContextConfiguration;
1112
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
1213

1314
import java.io.File;
1415
import java.io.IOException;
16+
import java.net.URI;
17+
import java.net.URISyntaxException;
1518
import java.nio.file.Files;
1619
import java.nio.file.Paths;
17-
import java.util.HashMap;
18-
import java.util.HashSet;
19-
import java.util.Map;
20-
import java.util.Set;
20+
import java.util.*;
21+
import java.util.concurrent.atomic.AtomicBoolean;
22+
import java.util.concurrent.atomic.AtomicReference;
2123
import java.util.stream.Collectors;
2224

23-
@ContextConfiguration(classes = KeyMatcher.class)
24-
@RunWith(SpringJUnit4ClassRunner.class)
2525
public class KeyMatcherPerformanceTest {
26-
2726
@Rule
2827
public ContiPerfRule contiPerfRule = new ContiPerfRule();
29-
Map<String, String> candidates = new HashMap<>();
30-
28+
public static AtomicReference<Map<String, String>> candidates = new AtomicReference<>();
29+
public static AtomicBoolean initialized = new AtomicBoolean(false);
3130
private KeyMatcher keyMatcher = new KeyMatcher();
32-
31+
private String DATASET_FILENAME = "candidateNamesForMatching.txt";
3332

3433
@Before
3534
public void init() {
36-
ClassLoader classLoader = getClass().getClassLoader();
37-
File file = new File(classLoader.getResource("candidateNamesForMatching.txt").getFile());
38-
try {
39-
Set<String> names = new HashSet<>(Files
40-
.readAllLines(Paths.get(file.getAbsolutePath())));
41-
candidates = names.stream()
42-
.collect(Collectors.toMap(name -> name, name -> name));
43-
} catch (IOException e) {
44-
e.printStackTrace();
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+
}
4549
}
4650
}
4751

@@ -50,14 +54,13 @@ public void init() {
5054
@Required(average = 200, max = 10000, throughput = 200)
5155
public void getFromMapTest() {
5256
String existentKey = "System.segment.3073.event.action";
53-
candidates.get(existentKey);
57+
candidates.get().get(existentKey);
5458
}
5559

56-
5760
@Test
5861
@PerfTest(threads = 4, duration = 4000)
5962
@Required(average = 200, max = 10000, throughput = 200)
6063
public void matchNameBeforeTest() {
61-
keyMatcher.match(candidates.keySet(), "System.segment.1.event.action");
64+
keyMatcher.match(candidates.get().keySet(), "System.segment.1.event.action");
6265
}
6366
}

0 commit comments

Comments
 (0)