.withInstanceId("test-instance") .withDatabaseId("test-database") .withServiceFactory(serviceFactory) .withBatchSizeBytes(0) .withFailureMode(SpannerIO.FailureMode.REPORT_FAILURES)
@Test @Category({NeedsRunner.class, UsesTestStream.class}) public void streamingWrites() throws Exception { TestStream<Mutation> testStream = TestStream.create(SerializableCoder.of(Mutation.class)) .addElements(m(1L), m(2L)) .advanceProcessingTime(Duration.standardMinutes(1)) .addElements(m(3L), m(4L)) .advanceProcessingTime(Duration.standardMinutes(1)) .addElements(m(5L), m(6L)) .advanceWatermarkToInfinity(); pipeline .apply(testStream) .apply( SpannerIO.write() .withProjectId("test-project") .withInstanceId("test-instance") .withDatabaseId("test-database") .withServiceFactory(serviceFactory)); pipeline.run(); verifyBatches(batch(m(1L), m(2L)), batch(m(3L), m(4L)), batch(m(5L), m(6L))); }
@Test @Category(NeedsRunner.class) public void singleMutationGroupPipeline() throws Exception { PCollection<MutationGroup> mutations = pipeline.apply(Create.<MutationGroup>of(g(m(1L), m(2L), m(3L)))); mutations.apply( SpannerIO.write() .withProjectId("test-project") .withInstanceId("test-instance") .withDatabaseId("test-database") .withServiceFactory(serviceFactory) .grouped()); pipeline.run(); verifyBatches(batch(m(1L), m(2L), m(3L))); }
@Test @Category(NeedsRunner.class) public void noBatching() throws Exception { PCollection<MutationGroup> mutations = pipeline.apply(Create.of(g(m(1L)), g(m(2L)))); mutations.apply( SpannerIO.write() .withProjectId("test-project") .withInstanceId("test-instance") .withDatabaseId("test-database") .withServiceFactory(serviceFactory) .withBatchSizeBytes(1) .grouped()); pipeline.run(); verifyBatches(batch(m(1L)), batch(m(2L))); }
@Test @Category(NeedsRunner.class) public void singleMutationPipeline() throws Exception { Mutation mutation = m(2L); PCollection<Mutation> mutations = pipeline.apply(Create.of(mutation)); mutations.apply( SpannerIO.write() .withProjectId("test-project") .withInstanceId("test-instance") .withDatabaseId("test-database") .withServiceFactory(serviceFactory)); pipeline.run(); verifyBatches(batch(m(2L))); }