use of com.google.spanner.v1.Mutation in project java-spanner by googleapis.
the class SpannerClientTest method commitExceptionTest.
@Test
public void commitExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockSpanner.addException(exception);
try {
SessionName session = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]");
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 java-spanner by googleapis.
the class SessionImpl method writeAtLeastOnceWithOptions.
@Override
public CommitResponse writeAtLeastOnceWithOptions(Iterable<Mutation> mutations, TransactionOption... transactionOptions) throws SpannerException {
setActive(null);
Options commitRequestOptions = Options.fromTransactionOptions(transactionOptions);
List<com.google.spanner.v1.Mutation> mutationsProto = new ArrayList<>();
Mutation.toProto(mutations, mutationsProto);
final CommitRequest.Builder requestBuilder = CommitRequest.newBuilder().setSession(name).setReturnCommitStats(Options.fromTransactionOptions(transactionOptions).withCommitStats()).addAllMutations(mutationsProto).setSingleUseTransaction(TransactionOptions.newBuilder().setReadWrite(TransactionOptions.ReadWrite.getDefaultInstance()));
if (commitRequestOptions.hasPriority() || commitRequestOptions.hasTag()) {
RequestOptions.Builder requestOptionsBuilder = RequestOptions.newBuilder();
if (commitRequestOptions.hasPriority()) {
requestOptionsBuilder.setPriority(commitRequestOptions.priority());
}
if (commitRequestOptions.hasTag()) {
requestOptionsBuilder.setTransactionTag(commitRequestOptions.tag());
}
requestBuilder.setRequestOptions(requestOptionsBuilder.build());
}
Span span = tracer.spanBuilder(SpannerImpl.COMMIT).startSpan();
try (Scope s = tracer.withSpan(span)) {
com.google.spanner.v1.CommitResponse response = spanner.getRpc().commit(requestBuilder.build(), this.options);
return new CommitResponse(response);
} catch (RuntimeException e) {
TraceUtil.setWithFailure(span, e);
throw e;
} finally {
span.end(TraceUtil.END_SPAN_OPTIONS);
}
}
use of com.google.spanner.v1.Mutation in project SpinalTap by airbnb.
the class ColumnSerializationUtilTest method testDeserializeColumn.
@Test
public void testDeserializeColumn() throws Exception {
Mutation mutation = new Mutation(MutationType.DELETE, TIMESTAMP, SOURCE_ID, DATA_SOURCE, BINLOG_HEADER, TABLE, getEntity());
TSerializer serializer = new TSerializer(new TBinaryProtocol.Factory());
TDeserializer deserializer = new TDeserializer(new TBinaryProtocol.Factory());
byte[] serialized = serializer.serialize(mutation);
Mutation deserialized = new Mutation();
deserializer.deserialize(deserialized, serialized);
assertEquals(mutation, deserialized);
}
use of com.google.spanner.v1.Mutation in project java-bigtable-hbase by googleapis.
the class TestPutAdapter method testSingleCellIsConverted.
@Test
public void testSingleCellIsConverted() {
byte[] row = dataHelper.randomData("rk-");
byte[] family = dataHelper.randomData("f");
byte[] qualifier = dataHelper.randomData("qual");
byte[] value = dataHelper.randomData("v1");
long timestamp = 2L;
Put hbasePut = new Put(row);
hbasePut.addColumn(family, qualifier, timestamp, value);
MutateRowRequest request = adapt(hbasePut);
Assert.assertArrayEquals(row, request.getRowKey().toByteArray());
Assert.assertEquals(1, request.getMutationsCount());
Mutation mutation = request.getMutations(0);
Assert.assertEquals(MutationCase.SET_CELL, mutation.getMutationCase());
SetCell setCell = mutation.getSetCell();
Assert.assertArrayEquals(family, setCell.getFamilyNameBytes().toByteArray());
Assert.assertArrayEquals(qualifier, setCell.getColumnQualifier().toByteArray());
Assert.assertEquals(TimeUnit.MILLISECONDS.toMicros(timestamp), setCell.getTimestampMicros());
Assert.assertArrayEquals(value, setCell.getValue().toByteArray());
}
use of com.google.spanner.v1.Mutation in project java-bigtable-hbase by googleapis.
the class TestPutAdapter method testUnsetTimestampsArePopulated.
@Test
public void testUnsetTimestampsArePopulated() {
byte[] row = dataHelper.randomData("rk-");
byte[] family1 = dataHelper.randomData("f1");
byte[] qualifier1 = dataHelper.randomData("qual1");
byte[] value1 = dataHelper.randomData("v1");
long startTimeMillis = System.currentTimeMillis();
Put hbasePut = new Put(row).addColumn(family1, qualifier1, value1);
com.google.cloud.bigtable.data.v2.models.Mutation unsafeMutation = com.google.cloud.bigtable.data.v2.models.Mutation.createUnsafe();
adapter.adapt(hbasePut, unsafeMutation);
MutateRowRequest request = RowMutation.create(TABLE_ID, ByteString.copyFrom(hbasePut.getRow()), unsafeMutation).toProto(REQUEST_CONTEXT);
Assert.assertArrayEquals(row, request.getRowKey().toByteArray());
Assert.assertEquals(1, request.getMutationsCount());
Mutation mutation = request.getMutations(0);
Assert.assertEquals(MutationCase.SET_CELL, mutation.getMutationCase());
SetCell setCell = mutation.getSetCell();
Assert.assertArrayEquals(family1, setCell.getFamilyNameBytes().toByteArray());
Assert.assertArrayEquals(qualifier1, setCell.getColumnQualifier().toByteArray());
Assert.assertTrue(startTimeMillis * 1000 <= setCell.getTimestampMicros());
Assert.assertTrue(setCell.getTimestampMicros() <= System.currentTimeMillis() * 1000);
Assert.assertArrayEquals(value1, setCell.getValue().toByteArray());
}
Aggregations