use of com.google.bigtable.v2.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());
}
use of com.google.bigtable.v2.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());
}
use of com.google.bigtable.v2.Mutation in project beam by apache.
the class DatastoreV1Test method testDeleteEntities.
/**
* Test that entities with valid keys are transformed to delete mutations.
*/
@Test
public void testDeleteEntities() throws Exception {
Key key = makeKey("bird", "finch").build();
Entity entity = Entity.newBuilder().setKey(key).build();
DeleteEntityFn deleteEntityFn = new DeleteEntityFn();
Mutation expectedMutation = makeDelete(entity.getKey()).build();
assertEquals(expectedMutation, deleteEntityFn.apply(entity));
}
use of com.google.bigtable.v2.Mutation in project beam by apache.
the class DatastoreV1Test method testDatatoreWriterFnWithLargeEntities.
/**
* Tests {@link DatastoreWriterFn} with large entities that need to be split into more batches.
*/
@Test
public void testDatatoreWriterFnWithLargeEntities() throws Exception {
List<Mutation> mutations = new ArrayList<>();
int entitySize = 0;
for (int i = 0; i < 12; ++i) {
Entity entity = Entity.newBuilder().setKey(makeKey("key" + i, i + 1)).putProperties("long", makeValue(new String(new char[900_000])).setExcludeFromIndexes(true).build()).build();
// Take the size of any one entity.
entitySize = entity.getSerializedSize();
mutations.add(makeUpsert(entity).build());
}
DatastoreWriterFn datastoreWriter = new DatastoreWriterFn(StaticValueProvider.of(PROJECT_ID), null, mockDatastoreFactory, new FakeWriteBatcher());
DoFnTester<Mutation, Void> doFnTester = DoFnTester.of(datastoreWriter);
doFnTester.setCloningBehavior(CloningBehavior.DO_NOT_CLONE);
doFnTester.processBundle(mutations);
// This test is over-specific currently; it requires that we split the 12 entity writes into 3
// requests, but we only need each CommitRequest to be less than 10MB in size.
int entitiesPerRpc = DATASTORE_BATCH_UPDATE_BYTES_LIMIT / entitySize;
int start = 0;
while (start < mutations.size()) {
int end = Math.min(mutations.size(), start + entitiesPerRpc);
CommitRequest.Builder commitRequest = CommitRequest.newBuilder();
commitRequest.setMode(CommitRequest.Mode.NON_TRANSACTIONAL);
commitRequest.addAllMutations(mutations.subList(start, end));
// Verify all the batch requests were made with the expected mutations.
verify(mockDatastore).commit(commitRequest.build());
start = end;
}
}
use of com.google.bigtable.v2.Mutation in project beam by apache.
the class BigtableIOTest method testWritingFailsTableDoesNotExist.
/**
* Tests that when writing to a non-existent table, the write fails.
*/
@Test
public void testWritingFailsTableDoesNotExist() throws Exception {
final String table = "TEST-TABLE";
PCollection<KV<ByteString, Iterable<Mutation>>> emptyInput = p.apply(Create.empty(KvCoder.of(ByteStringCoder.of(), IterableCoder.of(ProtoCoder.of(Mutation.class)))));
// Exception will be thrown by write.validate() when writeToDynamic is applied.
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(String.format("Table %s does not exist", table));
emptyInput.apply("write", defaultWrite.withTableId(table));
p.run();
}
Aggregations