Search in sources :

Example 1 with RpcPriority

use of com.google.cloud.spanner.Options.RpcPriority in project java-spanner by googleapis.

the class OptionsTest method testTransactionOptions.

@Test
public void testTransactionOptions() {
    RpcPriority prio = RpcPriority.HIGH;
    Options options = Options.fromTransactionOptions(Options.priority(prio));
    assertThat(options.toString()).isEqualTo("priority: " + prio + " ");
    assertThat(options.priority()).isEqualTo(Priority.PRIORITY_HIGH);
}
Also used : RpcPriority(com.google.cloud.spanner.Options.RpcPriority) Test(org.junit.Test)

Example 2 with RpcPriority

use of com.google.cloud.spanner.Options.RpcPriority in project java-spanner by googleapis.

the class OptionsTest method testQueryOptionsPriority.

@Test
public void testQueryOptionsPriority() {
    RpcPriority priority = RpcPriority.MEDIUM;
    Options options = Options.fromQueryOptions(Options.priority(priority));
    assertTrue(options.hasPriority());
    assertEquals("priority: " + priority + " ", options.toString());
}
Also used : RpcPriority(com.google.cloud.spanner.Options.RpcPriority) Test(org.junit.Test)

Example 3 with RpcPriority

use of com.google.cloud.spanner.Options.RpcPriority in project java-spanner by googleapis.

the class OptionsTest method testUpdateOptionsPriority.

@Test
public void testUpdateOptionsPriority() {
    RpcPriority priority = RpcPriority.LOW;
    Options options = Options.fromUpdateOptions(Options.priority(priority));
    assertTrue(options.hasPriority());
    assertEquals("priority: " + priority + " ", options.toString());
}
Also used : RpcPriority(com.google.cloud.spanner.Options.RpcPriority) Test(org.junit.Test)

Example 4 with RpcPriority

use of com.google.cloud.spanner.Options.RpcPriority in project DataflowTemplates by GoogleCloudPlatform.

the class SpannerChangeStreamsToGcs method run.

public static PipelineResult run(SpannerChangeStreamsToGcsOptions options) {
    LOG.info("Requested File Format is " + options.getOutputFileFormat());
    options.setStreaming(true);
    options.setEnableStreamingEngine(true);
    options.setAutoscalingAlgorithm(DataflowPipelineWorkerPoolOptions.AutoscalingAlgorithmType.NONE);
    final Pipeline pipeline = Pipeline.create(options);
    // Get the Spanner project, instance, database, and change stream parameters.
    String projectId = getProjectId(options);
    String instanceId = options.getSpannerInstanceId();
    String databaseId = options.getSpannerDatabase();
    String metadataInstanceId = options.getSpannerMetadataInstanceId();
    String metadataDatabaseId = options.getSpannerMetadataDatabase();
    String changeStreamName = options.getSpannerChangeStreamName();
    // Retrieve and parse the start / end timestamps.
    Timestamp startTimestamp = options.getStartTimestamp().isEmpty() ? Timestamp.now() : Timestamp.parseTimestamp(options.getStartTimestamp());
    Timestamp endTimestamp = options.getEndTimestamp().isEmpty() ? Timestamp.MAX_VALUE : Timestamp.parseTimestamp(options.getEndTimestamp());
    // Add use_runner_v2 to the experiments option, since Change Streams connector is only supported
    // on Dataflow runner v2.
    List<String> experiments = options.getExperiments();
    if (experiments == null) {
        experiments = new ArrayList<>();
    }
    boolean hasUseRunnerV2 = false;
    for (String experiment : experiments) {
        if (experiment.toLowerCase().equals(USE_RUNNER_V2_EXPERIMENT)) {
            hasUseRunnerV2 = true;
            break;
        }
    }
    if (!hasUseRunnerV2) {
        experiments.add(USE_RUNNER_V2_EXPERIMENT);
    }
    options.setExperiments(experiments);
    String metadataTableName = options.getSpannerMetadataTableName() == null ? null : options.getSpannerMetadataTableName();
    final RpcPriority rpcPriority = options.getRpcPriority();
    pipeline.apply(SpannerIO.readChangeStream().withSpannerConfig(SpannerConfig.create().withHost(ValueProvider.StaticValueProvider.of(options.getSpannerHost())).withProjectId(projectId).withInstanceId(instanceId).withDatabaseId(databaseId)).withMetadataInstance(metadataInstanceId).withMetadataDatabase(metadataDatabaseId).withChangeStreamName(changeStreamName).withInclusiveStartAt(startTimestamp).withInclusiveEndAt(endTimestamp).withRpcPriority(rpcPriority).withMetadataTable(metadataTableName)).apply("Creating " + options.getWindowDuration() + " Window", Window.into(FixedWindows.of(DurationUtils.parseDuration(options.getWindowDuration())))).apply("Write To GCS", FileFormatFactorySpannerChangeStreams.newBuilder().setOptions(options).build());
    return pipeline.run();
}
Also used : RpcPriority(com.google.cloud.spanner.Options.RpcPriority) Timestamp(com.google.cloud.Timestamp) Pipeline(org.apache.beam.sdk.Pipeline)

Example 5 with RpcPriority

use of com.google.cloud.spanner.Options.RpcPriority in project java-spanner by googleapis.

the class ConnectionStatementExecutorImpl method statementSetRPCPriority.

@Override
public StatementResult statementSetRPCPriority(Priority priority) {
    RpcPriority value = validRPCPriorityValues.get(priority);
    getConnection().setRPCPriority(value);
    return noResult(SET_RPC_PRIORITY);
}
Also used : RpcPriority(com.google.cloud.spanner.Options.RpcPriority)

Aggregations

RpcPriority (com.google.cloud.spanner.Options.RpcPriority)7 Test (org.junit.Test)5 Timestamp (com.google.cloud.Timestamp)1 Pipeline (org.apache.beam.sdk.Pipeline)1