Search in sources :

Example 1 with EchoRequest

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");
}
Also used : EchoResponse(com.google.showcase.v1beta1.EchoResponse) ArrayList(java.util.ArrayList) EchoRequest(com.google.showcase.v1beta1.EchoRequest) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 2 with EchoRequest

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();
}
Also used : SequenceServiceClient(com.google.showcase.v1beta1.SequenceServiceClient) IntStream(java.util.stream.IntStream) BidiStreamObserver(com.google.api.gax.rpc.BidiStreamObserver) EchoSettings(com.google.showcase.v1beta1.EchoSettings) SequenceReport(com.google.showcase.v1beta1.SequenceReport) SequenceServiceSettings(com.google.showcase.v1beta1.SequenceServiceSettings) RunWith(org.junit.runner.RunWith) Random(java.util.Random) AttemptSequenceRequest(com.google.showcase.v1beta1.AttemptSequenceRequest) EchoClient(com.google.showcase.v1beta1.EchoClient) ArrayList(java.util.ArrayList) After(org.junit.After) Assert.fail(org.junit.Assert.fail) ServerStream(com.google.api.gax.rpc.ServerStream) Code(com.google.rpc.Code) Before(org.junit.Before) ClientStream(com.google.api.gax.rpc.ClientStream) Sequence(com.google.showcase.v1beta1.Sequence) EchoRequest(com.google.showcase.v1beta1.EchoRequest) EchoResponse(com.google.showcase.v1beta1.EchoResponse) BlockResponse(com.google.showcase.v1beta1.BlockResponse) ExpandRequest(com.google.showcase.v1beta1.ExpandRequest) Status(com.google.rpc.Status) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) AbortedException(com.google.api.gax.rpc.AbortedException) Collectors(java.util.stream.Collectors) StatusRuntimeException(io.grpc.StatusRuntimeException) TimeUnit(java.util.concurrent.TimeUnit) ApiStreamObserver(com.google.api.gax.rpc.ApiStreamObserver) CountDownLatch(java.util.concurrent.CountDownLatch) Duration(com.google.protobuf.Duration) List(java.util.List) BlockRequest(com.google.showcase.v1beta1.BlockRequest) StreamController(com.google.api.gax.rpc.StreamController) EchoResponse(com.google.showcase.v1beta1.EchoResponse) ArrayList(java.util.ArrayList) EchoRequest(com.google.showcase.v1beta1.EchoRequest) CountDownLatch(java.util.concurrent.CountDownLatch) StreamController(com.google.api.gax.rpc.StreamController) Random(java.util.Random) Test(org.junit.Test)

Example 3 with EchoRequest

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;
}
Also used : EchoRequest(org.eblocker.server.common.network.icmpv6.EchoRequest)

Aggregations

EchoRequest (com.google.showcase.v1beta1.EchoRequest)2 EchoResponse (com.google.showcase.v1beta1.EchoResponse)2 ArrayList (java.util.ArrayList)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Test (org.junit.Test)2 AbortedException (com.google.api.gax.rpc.AbortedException)1 ApiStreamObserver (com.google.api.gax.rpc.ApiStreamObserver)1 BidiStreamObserver (com.google.api.gax.rpc.BidiStreamObserver)1 ClientStream (com.google.api.gax.rpc.ClientStream)1 ServerStream (com.google.api.gax.rpc.ServerStream)1 StreamController (com.google.api.gax.rpc.StreamController)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 Duration (com.google.protobuf.Duration)1 Code (com.google.rpc.Code)1 Status (com.google.rpc.Status)1 AttemptSequenceRequest (com.google.showcase.v1beta1.AttemptSequenceRequest)1 BlockRequest (com.google.showcase.v1beta1.BlockRequest)1 BlockResponse (com.google.showcase.v1beta1.BlockResponse)1 EchoClient (com.google.showcase.v1beta1.EchoClient)1 EchoSettings (com.google.showcase.v1beta1.EchoSettings)1