use java8 functional
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-02-08 18:15:39 +08:00
parent 169bf6f290
commit d395b987e6
9 changed files with 69 additions and 39 deletions

View File

@@ -1,10 +1,13 @@
package io.github.ehlxr.did;
import io.github.ehlxr.did.client.SdkClient;
import io.github.ehlxr.did.common.Try;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;
/**
@@ -31,19 +34,19 @@ public class DidSdkTest {
// 测试同步请求
IntStream.range(0, NUM).parallel().forEach(i -> System.out.println(client.invokeSync()));
// System.out.println("invokeync test finish");
System.out.println("invokeync test finish");
// 测试异步请求
// final CountDownLatch countDownLatch = new CountDownLatch(NUM);
// IntStream.range(0, NUM).forEach(i ->
// Try.of(() -> client.invokeAsync(responseFuture -> {
// System.out.println(responseFuture.getSdkProto());
// countDownLatch.countDown();
// })).trap(Throwable::printStackTrace).run());
//
// //noinspection ResultOfMethodCallIgnored
// countDownLatch.await(10, TimeUnit.SECONDS);
// System.out.println("invokeAsync test finish");
final CountDownLatch countDownLatch = new CountDownLatch(NUM);
IntStream.range(0, NUM).forEach(i ->
Try.of(() -> client.invokeAsync(responseFuture -> {
System.out.println(responseFuture.getSdkProto());
countDownLatch.countDown();
})).trap(Throwable::printStackTrace).run());
//noinspection ResultOfMethodCallIgnored
countDownLatch.await(10, TimeUnit.SECONDS);
System.out.println("invokeAsync test finish");
}
@Test