All Downloads are FREE. Search and download functionalities are using the official Maven repository.

test.MultiThreadDoipClientTest Maven / Gradle / Ivy

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());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy