use of com.google.cloud.spanner.Mutation in project spanner-jdbc by olavloite.
the class XATransaction method cleanupPrepared.
private static void cleanupPrepared(TransactionContext transaction, String xid) {
boolean foundRecords = false;
KeySet.Builder builder = KeySet.newBuilder();
try (ResultSet rs = transaction.executeQuery(getPreparedMutationsStatement(xid))) {
while (rs.next()) {
foundRecords = true;
long number = rs.getLong(0);
builder.addKey(Key.of(xid, number));
}
}
if (foundRecords) {
Mutation delete = Mutation.delete(CloudSpannerXAConnection.XA_PREPARED_MUTATIONS_TABLE, builder.build());
transaction.buffer(delete);
}
}
use of com.google.cloud.spanner.Mutation in project spanner-jdbc by olavloite.
the class TransactionContextMock method createTransactionContextMock.
@SuppressWarnings("unchecked")
TransactionContext createTransactionContextMock() {
TransactionContext res = mock(TransactionContext.class);
when(res.executeQuery(XATransaction.getPreparedMutationsStatement(RecoveredXid.xidToString(XID_WITHOUT_MUTATIONS)))).then(new Answer<ResultSet>() {
@Override
public ResultSet answer(InvocationOnMock invocation) throws Throwable {
return mockPreparedWithoutMutationsResultSet();
}
});
when(res.executeQuery(XATransaction.getPreparedMutationsStatement(RecoveredXid.xidToString(XID_WITH_MUTATIONS)))).then(new Answer<ResultSet>() {
@Override
public ResultSet answer(InvocationOnMock invocation) throws Throwable {
return mockPreparedWithMutationsResultSet();
}
});
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
buffer.add((Mutation) invocation.getArgument(0));
return null;
}
}).when(res).buffer(ArgumentMatchers.any(Mutation.class));
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
Iterable<Mutation> it = (Iterable<Mutation>) invocation.getArgument(0);
it.forEach(e -> buffer.add(e));
return null;
}
}).when(res).buffer(ArgumentMatchers.any(Iterable.class));
return res;
}
use of com.google.cloud.spanner.Mutation in project beam by apache.
the class SpannerIOTest method batching.
@Test
public void batching() throws Exception {
Mutation one = Mutation.newInsertOrUpdateBuilder("test").set("one").to(1).build();
Mutation two = Mutation.newInsertOrUpdateBuilder("test").set("two").to(2).build();
SpannerIO.Write write = SpannerIO.write().withProjectId("test-project").withInstanceId("test-instance").withDatabaseId("test-database").withBatchSizeBytes(1000000000).withServiceFactory(serviceFactory);
SpannerIO.SpannerWriteFn writerFn = new SpannerIO.SpannerWriteFn(write);
DoFnTester<Mutation, Void> fnTester = DoFnTester.of(writerFn);
fnTester.processBundle(Arrays.asList(one, two));
verify(serviceFactory.mockSpanner()).getDatabaseClient(DatabaseId.of("test-project", "test-instance", "test-database"));
verify(serviceFactory.mockDatabaseClient(), times(1)).writeAtLeastOnce(argThat(new IterableOfSize(2)));
}
use of com.google.cloud.spanner.Mutation in project google-cloud-java by GoogleCloudPlatform.
the class ITReadOnlyTxnTest method writeNewValue.
private static void writeNewValue(DatabaseClient client, int i, @Nullable ImmutableList.Builder<History> historyBuilder) {
String value = "v" + i;
Mutation m = Mutation.newInsertOrUpdateBuilder(TABLE_NAME).set("StringValue").to(value).build();
long minCommitNanoTime = System.nanoTime();
Timestamp timestamp = client.writeAtLeastOnce(Arrays.asList(m));
if (historyBuilder != null) {
historyBuilder.add(new History(timestamp, value, minCommitNanoTime));
}
}
use of com.google.cloud.spanner.Mutation in project spring-cloud-gcp by spring-cloud.
the class SpannerMutationFactoryImplTests method insertTest.
@Test
public void insertTest() {
Mutation mutation = this.spannerMutationFactory.insert(new TestEntity());
assertEquals("custom_test_table", mutation.getTable());
assertEquals(Op.INSERT, mutation.getOperation());
}
Aggregations