use of org.eblocker.server.common.network.icmpv6.EchoRequest in project toolkit by googleapis.
the class ShowcaseTest method canCollectAStreamOfRequests.
@Test
public void canCollectAStreamOfRequests() throws InterruptedException {
List<String> collections = new ArrayList<>();
CountDownLatch latch = new CountDownLatch(1);
ApiStreamObserver<EchoRequest> requestStream = client.collectCallable().clientStreamingCall(new ApiStreamObserver<EchoResponse>() {
@Override
public void onNext(EchoResponse value) {
collections.add(value.getContent());
}
@Override
public void onError(Throwable t) {
fail("error not expected");
}
@Override
public void onCompleted() {
latch.countDown();
}
});
for (String request : new String[] { "a", "b", "c", "done" }) {
requestStream.onNext(EchoRequest.newBuilder().setContent(request).build());
}
requestStream.onCompleted();
latch.await(7, TimeUnit.SECONDS);
assertThat(collections).containsExactly("a b c done");
}
use of org.eblocker.server.common.network.icmpv6.EchoRequest in project toolkit by googleapis.
the class ShowcaseTest method canHaveARandomChat.
@Test
public void canHaveARandomChat() throws InterruptedException {
List<String> responses = new ArrayList<>();
CountDownLatch latch = new CountDownLatch(1);
List<String> inputs = IntStream.range(0, 5).mapToObj(idx -> new Random().ints(20).mapToObj(Integer::toString).collect(Collectors.joining("->"))).collect(Collectors.toList());
client.chatCallable().call(new BidiStreamObserver<EchoRequest, EchoResponse>() {
@Override
public void onReady(ClientStream<EchoRequest> stream) {
inputs.forEach(message -> stream.send(EchoRequest.newBuilder().setContent(message).build()));
stream.closeSend();
}
@Override
public void onStart(StreamController controller) {
// skip...
}
@Override
public void onResponse(EchoResponse response) {
responses.add(response.getContent());
}
@Override
public void onError(Throwable t) {
fail("error not expected");
}
@Override
public void onComplete() {
latch.countDown();
}
});
latch.await(7, TimeUnit.SECONDS);
assertThat(responses).containsExactlyElementsIn(inputs).inOrder();
}
use of org.eblocker.server.common.network.icmpv6.EchoRequest in project eblocker by eblocker.
the class Ip6MulticastPing method ping.
public void ping() {
if (!featureToggleRouter.isIp6Enabled()) {
return;
}
byte[] data = new byte[32];
random.nextBytes(data);
EchoRequest echoRequest = new EchoRequest(networkInterface.getHardwareAddress(), networkInterface.getIp6LinkLocalAddress(), MULTICAST_ALL_NODES_HW_ADDRESS, Ip6Address.MULTICAST_ALL_NODES_ADDRESS, identifier, sequence, data);
String message = echoRequest.toString();
pubSubService.publish("ip6:out", message);
sequence = (sequence + 1) & 0xffff;
}
Aggregations