use of com.google.spanner.v1.RollbackRequest in project java-firestore by googleapis.
the class FirestoreClient method rollback.
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Rolls back a transaction.
*
* <p>Sample code:
*
* <pre>{@code
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
* String database = "database1789464955";
* ByteString transaction = ByteString.EMPTY;
* firestoreClient.rollback(database, transaction);
* }
* }</pre>
*
* @param database Required. The database name. In the format:
* `projects/{project_id}/databases/{database_id}`.
* @param transaction Required. The transaction to roll back.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final void rollback(String database, ByteString transaction) {
RollbackRequest request = RollbackRequest.newBuilder().setDatabase(database).setTransaction(transaction).build();
rollback(request);
}
use of com.google.spanner.v1.RollbackRequest in project java-firestore by googleapis.
the class FirestoreClientTest method rollbackTest.
@Test
public void rollbackTest() throws Exception {
Empty expectedResponse = Empty.newBuilder().build();
mockFirestore.addResponse(expectedResponse);
String database = "database1789464955";
ByteString transaction = ByteString.EMPTY;
client.rollback(database, transaction);
List<AbstractMessage> actualRequests = mockFirestore.getRequests();
Assert.assertEquals(1, actualRequests.size());
RollbackRequest actualRequest = ((RollbackRequest) actualRequests.get(0));
Assert.assertEquals(database, actualRequest.getDatabase());
Assert.assertEquals(transaction, actualRequest.getTransaction());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.spanner.v1.RollbackRequest in project spring-cloud-gcp by spring-cloud.
the class ReactiveFirestoreTransactionManagerTest method getFirestoreTemplate.
private FirestoreTemplate getFirestoreTemplate() {
doAnswer(invocation -> {
StreamObserver<BeginTransactionResponse> streamObserver = invocation.getArgument(1);
streamObserver.onNext(BeginTransactionResponse.newBuilder().setTransaction(ByteString.copyFromUtf8("transaction1")).build());
streamObserver.onCompleted();
return null;
}).when(this.firestoreStub).beginTransaction(any(), any());
doAnswer(invocation -> {
CommitRequest commitRequest = invocation.getArgument(0);
StreamObserver<CommitResponse> streamObserver = invocation.getArgument(1);
assertThat(commitRequest.getTransaction()).isEqualTo(ByteString.copyFromUtf8("transaction1"));
streamObserver.onNext(CommitResponse.newBuilder().build());
streamObserver.onCompleted();
return null;
}).when(this.firestoreStub).commit(any(), any());
doAnswer(invocation -> {
RollbackRequest rollbackRequest = invocation.getArgument(0);
StreamObserver<Empty> streamObserver = invocation.getArgument(1);
assertThat(rollbackRequest.getTransaction()).isEqualTo(ByteString.copyFromUtf8("transaction1"));
streamObserver.onCompleted();
return null;
}).when(this.firestoreStub).rollback(any(), any());
doAnswer(invocation -> {
GetDocumentRequest request = invocation.getArgument(0);
StreamObserver<Document> streamObserver = invocation.getArgument(1);
assertThat(request.getTransaction()).isEqualTo(ByteString.copyFromUtf8("transaction1"));
String name = request.getName();
streamObserver.onNext(FirestoreTemplateTests.buildDocument(name.substring(name.length() - 2), 100L));
streamObserver.onCompleted();
return null;
}).when(this.firestoreStub).getDocument(any(), any());
FirestoreTemplate template = new FirestoreTemplate(this.firestoreStub, this.parent, new FirestoreDefaultClassMapper(), new FirestoreMappingContext());
StepVerifier.setDefaultTimeout(Duration.ofSeconds(5));
return template;
}
use of com.google.spanner.v1.RollbackRequest in project spring-cloud-gcp by GoogleCloudPlatform.
the class ReactiveFirestoreTransactionManagerTest method getFirestoreTemplate.
private FirestoreTemplate getFirestoreTemplate() {
doAnswer(invocation -> {
StreamObserver<BeginTransactionResponse> streamObserver = invocation.getArgument(1);
streamObserver.onNext(BeginTransactionResponse.newBuilder().setTransaction(ByteString.copyFromUtf8("transaction1")).build());
streamObserver.onCompleted();
return null;
}).when(this.firestoreStub).beginTransaction(any(), any());
doAnswer(invocation -> {
CommitRequest commitRequest = invocation.getArgument(0);
StreamObserver<CommitResponse> streamObserver = invocation.getArgument(1);
assertThat(commitRequest.getTransaction()).isEqualTo(ByteString.copyFromUtf8("transaction1"));
streamObserver.onNext(CommitResponse.newBuilder().build());
streamObserver.onCompleted();
return null;
}).when(this.firestoreStub).commit(any(), any());
doAnswer(invocation -> {
RollbackRequest rollbackRequest = invocation.getArgument(0);
StreamObserver<Empty> streamObserver = invocation.getArgument(1);
assertThat(rollbackRequest.getTransaction()).isEqualTo(ByteString.copyFromUtf8("transaction1"));
streamObserver.onCompleted();
return null;
}).when(this.firestoreStub).rollback(any(), any());
doAnswer(invocation -> {
GetDocumentRequest request = invocation.getArgument(0);
StreamObserver<Document> streamObserver = invocation.getArgument(1);
assertThat(request.getTransaction()).isEqualTo(ByteString.copyFromUtf8("transaction1"));
String name = request.getName();
streamObserver.onNext(FirestoreTemplateTests.buildDocument(name.substring(name.length() - 2), 100L));
streamObserver.onCompleted();
return null;
}).when(this.firestoreStub).getDocument(any(), any());
FirestoreMappingContext mappingContext = new FirestoreMappingContext();
FirestoreTemplate template = new FirestoreTemplate(this.firestoreStub, this.parent, new FirestoreDefaultClassMapper(mappingContext), mappingContext);
StepVerifier.setDefaultTimeout(Duration.ofSeconds(5));
return template;
}
use of com.google.spanner.v1.RollbackRequest in project pgadapter by GoogleCloudPlatform.
the class JdbcSimpleModeMockServerTest method testErrorHandlingInExplicitTransactionWithoutCommit.
@Test
public void testErrorHandlingInExplicitTransactionWithoutCommit() throws SQLException {
String sql = String.format("%s; %s; %s; %s;", INSERT_STATEMENT, "BEGIN", UPDATE_STATEMENT, INVALID_DML);
try (Connection connection = DriverManager.getConnection(createUrl())) {
try (java.sql.Statement statement = connection.createStatement()) {
SQLException exception = assertThrows(SQLException.class, () -> statement.execute(sql));
assertThat(exception.getMessage(), containsString("INVALID_ARGUMENT: Statement is invalid."));
}
}
// Verify that the DML statements were batched together by PgAdapter.
List<ExecuteSqlRequest> requests = mockSpanner.getRequestsOfType(ExecuteSqlRequest.class);
assertEquals(1, requests.size());
assertEquals(INSERT_STATEMENT.getSql(), requests.get(0).getSql());
List<ExecuteBatchDmlRequest> batchDmlRequests = mockSpanner.getRequestsOfType(ExecuteBatchDmlRequest.class);
assertEquals(1, requests.size());
ExecuteBatchDmlRequest request = batchDmlRequests.get(0);
assertEquals(2, request.getStatementsCount());
assertEquals(UPDATE_STATEMENT.getSql(), request.getStatements(0).getSql());
assertEquals(INVALID_DML.getSql(), request.getStatements(1).getSql());
// The aborted transaction should be rolled back by PGAdapter.
List<RollbackRequest> rollbackRequests = mockSpanner.getRequestsOfType(RollbackRequest.class);
assertEquals(1, rollbackRequests.size());
// BEGIN statement converts the implicit transaction to an explicit transaction, but is
// otherwise a no-op. We should therefore not receive any commits.
List<CommitRequest> commitRequests = mockSpanner.getRequestsOfType(CommitRequest.class);
assertEquals(0, commitRequests.size());
}
Aggregations