diff --git a/async/async-commons/async-commons.gradle b/async/async-commons/async-commons.gradle index ca0f0efd..9e525075 100644 --- a/async/async-commons/async-commons.gradle +++ b/async/async-commons/async-commons.gradle @@ -79,6 +79,5 @@ dependencies { api "io.projectreactor.rabbitmq:reactor-rabbitmq" api 'com.fasterxml.jackson.core:jackson-databind' testImplementation 'io.projectreactor:reactor-test' - testCompile group: 'org.databene', name: 'contiperf', version: '2.3.4' - + testCompile group: 'com.github.javatlacati', name: 'contiperf', version: '2.4.3' } \ No newline at end of file diff --git a/async/async-commons/src/test/java/org/reactivecommons/async/impl/utils/matcher/KeyMatcherPerformanceTest.java b/async/async-commons/src/test/java/org/reactivecommons/async/impl/utils/matcher/KeyMatcherPerformanceTest.java index 2abe60c3..cce4cc9c 100755 --- a/async/async-commons/src/test/java/org/reactivecommons/async/impl/utils/matcher/KeyMatcherPerformanceTest.java +++ b/async/async-commons/src/test/java/org/reactivecommons/async/impl/utils/matcher/KeyMatcherPerformanceTest.java @@ -1,47 +1,51 @@ package org.reactivecommons.async.impl.utils.matcher; -import org.databene.contiperf.PerfTest; -import org.databene.contiperf.Required; -import org.databene.contiperf.junit.ContiPerfRule; +import com.github.javatlacati.contiperf.PerfTest; +import com.github.javatlacati.contiperf.Required; +import com.github.javatlacati.contiperf.junit.ContiPerfRule; import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.io.File; import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Paths; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; +import java.util.*; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; -@ContextConfiguration(classes = KeyMatcher.class) -@RunWith(SpringJUnit4ClassRunner.class) public class KeyMatcherPerformanceTest { - @Rule public ContiPerfRule contiPerfRule = new ContiPerfRule(); - Map candidates = new HashMap<>(); - + public static AtomicReference> candidates = new AtomicReference<>(); + public static AtomicBoolean initialized = new AtomicBoolean(false); private KeyMatcher keyMatcher = new KeyMatcher(); - + private String DATASET_FILENAME = "candidateNamesForMatching.txt"; @Before public void init() { - ClassLoader classLoader = getClass().getClassLoader(); - File file = new File(classLoader.getResource("candidateNamesForMatching.txt").getFile()); - try { - Set names = new HashSet<>(Files - .readAllLines(Paths.get(file.getAbsolutePath()))); - candidates = names.stream() - .collect(Collectors.toMap(name -> name, name -> name)); - } catch (IOException e) { - e.printStackTrace(); + if (!initialized.get()) { + initialized.set(true); + try { + ClassLoader classLoader = KeyMatcherPerformanceTest.class.getClassLoader(); + File file = new File(Objects.requireNonNull(classLoader.getResource(DATASET_FILENAME)) + .getFile()); + Set names = new HashSet<>(Files + .readAllLines(Paths.get(file.getAbsolutePath()))); + candidates.set(names.stream() + .collect(Collectors.toMap(name -> name, name -> name))); + } catch (IOException e) { + e.printStackTrace(); + candidates.set(new HashMap<>()); + } } } @@ -50,14 +54,13 @@ public void init() { @Required(average = 200, max = 10000, throughput = 200) public void getFromMapTest() { String existentKey = "System.segment.3073.event.action"; - candidates.get(existentKey); + candidates.get().get(existentKey); } - @Test @PerfTest(threads = 4, duration = 4000) @Required(average = 200, max = 10000, throughput = 200) public void matchNameBeforeTest() { - keyMatcher.match(candidates.keySet(), "System.segment.1.event.action"); + keyMatcher.match(candidates.get().keySet(), "System.segment.1.event.action"); } }