test.MultiThreadDoipClientTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of doip-audit-tool Show documentation
Show all versions of doip-audit-tool Show documentation
doip audit tool developed by bdware
The newest version!
package test;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
public class MultiThreadDoipClientTest {
static Logger LOGGER = LogManager.getLogger(MultiThreadDoipClientTest.class);
static int threadCount = 30;
static int reqDur = 180;
static String serverAddr = "tcp://127.0.0.1:21042";
static Executor executor;
public static void main(String[] args) {
if (args.length > 0) {
serverAddr = args[0];
threadCount = Integer.valueOf(args[1]);
reqDur = Integer.valueOf(args[2]);
}
executor = Executors.newFixedThreadPool(threadCount);
new MultiThreadDoipClientTest().run();
}
public void run() {
DoipClientTest.TestResult total = new DoipClientTest.TestResult();
AtomicInteger counter = new AtomicInteger(0);
AtomicInteger totalRps = new AtomicInteger(0);
long start = System.currentTimeMillis();
for (int i = 0; i < threadCount; i++)
executor.execute(new Runnable() {
@Override
public void run() {
DoipClientTest test = new DoipClientTest();
try {
// DoipClientTest.TestResult result = test.testRetriveWithTime(serverAddr, reqDur, "bdware.test/small");
DoipClientTest.TestResult result = test.testRetriveReconnectEveryTimeWithTime(serverAddr, reqDur, "bdware.test/small");
// DoipClientTest.TestResult result = test.testRetriveReconenctEveryTime(serverAddr, reqDur, "bdware.test/small");
total.merge(result);
totalRps.addAndGet((int) result.rps);
} catch (Exception e) {
}
counter.getAndIncrement();
}
});
for (; counter.get() < threadCount; ) {
Thread.yield();
}
total.dur = System.currentTimeMillis() - start;
LOGGER.info(total.getResultStr());
}
}