Search in sources :

Example 16 with Mutation

use of com.airbnb.jitney.event.spinaltap.v1.Mutation in project simple-bigtable by spotify.

the class BigtableMutationImplTest method testDeleteColumnFamily.

@Test
public void testDeleteColumnFamily() throws Exception {
    final BigtableMutationImpl bigtableMutationImpl = (BigtableMutationImpl) this.bigtableMutation.deleteColumnFamily("family");
    verifyGetMutateRowRequest();
    bigtableMutationImpl.execute();
    bigtableMutationImpl.executeAsync();
    assertEquals(1, bigtableMutationImpl.getMutateRowRequest().getMutationsCount());
    final Mutation mutation = bigtableMutationImpl.getMutateRowRequest().getMutations(0);
    assertEquals(Mutation.MutationCase.DELETE_FROM_FAMILY, mutation.getMutationCase());
    assertEquals("family", mutation.getDeleteFromFamily().getFamilyName());
    assertEquals(Mutation.DeleteFromRow.getDefaultInstance(), mutation.getDeleteFromRow());
    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 17 with Mutation

use of com.airbnb.jitney.event.spinaltap.v1.Mutation in project simple-bigtable by spotify.

the class BigtableMutationImplTest method testDeleteCellsFromColumn.

@Test
public void testDeleteCellsFromColumn() throws Exception {
    final BigtableMutationImpl bigtableMutationImpl = (BigtableMutationImpl) this.bigtableMutation.deleteCellsFromColumn("family", "qualifier", Optional.empty(), Optional.empty()).deleteCellsFromColumn("family", "qualifier", Optional.of(100L), Optional.of(999L));
    verifyGetMutateRowRequest();
    bigtableMutationImpl.execute();
    bigtableMutationImpl.executeAsync();
    assertEquals(2, bigtableMutationImpl.getMutateRowRequest().getMutationsCount());
    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(TimestampRange.getDefaultInstance(), mutation.getDeleteFromColumn().getTimeRange());
    assertEquals(Mutation.DeleteFromRow.getDefaultInstance(), mutation.getDeleteFromRow());
    assertEquals(Mutation.DeleteFromFamily.getDefaultInstance(), mutation.getDeleteFromFamily());
    assertEquals(Mutation.SetCell.getDefaultInstance(), mutation.getSetCell());
    mutation = bigtableMutationImpl.getMutateRowRequest().getMutations(1);
    assertEquals(Mutation.MutationCase.DELETE_FROM_COLUMN, mutation.getMutationCase());
    assertEquals("family", mutation.getDeleteFromColumn().getFamilyName());
    assertEquals("qualifier", mutation.getDeleteFromColumn().getColumnQualifier().toStringUtf8());
    assertEquals(100L, mutation.getDeleteFromColumn().getTimeRange().getStartTimestampMicros());
    assertEquals(999L, mutation.getDeleteFromColumn().getTimeRange().getEndTimestampMicros());
    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 18 with Mutation

use of com.airbnb.jitney.event.spinaltap.v1.Mutation in project SpinalTap by airbnb.

the class UpdateMutationMapper method map.

public Mutation map(MysqlUpdateMutation mutation) {
    MysqlMutationMetadata metadata = mutation.getMetadata();
    Mutation thriftMutation = new Mutation(MutationType.UPDATE, metadata.getTimestamp(), sourceId, metadata.getDataSource().getThriftDataSource(), createBinlogHeader(metadata, mutation.getType().getCode()), metadata.getTable().getThriftTable(), transformToEntity(mutation.getRow()));
    thriftMutation.setPreviousEntity(transformToEntity(mutation.getPreviousRow()));
    return thriftMutation;
}
Also used : MysqlMutationMetadata(com.airbnb.spinaltap.mysql.mutation.MysqlMutationMetadata) Mutation(com.airbnb.jitney.event.spinaltap.v1.Mutation) MysqlUpdateMutation(com.airbnb.spinaltap.mysql.mutation.MysqlUpdateMutation)

Example 19 with Mutation

use of com.airbnb.jitney.event.spinaltap.v1.Mutation in project SpinalTap by airbnb.

the class KafkaDestinationTest method KafkaDestination.

@Test
public void KafkaDestination() throws Exception {
    createKafkaTopic(TOPIC);
    KafkaProducerConfiguration configs = new KafkaProducerConfiguration(this.bootstrapServers());
    KafkaDestination kafkaDestination = new KafkaDestination(null, configs, null, null, 0L);
    List<Mutation> messages = new ArrayList<>();
    messages.add(createMutation(MutationType.INSERT));
    messages.add(createMutation(MutationType.UPDATE));
    messages.add(createMutation(MutationType.DELETE));
    kafkaDestination.publish(messages);
    Properties props = new Properties();
    props.setProperty("bootstrap.servers", this.bootstrapServers());
    props.setProperty("key.deserializer", "org.apache.kafka.common.serialization.ByteArrayDeserializer");
    props.setProperty("value.deserializer", "org.apache.kafka.common.serialization.ByteArrayDeserializer");
    KafkaConsumer<byte[], byte[]> kafkaConsumer = new KafkaConsumer<>(props);
    kafkaConsumer.assign(Collections.singletonList(new TopicPartition(TOPIC, 0)));
    kafkaConsumer.seekToBeginning(new TopicPartition(TOPIC, 0));
    List<ConsumerRecords<byte[], byte[]>> records = new ArrayList<>();
    ConsumerRecords<byte[], byte[]> record;
    long startMs = current();
    while (current() - startMs <= 10000L) {
        record = kafkaConsumer.poll(1000L);
        records.add(record);
        if (records.size() == 3)
            break;
    }
    Assert.assertEquals(records.size(), 3);
    for (ConsumerRecords<byte[], byte[]> consumerRecords : records) {
        for (ConsumerRecord<byte[], byte[]> consumerRecord : consumerRecords) {
            com.airbnb.jitney.event.spinaltap.v1.Mutation mutation = getMutation(consumerRecord.value());
            switch(mutation.getType()) {
                case INSERT:
                    Assert.assertEquals(mutation, createMutation(MutationType.INSERT));
                    break;
                case UPDATE:
                    Assert.assertEquals(mutation, createMutation(MutationType.UPDATE));
                    break;
                case DELETE:
                    Assert.assertEquals(mutation, createMutation(MutationType.DELETE));
                    break;
            }
        }
    }
    kafkaDestination.close();
    kafkaConsumer.close();
}
Also used : Mutation(com.airbnb.jitney.event.spinaltap.v1.Mutation) ArrayList(java.util.ArrayList) KafkaConsumer(org.apache.kafka.clients.consumer.KafkaConsumer) Properties(java.util.Properties) ConsumerRecords(org.apache.kafka.clients.consumer.ConsumerRecords) TopicPartition(org.apache.kafka.common.TopicPartition) MysqlUpdateMutation(com.airbnb.spinaltap.mysql.mutation.MysqlUpdateMutation) Mutation(com.airbnb.jitney.event.spinaltap.v1.Mutation) MysqlMutation(com.airbnb.spinaltap.mysql.mutation.MysqlMutation) MysqlDeleteMutation(com.airbnb.spinaltap.mysql.mutation.MysqlDeleteMutation) MysqlInsertMutation(com.airbnb.spinaltap.mysql.mutation.MysqlInsertMutation) Test(org.junit.Test)

Example 20 with Mutation

use of com.airbnb.jitney.event.spinaltap.v1.Mutation in project SpinalTap by airbnb.

the class KafkaDestinationTest method createMutation.

private Mutation createMutation(MutationType type) {
    Mapper<com.airbnb.spinaltap.Mutation<?>, ? extends TBase<?, ?>> thriftMutationMapper = ThriftMutationMapper.create("spinaltap");
    Table table = new Table(0L, TABLE, DATABASE, ImmutableList.of(new ColumnMetadata("id", ColumnDataType.LONGLONG, true, 0)), ImmutableList.of("id"));
    MysqlMutationMetadata metadata = new MysqlMutationMetadata(new DataSource(HOSTNAME, 0, "service"), new BinlogFilePos(), table, 0L, 0L, 0L, null, null, 0L, 0);
    Row row = new Row(table, ImmutableMap.of("id", new Column(new ColumnMetadata("id", ColumnDataType.LONGLONG, true, 0), 1L)));
    MysqlMutation mutation;
    switch(type) {
        case INSERT:
            mutation = new MysqlInsertMutation(metadata, row);
            break;
        case UPDATE:
            mutation = new MysqlUpdateMutation(metadata, row, row);
            break;
        case DELETE:
            mutation = new MysqlDeleteMutation(metadata, row);
            break;
        default:
            mutation = null;
    }
    return (Mutation) (thriftMutationMapper.map(mutation));
}
Also used : MysqlDeleteMutation(com.airbnb.spinaltap.mysql.mutation.MysqlDeleteMutation) ColumnMetadata(com.airbnb.spinaltap.mysql.mutation.schema.ColumnMetadata) MysqlMutationMetadata(com.airbnb.spinaltap.mysql.mutation.MysqlMutationMetadata) Table(com.airbnb.spinaltap.mysql.mutation.schema.Table) MysqlUpdateMutation(com.airbnb.spinaltap.mysql.mutation.MysqlUpdateMutation) DataSource(com.airbnb.spinaltap.mysql.DataSource) MysqlMutation(com.airbnb.spinaltap.mysql.mutation.MysqlMutation) Column(com.airbnb.spinaltap.mysql.mutation.schema.Column) MysqlInsertMutation(com.airbnb.spinaltap.mysql.mutation.MysqlInsertMutation) BinlogFilePos(com.airbnb.spinaltap.mysql.BinlogFilePos) MysqlUpdateMutation(com.airbnb.spinaltap.mysql.mutation.MysqlUpdateMutation) Mutation(com.airbnb.jitney.event.spinaltap.v1.Mutation) MysqlMutation(com.airbnb.spinaltap.mysql.mutation.MysqlMutation) MysqlDeleteMutation(com.airbnb.spinaltap.mysql.mutation.MysqlDeleteMutation) MysqlInsertMutation(com.airbnb.spinaltap.mysql.mutation.MysqlInsertMutation) Row(com.airbnb.spinaltap.mysql.mutation.schema.Row)

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