use of com.google.spanner.v1.Mutation in project java-spanner by googleapis.
the class SpannerClientTest method commitExceptionTest3.
@Test
public void commitExceptionTest3() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockSpanner.addException(exception);
try {
String session = "session1984987798";
ByteString transactionId = ByteString.EMPTY;
List<Mutation> mutations = new ArrayList<>();
client.commit(session, transactionId, mutations);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.spanner.v1.Mutation in project appengine-java-standard by GoogleCloudPlatform.
the class BaseCloudDatastoreV1ServiceImplTest method createCommitResponse.
CommitResponse createCommitResponse(CommitRequest request, Long... allocatedIds) {
CommitResponse.Builder req = CommitResponse.newBuilder();
Iterator<Long> idIterator = Iterators.forArray(allocatedIds);
for (Mutation mutation : request.getMutationsList()) {
MutationResult.Builder mutationResult = MutationResult.newBuilder();
com.google.datastore.v1.Entity.Builder entity;
switch(mutation.getOperationCase()) {
case INSERT:
entity = mutation.getInsert().toBuilder();
break;
case UPSERT:
entity = mutation.getUpsert().toBuilder();
break;
default:
entity = null;
}
if (entity != null) {
com.google.datastore.v1.Key key = entity.getKey();
PathElement lastPathElem = key.getPath(key.getPathCount() - 1);
if (lastPathElem.getIdTypeCase() == IdTypeCase.IDTYPE_NOT_SET) {
mutationResult.setKey(completeKey(key, idIterator.next()));
}
}
req.addMutationResults(mutationResult);
}
assertThat(idIterator.hasNext()).isFalse();
return req.build();
}
use of com.google.spanner.v1.Mutation in project gapic-generator-java by googleapis.
the class BaseBigtableDataClientTest method mutateRowTest2.
@Test
public void mutateRowTest2() throws Exception {
MutateRowResponse expectedResponse = MutateRowResponse.newBuilder().build();
mockBigtable.addResponse(expectedResponse);
String tableName = "tableName-1988717703";
ByteString rowKey = ByteString.EMPTY;
List<Mutation> mutations = new ArrayList<>();
MutateRowResponse actualResponse = client.mutateRow(tableName, rowKey, mutations);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockBigtable.getRequests();
Assert.assertEquals(1, actualRequests.size());
MutateRowRequest actualRequest = ((MutateRowRequest) actualRequests.get(0));
Assert.assertEquals(tableName, actualRequest.getTableName());
Assert.assertEquals(rowKey, actualRequest.getRowKey());
Assert.assertEquals(mutations, actualRequest.getMutationsList());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.spanner.v1.Mutation in project gapic-generator-java by googleapis.
the class BaseBigtableDataClientTest method checkAndMutateRowExceptionTest2.
@Test
public void checkAndMutateRowExceptionTest2() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockBigtable.addException(exception);
try {
String tableName = "tableName-1988717703";
ByteString rowKey = ByteString.EMPTY;
RowFilter predicateFilter = RowFilter.newBuilder().build();
List<Mutation> trueMutations = new ArrayList<>();
List<Mutation> falseMutations = new ArrayList<>();
client.checkAndMutateRow(tableName, rowKey, predicateFilter, trueMutations, falseMutations);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.spanner.v1.Mutation in project gapic-generator-java by googleapis.
the class BaseBigtableDataClientTest method mutateRowExceptionTest3.
@Test
public void mutateRowExceptionTest3() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockBigtable.addException(exception);
try {
TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
ByteString rowKey = ByteString.EMPTY;
List<Mutation> mutations = new ArrayList<>();
String appProfileId = "appProfileId704923523";
client.mutateRow(tableName, rowKey, mutations, appProfileId);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
Aggregations