use of com.airbnb.jitney.event.spinaltap.v1.Mutation in project simple-bigtable by spotify.
the class BigtableMutationImplTest method testWriteColumnValue.
@Test
public void testWriteColumnValue() throws Exception {
final BigtableMutationImpl bigtableMutationImpl = (BigtableMutationImpl) this.bigtableMutation.write("family:qualifier", ByteString.copyFromUtf8("value")).write("family", "qualifier", ByteString.copyFromUtf8("value"));
verifyGetMutateRowRequest();
bigtableMutationImpl.execute();
bigtableMutationImpl.executeAsync();
assertEquals(2, bigtableMutationImpl.getMutateRowRequest().getMutationsCount());
for (Mutation mutation : bigtableMutationImpl.getMutateRowRequest().getMutationsList()) {
assertEquals(Mutation.MutationCase.SET_CELL, mutation.getMutationCase());
assertEquals("family", mutation.getSetCell().getFamilyName());
assertEquals("qualifier", mutation.getSetCell().getColumnQualifier().toStringUtf8());
assertEquals("value", mutation.getSetCell().getValue().toStringUtf8());
assertEquals(Mutation.DeleteFromRow.getDefaultInstance(), mutation.getDeleteFromRow());
assertEquals(Mutation.DeleteFromFamily.getDefaultInstance(), mutation.getDeleteFromFamily());
assertEquals(Mutation.DeleteFromColumn.getDefaultInstance(), mutation.getDeleteFromColumn());
// Check timestamp in last 1 second
final long tsMillis = TimeUnit.MICROSECONDS.toMillis(mutation.getSetCell().getTimestampMicros());
final long nowMillis = System.currentTimeMillis();
assertTrue(tsMillis <= nowMillis && tsMillis > nowMillis - TimeUnit.SECONDS.toMillis(1));
}
verify(bigtableMock.getMockedDataClient()).mutateRow(bigtableMutation.getMutateRowRequest().build());
verify(bigtableMock.getMockedDataClient()).mutateRowAsync(bigtableMutation.getMutateRowRequest().build());
verifyNoMoreInteractions(bigtableMock.getMockedDataClient());
}
use of com.airbnb.jitney.event.spinaltap.v1.Mutation in project simple-bigtable by spotify.
the class BigtableMutationImplTest method testDeleteRow.
@Test
public void testDeleteRow() throws Exception {
final BigtableMutationImpl bigtableMutationImpl = (BigtableMutationImpl) this.bigtableMutation.deleteRow();
verifyGetMutateRowRequest();
bigtableMutationImpl.execute();
bigtableMutationImpl.executeAsync();
assertEquals(1, bigtableMutationImpl.getMutateRowRequest().getMutationsCount());
final Mutation mutation = bigtableMutationImpl.getMutateRowRequest().getMutations(0);
assertEquals(Mutation.MutationCase.DELETE_FROM_ROW, mutation.getMutationCase());
assertEquals(Mutation.DeleteFromRow.getDefaultInstance(), mutation.getDeleteFromRow());
assertEquals(Mutation.DeleteFromFamily.getDefaultInstance(), mutation.getDeleteFromFamily());
assertEquals(Mutation.DeleteFromColumn.getDefaultInstance(), mutation.getDeleteFromColumn());
assertEquals(Mutation.SetCell.getDefaultInstance(), mutation.getSetCell());
verify(bigtableMock.getMockedDataClient()).mutateRow(bigtableMutation.getMutateRowRequest().build());
verify(bigtableMock.getMockedDataClient()).mutateRowAsync(bigtableMutation.getMutateRowRequest().build());
verifyNoMoreInteractions(bigtableMock.getMockedDataClient());
}
use of com.airbnb.jitney.event.spinaltap.v1.Mutation in project simple-bigtable by spotify.
the class BigtableMutationImplTest method testDeleteColumn.
@Test
public void testDeleteColumn() throws Exception {
final BigtableMutationImpl bigtableMutationImpl = (BigtableMutationImpl) this.bigtableMutation.deleteColumn("family:qualifier");
verifyGetMutateRowRequest();
bigtableMutationImpl.execute();
bigtableMutationImpl.executeAsync();
assertEquals(1, bigtableMutationImpl.getMutateRowRequest().getMutationsCount());
final Mutation mutation = bigtableMutationImpl.getMutateRowRequest().getMutations(0);
assertEquals(Mutation.MutationCase.DELETE_FROM_COLUMN, mutation.getMutationCase());
assertEquals("family", mutation.getDeleteFromColumn().getFamilyName());
assertEquals("qualifier", mutation.getDeleteFromColumn().getColumnQualifier().toStringUtf8());
assertEquals(Mutation.DeleteFromRow.getDefaultInstance(), mutation.getDeleteFromRow());
assertEquals(Mutation.DeleteFromFamily.getDefaultInstance(), mutation.getDeleteFromFamily());
assertEquals(Mutation.SetCell.getDefaultInstance(), mutation.getSetCell());
verify(bigtableMock.getMockedDataClient()).mutateRow(bigtableMutation.getMutateRowRequest().build());
verify(bigtableMock.getMockedDataClient()).mutateRowAsync(bigtableMutation.getMutateRowRequest().build());
verifyNoMoreInteractions(bigtableMock.getMockedDataClient());
}
use of com.airbnb.jitney.event.spinaltap.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.airbnb.jitney.event.spinaltap.v1.Mutation in project beam by apache.
the class BigtableClientWrapper method writeRow.
void writeRow(String key, String table, String familyColumn, String columnQualifier, byte[] value, long timestampMicros) {
Mutation.SetCell setCell = Mutation.SetCell.newBuilder().setFamilyName(familyColumn).setColumnQualifier(byteStringUtf8(columnQualifier)).setValue(byteString(value)).setTimestampMicros(timestampMicros).build();
Mutation mutation = Mutation.newBuilder().setSetCell(setCell).build();
MutateRowRequest mutateRowRequest = MutateRowRequest.newBuilder().setRowKey(byteStringUtf8(key)).setTableName(bigtableOptions.getInstanceName().toTableNameStr(table)).addMutations(mutation).build();
dataClient.mutateRow(mutateRowRequest);
}
Aggregations