did/did-sdk/src/test/java/io/github/ehlxr/did/DidSdkPressTest.java

93 lines
2.6 KiB
Java
Raw Normal View History

2021-01-22 07:40:02 +00:00
package io.github.ehlxr.did;
2018-08-14 07:21:56 +00:00
2021-01-22 07:40:02 +00:00
import io.github.ehlxr.did.client.SdkClient;
2018-08-15 02:40:37 +00:00
import org.junit.After;
import org.junit.Before;
2018-08-14 07:21:56 +00:00
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.CountDownLatch;
/**
*
*
* @author ehlxr
*/
2018-08-15 02:40:37 +00:00
public class DidSdkPressTest {
private static final Logger logger = LoggerFactory.getLogger(DidSdkPressTest.class);
private SdkClient client;
2018-08-14 07:21:56 +00:00
2018-08-15 02:40:37 +00:00
@Before
public void init() {
2021-01-20 07:25:58 +00:00
client = new SdkClient();
2018-08-14 07:21:56 +00:00
client.start();
2018-08-15 02:40:37 +00:00
}
@After
public void destroy() {
client.shutdown();
}
2018-08-14 07:21:56 +00:00
2018-08-15 02:40:37 +00:00
@Test
public void asyncTest() throws Exception {
2018-08-14 07:21:56 +00:00
long start;
long end;
long cast;
long amount = 0;
long allcast = 0;
for (int k = 0; k < 10; k++) {
2018-08-15 02:40:37 +00:00
// 初始发送总量
int NUM = 80000;
2018-08-14 07:21:56 +00:00
final CountDownLatch countDownLatch = new CountDownLatch(NUM);
start = System.currentTimeMillis();
for (int i = 0; i < NUM; i++) {
2021-01-20 07:25:58 +00:00
client.invokeAsync(responseFuture -> countDownLatch.countDown());
2018-08-14 07:21:56 +00:00
}
2018-08-14 10:37:34 +00:00
// countDownLatch.await(10, TimeUnit.SECONDS);
countDownLatch.await();
2018-08-14 07:21:56 +00:00
end = System.currentTimeMillis();
cast = (end - start);
allcast += cast;
logger.info("invokeAsync test num is: {}, cast time: {} millsec, throughput: {} send/millsec", NUM, cast, (double) NUM / cast);
amount += NUM;
2018-08-14 10:37:34 +00:00
// NUM = NUM + 5000;
// TimeUnit.SECONDS.sleep(2);
2018-08-14 07:21:56 +00:00
}
logger.info("invokeAsync test all num is: {}, all cast time: {} millsec, all throughput: {} send/millsec", amount, allcast, (double) amount / allcast);
}
2018-08-15 02:40:37 +00:00
@Test
public void syncTest() throws Exception {
long start;
long end;
long cast;
long amount = 0;
long allcast = 0;
2021-01-20 07:25:58 +00:00
for (int k = 0; k < 10; k++) {
2018-08-15 02:40:37 +00:00
start = System.currentTimeMillis();
int NUM = 60000;
for (int i = 0; i < NUM; i++) {
2021-01-20 07:25:58 +00:00
client.invokeSync();
2018-08-15 02:40:37 +00:00
}
end = System.currentTimeMillis();
cast = (end - start);
allcast += cast;
logger.info("invokeSync test num is: {}, cast time: {} millsec, throughput: {} send/millsec", NUM, cast, (double) NUM / cast);
amount += NUM;
// NUM += 5000;
// TimeUnit.SECONDS.sleep(2);
}
logger.info("invokeSync test all num is: {}, all cast time: {} millsec, all throughput: {} send/millsec", amount, allcast, (double) amount / allcast);
}
2018-08-14 07:21:56 +00:00
}