| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 99b1089 commit 4fc58e6
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -123,6 +123,12 @@ public CreateTableRequest addChangeStreamRetention(Duration retention) { | |||
| 123 | 123 | return this; | |
| 124 | 124 | } | |
| 125 | 125 | ||
| 126 | + /** Configures if the table is deletion protected. */ | ||
| 127 | + public CreateTableRequest setDeletionProtection(boolean deletionProtection) { | ||
| 128 | + requestBuilder.getTableBuilder().setDeletionProtection(deletionProtection); | ||
| 129 | + return this; | ||
| 130 | + } | ||
| 131 | + | ||
| 126 | 132 | @Override | |
| 127 | 133 | public boolean equals(Object o) { | |
| 128 | 134 | if (this == o) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -105,6 +105,7 @@ public com.google.bigtable.admin.v2.Table.ClusterState.ReplicationState toProto( | |||
| 105 | 105 | private final List<ColumnFamily> columnFamilies; | |
| 106 | 106 | ||
| 107 | 107 | private final Duration changeStreamRetention; | |
| 108 | + private final boolean deletionProtection; | ||
| 108 | 109 | ||
| 109 | 110 | @InternalApi | |
| 110 | 111 | public static Table fromProto(@Nonnull com.google.bigtable.admin.v2.Table proto) { | |
@@ -135,19 +136,22 @@ public static Table fromProto(@Nonnull com.google.bigtable.admin.v2.Table proto) | |||
| 135 | 136 | TableName.parse(proto.getName()), | |
| 136 | 137 | replicationStates.build(), | |
| 137 | 138 | columnFamilies.build(), | |
| 138 | - changeStreamConfig); | ||
| 139 | + changeStreamConfig, | ||
| 140 | + proto.getDeletionProtection()); | ||
| 139 | 141 | } | |
| 140 | 142 | ||
| 141 | 143 | private Table( | |
| 142 | 144 | TableName tableName, | |
| 143 | 145 | Map<String, ReplicationState> replicationStatesByClusterId, | |
| 144 | 146 | List<ColumnFamily> columnFamilies, | |
| 145 | - Duration changeStreamRetention) { | ||
| 147 | + Duration changeStreamRetention, | ||
| 148 | + boolean deletionProtection) { | ||
| 146 | 149 | this.instanceId = tableName.getInstance(); | |
| 147 | 150 | this.id = tableName.getTable(); | |
| 148 | 151 | this.replicationStatesByClusterId = replicationStatesByClusterId; | |
| 149 | 152 | this.columnFamilies = columnFamilies; | |
| 150 | 153 | this.changeStreamRetention = changeStreamRetention; | |
| 154 | + this.deletionProtection = deletionProtection; | ||
| 151 | 155 | } | |
| 152 | 156 | ||
| 153 | 157 | /** Gets the table's id. */ | |
@@ -172,6 +176,11 @@ public Duration getChangeStreamRetention() { | |||
| 172 | 176 | return changeStreamRetention; | |
| 173 | 177 | } | |
| 174 | 178 | ||
| 179 | + /** Returns whether this table is deletion protected. */ | ||
| 180 | + public boolean isDeletionProtected() { | ||
| 181 | + return deletionProtection; | ||
| 182 | + } | ||
| 183 | + | ||
| 175 | 184 | @Override | |
| 176 | 185 | public boolean equals(Object o) { | |
| 177 | 186 | if (this == o) { | |
@@ -185,12 +194,18 @@ public boolean equals(Object o) { | |||
| 185 | 194 | && Objects.equal(instanceId, table.instanceId) | |
| 186 | 195 | && Objects.equal(replicationStatesByClusterId, table.replicationStatesByClusterId) | |
| 187 | 196 | && Objects.equal(columnFamilies, table.columnFamilies) | |
| 188 | - && Objects.equal(changeStreamRetention, table.changeStreamRetention); | ||
| 197 | + && Objects.equal(changeStreamRetention, table.changeStreamRetention) | ||
| 198 | + && Objects.equal(deletionProtection, table.deletionProtection); | ||
| 189 | 199 | } | |
| 190 | 200 | ||
| 191 | 201 | @Override | |
| 192 | 202 | public int hashCode() { | |
| 193 | 203 | return Objects.hashCode( | |
| 194 | - id, instanceId, replicationStatesByClusterId, columnFamilies, changeStreamRetention); | ||
| 204 | + id, | ||
| 205 | + instanceId, | ||
| 206 | + replicationStatesByClusterId, | ||
| 207 | + columnFamilies, | ||
| 208 | + changeStreamRetention, | ||
| 209 | + deletionProtection); | ||
| 195 | 210 | } | |
| 196 | 211 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -74,6 +74,13 @@ public UpdateTableRequest disableChangeStreamRetention() { | |||
| 74 | 74 | return addChangeStreamRetention(Duration.ZERO); | |
| 75 | 75 | } | |
| 76 | 76 | ||
| 77 | + /** Changes the deletion protection of an existing table. */ | ||
| 78 | + public UpdateTableRequest setDeletionProtection(boolean deletionProtection) { | ||
| 79 | + requestBuilder.getTableBuilder().setDeletionProtection(deletionProtection); | ||
| 80 | + requestBuilder.getUpdateMaskBuilder().addPaths("deletion_protection"); | ||
| 81 | + return this; | ||
| 82 | + } | ||
| 83 | + | ||
| 77 | 84 | @InternalApi | |
| 78 | 85 | public com.google.bigtable.admin.v2.UpdateTableRequest toProto( | |
| 79 | 86 | String projectId, String instanceId) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -299,6 +299,43 @@ public void testCreateTable() { | |||
| 299 | 299 | assertThat(result).isEqualTo(Table.fromProto(expectedResponse)); | |
| 300 | 300 | } | |
| 301 | 301 | ||
| 302 | + @Test | ||
| 303 | + public void testCreateTableWithDeletionProtectionSet() { | ||
| 304 | + // Setup | ||
| 305 | + Mockito.when(mockStub.createTableCallable()).thenReturn(mockCreateTableCallable); | ||
| 306 | + | ||
| 307 | + com.google.bigtable.admin.v2.CreateTableRequest expectedRequest = | ||
| 308 | + com.google.bigtable.admin.v2.CreateTableRequest.newBuilder() | ||
| 309 | + .setParent(INSTANCE_NAME) | ||
| 310 | + .setTableId(TABLE_ID) | ||
| 311 | + .setTable( | ||
| 312 | + com.google.bigtable.admin.v2.Table.newBuilder() | ||
| 313 | + .setDeletionProtection(true) | ||
| 314 | + .putColumnFamilies( | ||
| 315 | + "cf1", | ||
| 316 | + ColumnFamily.newBuilder() | ||
| 317 | + .setGcRule(GcRule.getDefaultInstance()) | ||
| 318 | + .setValueType(TypeProtos.intSumType()) | ||
| 319 | + .build())) | ||
| 320 | + .build(); | ||
| 321 | + | ||
| 322 | + com.google.bigtable.admin.v2.Table expectedResponse = | ||
| 323 | + com.google.bigtable.admin.v2.Table.newBuilder().setName(TABLE_NAME).build(); | ||
| 324 | + | ||
| 325 | + Mockito.when(mockCreateTableCallable.futureCall(expectedRequest)) | ||
| 326 | + .thenReturn(ApiFutures.immediateFuture(expectedResponse)); | ||
| 327 | + | ||
| 328 | + // Execute | ||
| 329 | + Table result = | ||
| 330 | + adminClient.createTable( | ||
| 331 | + CreateTableRequest.of(TABLE_ID) | ||
| 332 | + .addFamily("cf1", Type.int64Sum()) | ||
| 333 | + .setDeletionProtection(true)); | ||
| 334 | + | ||
| 335 | + // Verify | ||
| 336 | + assertThat(result).isEqualTo(Table.fromProto(expectedResponse)); | ||
| 337 | + } | ||
| 338 | + | ||
| 302 | 339 | @Test | |
| 303 | 340 | public void testUpdateTable() { | |
| 304 | 341 | // Setup | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -48,7 +48,8 @@ public void testToProto() { | |||
| 48 | 48 | .addFamily("another-family", GCRULES.maxAge(100, TimeUnit.HOURS)) | |
| 49 | 49 | .addSplit(splitKey) | |
| 50 | 50 | .addSplit(secondSplitKey) | |
| 51 | - .addChangeStreamRetention(Duration.ofHours(24)); | ||
| 51 | + .addChangeStreamRetention(Duration.ofHours(24)) | ||
| 52 | + .setDeletionProtection(true); | ||
| 52 | 53 | ||
| 53 | 54 | com.google.bigtable.admin.v2.CreateTableRequest requestProto = | |
| 54 | 55 | com.google.bigtable.admin.v2.CreateTableRequest.newBuilder() | |
@@ -70,7 +71,8 @@ public void testToProto() { | |||
| 70 | 71 | ChangeStreamConfig.newBuilder() | |
| 71 | 72 | .setRetentionPeriod( | |
| 72 | 73 | com.google.protobuf.Duration.newBuilder().setSeconds(86400)) | |
| 73 | - .build())) | ||
| 74 | + .build()) | ||
| 75 | + .setDeletionProtection(true)) | ||
| 74 | 76 | .setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)) | |
| 75 | 77 | .addInitialSplits( | |
| 76 | 78 | com.google.bigtable.admin.v2.CreateTableRequest.Split.newBuilder().setKey(splitKey)) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -67,6 +67,7 @@ public void testFromProto() { | |||
| 67 | 67 | .setSeconds(1) | |
| 68 | 68 | .setNanos(99))) | |
| 69 | 69 | .build()) | |
| 70 | + .setDeletionProtection(true) | ||
| 70 | 71 | .build(); | |
| 71 | 72 | ||
| 72 | 73 | Table result = Table.fromProto(proto); | |
@@ -78,6 +79,7 @@ public void testFromProto() { | |||
| 78 | 79 | "cluster1", Table.ReplicationState.READY, | |
| 79 | 80 | "cluster2", Table.ReplicationState.INITIALIZING); | |
| 80 | 81 | assertThat(result.getColumnFamilies()).hasSize(3); | |
| 82 | + assertThat(result.isDeletionProtected()).isTrue(); | ||
| 81 | 83 | ||
| 82 | 84 | for (Entry<String, ColumnFamily> entry : proto.getColumnFamiliesMap().entrySet()) { | |
| 83 | 85 | assertThat(result.getColumnFamilies()) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -81,4 +81,36 @@ public void testNoChangeChangeStreamToProto() { | |||
| 81 | 81 | .build(); | |
| 82 | 82 | assertThat(request.toProto(PROJECT_ID, INSTANCE_ID)).isEqualTo(requestProto); | |
| 83 | 83 | } | |
| 84 | + | ||
| 85 | + @Test | ||
| 86 | + public void testEnableDeletionProtection() { | ||
| 87 | + UpdateTableRequest request = UpdateTableRequest.of(TABLE_ID).setDeletionProtection(true); | ||
| 88 | + | ||
| 89 | + com.google.bigtable.admin.v2.UpdateTableRequest requestProto = | ||
| 90 | + com.google.bigtable.admin.v2.UpdateTableRequest.newBuilder() | ||
| 91 | + .setTable( | ||
| 92 | + Table.newBuilder() | ||
| 93 | + .setName(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID)) | ||
| 94 | + .setDeletionProtection(true)) | ||
| 95 | + .setUpdateMask(FieldMask.newBuilder().addPaths("deletion_protection").build()) | ||
| 96 | + .build(); | ||
| 97 | + | ||
| 98 | + assertThat(request.toProto(PROJECT_ID, INSTANCE_ID)).isEqualTo(requestProto); | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + @Test | ||
| 102 | + public void testDisableDeletionProtection() { | ||
| 103 | + UpdateTableRequest request = UpdateTableRequest.of(TABLE_ID).setDeletionProtection(false); | ||
| 104 | + | ||
| 105 | + com.google.bigtable.admin.v2.UpdateTableRequest requestProto = | ||
| 106 | + com.google.bigtable.admin.v2.UpdateTableRequest.newBuilder() | ||
| 107 | + .setTable( | ||
| 108 | + Table.newBuilder() | ||
| 109 | + .setName(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID)) | ||
| 110 | + .setDeletionProtection(false)) | ||
| 111 | + .setUpdateMask(FieldMask.newBuilder().addPaths("deletion_protection").build()) | ||
| 112 | + .build(); | ||
| 113 | + | ||
| 114 | + assertThat(request.toProto(PROJECT_ID, INSTANCE_ID)).isEqualTo(requestProto); | ||
| 115 | + } | ||
| 84 | 116 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments