Skip to content

Commit 58692cb

Browse files
rahulKQLsduskis
authored andcommitted
---
yaml --- r: 32373 b: refs/heads/autosynth-errorreporting c: cc54764 h: refs/heads/master i: 32371: 5c42e5e
1 parent 2cf3acd commit 58692cb

4 files changed

Lines changed: 123 additions & 18 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ refs/heads/autosynth-bigtable-admin: 6379a2bc712f2736c83de0e009b4d26da4fa82ca
129129
refs/heads/autosynth-containeranalysis: 18d210f81f17cf74864d0db2c29e834302f74f2a
130130
refs/heads/autosynth-datastore: f1efc3dc465174f41041acd56cf29badcec3e5bd
131131
refs/heads/autosynth-dialogflow: 73974cc32e5212aec0126472e0bc1442886fedaf
132-
refs/heads/autosynth-errorreporting: 57ac06ab786d6227c8200fc547445b3bfe5c5228
132+
refs/heads/autosynth-errorreporting: cc547642f3dd4b5f2420d350adda216e87de5877
133133
refs/heads/autosynth-firestore: 983c75e4fb1076502c8cac73ef0538bdb10884f3
134134
refs/heads/autosynth-iot: 4025d1804241e74d54950a324dc4f667aeaad4b3
135135
refs/heads/autosynth-kms: 6b65b0f34c12d141031c7288cdc01e550212d0f6

branches/autosynth-errorreporting/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateTableRequest.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import com.google.api.core.InternalApi;
1919
import com.google.bigtable.admin.v2.ColumnFamily;
20-
import com.google.bigtable.admin.v2.Table;
2120
import com.google.cloud.bigtable.admin.v2.internal.NameUtil;
2221
import com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule;
2322
import com.google.common.base.Objects;
@@ -38,10 +37,8 @@
3837
*/
3938
public final class CreateTableRequest {
4039
// TODO(igorbernstein): rename to requestBuilder
41-
private final com.google.bigtable.admin.v2.CreateTableRequest.Builder createTableRequest =
40+
private final com.google.bigtable.admin.v2.CreateTableRequest.Builder requestBuilder =
4241
com.google.bigtable.admin.v2.CreateTableRequest.newBuilder();
43-
// TODO(igorbernstein): use the embedded TableBuilder in createTableRequest
44-
private final Table.Builder tableRequest = Table.newBuilder();
4542

4643
public static CreateTableRequest of(String tableId) {
4744
return new CreateTableRequest(tableId);
@@ -53,7 +50,7 @@ public static CreateTableRequest of(String tableId) {
5350
* @param tableId
5451
*/
5552
private CreateTableRequest(String tableId) {
56-
createTableRequest.setTableId(tableId);
53+
requestBuilder.setTableId(tableId);
5754
}
5855

5956
/**
@@ -63,7 +60,7 @@ private CreateTableRequest(String tableId) {
6360
*/
6461
public CreateTableRequest addFamily(String familyId) {
6562
Preconditions.checkNotNull(familyId);
66-
tableRequest.putColumnFamilies(familyId, ColumnFamily.getDefaultInstance());
63+
requestBuilder.getTableBuilder().putColumnFamilies(familyId, ColumnFamily.getDefaultInstance());
6764
return this;
6865
}
6966

@@ -76,8 +73,9 @@ public CreateTableRequest addFamily(String familyId) {
7673
*/
7774
public CreateTableRequest addFamily(String familyId, GCRule gcRule) {
7875
Preconditions.checkNotNull(familyId);
79-
tableRequest.putColumnFamilies(
80-
familyId, ColumnFamily.newBuilder().setGcRule(gcRule.toProto()).build());
76+
requestBuilder
77+
.getTableBuilder()
78+
.putColumnFamilies(familyId, ColumnFamily.newBuilder().setGcRule(gcRule.toProto()).build());
8179
return this;
8280
}
8381

@@ -88,7 +86,7 @@ public CreateTableRequest addFamily(String familyId, GCRule gcRule) {
8886
*/
8987
public CreateTableRequest addSplit(ByteString key) {
9088
Preconditions.checkNotNull(key);
91-
createTableRequest.addInitialSplitsBuilder().setKey(key);
89+
requestBuilder.addInitialSplitsBuilder().setKey(key);
9290
return this;
9391
}
9492

@@ -101,13 +99,12 @@ public boolean equals(Object o) {
10199
return false;
102100
}
103101
CreateTableRequest that = (CreateTableRequest) o;
104-
return Objects.equal(createTableRequest, that.createTableRequest)
105-
&& Objects.equal(tableRequest, that.tableRequest);
102+
return Objects.equal(requestBuilder.build(), that.requestBuilder.build());
106103
}
107104

108105
@Override
109106
public int hashCode() {
110-
return Objects.hashCode(createTableRequest, tableRequest);
107+
return Objects.hashCode(requestBuilder.build());
111108
}
112109

113110
@InternalApi
@@ -116,9 +113,6 @@ public com.google.bigtable.admin.v2.CreateTableRequest toProto(
116113
Preconditions.checkNotNull(projectId);
117114
Preconditions.checkNotNull(instanceId);
118115

119-
return createTableRequest
120-
.setParent(NameUtil.formatInstanceName(projectId, instanceId))
121-
.setTable(tableRequest.build())
122-
.build();
116+
return requestBuilder.setParent(NameUtil.formatInstanceName(projectId, instanceId)).build();
123117
}
124118
}

branches/autosynth-errorreporting/google-cloud-clients/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ public void testCreateTable() {
115115
com.google.bigtable.admin.v2.CreateTableRequest.newBuilder()
116116
.setParent(INSTANCE_NAME)
117117
.setTableId(TABLE_ID)
118-
.setTable(com.google.bigtable.admin.v2.Table.getDefaultInstance())
119118
.build();
120119

121120
com.google.bigtable.admin.v2.Table expectedResponse =
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.cloud.bigtable.admin.v2.models;
17+
18+
import static com.google.cloud.bigtable.admin.v2.models.GCRules.GCRULES;
19+
import static com.google.common.truth.Truth.assertThat;
20+
21+
import com.google.bigtable.admin.v2.ColumnFamily;
22+
import com.google.bigtable.admin.v2.GcRule;
23+
import com.google.bigtable.admin.v2.Table;
24+
import com.google.cloud.bigtable.admin.v2.internal.NameUtil;
25+
import com.google.protobuf.ByteString;
26+
import java.util.concurrent.TimeUnit;
27+
import org.junit.Test;
28+
import org.junit.runner.RunWith;
29+
import org.junit.runners.JUnit4;
30+
import org.threeten.bp.Duration;
31+
32+
@RunWith(JUnit4.class)
33+
public class CreateTableRequestTest {
34+
35+
private static final String TABLE_ID = "my-table";
36+
private static final String PROJECT_ID = "my-project";
37+
private static final String INSTANCE_ID = "my-instance";
38+
private static final ByteString splitKey = ByteString.copyFromUtf8("first-split");
39+
40+
@Test
41+
public void testToProto() {
42+
ByteString secondSplitKey = ByteString.copyFromUtf8("second-split");
43+
44+
CreateTableRequest request =
45+
CreateTableRequest.of(TABLE_ID)
46+
.addFamily("family-id")
47+
.addFamily("another-family", GCRULES.maxAge(100, TimeUnit.HOURS))
48+
.addSplit(splitKey)
49+
.addSplit(secondSplitKey);
50+
51+
com.google.bigtable.admin.v2.CreateTableRequest requestProto =
52+
com.google.bigtable.admin.v2.CreateTableRequest.newBuilder()
53+
.setTableId(TABLE_ID)
54+
.setTable(
55+
Table.newBuilder()
56+
.putColumnFamilies("family-id", ColumnFamily.getDefaultInstance())
57+
.putColumnFamilies(
58+
"another-family",
59+
ColumnFamily.newBuilder()
60+
.setGcRule(
61+
GcRule.newBuilder()
62+
.setMaxAge(
63+
com.google.protobuf.Duration.newBuilder()
64+
.setSeconds(100 * 60 * 60))
65+
.build())
66+
.build()))
67+
.setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID))
68+
.addInitialSplits(
69+
com.google.bigtable.admin.v2.CreateTableRequest.Split.newBuilder().setKey(splitKey))
70+
.addInitialSplits(
71+
com.google.bigtable.admin.v2.CreateTableRequest.Split.newBuilder()
72+
.setKey(secondSplitKey))
73+
.build();
74+
assertThat(request.toProto(PROJECT_ID, INSTANCE_ID)).isEqualTo(requestProto);
75+
}
76+
77+
@Test
78+
public void testEquality() {
79+
CreateTableRequest request =
80+
CreateTableRequest.of(TABLE_ID)
81+
.addFamily("family-id")
82+
.addFamily("another-family", GCRULES.maxAge(100, TimeUnit.HOURS))
83+
.addSplit(splitKey);
84+
85+
assertThat(request)
86+
.isEqualTo(
87+
CreateTableRequest.of(TABLE_ID)
88+
.addFamily("family-id")
89+
.addFamily("another-family", GCRULES.maxAge(Duration.ofHours(100)))
90+
.addSplit(splitKey));
91+
92+
assertThat(request)
93+
.isNotEqualTo(
94+
CreateTableRequest.of(TABLE_ID)
95+
.addFamily("family-id")
96+
.addFamily("another-family")
97+
.addSplit(splitKey));
98+
}
99+
100+
@Test
101+
public void testHashCode() {
102+
CreateTableRequest request =
103+
CreateTableRequest.of(TABLE_ID).addFamily("family-id").addSplit(splitKey);
104+
105+
assertThat(request.hashCode())
106+
.isEqualTo(
107+
CreateTableRequest.of(TABLE_ID).addFamily("family-id").addSplit(splitKey).hashCode());
108+
109+
assertThat(request.hashCode())
110+
.isNotEqualTo(CreateTableRequest.of(TABLE_ID).addFamily("other-family").hashCode());
111+
}
112+
}

0 commit comments

Comments
 (0)