use of com.swiftmq.impl.routing.single.smqpr.v400.CommitRequest in project java-spanner by googleapis.
the class DatabaseClientImplTest method testAsyncTransactionManagerCommitWithPriority.
@Test
public void testAsyncTransactionManagerCommitWithPriority() {
DatabaseClient client = spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE));
try (AsyncTransactionManager manager = client.transactionManagerAsync(Options.priority(RpcPriority.HIGH))) {
TransactionContextFuture transaction = manager.beginAsync();
get(transaction.then((txn, input) -> {
txn.buffer(Mutation.delete("TEST", KeySet.all()));
return ApiFutures.immediateFuture(null);
}, executor).commitAsync());
}
List<CommitRequest> requests = mockSpanner.getRequestsOfType(CommitRequest.class);
assertThat(requests).hasSize(1);
CommitRequest request = requests.get(0);
assertNotNull(request.getRequestOptions());
assertEquals(Priority.PRIORITY_HIGH, request.getRequestOptions().getPriority());
}
use of com.swiftmq.impl.routing.single.smqpr.v400.CommitRequest in project java-spanner by googleapis.
the class DatabaseClientImplTest method testWrite.
@Test
public void testWrite() {
DatabaseClient client = spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE));
Timestamp timestamp = client.write(Collections.singletonList(Mutation.newInsertBuilder("FOO").set("ID").to(1L).set("NAME").to("Bar").build()));
assertNotNull(timestamp);
List<CommitRequest> commitRequests = mockSpanner.getRequestsOfType(CommitRequest.class);
assertThat(commitRequests).hasSize(1);
CommitRequest commit = commitRequests.get(0);
assertNotNull(commit.getRequestOptions());
assertEquals(Priority.PRIORITY_UNSPECIFIED, commit.getRequestOptions().getPriority());
}
use of com.swiftmq.impl.routing.single.smqpr.v400.CommitRequest in project java-spanner by googleapis.
the class DatabaseClientImplTest method testAsyncRunnerCommitWithPriority.
@Test
public void testAsyncRunnerCommitWithPriority() {
DatabaseClient client = spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE));
AsyncRunner runner = client.runAsync(Options.priority(RpcPriority.HIGH));
get(runner.runAsync(txn -> {
txn.buffer(Mutation.delete("TEST", KeySet.all()));
return ApiFutures.immediateFuture(null);
}, executor));
List<CommitRequest> requests = mockSpanner.getRequestsOfType(CommitRequest.class);
assertThat(requests).hasSize(1);
CommitRequest request = requests.get(0);
assertNotNull(request.getRequestOptions());
assertEquals(Priority.PRIORITY_HIGH, request.getRequestOptions().getPriority());
}
use of com.swiftmq.impl.routing.single.smqpr.v400.CommitRequest in project java-spanner by googleapis.
the class PgNumericTest method testMutation.
@Test
public void testMutation() {
final List<Mutation> mutations = Collections.singletonList(Mutation.newInsertBuilder("Table").set("PgNumeric").to("1.23").set("PgNumericNull").to((String) null).set("PgNumericNaN").to("NaN").set("PgNumericValue").to(Value.pgNumeric("2.34")).set("PgNumericArray").toStringArray(Arrays.asList("2.34", null, "3.45")).set("PgNumericArrayNull").toStringArray(null).build());
final List<com.google.spanner.v1.Mutation> expectedMutations = new ArrayList<>();
Mutation.toProto(mutations, expectedMutations);
databaseClient.readWriteTransaction().run(transaction -> {
transaction.buffer(mutations);
return null;
});
final List<CommitRequest> requests = mockSpanner.getRequestsOfType(CommitRequest.class);
final CommitRequest request = requests.get(0);
assertEquals(1, requests.size());
assertEquals(expectedMutations, request.getMutationsList());
}
use of com.swiftmq.impl.routing.single.smqpr.v400.CommitRequest in project java-spanner by googleapis.
the class SessionImplTest method writeAtLeastOnce.
@Test
public void writeAtLeastOnce() throws ParseException {
String timestampString = "2015-10-01T10:54:20.021Z";
ArgumentCaptor<CommitRequest> commit = ArgumentCaptor.forClass(CommitRequest.class);
CommitResponse response = CommitResponse.newBuilder().setCommitTimestamp(Timestamps.parse(timestampString)).build();
Mockito.when(rpc.commit(commit.capture(), Mockito.eq(options))).thenReturn(response);
Timestamp timestamp = session.writeAtLeastOnce(Collections.singletonList(Mutation.newInsertBuilder("T").set("C").to("x").build()));
assertThat(timestamp.getSeconds()).isEqualTo(utcTimeSeconds(2015, Calendar.OCTOBER, 1, 10, 54, 20));
assertThat(timestamp.getNanos()).isEqualTo(TimeUnit.MILLISECONDS.toNanos(21));
CommitRequest request = commit.getValue();
assertThat(request.getSingleUseTransaction()).isNotNull();
assertThat(request.getSingleUseTransaction().getReadWrite()).isNotNull();
com.google.spanner.v1.Mutation mutation = com.google.spanner.v1.Mutation.newBuilder().setInsert(Write.newBuilder().setTable("T").addColumns("C").addValues(ListValue.newBuilder().addValues(com.google.protobuf.Value.newBuilder().setStringValue("x")))).build();
assertThat(request.getMutationsList()).containsExactly(mutation);
}
Aggregations