本文整理汇总了Java中io.grpc.inprocess.InProcessChannelBuilder类的典型用法代码示例。如果您正苦于以下问题:Java InProcessChannelBuilder类的具体用法?Java InProcessChannelBuilder怎么用?Java InProcessChannelBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InProcessChannelBuilder类属于io.grpc.inprocess包,在下文中一共展示了InProcessChannelBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: AbstractStubFeaturesShouldPropagate
import io.grpc.inprocess.InProcessChannelBuilder; //导入依赖的package包/类
@Test
public void AbstractStubFeaturesShouldPropagate() throws Exception {
com.google.common.base.Preconditions.checkArgument(true);
Channel channel = InProcessChannelBuilder.forName("ignore").build();
com.salesforce.jprotoc.GreeterGrpc8.GreeterCompletableFutureStub stub = com.salesforce.jprotoc.GreeterGrpc8
.newCompletableFutureStub(channel)
.withCompression("bz2")
.withMaxInboundMessageSize(42);
Field innerStubField = com.salesforce.jprotoc.GreeterGrpc8.GreeterCompletableFutureStub.class.getDeclaredField("innerStub");
innerStubField.setAccessible(true);
com.salesforce.jprotoc.GreeterGrpc.GreeterFutureStub innerStub = (com.salesforce.jprotoc.GreeterGrpc.GreeterFutureStub) innerStubField.get(stub);
assertEquals("bz2", stub.getCallOptions().getCompressor());
assertEquals(new Integer(42), stub.getCallOptions().getMaxInboundMessageSize());
assertEquals("bz2", innerStub.getCallOptions().getCompressor());
assertEquals(new Integer(42), innerStub.getCallOptions().getMaxInboundMessageSize());
assertEquals(stub.getCallOptions().toString(), innerStub.getCallOptions().toString());
}
示例2: setUp
import io.grpc.inprocess.InProcessChannelBuilder; //导入依赖的package包/类
@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());
}
示例3: setup
import io.grpc.inprocess.InProcessChannelBuilder; //导入依赖的package包/类
@Before
public void setup() throws Exception {
service =
ReferenceRunnerJobService.create(serverFactory)
.withStagingPathSupplier(
new Callable<Path>() {
@Override
public Path call() throws Exception {
return runnerTemp.getRoot().toPath();
}
});
server = GrpcFnServer.allocatePortAndCreateFor(service, serverFactory);
stub =
JobServiceGrpc.newBlockingStub(
InProcessChannelBuilder.forName(server.getApiServiceDescriptor().getUrl()).build());
}
示例4: testPrepareJob
import io.grpc.inprocess.InProcessChannelBuilder; //导入依赖的package包/类
@Test
public void testPrepareJob() throws Exception {
PrepareJobResponse response =
stub.prepare(
PrepareJobRequest.newBuilder()
.setPipelineOptions(Struct.getDefaultInstance())
.setPipeline(Pipeline.getDefaultInstance())
.setJobName("myJobName")
.build());
ApiServiceDescriptor stagingEndpoint = response.getArtifactStagingEndpoint();
ArtifactServiceStager stager =
ArtifactServiceStager.overChannel(
InProcessChannelBuilder.forName(stagingEndpoint.getUrl()).build());
File foo = writeTempFile("foo", "foo, bar, baz".getBytes());
File bar = writeTempFile("spam", "spam, ham, eggs".getBytes());
stager.stage(ImmutableList.<File>of(foo, bar));
List<byte[]> tempDirFiles = readFlattendFiles(runnerTemp.getRoot());
assertThat(
tempDirFiles,
hasItems(
arrayEquals(Files.readAllBytes(foo.toPath())),
arrayEquals(Files.readAllBytes(bar.toPath()))));
// TODO: 'run' the job with some sort of noop backend, to verify state is cleaned up.
}
示例5: setUp
import io.grpc.inprocess.InProcessChannelBuilder; //导入依赖的package包/类
/**
* Initializes the test environment.
*/
@Before
public void setUp() throws IllegalAccessException, IOException, InstantiationException {
GrpcNbMastershipService grpcMastershipService = new GrpcNbMastershipService();
grpcMastershipService.mastershipService = mastershipService;
inprocessServer = grpcMastershipService.registerInProcessServer();
inprocessServer.start();
channel = InProcessChannelBuilder.forName("test").directExecutor()
.usePlaintext(true).build();
blockingStub = MastershipServiceGrpc.newBlockingStub(channel);
initMastershipMap();
initNodeIdMap();
initRoleInfoMap();
}
示例6: setup
import io.grpc.inprocess.InProcessChannelBuilder; //导入依赖的package包/类
/**
* Create inProcessServer and bind grpcNbMeterService.
*
* @throws IllegalAccessException
* @throws IOException
* @throws InstantiationException
*/
@BeforeClass
public static void setup() throws IllegalAccessException, IOException, InstantiationException {
GrpcNbMeterService grpcNbMeterService = new GrpcNbMeterService();
grpcNbMeterService.meterService = MOCK_METER;
inProcessServer = new InProcessServer(GrpcNbMeterService.class);
inProcessServer.addServiceToBind(grpcNbMeterService);
inProcessServer.start();
channel = InProcessChannelBuilder.forName("test").directExecutor()
// Channels are secure by default (via SSL/TLS). For the example we disable TLS to avoid
// needing certificates.
.usePlaintext(true).build();
blockingStub = MeterServiceGrpc.newBlockingStub(channel);
allMeters.add(METER_2);
allMeters.add(METER_3);
allMeters.add(METER_4);
}
示例7: before
import io.grpc.inprocess.InProcessChannelBuilder; //导入依赖的package包/类
/**
* 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();
}
示例8: doClient
import io.grpc.inprocess.InProcessChannelBuilder; //导入依赖的package包/类
public String doClient(String name) {
ManagedChannel channel = InProcessChannelBuilder
.forName("GradleProof")
.build();
try {
GreeterGrpc.GreeterBlockingStub stub = GreeterGrpc.newBlockingStub(channel);
HelloRequest request = HelloRequest.newBuilder().setName(name).build();
HelloResponse response = stub.sayHello(request);
return response.getMessage();
} finally {
channel.shutdownNow();
}
}
示例9: serverIsRunningAndSayHelloReturnsExpectedResponse
import io.grpc.inprocess.InProcessChannelBuilder; //导入依赖的package包/类
@Test
public void serverIsRunningAndSayHelloReturnsExpectedResponse() throws Exception {
final String name = UUID.randomUUID().toString();
grpcServerHost.start();
ManagedChannel channel = InProcessChannelBuilder
.forName(SERVER_NAME)
.usePlaintext(true)
.build();
GreeterGrpc.GreeterFutureStub stub = GreeterGrpc.newFutureStub(channel);
ListenableFuture<HelloResponse> responseFuture = stub.sayHello(HelloRequest.newBuilder().setName(name).build());
AtomicReference<HelloResponse> response = new AtomicReference<>();
Futures.addCallback(
responseFuture,
new FutureCallback<HelloResponse>() {
@Override
public void onSuccess(@Nullable HelloResponse result) {
response.set(result);
}
@Override
public void onFailure(Throwable t) {
}
},
MoreExecutors.directExecutor());
await().atMost(10, TimeUnit.SECONDS).until(responseFuture::isDone);
channel.shutdownNow();
assertThat(response.get()).isNotNull();
assertThat(response.get().getMessage()).contains(name);
}
示例10: uniqueSessionIdPerChannel
import io.grpc.inprocess.InProcessChannelBuilder; //导入依赖的package包/类
@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();
}
}
示例11: interceptorThrowsIfMissingTransportFilter
import io.grpc.inprocess.InProcessChannelBuilder; //导入依赖的package包/类
@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();
}
}
示例12: perSessionShouldFailMissingTransportFilter
import io.grpc.inprocess.InProcessChannelBuilder; //导入依赖的package包/类
@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();
}
}
示例13: setUp
import io.grpc.inprocess.InProcessChannelBuilder; //导入依赖的package包/类
@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();
}
示例14: setUp
import io.grpc.inprocess.InProcessChannelBuilder; //导入依赖的package包/类
@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());
}
示例15: setUp
import io.grpc.inprocess.InProcessChannelBuilder; //导入依赖的package包/类
@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());
}