Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions async/async-commons/async-commons.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Original file line number Diff line number Diff line change
@@ -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<String, String> candidates = new HashMap<>();

public static AtomicReference<Map<String, String>> 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<String> 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<String> 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<>());
}
}
}

Expand All @@ -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");
}
}