use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project vertx-examples by vert-x3.
the class Client method start.
@Override
public void start() throws Exception {
ManagedChannel channel = VertxChannelBuilder.forAddress(vertx, "localhost", 8080).usePlaintext(true).build();
GreeterGrpc.GreeterVertxStub stub = GreeterGrpc.newVertxStub(channel);
HelloRequest request = HelloRequest.newBuilder().setName("Julien").build();
stub.sayHello(request, asyncResponse -> {
if (asyncResponse.succeeded()) {
System.out.println("Succeeded " + asyncResponse.result().getMessage());
} else {
asyncResponse.cause().printStackTrace();
}
});
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project grpc-java by grpc.
the class GrpclbLoadBalancerTest method switchPolicy.
@SuppressWarnings("unchecked")
@Test
public void switchPolicy() {
// Go to GRPCLB first
List<ResolvedServerInfoGroup> grpclbResolutionList = createResolvedServerInfoGroupList(true, false, true);
Attributes grpclbResolutionAttrs = Attributes.newBuilder().set(GrpclbConstants.ATTR_LB_POLICY, LbPolicy.GRPCLB).build();
deliverResolvedAddresses(grpclbResolutionList, grpclbResolutionAttrs);
assertSame(LbPolicy.GRPCLB, balancer.getLbPolicy());
assertNull(balancer.getDelegate());
verify(helper).createOobChannel(eq(grpclbResolutionList.get(0).toEquivalentAddressGroup()), eq(lbAuthority(0)));
assertEquals(1, fakeOobChannels.size());
ManagedChannel oobChannel = fakeOobChannels.poll();
verify(mockLbService).balanceLoad(lbResponseObserverCaptor.capture());
// Switch to PICK_FIRST
List<ResolvedServerInfoGroup> pickFirstResolutionList = createResolvedServerInfoGroupList(true, false, true);
Attributes pickFirstResolutionAttrs = Attributes.newBuilder().set(GrpclbConstants.ATTR_LB_POLICY, LbPolicy.PICK_FIRST).build();
verify(pickFirstBalancerFactory, never()).newLoadBalancer(any(Helper.class));
assertEquals(1, lbRequestObservers.size());
StreamObserver<LoadBalanceRequest> lbRequestObserver = lbRequestObservers.poll();
verify(lbRequestObserver, never()).onCompleted();
assertFalse(oobChannel.isShutdown());
deliverResolvedAddresses(pickFirstResolutionList, pickFirstResolutionAttrs);
verify(pickFirstBalancerFactory).newLoadBalancer(same(helper));
// Only non-LB addresses are passed to the delegate
verify(pickFirstBalancer).handleResolvedAddresses(eq(Arrays.asList(pickFirstResolutionList.get(1))), same(pickFirstResolutionAttrs));
assertSame(LbPolicy.PICK_FIRST, balancer.getLbPolicy());
assertSame(pickFirstBalancer, balancer.getDelegate());
// GRPCLB connection is closed
verify(lbRequestObserver).onCompleted();
assertTrue(oobChannel.isShutdown());
// Switch to ROUND_ROBIN
List<ResolvedServerInfoGroup> roundRobinResolutionList = createResolvedServerInfoGroupList(true, false, false);
Attributes roundRobinResolutionAttrs = Attributes.newBuilder().set(GrpclbConstants.ATTR_LB_POLICY, LbPolicy.ROUND_ROBIN).build();
verify(roundRobinBalancerFactory, never()).newLoadBalancer(any(Helper.class));
deliverResolvedAddresses(roundRobinResolutionList, roundRobinResolutionAttrs);
verify(roundRobinBalancerFactory).newLoadBalancer(same(helper));
// Only non-LB addresses are passed to the delegate
verify(roundRobinBalancer).handleResolvedAddresses(eq(roundRobinResolutionList.subList(1, 3)), same(roundRobinResolutionAttrs));
assertSame(LbPolicy.ROUND_ROBIN, balancer.getLbPolicy());
assertSame(roundRobinBalancer, balancer.getDelegate());
// Special case: if all addresses are loadbalancers, use GRPCLB no matter what the NameResolver
// says.
grpclbResolutionList = createResolvedServerInfoGroupList(true, true, true);
grpclbResolutionAttrs = Attributes.newBuilder().set(GrpclbConstants.ATTR_LB_POLICY, LbPolicy.PICK_FIRST).build();
deliverResolvedAddresses(grpclbResolutionList, grpclbResolutionAttrs);
assertSame(LbPolicy.GRPCLB, balancer.getLbPolicy());
assertNull(balancer.getDelegate());
verify(helper, times(2)).createOobChannel(eq(grpclbResolutionList.get(0).toEquivalentAddressGroup()), eq(lbAuthority(0)));
verify(helper, times(2)).createOobChannel(any(EquivalentAddressGroup.class), any(String.class));
assertEquals(1, fakeOobChannels.size());
oobChannel = fakeOobChannels.poll();
verify(mockLbService, times(2)).balanceLoad(lbResponseObserverCaptor.capture());
// Special case: PICK_FIRST is the default
pickFirstResolutionList = createResolvedServerInfoGroupList(true, false, false);
pickFirstResolutionAttrs = Attributes.EMPTY;
verify(pickFirstBalancerFactory).newLoadBalancer(any(Helper.class));
assertFalse(oobChannel.isShutdown());
deliverResolvedAddresses(pickFirstResolutionList, pickFirstResolutionAttrs);
verify(pickFirstBalancerFactory, times(2)).newLoadBalancer(same(helper));
// Only non-LB addresses are passed to the delegate
verify(pickFirstBalancer).handleResolvedAddresses(eq(pickFirstResolutionList.subList(1, 3)), same(pickFirstResolutionAttrs));
assertSame(LbPolicy.PICK_FIRST, balancer.getLbPolicy());
assertSame(pickFirstBalancer, balancer.getDelegate());
// GRPCLB connection is closed
assertTrue(oobChannel.isShutdown());
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project beam by apache.
the class ManagedChannelFactoryTest method testDefaultChannel.
@Test
public void testDefaultChannel() {
ApiServiceDescriptor apiServiceDescriptor = ApiServiceDescriptor.newBuilder().setUrl("localhost:123").build();
ManagedChannel channel = ManagedChannelFactory.from(PipelineOptionsFactory.create()).forDescriptor(apiServiceDescriptor);
assertEquals("localhost:123", channel.authority());
channel.shutdownNow();
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project beam by apache.
the class ManagedChannelFactoryTest method testEpollDomainSocketChannel.
@Test
public void testEpollDomainSocketChannel() throws Exception {
assumeTrue(io.netty.channel.epoll.Epoll.isAvailable());
ApiServiceDescriptor apiServiceDescriptor = ApiServiceDescriptor.newBuilder().setUrl("unix://" + tmpFolder.newFile().getAbsolutePath()).build();
ManagedChannel channel = ManagedChannelFactory.from(PipelineOptionsFactory.fromArgs(new String[] { "--experiments=beam_fn_api_epoll" }).create()).forDescriptor(apiServiceDescriptor);
assertEquals(apiServiceDescriptor.getUrl().substring("unix://".length()), channel.authority());
channel.shutdownNow();
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project nifi by apache.
the class ITListenGRPC method testSecureOneWaySSL.
@Test
public void testSecureOneWaySSL() throws UnrecoverableKeyException, CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, InterruptedException {
final int randPort = TestGRPCClient.randomPort();
final Map<String, String> sslProperties = getTruststoreProperties();
final ManagedChannel channel = TestGRPCClient.buildChannel(HOST, randPort, sslProperties);
final FlowFileServiceGrpc.FlowFileServiceBlockingStub stub = FlowFileServiceGrpc.newBlockingStub(channel);
final ListenGRPC listenGRPC = new ListenGRPC();
final TestRunner runner = TestRunners.newTestRunner(listenGRPC);
runner.setProperty(ListenGRPC.PROP_SERVICE_PORT, String.valueOf(randPort));
runner.setProperty(ListenGRPC.PROP_USE_SECURE, "true");
useSSLContextService(runner, getKeystoreProperties());
final ProcessContext processContext = runner.getProcessContext();
final ProcessSessionFactory processSessionFactory = runner.getProcessSessionFactory();
try {
// start the server. The order of the following statements shouldn't matter, because the
// startServer() method waits for a processSessionFactory to be available to it.
listenGRPC.startServer(processContext);
listenGRPC.onTrigger(processContext, processSessionFactory);
final FlowFileRequest ingestFile = FlowFileRequest.newBuilder().putAttributes("FOO", "BAR").setContent(ByteString.copyFrom("content".getBytes())).build();
final FlowFileReply reply = stub.send(ingestFile);
assertThat(reply.getResponseCode(), equalTo(FlowFileReply.ResponseCode.SUCCESS));
assertThat(reply.getBody(), equalTo("FlowFile successfully received."));
// known race condition spot: grpc reply vs flowfile transfer
Thread.sleep(10);
runner.assertTransferCount(ListenGRPC.REL_SUCCESS, 1);
final List<MockFlowFile> successFiles = runner.getFlowFilesForRelationship(ListenGRPC.REL_SUCCESS);
assertThat(successFiles.size(), equalTo(1));
final MockFlowFile mockFlowFile = successFiles.get(0);
assertThat(mockFlowFile.getAttribute("FOO"), equalTo("BAR"));
assertThat(mockFlowFile.getAttribute(ListenGRPC.REMOTE_HOST), equalTo("127.0.0.1"));
assertThat(mockFlowFile.getAttribute(ListenGRPC.REMOTE_USER_DN), equalTo(FlowFileIngestServiceInterceptor.DEFAULT_FOUND_SUBJECT));
} finally {
// stop the server
listenGRPC.stopServer(processContext);
channel.shutdown();
}
}
Aggregations