Optimized code
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package cn.ceres.did;
|
||||
|
||||
import cn.ceres.did.client.SdkClient;
|
||||
import cn.ceres.did.sdk.SdkProto;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -21,9 +20,7 @@ public class DidSdkPressTest {
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
client = new SdkClient("127.0.0.1", 16831);
|
||||
// client = new SdkClient();
|
||||
client.init();
|
||||
client = new SdkClient();
|
||||
client.start();
|
||||
}
|
||||
|
||||
@@ -32,7 +29,6 @@ public class DidSdkPressTest {
|
||||
client.shutdown();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void asyncTest() throws Exception {
|
||||
long start;
|
||||
@@ -47,8 +43,7 @@ public class DidSdkPressTest {
|
||||
final CountDownLatch countDownLatch = new CountDownLatch(NUM);
|
||||
start = System.currentTimeMillis();
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
final SdkProto sdkProto = new SdkProto();
|
||||
client.invokeAsync(sdkProto, 5000, responseFuture -> countDownLatch.countDown());
|
||||
client.invokeAsync(responseFuture -> countDownLatch.countDown());
|
||||
}
|
||||
|
||||
// countDownLatch.await(10, TimeUnit.SECONDS);
|
||||
@@ -74,12 +69,11 @@ public class DidSdkPressTest {
|
||||
long amount = 0;
|
||||
long allcast = 0;
|
||||
|
||||
for (int k = 0; k < 20; k++) {
|
||||
for (int k = 0; k < 10; k++) {
|
||||
start = System.currentTimeMillis();
|
||||
int NUM = 60000;
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
final SdkProto sdkProto = new SdkProto();
|
||||
client.invokeSync(sdkProto, 5000);
|
||||
client.invokeSync();
|
||||
}
|
||||
|
||||
end = System.currentTimeMillis();
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package cn.ceres.did;
|
||||
|
||||
import cn.ceres.did.client.SdkClient;
|
||||
import cn.ceres.did.sdk.SdkProto;
|
||||
import cn.ceres.did.common.SdkProto;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -17,37 +18,35 @@ public class DidSdkTest {
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
client = new SdkClient("127.0.0.1", 16831);
|
||||
// SdkClient client = new SdkClient();
|
||||
client.init();
|
||||
client = new SdkClient("127.0.0.1", 16831, 5000);
|
||||
client.start();
|
||||
}
|
||||
|
||||
@After
|
||||
public void destroy() {
|
||||
client.shutdown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void didSdkTest() throws Exception {
|
||||
// 测试同步请求,关注rqid是否对应
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
SdkProto sdkProto = new SdkProto();
|
||||
System.out.println(i + " sendProto: " + sdkProto.toString());
|
||||
SdkProto resultProto = client.invokeSync(sdkProto, 2000);
|
||||
System.out.println(i + " resultProto: " + resultProto.toString());
|
||||
SdkProto resultProto = client.invokeSync();
|
||||
System.out.println(i + " resultProto: " + resultProto);
|
||||
}
|
||||
System.out.println("invokeync test finish");
|
||||
|
||||
// 测试异步请求,关注rqid是否对应
|
||||
final CountDownLatch countDownLatch = new CountDownLatch(NUM);
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
final SdkProto sdkProto = new SdkProto();
|
||||
final int finalI = i;
|
||||
client.invokeAsync(sdkProto, 2000, responseFuture -> {
|
||||
System.out.println(finalI + " sendProto: " + sdkProto.toString());
|
||||
client.invokeAsync(responseFuture -> {
|
||||
countDownLatch.countDown();
|
||||
System.out.println(finalI + " resultProto: " + responseFuture.getSdkProto().toString());
|
||||
System.out.println(finalI + " resultProto: " + responseFuture.getSdkProto());
|
||||
});
|
||||
}
|
||||
countDownLatch.await(10, TimeUnit.SECONDS);
|
||||
System.out.println("invokeAsync test finish");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user