Search in sources :

Example 1 with SpannerSettings

use of com.google.cloud.spanner.v1.SpannerSettings in project java-spanner by googleapis.

the class RetryOnInvalidatedSessionTest method startStaticServer.

@BeforeClass
public static void startStaticServer() throws IOException {
    mockSpanner = new MockSpannerServiceImpl();
    // We don't want any unpredictable aborted transactions.
    mockSpanner.setAbortProbability(0.0D);
    mockSpanner.putStatementResult(StatementResult.read("FOO", KeySet.all(), Collections.singletonList("BAR"), READ_RESULTSET));
    mockSpanner.putStatementResult(StatementResult.read("FOO", KeySet.singleKey(Key.of()), Collections.singletonList("BAR"), READ_ROW_RESULTSET));
    mockSpanner.putStatementResult(StatementResult.query(SELECT1AND2, SELECT1_RESULTSET));
    mockSpanner.putStatementResult(StatementResult.update(UPDATE_STATEMENT, UPDATE_COUNT));
    String uniqueName = InProcessServerBuilder.generateName();
    server = InProcessServerBuilder.forName(uniqueName).directExecutor().addService(mockSpanner).build().start();
    channelProvider = LocalChannelProvider.create(uniqueName);
    SpannerSettings settings = SpannerSettings.newBuilder().setTransportChannelProvider(channelProvider).setCredentialsProvider(NoCredentialsProvider.create()).build();
    spannerClient = SpannerClient.create(settings);
    executor = Executors.newSingleThreadExecutor();
}
Also used : SpannerSettings(com.google.cloud.spanner.v1.SpannerSettings) BeforeClass(org.junit.BeforeClass)

Example 2 with SpannerSettings

use of com.google.cloud.spanner.v1.SpannerSettings in project java-spanner by googleapis.

the class TransactionManagerAbortedTest method startStaticServer.

@BeforeClass
public static void startStaticServer() throws IOException {
    mockSpanner = new MockSpannerServiceImpl();
    // We don't want any unpredictable aborted transactions.
    mockSpanner.setAbortProbability(0.0D);
    mockSpanner.putStatementResult(StatementResult.read("FOO", KeySet.all(), Collections.singletonList("BAR"), READ_RESULTSET));
    mockSpanner.putStatementResult(StatementResult.read("FOO", KeySet.singleKey(Key.of()), Collections.singletonList("BAR"), READ_ROW_RESULTSET));
    mockSpanner.putStatementResult(StatementResult.query(SELECT1AND2, SELECT1AND2_RESULTSET));
    mockSpanner.putStatementResult(StatementResult.update(UPDATE_STATEMENT, UPDATE_COUNT));
    mockSpanner.putStatementResult(StatementResult.exception(UPDATE_ABORTED_STATEMENT, mockSpanner.createAbortedException(ByteString.copyFromUtf8("test"))));
    String uniqueName = InProcessServerBuilder.generateName();
    server = InProcessServerBuilder.forName(uniqueName).scheduledExecutorService(new ScheduledThreadPoolExecutor(1)).addService(mockSpanner).build().start();
    channelProvider = LocalChannelProvider.create(uniqueName);
    SpannerSettings settings = SpannerSettings.newBuilder().setTransportChannelProvider(channelProvider).setCredentialsProvider(NoCredentialsProvider.create()).build();
    spannerClient = SpannerClient.create(settings);
}
Also used : ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) ByteString(com.google.protobuf.ByteString) SpannerSettings(com.google.cloud.spanner.v1.SpannerSettings) BeforeClass(org.junit.BeforeClass)

Aggregations

SpannerSettings (com.google.cloud.spanner.v1.SpannerSettings)2 BeforeClass (org.junit.BeforeClass)2 ByteString (com.google.protobuf.ByteString)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1