@Bean public GrpcServerFactory factory() { return new SimpleGrpcServerFactory() { @Override public Server buildServerForServices(int port, Collection<BindableService> services) { System.out.println("Building an IN-PROC service for " + services.size() + " services"); ServerBuilder builder = InProcessServerBuilder.forName(SERVER_NAME); services.forEach(builder::addService); return builder.build(); } @Override public List<Class<? extends Annotation>> forAnnotations() { return ImmutableList.of(InProcessGrpcService.class); } }; }
@Before public void setUp() throws IOException { MockitoAnnotations.initMocks(this); String mockProfile[] = {"other", "test"}; JHipsterProperties.Ribbon ribbon = new JHipsterProperties.Ribbon(); ribbon.setDisplayOnActiveProfiles(mockProfile); when(jHipsterProperties.getRibbon()).thenReturn(ribbon); String activeProfiles[] = {"test"}; when(environment.getDefaultProfiles()).thenReturn(activeProfiles); when(environment.getActiveProfiles()).thenReturn(activeProfiles); ProfileInfoService service = new ProfileInfoService(jHipsterProperties, environment); String uniqueServerName = "Mock server for " + ProfileInfoService.class; mockServer = InProcessServerBuilder .forName(uniqueServerName).directExecutor().addService(service).build().start(); InProcessChannelBuilder channelBuilder = InProcessChannelBuilder.forName(uniqueServerName).directExecutor(); stub = ProfileInfoServiceGrpc.newBlockingStub(channelBuilder.build()); }
@Before public final void setUp() throws Exception { // Use a mutable service registry for later registering the service impl for each test case. fakeServer = InProcessServerBuilder.forName(fakeServerName) .fallbackHandlerRegistry(serviceRegistry) .directExecutor() .build() .start(); Chunker.setDefaultChunkSizeForTesting(1000); // Enough for everything to be one chunk. fs = new InMemoryFileSystem(new JavaClock(), HashFunction.SHA256); execRoot = fs.getPath("/exec/root"); FileSystemUtils.createDirectoryAndParents(execRoot); fakeFileCache = new FakeActionInputFileCache(execRoot); Path stdout = fs.getPath("/tmp/stdout"); Path stderr = fs.getPath("/tmp/stderr"); FileSystemUtils.createDirectoryAndParents(stdout.getParentDirectory()); FileSystemUtils.createDirectoryAndParents(stderr.getParentDirectory()); outErr = new FileOutErr(stdout, stderr); Context withEmptyMetadata = TracingMetadataUtils.contextWithMetadata( "none", "none", DIGEST_UTIL.asActionKey(Digest.getDefaultInstance())); withEmptyMetadata.attach(); }
/** * Before the test has started, create the server and channel. */ @Override protected void before() throws Throwable { serverName = UUID.randomUUID().toString(); serviceRegistry = new MutableHandlerRegistry(); InProcessServerBuilder serverBuilder = InProcessServerBuilder.forName(serverName) .fallbackHandlerRegistry(serviceRegistry); if (useDirectExecutor) { serverBuilder.directExecutor(); } server = serverBuilder.build().start(); InProcessChannelBuilder channelBuilder = InProcessChannelBuilder.forName(serverName); if (useDirectExecutor) { channelBuilder.directExecutor(); } channel = channelBuilder.build(); }
public void startServer() throws Exception { server = InProcessServerBuilder .forName("GradleProof") .addService(this) .build() .start(); }
@Test public void uniqueSessionIdPerChannel() throws Exception { GreeterGrpc.GreeterImplBase svc = new GreeterGrpc.GreeterImplBase() { @Override public void sayHello(HelloRequest request, StreamObserver<HelloResponse> responseObserver) { responseObserver.onNext(HelloResponse.newBuilder().setMessage(SessionIdServerInterceptor.SESSION_ID.get().toString()).build()); responseObserver.onCompleted(); } }; Server server = InProcessServerBuilder.forName("uniqueSessionIdPerChannel") .addTransportFilter(new ClientSessionTransportFilter()) .intercept(new SessionIdServerInterceptor()) .addService(svc) .build() .start(); ManagedChannel channel1 = InProcessChannelBuilder.forName("uniqueSessionIdPerChannel") .usePlaintext(true) .build(); GreeterGrpc.GreeterBlockingStub stub1 = GreeterGrpc.newBlockingStub(channel1); ManagedChannel channel2 = InProcessChannelBuilder.forName("uniqueSessionIdPerChannel") .usePlaintext(true) .build(); GreeterGrpc.GreeterBlockingStub stub2 = GreeterGrpc.newBlockingStub(channel2); try { String sessionId1 = stub1.sayHello(HelloRequest.getDefaultInstance()).getMessage(); String sessionId2 = stub2.sayHello(HelloRequest.getDefaultInstance()).getMessage(); assertThat(sessionId1).isNotEqualTo(sessionId2); } finally { channel1.shutdown(); channel2.shutdown(); server.shutdown(); } }
@Test public void interceptorThrowsIfMissingTransportFilter() throws Exception { GreeterGrpc.GreeterImplBase svc = new GreeterGrpc.GreeterImplBase() { @Override public void sayHello(HelloRequest request, StreamObserver<HelloResponse> responseObserver) { responseObserver.onNext(HelloResponse.newBuilder().setMessage(SessionIdServerInterceptor.SESSION_ID.get().toString()).build()); responseObserver.onCompleted(); } }; Server server = InProcessServerBuilder.forName("interceptorThrowsIfMissingTransportFilter") .intercept(new SessionIdServerInterceptor()) .addService(svc) .build() .start(); ManagedChannel channel = InProcessChannelBuilder.forName("interceptorThrowsIfMissingTransportFilter") .usePlaintext(true) .build(); GreeterGrpc.GreeterBlockingStub stub = GreeterGrpc.newBlockingStub(channel); try { assertThatThrownBy(() -> stub.sayHello(HelloRequest.getDefaultInstance()).getMessage()).isInstanceOf(StatusRuntimeException.class); } finally { channel.shutdown(); server.shutdown(); } }
@Test public void perSessionShouldFailMissingTransportFilter() throws Exception { class TestService extends GreeterGrpc.GreeterImplBase { @Override public void sayHello(HelloRequest request, StreamObserver<HelloResponse> responseObserver) { responseObserver.onNext(HelloResponse.newBuilder().setMessage(Integer.toString(System.identityHashCode(this))).build()); responseObserver.onCompleted(); } } ClientSessionTransportFilter tf = new ClientSessionTransportFilter(); Server server = InProcessServerBuilder.forName("perSessionShouldInstantiateOneInstancePerSession") .addService(new PerSessionService<>(() -> new TestService(), tf)) .build() .start(); ManagedChannel channel = InProcessChannelBuilder.forName("perSessionShouldInstantiateOneInstancePerSession") .usePlaintext(true) .build(); GreeterGrpc.GreeterBlockingStub stub = GreeterGrpc.newBlockingStub(channel); try { assertThatThrownBy(() -> stub.sayHello(HelloRequest.getDefaultInstance()).getMessage()).isInstanceOf(StatusRuntimeException.class); } finally { channel.shutdown(); server.shutdown(); } }
@Before public void setUp() throws Exception { String uniqueServerName = "in-process server for " + getClass(); memoryInstanceConfig = MemoryInstanceConfig.newBuilder() .setListOperationsDefaultPageSize(1024) .setListOperationsMaxPageSize(16384) .setTreeDefaultPageSize(1024) .setTreeMaxPageSize(16384) .setOperationPollTimeout(Duration.newBuilder() .setSeconds(10) .setNanos(0)) .setOperationCompletedDelay(Duration.newBuilder() .setSeconds(10) .setNanos(0)) .build(); BuildFarmServerConfig.Builder configBuilder = BuildFarmServerConfig.newBuilder().setPort(0); configBuilder.addInstancesBuilder() .setName("memory") .setMemoryInstanceConfig(memoryInstanceConfig); server = new BuildFarmServer( InProcessServerBuilder.forName(uniqueServerName).directExecutor(), configBuilder.build()); server.start(); inProcessChannel = InProcessChannelBuilder.forName(uniqueServerName) .directExecutor().build(); }
@Before public void setUp() throws IOException { JWTService service = new JWTService(tokenProvider, authenticationManager); String uniqueServerName = "Mock server for " + JWTService.class; mockServer = InProcessServerBuilder .forName(uniqueServerName).directExecutor().addService(service).build().start(); InProcessChannelBuilder channelBuilder = InProcessChannelBuilder.forName(uniqueServerName).directExecutor(); stub = JWTServiceGrpc.newBlockingStub(channelBuilder.build()); }
@Before public void setUp() throws IOException { MetricService service = new MetricService(publicMetrics); String uniqueServerName = "Mock server for " + MetricService.class; mockServer = InProcessServerBuilder .forName(uniqueServerName).directExecutor().addService(service).build().start(); InProcessChannelBuilder channelBuilder = InProcessChannelBuilder.forName(uniqueServerName).directExecutor(); stub = MetricServiceGrpc.newBlockingStub(channelBuilder.build()); }
@Before public void setUp() throws IOException { ConfigurationPropertiesReportService service = new ConfigurationPropertiesReportService(configurationPropertiesReportEndpoint); String uniqueServerName = "Mock server for " + ConfigurationPropertiesReportService.class; mockServer = InProcessServerBuilder .forName(uniqueServerName).directExecutor().addService(service).build().start(); InProcessChannelBuilder channelBuilder = InProcessChannelBuilder.forName(uniqueServerName).directExecutor(); stub = ConfigurationPropertiesReportServiceGrpc.newBlockingStub(channelBuilder.build()); }
@Before public void setUp() throws IOException { LoggersService service = new LoggersService(loggingSystem); String uniqueServerName = "Mock server for " + LoggersService.class; mockServer = InProcessServerBuilder .forName(uniqueServerName).directExecutor().addService(service).build().start(); InProcessChannelBuilder channelBuilder = InProcessChannelBuilder.forName(uniqueServerName).directExecutor(); stub = LoggersServiceGrpc.newBlockingStub(channelBuilder.build()); }
@Before public void setUp() throws IOException { EnvironmentService service = new EnvironmentService(endpoint); String uniqueServerName = "Mock server for " + EnvironmentService.class; mockServer = InProcessServerBuilder .forName(uniqueServerName).directExecutor().addService(service).build().start(); InProcessChannelBuilder channelBuilder = InProcessChannelBuilder.forName(uniqueServerName).directExecutor(); stub = EnvironmentServiceGrpc.newBlockingStub(channelBuilder.build()); }
@Before public void setUp() throws IOException { HealthService service = new HealthService(healthAggregator, healthIndicators); String uniqueServerName = "Mock server for " + HealthService.class; mockServer = InProcessServerBuilder .forName(uniqueServerName).directExecutor().addService(service).build().start(); InProcessChannelBuilder channelBuilder = InProcessChannelBuilder.forName(uniqueServerName).directExecutor(); stub = HealthServiceGrpc.newBlockingStub(channelBuilder.build()); }
@Before public void setUp() throws IOException { AuditEventService auditEventService = new AuditEventService(auditEventRepository, auditEventConverter); AuditGrpcService service = new AuditGrpcService(auditEventService); String uniqueServerName = "Mock server for " + AuditGrpcService.class; mockServer = InProcessServerBuilder .forName(uniqueServerName).directExecutor().addService(service).build().start(); InProcessChannelBuilder channelBuilder = InProcessChannelBuilder.forName(uniqueServerName).directExecutor(); stub = AuditServiceGrpc.newBlockingStub(channelBuilder.build()); }
@Bean @ConditionalOnExpression("#{environment.getProperty('grpc.inProcessServerName','')!=''}") public GRpcServerRunner grpcInprocessServerRunner(GRpcServerBuilderConfigurer configurer){ return new GRpcServerRunner(configurer, InProcessServerBuilder.forName(grpcServerProperties.getInProcessServerName())); }
@Before public void setUp() throws Exception { values = new LinkedBlockingQueue<>(); outboundServerObservers = new LinkedBlockingQueue<>(); CallStreamObserver<StateRequest> inboundServerObserver = TestStreams.withOnNext(values::add).build(); apiServiceDescriptor = Endpoints.ApiServiceDescriptor.newBuilder() .setUrl(this.getClass().getName() + "-" + UUID.randomUUID().toString()) .build(); testServer = InProcessServerBuilder.forName(apiServiceDescriptor.getUrl()) .addService(new BeamFnStateGrpc.BeamFnStateImplBase() { @Override public StreamObserver<StateRequest> state( StreamObserver<StateResponse> outboundObserver) { Uninterruptibles.putUninterruptibly(outboundServerObservers, outboundObserver); return inboundServerObserver; } }) .build(); testServer.start(); testChannel = InProcessChannelBuilder.forName(apiServiceDescriptor.getUrl()).build(); clientCache = new BeamFnStateGrpcClientCache( PipelineOptionsFactory.create(), IdGenerator::generate, (Endpoints.ApiServiceDescriptor descriptor) -> testChannel, this::createStreamForTest); }
@Before public void setup() throws IOException { stager = ArtifactServiceStager.overChannel( InProcessChannelBuilder.forName("service_stager").build(), 6); service = new InMemoryArtifactStagerService(); server = InProcessServerBuilder.forName("service_stager") .directExecutor() .addService(service) .build() .start(); }
@Before public void setup() throws Exception { stager = LocalFileSystemArtifactStagerService.withRootDirectory(temporaryFolder.newFolder()); server = InProcessServerBuilder.forName("fs_stager") .directExecutor() .addService(stager) .build() .start(); stub = ArtifactStagingServiceGrpc.newStub( InProcessChannelBuilder.forName("fs_stager").usePlaintext(true).build()); }
@Override public Server allocatePortAndCreate(BindableService service, ApiServiceDescriptor.Builder builder) throws IOException { String name = String.format("InProcessServer_%s", serviceNameUniqifier.getAndIncrement()); builder.setUrl(name); return InProcessServerBuilder.forName(name).addService(service).build().start(); }
@Override public Server create(BindableService service, ApiServiceDescriptor serviceDescriptor) throws IOException { return InProcessServerBuilder.forName(serviceDescriptor.getUrl()) .addService(service) .build() .start(); }
@Before public final void setUp() throws Exception { MockitoAnnotations.initMocks(this); String serverName = "Server for " + this.getClass(); server = InProcessServerBuilder.forName(serverName).fallbackHandlerRegistry(serviceRegistry) .build().start(); channel = InProcessChannelBuilder.forName(serverName).build(); withEmptyMetadata = TracingMetadataUtils.contextWithMetadata( "none", "none", DIGEST_UTIL.asActionKey(Digest.getDefaultInstance())); // Needs to be repeated in every test that uses the timeout setting, since the tests run // on different threads than the setUp. withEmptyMetadata.attach(); }
/** * Starts the in-process server configured to inject one fault at the specified target site. * * @param targetSite */ public void startServer(InjectionSite targetSite) { try { server = InProcessServerBuilder.forName(testName.getMethodName()) .addService(new ReadUnitServerImpl(targetSite)) .addService(new VariantUnitServerImpl(targetSite)) .build() .start(); } catch (IOException ex) { throw new RuntimeException(ex); } }
/** * Starts the in-process server. */ @BeforeClass public static void startServer() { try { server = InProcessServerBuilder.forName(SERVER_NAME) .addService(new ReadsUnitServerImpl()) .addService(new VariantsUnitServerImpl()) .build().start(); } catch (IOException ex) { throw new RuntimeException(ex); } }
/** * Starts the in-process server that calls the real service. * * @throws GeneralSecurityException * @throws IOException */ @BeforeClass public static void startServer() throws IOException, GeneralSecurityException { try { server = InProcessServerBuilder.forName(SERVER_NAME) .addService(new VariantsIntegrationServerImpl()) .build().start(); } catch (IOException ex) { throw new RuntimeException(ex); } genomicsChannel = GenomicsChannel.fromOfflineAuth(IntegrationTestHelper.getAuthFromApplicationDefaultCredential()); }
@BeforeClass public static void globalSetup() throws IOException { AbstractServerImplBuilder builder = InProcessServerBuilder .forName(GRPC_SERVER_NAME).directExecutor(); builder.addService(p4RuntimeServerImpl); grpcServer = builder.build().start(); grpcChannel = InProcessChannelBuilder.forName(GRPC_SERVER_NAME) .directExecutor() .usePlaintext(true) .build(); }
public void start() throws IOException, InstantiationException, IllegalAccessException { AbstractServerImplBuilder builder = InProcessServerBuilder.forName("test").directExecutor(); services.forEach(service -> builder.addService(service)); server = builder.build().start(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { // Use stderr here since the logger may have been reset by its JVM shutdown hook. System.err.println("*** shutting down gRPC server since JVM is shutting down"); InProcessServer.this.stop(); System.err.println("*** server shut down"); } }); }
@Before public void setUp() throws Exception { String uniqueServerName = "in-process server for " + getClass(); features = new ArrayList<Feature>(); // use directExecutor for both InProcessServerBuilder and InProcessChannelBuilder can reduce the // usage timeouts and latches in test. But we still add timeout and latches where they would be // needed if no directExecutor were used, just for demo purpose. server = new RouteGuideServer( InProcessServerBuilder.forName(uniqueServerName).directExecutor(), 0, features); server.start(); inProcessChannel = InProcessChannelBuilder.forName(uniqueServerName).directExecutor().build(); }
@Before public void setUp() throws Exception { String uniqueServerName = "fake server for " + getClass(); // use a mutable service registry for later registering the service impl for each test case. fakeServer = InProcessServerBuilder.forName(uniqueServerName) .fallbackHandlerRegistry(serviceRegistry).directExecutor().build().start(); client = new RouteGuideClient(InProcessChannelBuilder.forName(uniqueServerName).directExecutor()); client.setTestHelper(testHelper); }
@Test public void testDeadlinePropagation() throws Exception { final AtomicInteger recursionDepthRemaining = new AtomicInteger(3); final SettableFuture<Deadline> finalDeadline = SettableFuture.create(); class DeadlineSaver extends TestServiceGrpc.TestServiceImplBase { @Override public void unaryCall(final SimpleRequest request, final StreamObserver<SimpleResponse> responseObserver) { Context.currentContextExecutor(otherWork).execute(new Runnable() { @Override public void run() { try { if (recursionDepthRemaining.decrementAndGet() == 0) { finalDeadline.set(Context.current().getDeadline()); responseObserver.onNext(SimpleResponse.getDefaultInstance()); } else { responseObserver.onNext(blockingStub.unaryCall(request)); } responseObserver.onCompleted(); } catch (Exception ex) { responseObserver.onError(ex); } } }); } } server = InProcessServerBuilder.forName("channel").executor(otherWork) .addService(new DeadlineSaver()) .build().start(); Deadline initialDeadline = Deadline.after(1, TimeUnit.MINUTES); blockingStub.withDeadline(initialDeadline).unaryCall(SimpleRequest.getDefaultInstance()); assertNotSame(initialDeadline, finalDeadline); // Since deadline is re-calculated at each hop, some variance is acceptable and expected. assertAbout(deadline()) .that(finalDeadline.get()).isWithin(1, TimeUnit.SECONDS).of(initialDeadline); }
@Before public void setUp() throws Exception { reflectionService = ProtoReflectionService.newInstance(); server = InProcessServerBuilder.forName("proto-reflection-test") .directExecutor() .addService(reflectionService) .addService(new ReflectableServiceGrpc.ReflectableServiceImplBase() {}) .fallbackHandlerRegistry(handlerRegistry) .build() .start(); channel = InProcessChannelBuilder.forName("proto-reflection-test").directExecutor().build(); stub = ServerReflectionGrpc.newStub(channel); }
@BeforeClass public static void setup() throws Exception { System.out.println("RxGrpcPublisherOneToManyVerificationTest"); server = InProcessServerBuilder.forName("RxGrpcPublisherOneToManyVerificationTest").addService(new TckService()).build().start(); channel = InProcessChannelBuilder.forName("RxGrpcPublisherOneToManyVerificationTest").usePlaintext(true).build(); }
@BeforeClass public static void setup() throws Exception { System.out.println("RxGrpcPublisherManyToOneVerificationTest"); server = InProcessServerBuilder.forName("RxGrpcPublisherManyToOneVerificationTest").addService(new TckService()).build().start(); channel = InProcessChannelBuilder.forName("RxGrpcPublisherManyToOneVerificationTest").usePlaintext(true).build(); }
@BeforeClass public static void setup() throws Exception { System.out.println("RxGrpcPublisherOneToOneVerificationTest"); server = InProcessServerBuilder.forName("RxGrpcPublisherOneToOneVerificationTest").addService(new TckService()).build().start(); channel = InProcessChannelBuilder.forName("RxGrpcPublisherOneToOneVerificationTest").usePlaintext(true).build(); }
@BeforeClass public static void setup() throws Exception { System.out.println("RxGrpcPublisherManyToManyVerificationTest"); server = InProcessServerBuilder.forName("RxGrpcPublisherManyToManyVerificationTest").addService(new TckService()).build().start(); channel = InProcessChannelBuilder.forName("RxGrpcPublisherManyToManyVerificationTest").usePlaintext(true).build(); }
@BeforeClass public static void setup() throws Exception { System.out.println("ReactorGrpcPublisherManyToOneVerificationTest"); server = InProcessServerBuilder.forName("ReactorGrpcPublisherManyToOneVerificationTest").addService(new TckService()).build().start(); channel = InProcessChannelBuilder.forName("ReactorGrpcPublisherManyToOneVerificationTest").usePlaintext(true).build(); }
@BeforeClass public static void setup() throws Exception { System.out.println("ReactorGrpcPublisherManyToManyVerificationTest"); server = InProcessServerBuilder.forName("ReactorGrpcPublisherManyToManyVerificationTest").addService(new TckService()).build().start(); channel = InProcessChannelBuilder.forName("ReactorGrpcPublisherManyToManyVerificationTest").usePlaintext(true).build(); }
@BeforeClass public static void setup() throws Exception { System.out.println("ReactorGrpcPublisherOneToOneVerificationTest"); server = InProcessServerBuilder.forName("ReactorGrpcPublisherOneToOneVerificationTest").addService(new TckService()).build().start(); channel = InProcessChannelBuilder.forName("ReactorGrpcPublisherOneToOneVerificationTest").usePlaintext(true).build(); }
@BeforeClass public static void setup() throws Exception { System.out.println("ReactorGrpcPublisherOneToManyVerificationTest"); server = InProcessServerBuilder.forName("ReactorGrpcPublisherOneToManyVerificationTest").addService(new TckService()).build().start(); channel = InProcessChannelBuilder.forName("ReactorGrpcPublisherOneToManyVerificationTest").usePlaintext(true).build(); }