public static GrpcTransportOptions getDefaultGrpcTransportOptions() { return GrpcTransportOptions.newBuilder().build(); }
@Override public void run() { executorFactory.release(executor); } },
public static Builder newBuilder() { return new Builder(); } }
@Test public void testBaseHashCode() { assertEquals(OPTIONS.hashCode(), OPTIONS_COPY.hashCode()); assertNotEquals(DEFAULT_OPTIONS.hashCode(), OPTIONS.hashCode()); GrpcTransportOptions options = OPTIONS.toBuilder().setExecutorFactory(new DefaultExecutorFactory()).build(); assertNotEquals(OPTIONS.hashCode(), options.hashCode()); }
@Test public void testDefaultExecutorFactory() { ExecutorFactory<ScheduledExecutorService> executorFactory = new DefaultExecutorFactory(); ScheduledExecutorService executorService = executorFactory.get(); assertSame(executorService, executorFactory.get()); } }
/** * Create a session pool with the given options and for the given database. It will also start * eagerly creating sessions if {@link SessionPoolOptions#getMinSessions()} is greater than 0. * Return pool is immediately ready for use, though getting a session might block for sessions to * be created. */ static SessionPool createPool(SpannerOptions spannerOptions, DatabaseId db, SpannerImpl spanner) { return createPool( spannerOptions.getSessionPoolOptions(), ((GrpcTransportOptions) spannerOptions.getTransportOptions()).getExecutorFactory(), db, spanner); }
@InternalApi("This class should only be extended within google-cloud-java") protected FirestoreOptions(Builder builder) { super(FirestoreFactory.class, FirestoreRpcFactory.class, builder, new FirestoreDefaults()); this.databaseId = builder.databaseId != null ? builder.databaseId : FirestoreDefaults.INSTANCE.getDatabaseId(); this.timestampsInSnapshotsEnabled = builder.timestampsInSnapshotsEnabled != null ? builder.timestampsInSnapshotsEnabled : DEFAULT_TIMESTAMPS_IN_SNAPSHOTS_ENABLED; this.channelProvider = builder.channelProvider != null ? builder.channelProvider : GrpcTransportOptions.setUpChannelProvider( FirestoreSettings.defaultGrpcTransportProviderBuilder(), this); this.credentialsProvider = builder.credentialsProvider != null ? builder.credentialsProvider : GrpcTransportOptions.setUpCredentialsProvider(this); }
@Nonnull public static GrpcTransportOptions.Builder getDefaultTransportOptionsBuilder() { return GrpcTransportOptions.newBuilder(); }
static SessionPool createPool( SessionPoolOptions poolOptions, ExecutorFactory<ScheduledExecutorService> executorFactory, DatabaseId db, SpannerImpl spanner, Clock clock) { SessionPool pool = new SessionPool(poolOptions, executorFactory, executorFactory.get(), db, spanner, clock); pool.initPool(); return pool; }
public GrpcTransportOptions build() { return new GrpcTransportOptions(this); }
@InternalApi("This class should only be extended within google-cloud-java") protected BaseGrpcServiceException(IOException exception, boolean idempotent) { super(makeExceptionData(exception, idempotent)); }
@Test public void testTranslateAndThrow() throws Exception { IOException exception = new SocketTimeoutException(); BaseGrpcServiceException cause = new BaseGrpcServiceException(exception, IDEMPOTENT); RetryHelper.RetryHelperException exceptionMock = createMock(RetryHelper.RetryHelperException.class); expect(exceptionMock.getCause()).andReturn(cause).times(2); replay(exceptionMock); try { BaseServiceException.translate(exceptionMock); } catch (BaseServiceException ex) { assertEquals(0, ex.getCode()); assertNull(ex.getMessage()); assertTrue(ex.isRetryable()); } finally { verify(exceptionMock); } } }
public static GrpcTransportOptions getDefaultGrpcTransportOptions() { return GrpcTransportOptions.newBuilder().build(); }
@Test public void testBaseEquals() { assertEquals(OPTIONS, OPTIONS_COPY); assertNotEquals(DEFAULT_OPTIONS, OPTIONS); GrpcTransportOptions options = OPTIONS.toBuilder().setExecutorFactory(new DefaultExecutorFactory()).build(); assertNotEquals(OPTIONS, options); }
@Test public void testBuilder() { assertSame(MOCK_EXECUTOR_FACTORY, OPTIONS.getExecutorFactory()); assertTrue(DEFAULT_OPTIONS.getExecutorFactory() instanceof DefaultExecutorFactory); }
@Override public void close() throws Exception { if (closed) { return; } closed = true; firestoreStub.close(); for (BackgroundResource resource : clientContext.getBackgroundResources()) { resource.close(); } executorFactory.release(executor); }
public Builder toBuilder() { return new Builder(this); }
@Test public void getDbclientAgainGivesSame() { Map<String, String> labels = new HashMap<>(); labels.put("env", "dev"); Mockito.when(spannerOptions.getSessionLabels()).thenReturn(labels); String dbName = "projects/p1/instances/i1/databases/d1"; DatabaseId db = DatabaseId.of(dbName); Mockito.when(spannerOptions.getTransportOptions()) .thenReturn(GrpcTransportOptions.newBuilder().build()); Mockito.when(spannerOptions.getSessionPoolOptions()) .thenReturn(SessionPoolOptions.newBuilder().build()); DatabaseClient databaseClient = impl.getDatabaseClient(db); // Get db client again DatabaseClient databaseClient1 = impl.getDatabaseClient(db); assertThat(databaseClient1).isSameAs(databaseClient); }
@Override public void close() throws Exception { if (closed) { return; } closed = true; configClient.close(); loggingClient.close(); metricsClient.close(); for (BackgroundResource resource : clientContext.getBackgroundResources()) { resource.close(); } executorFactory.release(executor); }
@Test public void getDbclientAfterCloseThrows() { SpannerImpl imp = new SpannerImpl(rpc, 1, spannerOptions); Map<String, String> labels = new HashMap<>(); labels.put("env", "dev"); Mockito.when(spannerOptions.getSessionLabels()).thenReturn(labels); String dbName = "projects/p1/instances/i1/databases/d1"; DatabaseId db = DatabaseId.of(dbName); Mockito.when(spannerOptions.getTransportOptions()) .thenReturn(GrpcTransportOptions.newBuilder().build()); Mockito.when(spannerOptions.getSessionPoolOptions()) .thenReturn(SessionPoolOptions.newBuilder().build()); imp.close(); try { imp.getDatabaseClient(db); fail("Expected exception"); } catch (IllegalStateException e) { assertThat(e.getMessage()).contains("Cloud Spanner client has been closed"); } }