use of com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest in project java-spanner by googleapis.
the class TransactionContextImplTest method testReturnCommitStats.
@SuppressWarnings("unchecked")
@Test
public void testReturnCommitStats() {
ByteString transactionId = ByteString.copyFromUtf8("test");
try (TransactionContextImpl context = TransactionContextImpl.newBuilder().setSession(session).setRpc(rpc).setTransactionId(transactionId).setOptions(Options.fromTransactionOptions(Options.commitStats())).build()) {
context.commitAsync();
CommitRequest request = CommitRequest.newBuilder().setReturnCommitStats(true).setSession(session.getName()).setTransactionId(transactionId).build();
verify(rpc).commitAsync(Mockito.eq(request), anyMap());
}
}
use of com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest in project java-spanner by googleapis.
the class ConnectionAsyncApiTest method testReadWriteMultipleAsyncStatements.
@Test
public void testReadWriteMultipleAsyncStatements() {
try (Connection connection = createConnection()) {
assertThat(connection.isAutocommit()).isFalse();
ApiFuture<Long> update1 = connection.executeUpdateAsync(INSERT_STATEMENT);
ApiFuture<Long> update2 = connection.executeUpdateAsync(INSERT_STATEMENT);
ApiFuture<long[]> batch = connection.executeBatchUpdateAsync(ImmutableList.of(INSERT_STATEMENT, INSERT_STATEMENT));
final SettableApiFuture<Integer> rowCount = SettableApiFuture.create();
try (AsyncResultSet rs = connection.executeQueryAsync(SELECT_RANDOM_STATEMENT)) {
rs.setCallback(executor, new ReadyCallback() {
int count = 0;
@Override
public CallbackResponse cursorReady(AsyncResultSet resultSet) {
try {
while (true) {
switch(resultSet.tryNext()) {
case DONE:
rowCount.set(count);
return CallbackResponse.DONE;
case NOT_READY:
return CallbackResponse.CONTINUE;
case OK:
count++;
}
}
} catch (SpannerException e) {
rowCount.setException(e);
return CallbackResponse.DONE;
}
}
});
}
ApiFuture<Void> commit = connection.commitAsync();
assertThat(get(update1)).isEqualTo(UPDATE_COUNT);
assertThat(get(update2)).isEqualTo(UPDATE_COUNT);
assertThat(get(batch)).asList().containsExactly(1L, 1L);
assertThat(get(rowCount)).isEqualTo(RANDOM_RESULT_SET_ROW_COUNT);
assertNull(get(commit));
// Get the last commit request.
CommitRequest commitRequest = mockSpanner.getRequestsOfType(CommitRequest.class).stream().reduce((first, second) -> second).get();
// Verify the order of the statements on the server.
List<? extends AbstractMessage> requests = Lists.newArrayList(Collections2.filter(mockSpanner.getRequests(), input -> (input instanceof ExecuteSqlRequest && ((ExecuteSqlRequest) input).getSession().equals(commitRequest.getSession())) || (input instanceof ExecuteBatchDmlRequest && ((ExecuteBatchDmlRequest) input).getSession().equals(commitRequest.getSession()))));
assertThat(requests).hasSize(4);
assertThat(requests.get(0)).isInstanceOf(ExecuteSqlRequest.class);
assertThat(((ExecuteSqlRequest) requests.get(0)).getSeqno()).isEqualTo(1L);
assertThat(requests.get(1)).isInstanceOf(ExecuteSqlRequest.class);
assertThat(((ExecuteSqlRequest) requests.get(1)).getSeqno()).isEqualTo(2L);
assertThat(requests.get(2)).isInstanceOf(ExecuteBatchDmlRequest.class);
assertThat(((ExecuteBatchDmlRequest) requests.get(2)).getSeqno()).isEqualTo(3L);
assertThat(requests.get(3)).isInstanceOf(ExecuteSqlRequest.class);
assertThat(((ExecuteSqlRequest) requests.get(3)).getSeqno()).isEqualTo(4L);
}
}
use of com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest in project java-spanner by googleapis.
the class SpannerClientTest method commitTest4.
@Test
public void commitTest4() throws Exception {
CommitResponse expectedResponse = CommitResponse.newBuilder().setCommitTimestamp(Timestamp.newBuilder().build()).setCommitStats(CommitResponse.CommitStats.newBuilder().build()).build();
mockSpanner.addResponse(expectedResponse);
String session = "session1984987798";
TransactionOptions singleUseTransaction = TransactionOptions.newBuilder().build();
List<Mutation> mutations = new ArrayList<>();
CommitResponse actualResponse = client.commit(session, singleUseTransaction, mutations);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockSpanner.getRequests();
Assert.assertEquals(1, actualRequests.size());
CommitRequest actualRequest = ((CommitRequest) actualRequests.get(0));
Assert.assertEquals(session, actualRequest.getSession());
Assert.assertEquals(singleUseTransaction, actualRequest.getSingleUseTransaction());
Assert.assertEquals(mutations, actualRequest.getMutationsList());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest in project java-spanner by googleapis.
the class SpannerClientTest method commitTest2.
@Test
public void commitTest2() throws Exception {
CommitResponse expectedResponse = CommitResponse.newBuilder().setCommitTimestamp(Timestamp.newBuilder().build()).setCommitStats(CommitResponse.CommitStats.newBuilder().build()).build();
mockSpanner.addResponse(expectedResponse);
SessionName session = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]");
TransactionOptions singleUseTransaction = TransactionOptions.newBuilder().build();
List<Mutation> mutations = new ArrayList<>();
CommitResponse actualResponse = client.commit(session, singleUseTransaction, mutations);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockSpanner.getRequests();
Assert.assertEquals(1, actualRequests.size());
CommitRequest actualRequest = ((CommitRequest) actualRequests.get(0));
Assert.assertEquals(session.toString(), actualRequest.getSession());
Assert.assertEquals(singleUseTransaction, actualRequest.getSingleUseTransaction());
Assert.assertEquals(mutations, actualRequest.getMutationsList());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest in project java-spanner by googleapis.
the class SpannerClientTest method commitTest.
@Test
public void commitTest() throws Exception {
CommitResponse expectedResponse = CommitResponse.newBuilder().setCommitTimestamp(Timestamp.newBuilder().build()).setCommitStats(CommitResponse.CommitStats.newBuilder().build()).build();
mockSpanner.addResponse(expectedResponse);
SessionName session = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]");
ByteString transactionId = ByteString.EMPTY;
List<Mutation> mutations = new ArrayList<>();
CommitResponse actualResponse = client.commit(session, transactionId, mutations);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockSpanner.getRequests();
Assert.assertEquals(1, actualRequests.size());
CommitRequest actualRequest = ((CommitRequest) actualRequests.get(0));
Assert.assertEquals(session.toString(), actualRequest.getSession());
Assert.assertEquals(transactionId, actualRequest.getTransactionId());
Assert.assertEquals(mutations, actualRequest.getMutationsList());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations