Search in sources :

Example 61 with Server

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server in project grpc-java by grpc.

the class XdsServerWrapperTest method discoverState_virtualhost.

@Test
public void discoverState_virtualhost() throws Exception {
    final SettableFuture<Server> start = SettableFuture.create();
    Executors.newSingleThreadExecutor().execute(new Runnable() {

        @Override
        public void run() {
            try {
                start.set(xdsServerWrapper.start());
            } catch (Exception ex) {
                start.setException(ex);
            }
        }
    });
    String ldsWatched = xdsClient.ldsResource.get(5, TimeUnit.SECONDS);
    assertThat(ldsWatched).isEqualTo("grpc/server?udpa.resource.listening_address=0.0.0.0:1");
    VirtualHost virtualHost = VirtualHost.create("virtual-host", Collections.singletonList("auth"), new ArrayList<Route>(), ImmutableMap.<String, FilterConfig>of());
    HttpConnectionManager httpConnectionManager = HttpConnectionManager.forVirtualHosts(0L, Collections.singletonList(virtualHost), new ArrayList<NamedFilterConfig>());
    EnvoyServerProtoData.FilterChain filterChain = EnvoyServerProtoData.FilterChain.create("filter-chain-foo", createMatch(), httpConnectionManager, createTls(), mock(TlsContextManager.class));
    xdsClient.deliverLdsUpdate(Collections.singletonList(filterChain), null);
    start.get(5000, TimeUnit.MILLISECONDS);
    assertThat(ldsWatched).isEqualTo("grpc/server?udpa.resource.listening_address=0.0.0.0:1");
    assertThat(selectorManager.getSelectorToUpdateSelector().getRoutingConfigs().size()).isEqualTo(1);
    ServerRoutingConfig realConfig = selectorManager.getSelectorToUpdateSelector().getRoutingConfigs().get(filterChain).get();
    assertThat(realConfig.virtualHosts()).isEqualTo(httpConnectionManager.virtualHosts());
    assertThat(realConfig.interceptors()).isEqualTo(ImmutableMap.of());
    verify(listener).onServing();
    verify(mockServer).start();
}
Also used : ServerRoutingConfig(io.grpc.xds.XdsServerWrapper.ServerRoutingConfig) Server(io.grpc.Server) TimeoutException(java.util.concurrent.TimeoutException) StatusException(io.grpc.StatusException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) NamedFilterConfig(io.grpc.xds.Filter.NamedFilterConfig) FilterChain(io.grpc.xds.EnvoyServerProtoData.FilterChain) Route(io.grpc.xds.VirtualHost.Route) Test(org.junit.Test)

Example 62 with Server

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server in project grpc-java by grpc.

the class XdsServerWrapperTest method shutdown.

@Test
public void shutdown() throws Exception {
    final SettableFuture<Server> start = SettableFuture.create();
    Executors.newSingleThreadExecutor().execute(new Runnable() {

        @Override
        public void run() {
            try {
                start.set(xdsServerWrapper.start());
            } catch (Exception ex) {
                start.setException(ex);
            }
        }
    });
    String ldsWatched = xdsClient.ldsResource.get(5, TimeUnit.SECONDS);
    assertThat(ldsWatched).isEqualTo("grpc/server?udpa.resource.listening_address=0.0.0.0:1");
    HttpConnectionManager hcm_virtual = HttpConnectionManager.forVirtualHosts(0L, Collections.singletonList(createVirtualHost("virtual-host-0")), new ArrayList<NamedFilterConfig>());
    FilterChain f0 = createFilterChain("filter-chain-0", hcm_virtual);
    FilterChain f1 = createFilterChain("filter-chain-1", createRds("rds"));
    xdsClient.deliverLdsUpdate(Collections.singletonList(f0), f1);
    xdsClient.rdsCount.await(5, TimeUnit.SECONDS);
    xdsClient.deliverRdsUpdate("rds", Collections.singletonList(createVirtualHost("virtual-host-1")));
    start.get(5000, TimeUnit.MILLISECONDS);
    verify(mockServer).start();
    xdsServerWrapper.shutdown();
    assertThat(xdsServerWrapper.isShutdown()).isTrue();
    assertThat(xdsClient.ldsResource).isNull();
    assertThat(xdsClient.shutdown).isTrue();
    verify(mockServer).shutdown();
    assertThat(f0.sslContextProviderSupplier().isShutdown()).isTrue();
    assertThat(f1.sslContextProviderSupplier().isShutdown()).isTrue();
    when(mockServer.isTerminated()).thenReturn(true);
    when(mockServer.awaitTermination(anyLong(), any(TimeUnit.class))).thenReturn(true);
    assertThat(xdsServerWrapper.awaitTermination(5, TimeUnit.SECONDS)).isTrue();
    xdsServerWrapper.awaitTermination();
    assertThat(xdsServerWrapper.isTerminated()).isTrue();
    assertThat(start.get()).isSameInstanceAs(xdsServerWrapper);
}
Also used : NamedFilterConfig(io.grpc.xds.Filter.NamedFilterConfig) Server(io.grpc.Server) FilterChain(io.grpc.xds.EnvoyServerProtoData.FilterChain) TimeUnit(java.util.concurrent.TimeUnit) TimeoutException(java.util.concurrent.TimeoutException) StatusException(io.grpc.StatusException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 63 with Server

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server in project hazelcast by hazelcast.

the class GrpcServiceTest method when_unary_distributed.

@Test
public void when_unary_distributed() throws IOException {
    // Given
    server = createServer(new GreeterServiceImpl());
    final int port = server.getPort();
    List<String> items = IntStream.range(0, ITEM_COUNT).mapToObj(Integer::toString).collect(toList());
    Pipeline p = Pipeline.create();
    BatchStageWithKey<String, String> stage = p.readFrom(TestSources.items(items)).groupingKey(i -> i);
    // When
    BatchStage<String> mapped = stage.mapUsingServiceAsync(unary(port), (service, key, item) -> {
        HelloRequest req = HelloRequest.newBuilder().setName(item).build();
        return service.call(req).thenApply(HelloReply::getMessage);
    });
    // Then
    mapped.writeTo(AssertionSinks.assertCollected(e -> {
        assertEquals("unexpected number of items received", ITEM_COUNT, e.size());
    }));
    instance().getJet().newJob(p).join();
}
Also used : AssertionSinks(com.hazelcast.jet.pipeline.test.AssertionSinks) IntStream(java.util.stream.IntStream) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) BindableService(io.grpc.BindableService) Arrays(java.util.Arrays) BeforeClass(org.junit.BeforeClass) QuickTest(com.hazelcast.test.annotation.QuickTest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BatchStage(com.hazelcast.jet.pipeline.BatchStage) StreamObserver(io.grpc.stub.StreamObserver) HelloReply(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloReply) ServerBuilder(io.grpc.ServerBuilder) After(org.junit.After) GreeterGrpc(com.hazelcast.jet.grpc.greeter.GreeterGrpc) ServiceFactory(com.hazelcast.jet.pipeline.ServiceFactory) Assert.fail(org.junit.Assert.fail) HelloRequestList(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloRequestList) Server(io.grpc.Server) ExceptionUtil(com.hazelcast.jet.impl.util.ExceptionUtil) SimpleTestInClusterSupport(com.hazelcast.jet.SimpleTestInClusterSupport) GrpcServices.unaryService(com.hazelcast.jet.grpc.GrpcServices.unaryService) Pipeline(com.hazelcast.jet.pipeline.Pipeline) HelloReplyList(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloReplyList) HelloRequest(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloRequest) Sinks(com.hazelcast.jet.pipeline.Sinks) Test(org.junit.Test) IOException(java.io.IOException) GrpcServices.bidirectionalStreamingService(com.hazelcast.jet.grpc.GrpcServices.bidirectionalStreamingService) Category(org.junit.experimental.categories.Category) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) ManagedChannelBuilder(io.grpc.ManagedChannelBuilder) TestSources(com.hazelcast.jet.pipeline.test.TestSources) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) BatchStageWithKey(com.hazelcast.jet.pipeline.BatchStageWithKey) Assert.assertEquals(org.junit.Assert.assertEquals) HelloRequest(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloRequest) HelloReply(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloReply) Pipeline(com.hazelcast.jet.pipeline.Pipeline) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 64 with Server

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server in project hazelcast by hazelcast.

the class GrpcServiceTest method whenNotAsync_bidirectionalStreaming_distributed.

@Test
public void whenNotAsync_bidirectionalStreaming_distributed() throws IOException {
    // Given
    server = createServer(new GreeterServiceImpl());
    final int port = server.getPort();
    List<String> items = IntStream.range(0, ITEM_COUNT).mapToObj(Integer::toString).collect(toList());
    Pipeline p = Pipeline.create();
    BatchStageWithKey<String, String> stage = p.readFrom(TestSources.items(items)).groupingKey(i -> i);
    // When
    BatchStage<String> mapped = stage.mapUsingService(bidirectionalStreaming(port), (service, key, item) -> {
        HelloRequest req = HelloRequest.newBuilder().setName(item).build();
        return service.call(req).thenApply(HelloReply::getMessage).get();
    });
    // Then
    mapped.writeTo(AssertionSinks.assertCollected(e -> {
        assertEquals("unexpected number of items received", ITEM_COUNT, e.size());
    }));
    instance().getJet().newJob(p).join();
}
Also used : AssertionSinks(com.hazelcast.jet.pipeline.test.AssertionSinks) IntStream(java.util.stream.IntStream) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) BindableService(io.grpc.BindableService) Arrays(java.util.Arrays) BeforeClass(org.junit.BeforeClass) QuickTest(com.hazelcast.test.annotation.QuickTest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BatchStage(com.hazelcast.jet.pipeline.BatchStage) StreamObserver(io.grpc.stub.StreamObserver) HelloReply(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloReply) ServerBuilder(io.grpc.ServerBuilder) After(org.junit.After) GreeterGrpc(com.hazelcast.jet.grpc.greeter.GreeterGrpc) ServiceFactory(com.hazelcast.jet.pipeline.ServiceFactory) Assert.fail(org.junit.Assert.fail) HelloRequestList(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloRequestList) Server(io.grpc.Server) ExceptionUtil(com.hazelcast.jet.impl.util.ExceptionUtil) SimpleTestInClusterSupport(com.hazelcast.jet.SimpleTestInClusterSupport) GrpcServices.unaryService(com.hazelcast.jet.grpc.GrpcServices.unaryService) Pipeline(com.hazelcast.jet.pipeline.Pipeline) HelloReplyList(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloReplyList) HelloRequest(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloRequest) Sinks(com.hazelcast.jet.pipeline.Sinks) Test(org.junit.Test) IOException(java.io.IOException) GrpcServices.bidirectionalStreamingService(com.hazelcast.jet.grpc.GrpcServices.bidirectionalStreamingService) Category(org.junit.experimental.categories.Category) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) ManagedChannelBuilder(io.grpc.ManagedChannelBuilder) TestSources(com.hazelcast.jet.pipeline.test.TestSources) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) BatchStageWithKey(com.hazelcast.jet.pipeline.BatchStageWithKey) Assert.assertEquals(org.junit.Assert.assertEquals) HelloRequest(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloRequest) Pipeline(com.hazelcast.jet.pipeline.Pipeline) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 65 with Server

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server in project hazelcast by hazelcast.

the class GrpcServiceTest method when_repeatedBidirectionalStreaming.

@Test
public void when_repeatedBidirectionalStreaming() throws IOException {
    // Given
    server = createServer(new GreeterServiceImpl());
    final int port = server.getPort();
    List<String> items = IntStream.range(0, ITEM_COUNT).mapToObj(Integer::toString).collect(toList());
    Pipeline p = Pipeline.create();
    BatchStage<String> stage = p.readFrom(TestSources.items(items));
    // When
    BatchStage<String> mapped = stage.mapUsingServiceAsyncBatched(repeatedBidirectionalStreaming(port), 128, (service, itemList) -> {
        HelloRequestList req = HelloRequestList.newBuilder().addAllName(itemList).build();
        return service.call(req).thenApply(HelloReplyList::getMessageList);
    });
    // Then
    List<String> expected = IntStream.range(0, ITEM_COUNT).boxed().map(t -> "Hello " + Integer.toString(t)).collect(toList());
    mapped.writeTo(AssertionSinks.assertAnyOrder(expected));
    instance().getJet().newJob(p).join();
}
Also used : AssertionSinks(com.hazelcast.jet.pipeline.test.AssertionSinks) IntStream(java.util.stream.IntStream) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) BindableService(io.grpc.BindableService) Arrays(java.util.Arrays) BeforeClass(org.junit.BeforeClass) QuickTest(com.hazelcast.test.annotation.QuickTest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BatchStage(com.hazelcast.jet.pipeline.BatchStage) StreamObserver(io.grpc.stub.StreamObserver) HelloReply(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloReply) ServerBuilder(io.grpc.ServerBuilder) After(org.junit.After) GreeterGrpc(com.hazelcast.jet.grpc.greeter.GreeterGrpc) ServiceFactory(com.hazelcast.jet.pipeline.ServiceFactory) Assert.fail(org.junit.Assert.fail) HelloRequestList(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloRequestList) Server(io.grpc.Server) ExceptionUtil(com.hazelcast.jet.impl.util.ExceptionUtil) SimpleTestInClusterSupport(com.hazelcast.jet.SimpleTestInClusterSupport) GrpcServices.unaryService(com.hazelcast.jet.grpc.GrpcServices.unaryService) Pipeline(com.hazelcast.jet.pipeline.Pipeline) HelloReplyList(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloReplyList) HelloRequest(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloRequest) Sinks(com.hazelcast.jet.pipeline.Sinks) Test(org.junit.Test) IOException(java.io.IOException) GrpcServices.bidirectionalStreamingService(com.hazelcast.jet.grpc.GrpcServices.bidirectionalStreamingService) Category(org.junit.experimental.categories.Category) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) ManagedChannelBuilder(io.grpc.ManagedChannelBuilder) TestSources(com.hazelcast.jet.pipeline.test.TestSources) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) BatchStageWithKey(com.hazelcast.jet.pipeline.BatchStageWithKey) Assert.assertEquals(org.junit.Assert.assertEquals) HelloRequestList(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloRequestList) HelloReplyList(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloReplyList) Pipeline(com.hazelcast.jet.pipeline.Pipeline) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)76 Server (io.grpc.Server)68 IOException (java.io.IOException)27 ByteString (org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString)24 ArrayList (java.util.ArrayList)21 StreamObserver (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver)21 ExecutionException (java.util.concurrent.ExecutionException)20 TimeoutException (java.util.concurrent.TimeoutException)20 CountDownLatch (java.util.concurrent.CountDownLatch)19 ManagedChannel (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel)19 Server (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server)18 StatusException (io.grpc.StatusException)17 Metadata (io.grpc.Metadata)12 List (java.util.List)12 BeamFnApi (org.apache.beam.model.fnexecution.v1.BeamFnApi)12 FilterChain (io.grpc.xds.EnvoyServerProtoData.FilterChain)11 ExecutorService (java.util.concurrent.ExecutorService)11 ParallelInstruction (com.google.api.services.dataflow.model.ParallelInstruction)10 ServerCall (io.grpc.ServerCall)10 StreamObserver (io.grpc.stub.StreamObserver)10