Skip to content

Commit

Permalink
Fix googleapis#3637 Bigtable RowMutation should allow passing of a Mu…
Browse files Browse the repository at this point in the history
…tation
  • Loading branch information
ajaaym committed Sep 5, 2018
1 parent c81ff3e commit 02e68a3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ private RowMutation(String tableId, ByteString key) {
this.mutation = Mutation.create();
}

private RowMutation(String tableId, ByteString key, Mutation mutation) {
this.tableId = tableId;
this.key = key;
this.mutation = mutation;
}

public static RowMutation create(@Nonnull String tableId, @Nonnull String key) {
return create(tableId, ByteString.copyFromUtf8(key));
}
Expand All @@ -51,6 +57,14 @@ public static RowMutation create(@Nonnull String tableId, @Nonnull ByteString ke
return new RowMutation(tableId, key);
}

public static RowMutation create(@Nonnull String tableId, @Nonnull String key, Mutation mutation) {
return create(tableId, ByteString.copyFromUtf8(key), mutation);
}

public static RowMutation create(@Nonnull String tableId, @Nonnull ByteString key, Mutation mutation) {
return new RowMutation(tableId, key, mutation);
}

@Override
public RowMutation setCell(
@Nonnull String familyName, @Nonnull String qualifier, @Nonnull String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,32 @@ public void toBulkProtoTest() {
.isIn(timestampRange);
}

@Test
public void toProtoTestWithProvidedMutation() {
long timestampMin = System.currentTimeMillis() * 1_000;

Mutation mutation = Mutation.create().setCell("fake-family", "fake-qualifier", "fake-value");
RowMutation rowMutation = RowMutation.create("fake-table", "fake-key", mutation);

MutateRowsRequest actualRowMutation = rowMutation.toBulkProto(REQUEST_CONTEXT);

com.google.common.collect.Range<Long> timestampRange =
com.google.common.collect.Range.closed(timestampMin, System.currentTimeMillis() * 1_000);

assertThat(actualRowMutation.getTableName())
.isEqualTo(
TableName.of(INSTANCE_NAME.getProject(), INSTANCE_NAME.getInstance(), "fake-table")
.toString());
assertThat(actualRowMutation.getAppProfileId()).isEqualTo(APP_PROFILE_ID);
assertThat(actualRowMutation.getEntriesList()).hasSize(1);
assertThat(actualRowMutation.getEntries(0).getMutationsList()).hasSize(1);
assertThat(actualRowMutation.getEntries(0).getMutations(0).getSetCell().getValue())
.isEqualTo(ByteString.copyFromUtf8("fake-value"));

assertThat(actualRowMutation.getEntries(0).getMutations(0).getSetCell().getTimestampMicros())
.isIn(timestampRange);
}

@Test
public void serializationTest() throws IOException, ClassNotFoundException {
RowMutation expected =
Expand Down

0 comments on commit 02e68a3

Please sign in to comment.