Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for table deletion protection #2430

Merged
merged 7 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
styling fix
  • Loading branch information
adashyan committed Nov 21, 2024
commit ff5dd5b92963e9bab4b855d304c3f45a33447eb2
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ public CreateTableRequest setDeletionProtection(boolean deletionProtection) {
return this;
}


@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ public boolean equals(Object o) {
@Override
public int hashCode() {
return Objects.hashCode(
id, instanceId, replicationStatesByClusterId, columnFamilies, changeStreamRetention, deletionProtection);
id,
instanceId,
replicationStatesByClusterId,
columnFamilies,
changeStreamRetention,
deletionProtection);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -305,32 +305,32 @@ public void testCreateTableWithDeletionProtectionSet() {
Mockito.when(mockStub.createTableCallable()).thenReturn(mockCreateTableCallable);

com.google.bigtable.admin.v2.CreateTableRequest expectedRequest =
com.google.bigtable.admin.v2.CreateTableRequest.newBuilder()
.setParent(INSTANCE_NAME)
.setTableId(TABLE_ID)
.setTable(
com.google.bigtable.admin.v2.Table.newBuilder()
.setDeletionProtection(true)
.putColumnFamilies(
"cf1",
ColumnFamily.newBuilder()
.setGcRule(GcRule.getDefaultInstance())
.setValueType(TypeProtos.intSumType())
.build()))
.build();
com.google.bigtable.admin.v2.CreateTableRequest.newBuilder()
.setParent(INSTANCE_NAME)
.setTableId(TABLE_ID)
.setTable(
com.google.bigtable.admin.v2.Table.newBuilder()
.setDeletionProtection(true)
.putColumnFamilies(
"cf1",
ColumnFamily.newBuilder()
.setGcRule(GcRule.getDefaultInstance())
.setValueType(TypeProtos.intSumType())
.build()))
.build();

com.google.bigtable.admin.v2.Table expectedResponse =
com.google.bigtable.admin.v2.Table.newBuilder().setName(TABLE_NAME).build();
com.google.bigtable.admin.v2.Table.newBuilder().setName(TABLE_NAME).build();

Mockito.when(mockCreateTableCallable.futureCall(expectedRequest))
.thenReturn(ApiFutures.immediateFuture(expectedResponse));
.thenReturn(ApiFutures.immediateFuture(expectedResponse));

// Execute
Table result =
adminClient.createTable(
CreateTableRequest.of(TABLE_ID)
.addFamily("cf1", Type.int64Sum())
.setDeletionProtection(true));
adminClient.createTable(
CreateTableRequest.of(TABLE_ID)
.addFamily("cf1", Type.int64Sum())
.setDeletionProtection(true));

// Verify
assertThat(result).isEqualTo(Table.fromProto(expectedResponse));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void testFromProto() {
.setSeconds(1)
.setNanos(99)))
.build())
.setDeletionProtection(true)
.setDeletionProtection(true)
.build();

Table result = Table.fromProto(proto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,30 +84,32 @@ public void testNoChangeChangeStreamToProto() {

@Test
public void testEnableDeletionProtection() {
UpdateTableRequest request =
UpdateTableRequest.of(TABLE_ID).setDeletionProtection(true);
UpdateTableRequest request = UpdateTableRequest.of(TABLE_ID).setDeletionProtection(true);

com.google.bigtable.admin.v2.UpdateTableRequest requestProto =
com.google.bigtable.admin.v2.UpdateTableRequest.newBuilder()
.setTable(Table.newBuilder().setName(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID))
.setDeletionProtection(true))
.setUpdateMask(FieldMask.newBuilder().addPaths("deletion_protection").build())
.build();
com.google.bigtable.admin.v2.UpdateTableRequest.newBuilder()
.setTable(
Table.newBuilder()
.setName(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID))
.setDeletionProtection(true))
.setUpdateMask(FieldMask.newBuilder().addPaths("deletion_protection").build())
.build();

assertThat(request.toProto(PROJECT_ID, INSTANCE_ID)).isEqualTo(requestProto);
}

@Test
public void testDisableDeletionProtection() {
UpdateTableRequest request =
UpdateTableRequest.of(TABLE_ID).setDeletionProtection(false);
UpdateTableRequest request = UpdateTableRequest.of(TABLE_ID).setDeletionProtection(false);

com.google.bigtable.admin.v2.UpdateTableRequest requestProto =
com.google.bigtable.admin.v2.UpdateTableRequest.newBuilder()
.setTable(Table.newBuilder().setName(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID))
.setDeletionProtection(false))
.setUpdateMask(FieldMask.newBuilder().addPaths("deletion_protection").build())
.build();
com.google.bigtable.admin.v2.UpdateTableRequest.newBuilder()
.setTable(
Table.newBuilder()
.setName(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID))
.setDeletionProtection(false))
.setUpdateMask(FieldMask.newBuilder().addPaths("deletion_protection").build())
.build();

assertThat(request.toProto(PROJECT_ID, INSTANCE_ID)).isEqualTo(requestProto);
}
Expand All @@ -117,8 +119,8 @@ public void testHashCodeWithDeleteProtection() {
UpdateTableRequest request = UpdateTableRequest.of(TABLE_ID).setDeletionProtection(true);

assertThat(request.hashCode())
.isEqualTo(UpdateTableRequest.of(TABLE_ID).setDeletionProtection(true).hashCode());
.isEqualTo(UpdateTableRequest.of(TABLE_ID).setDeletionProtection(true).hashCode());
assertThat(request.hashCode())
.isNotEqualTo(UpdateTableRequest.of(TABLE_ID).setDeletionProtection(false).hashCode());
.isNotEqualTo(UpdateTableRequest.of(TABLE_ID).setDeletionProtection(false).hashCode());
}
}
Loading