@BetaApi("A restructuring of stub classes is planned, so this may break in the future") public SessionEntityTypesStub createStub() throws IOException { if (getTransportChannelProvider() .getTransportName() .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcSessionEntityTypesStub.create(this); } else { throw new UnsupportedOperationException( "Transport not supported: " + getTransportChannelProvider().getTransportName()); } }
if (transportChannelProvider.needsExecutor()) { transportChannelProvider = transportChannelProvider.withExecutor(executor); .putAll(settings.getInternalHeaderProvider().getHeaders()) .build(); if (transportChannelProvider.needsHeaders()) { transportChannelProvider = transportChannelProvider.withHeaders(headers); if (transportChannelProvider.needsEndpoint()) { transportChannelProvider = transportChannelProvider.withEndpoint(settings.getEndpoint()); TransportChannel transportChannel = transportChannelProvider.getTransportChannel(); if (transportChannelProvider.shouldAutoClose()) { backgroundResources.add(transportChannel);
@Test public void testWithPoolSize() throws IOException { ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(1); executor.shutdown(); TransportChannelProvider provider = InstantiatingGrpcChannelProvider.newBuilder() .build() .withExecutor(executor) .withHeaders(Collections.<String, String>emptyMap()) .withEndpoint("localhost:8080"); assertThat(provider.acceptsPoolSize()).isTrue(); // Make sure we can create channels OK. provider.getTransportChannel().shutdownNow(); provider = provider.withPoolSize(2); assertThat(provider.acceptsPoolSize()).isFalse(); provider.getTransportChannel().shutdownNow(); try { provider.withPoolSize(3); fail("acceptsPoolSize() returned false; we shouldn't be able to set it again"); } catch (IllegalStateException e) { } }
@Before public void setUp() throws IOException { initialChannel = mock(FakeChannel.class); pollTransportChannel = mock(TransportChannel.class); TransportChannelProvider operationsChannelProvider = mock(TransportChannelProvider.class); when(operationsChannelProvider.getTransportChannel()).thenReturn(pollTransportChannel); clock = new FakeApiClock(0L); executor = RecordingScheduler.create(clock); pollingAlgorithm = OperationTimedPollAlgorithm.create(FAST_RECHECKING_SETTINGS, clock); UnaryCallSettings<Integer, OperationSnapshot> initialCallSettings = UnaryCallSettings.<Integer, OperationSnapshot>newUnaryCallSettingsBuilder() .setRetrySettings(FAST_RETRY_SETTINGS.toBuilder().setMaxAttempts(1).build()) .build(); callSettings = OperationCallSettings.<Integer, Color, Currency>newBuilder() .setInitialCallSettings(initialCallSettings) .setResponseTransformer(new ResponseTransformer()) .setMetadataTransformer(new MetadataTransformer()) .setPollingAlgorithm(pollingAlgorithm) .build(); initialContext = getClientContext(initialChannel, executor); }
@Test public void createMetricServiceClient() throws IOException { MetricServiceClient client; synchronized (StackdriverStatsExporter.monitor) { client = StackdriverStatsExporter.createMetricServiceClient(FAKE_CREDENTIALS); } assertThat(client.getSettings().getCredentialsProvider().getCredentials()) .isEqualTo(FAKE_CREDENTIALS); assertThat(client.getSettings().getTransportChannelProvider()) .isInstanceOf(InstantiatingGrpcChannelProvider.class); // There's no way to get HeaderProvider from TransportChannelProvider. assertThat(client.getSettings().getTransportChannelProvider().needsHeaders()).isFalse(); }
if (transportChannelProvider.needsExecutor()) { transportChannelProvider = transportChannelProvider.withExecutor(executor); .putAll(settings.getInternalHeaderProvider().getHeaders()) .build(); if (transportChannelProvider.needsHeaders()) { transportChannelProvider = transportChannelProvider.withHeaders(headers); if (transportChannelProvider.needsEndpoint()) { transportChannelProvider = transportChannelProvider.withEndpoint(settings.getEndpoint()); TransportChannel transportChannel = transportChannelProvider.getTransportChannel(); if (transportChannelProvider.shouldAutoClose()) { backgroundResources.add(transportChannel);
TransportChannel transportChannel = GrpcTransportChannel.newBuilder().setManagedChannel(channel).build(); when(operationsChannelProvider.getTransportChannel()).thenReturn(transportChannel);
@Test public void createMetricServiceClient_WithoutCredentials() { try { MetricServiceClient client; synchronized (StackdriverStatsExporter.monitor) { client = StackdriverStatsExporter.createMetricServiceClient(null); } assertThat(client.getSettings().getCredentialsProvider()) .isInstanceOf(GoogleCredentialsProvider.class); assertThat(client.getSettings().getTransportChannelProvider()) .isInstanceOf(InstantiatingGrpcChannelProvider.class); // There's no way to get HeaderProvider from TransportChannelProvider. assertThat(client.getSettings().getTransportChannelProvider().needsHeaders()).isFalse(); } catch (IOException e) { // This test depends on the Application Default Credentials settings (environment variable // GOOGLE_APPLICATION_CREDENTIALS). Some hosts may not have the expected environment settings // and this test should be skipped in that case. } } }
@BetaApi("A restructuring of stub classes is planned, so this may break in the future") public CloudTasksStub createStub() throws IOException { if (getTransportChannelProvider() .getTransportName() .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcCloudTasksStub.create(this); } else { throw new UnsupportedOperationException( "Transport not supported: " + getTransportChannelProvider().getTransportName()); } }
@BetaApi("A restructuring of stub classes is planned, so this may break in the future") public BigQueryStorageStub createStub() throws IOException { if (getTransportChannelProvider() .getTransportName() .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcBigQueryStorageStub.create(this); } else { throw new UnsupportedOperationException( "Transport not supported: " + getTransportChannelProvider().getTransportName()); } }
@BetaApi("A restructuring of stub classes is planned, so this may break in the future") public ContextsStub createStub() throws IOException { if (getTransportChannelProvider() .getTransportName() .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcContextsStub.create(this); } else { throw new UnsupportedOperationException( "Transport not supported: " + getTransportChannelProvider().getTransportName()); } }
@BetaApi("A restructuring of stub classes is planned, so this may break in the future") public SpeechStub createStub() throws IOException { if (getTransportChannelProvider() .getTransportName() .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcSpeechStub.create(this); } else { throw new UnsupportedOperationException( "Transport not supported: " + getTransportChannelProvider().getTransportName()); } }
@BetaApi("A restructuring of stub classes is planned, so this may break in the future") public AutoscalerStub createStub() throws IOException { if (getTransportChannelProvider() .getTransportName() .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { return HttpJsonAutoscalerStub.create(this); } else { throw new UnsupportedOperationException( "Transport not supported: " + getTransportChannelProvider().getTransportName()); } }
@BetaApi("A restructuring of stub classes is planned, so this may break in the future") public WebSecurityScannerStub createStub() throws IOException { if (getTransportChannelProvider() .getTransportName() .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcWebSecurityScannerStub.create(this); } else { throw new UnsupportedOperationException( "Transport not supported: " + getTransportChannelProvider().getTransportName()); } }
@BetaApi("A restructuring of stub classes is planned, so this may break in the future") public NodeGroupStub createStub() throws IOException { if (getTransportChannelProvider() .getTransportName() .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { return HttpJsonNodeGroupStub.create(this); } else { throw new UnsupportedOperationException( "Transport not supported: " + getTransportChannelProvider().getTransportName()); } }
@BetaApi("A restructuring of stub classes is planned, so this may break in the future") public VpnTunnelStub createStub() throws IOException { if (getTransportChannelProvider() .getTransportName() .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { return HttpJsonVpnTunnelStub.create(this); } else { throw new UnsupportedOperationException( "Transport not supported: " + getTransportChannelProvider().getTransportName()); } }
@BetaApi("A restructuring of stub classes is planned, so this may break in the future") public ForwardingRuleStub createStub() throws IOException { if (getTransportChannelProvider() .getTransportName() .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { return HttpJsonForwardingRuleStub.create(this); } else { throw new UnsupportedOperationException( "Transport not supported: " + getTransportChannelProvider().getTransportName()); } }
@BetaApi("A restructuring of stub classes is planned, so this may break in the future") public GroupServiceStub createStub() throws IOException { if (getTransportChannelProvider() .getTransportName() .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcGroupServiceStub.create(this); } else { throw new UnsupportedOperationException( "Transport not supported: " + getTransportChannelProvider().getTransportName()); } }
@BetaApi("A restructuring of stub classes is planned, so this may break in the future") public RouteStub createStub() throws IOException { if (getTransportChannelProvider() .getTransportName() .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { return HttpJsonRouteStub.create(this); } else { throw new UnsupportedOperationException( "Transport not supported: " + getTransportChannelProvider().getTransportName()); } }
@BetaApi("A restructuring of stub classes is planned, so this may break in the future") public SubnetworkStub createStub() throws IOException { if (getTransportChannelProvider() .getTransportName() .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { return HttpJsonSubnetworkStub.create(this); } else { throw new UnsupportedOperationException( "Transport not supported: " + getTransportChannelProvider().getTransportName()); } }