Search in sources :

Example 1 with Mutation

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());
}
Also used : Mutation(com.google.bigtable.v2.Mutation) Test(org.junit.Test)

Example 2 with Mutation

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());
}
Also used : Mutation(com.google.bigtable.v2.Mutation) Test(org.junit.Test)

Example 3 with Mutation

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());
}
Also used : Mutation(com.google.bigtable.v2.Mutation) Test(org.junit.Test)

Example 4 with Mutation

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);
}
Also used : TSerializer(org.apache.thrift.TSerializer) TDeserializer(org.apache.thrift.TDeserializer) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) Mutation(com.airbnb.jitney.event.spinaltap.v1.Mutation) Test(org.junit.Test)

Example 5 with Mutation

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);
}
Also used : MutateRowRequest(com.google.bigtable.v2.MutateRowRequest) Mutation(com.google.bigtable.v2.Mutation)

Aggregations

Test (org.junit.Test)19 Mutation (com.google.bigtable.v2.Mutation)13 Mutation (com.google.datastore.v1.Mutation)7 Mutation (com.airbnb.jitney.event.spinaltap.v1.Mutation)5 ByteString (com.google.protobuf.ByteString)5 ArrayList (java.util.ArrayList)5 MysqlUpdateMutation (com.airbnb.spinaltap.mysql.mutation.MysqlUpdateMutation)4 Key (com.google.datastore.v1.Key)4 DatastoreHelper.makeKey (com.google.datastore.v1.client.DatastoreHelper.makeKey)4 MysqlDeleteMutation (com.airbnb.spinaltap.mysql.mutation.MysqlDeleteMutation)3 MysqlInsertMutation (com.airbnb.spinaltap.mysql.mutation.MysqlInsertMutation)3 MysqlMutation (com.airbnb.spinaltap.mysql.mutation.MysqlMutation)3 CommitRequest (com.google.datastore.v1.CommitRequest)3 Entity (com.google.datastore.v1.Entity)3 DatastoreWriterFn (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.DatastoreWriterFn)3 DeleteEntity (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.DeleteEntity)3 DeleteKey (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.DeleteKey)3 DatastoreV1.isValidKey (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.isValidKey)3 KV (org.apache.beam.sdk.values.KV)3 MysqlMutationMetadata (com.airbnb.spinaltap.mysql.mutation.MysqlMutationMetadata)2