Skip to content

Commit 8ee4d33

Browse files
test: remove references to guava in the integration tests (#4271)
* test: remove references to guava in the integration tests This will pave the way for mixing and matching bigtable-hbase & hbase-client flavors Change-Id: I4836a5627a5e8673577db4051899a47e922cc7e6 * fix executor Change-Id: Ia6e9c1311239058f8efc006084407dda3d794cc8 * oops Change-Id: I3b6b8fe1708fa79278a8f67ae8c475c2a2d20109 * format Change-Id: Iee796f79e6e09fd1f5d1e2311fb235b22cdd8160
1 parent 5cadde6 commit 8ee4d33

File tree

17 files changed

+112
-117
lines changed

17 files changed

+112
-117
lines changed

bigtable-client-core-parent/bigtable-hbase-integration-tests-common/src/test/java/com/google/cloud/bigtable/hbase/AbstractTestBatch.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
import static org.junit.Assert.assertNull;
2121
import static org.junit.Assert.assertTrue;
2222

23-
import com.google.common.collect.ImmutableList;
2423
import java.io.IOException;
2524
import java.util.ArrayList;
2625
import java.util.Arrays;
26+
import java.util.Collections;
2727
import java.util.List;
2828
import java.util.Random;
2929
import org.apache.commons.lang.ArrayUtils;
@@ -429,14 +429,14 @@ public void testBatchWithNullAndEmptyElements() throws IOException {
429429
actualError = null;
430430

431431
try {
432-
table.batch(ImmutableList.<Row>of(), new Object[0]);
432+
table.batch(Collections.emptyList(), new Object[0]);
433433
} catch (Exception ex) {
434434
actualError = ex;
435435
}
436436
assertNull(actualError);
437437

438438
try {
439-
table.batch(ImmutableList.<Row>of(null), new Object[0]);
439+
table.batch(Collections.singletonList(null), new Object[0]);
440440
} catch (Exception ex) {
441441
actualError = ex;
442442
}

bigtable-client-core-parent/bigtable-hbase-integration-tests-common/src/test/java/com/google/cloud/bigtable/hbase/AbstractTestCreateTable.java

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,10 @@
1515
*/
1616
package com.google.cloud.bigtable.hbase;
1717

18-
import com.google.common.util.concurrent.Futures;
19-
import com.google.common.util.concurrent.ListenableFuture;
20-
import com.google.common.util.concurrent.ListeningExecutorService;
21-
import com.google.common.util.concurrent.MoreExecutors;
2218
import java.util.ArrayList;
2319
import java.util.List;
24-
import java.util.concurrent.Callable;
25-
import java.util.concurrent.TimeUnit;
20+
import java.util.concurrent.CompletableFuture;
21+
import java.util.concurrent.ExecutorService;
2622
import java.util.concurrent.atomic.AtomicInteger;
2723
import org.apache.commons.lang.RandomStringUtils;
2824
import org.apache.hadoop.hbase.HRegionLocation;
@@ -68,7 +64,7 @@ public void testCreate() throws Exception {
6864
}
6965

7066
/** Requirement 1.8 - Table names must match [_a-zA-Z0-9][-_.a-zA-Z0-9]* */
71-
@Test(timeout = 1000l * 60 * 4)
67+
@Test(timeout = 1000L * 60 * 4)
7268
public void testTableNames() throws Exception {
7369
String shouldTest = System.getProperty("bigtable.test.create.table", "true");
7470
if (!"true".equals(shouldTest) || testTableNames_Counter.incrementAndGet() > 1) {
@@ -103,24 +99,23 @@ public void testTableNames() throws Exception {
10399
"jklmnopqrstuvwxyz1234567890_-."
104100
};
105101
final TableName[] tableNames = getConnection().getAdmin().listTableNames();
106-
List<ListenableFuture<Void>> futures = new ArrayList<>();
107-
ListeningExecutorService es = MoreExecutors.listeningDecorator(sharedTestEnv.getExecutor());
102+
List<CompletableFuture<Void>> futures = new ArrayList<>();
103+
ExecutorService es = sharedTestEnv.getExecutor();
104+
108105
for (final String goodName : goodNames) {
109106
futures.add(
110-
es.submit(
111-
new Callable<Void>() {
112-
@Override
113-
public Void call() throws Exception {
107+
CompletableFuture.runAsync(
108+
() -> {
109+
try {
114110
createTable(goodName, tableNames);
115-
return null;
111+
} catch (Exception e) {
112+
throw new RuntimeException(e);
116113
}
117-
}));
118-
}
119-
try {
120-
Futures.allAsList(futures).get(3, TimeUnit.MINUTES);
121-
} catch (Exception e) {
122-
throw new RuntimeException(e);
114+
},
115+
es));
123116
}
117+
118+
futures.stream().forEach(CompletableFuture::join);
124119
}
125120

126121
private void createTable(String goodName, TableName[] tableNames) throws Exception {

bigtable-client-core-parent/bigtable-hbase-integration-tests-common/src/test/java/com/google/cloud/bigtable/hbase/AbstractTestFilters.java

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

1818
import static com.google.cloud.bigtable.hbase.test_env.SharedTestEnvRule.COLUMN_FAMILY;
1919
import static com.google.cloud.bigtable.hbase.test_env.SharedTestEnvRule.COLUMN_FAMILY2;
20+
import static com.google.common.truth.Truth.assertThat;
2021
import static org.junit.Assert.assertArrayEquals;
2122
import static org.junit.Assert.assertEquals;
2223
import static org.junit.Assert.assertNotNull;
2324
import static org.junit.Assert.assertNull;
2425

2526
import com.google.cloud.bigtable.hbase.test_env.SharedTestEnvRule;
26-
import com.google.common.collect.ImmutableList;
27-
import com.google.common.collect.Iterators;
2827
import java.io.IOException;
2928
import java.util.ArrayList;
3029
import java.util.Arrays;
@@ -1474,7 +1473,7 @@ public void testTimestampsFilter() throws IOException {
14741473
table.put(put);
14751474

14761475
// Filter for results
1477-
Filter filter = new TimestampsFilter(ImmutableList.<Long>of(0L, 1L));
1476+
Filter filter = new TimestampsFilter(Arrays.asList(0L, 1L));
14781477

14791478
Get get = new Get(rowKey).setFilter(filter);
14801479
Result result = table.get(get);
@@ -2038,7 +2037,7 @@ public void testPageFilters() throws IOException {
20382037
PageFilter pageFilter = new PageFilter(20);
20392038
scan.setFilter(pageFilter);
20402039
try (ResultScanner scanner = table.getScanner(scan)) {
2041-
Assert.assertEquals(20, Iterators.size(scanner.iterator()));
2040+
assertThat(scanner).hasSize(20);
20422041
}
20432042

20442043
FilterList filterList =
@@ -2048,7 +2047,7 @@ public void testPageFilters() throws IOException {
20482047
pageFilter);
20492048
scan.setFilter(filterList);
20502049
try (ResultScanner scanner = table.getScanner(scan)) {
2051-
Assert.assertEquals(20, Iterators.size(scanner.iterator()));
2050+
assertThat(scanner).hasSize(20);
20522051
}
20532052
}
20542053

@@ -2172,7 +2171,7 @@ public void testFuzzyDifferentSizes() throws Exception {
21722171
Pair<byte[], byte[]> fuzzyData =
21732172
Pair.newPair(createKey(1, 0, 0, 4), createFuzzyMask(0, 1, 1, 0));
21742173

2175-
Scan scan = new Scan().setFilter(new FuzzyRowFilter(ImmutableList.of(fuzzyData)));
2174+
Scan scan = new Scan().setFilter(new FuzzyRowFilter(Collections.singletonList(fuzzyData)));
21762175

21772176
// only the first and second keys should be matched
21782177
try (ResultScanner scanner = table.getScanner(scan)) {
@@ -2209,7 +2208,7 @@ public void testFuzzyWithIntKeys() throws Exception {
22092208
// match keys with 5 in the first position and 126/127/128/129 in the 3rd position
22102209
FuzzyRowFilter filter =
22112210
new FuzzyRowFilter(
2212-
ImmutableList.of(
2211+
Arrays.asList(
22132212
Pair.newPair(createKey(5, 0, 126, 0), createFuzzyMask(0, 1, 0, 1)),
22142213
Pair.newPair(createKey(5, 0, 127, 0), createFuzzyMask(0, 1, 0, 1)),
22152214
Pair.newPair(createKey(5, 0, 128, 0), createFuzzyMask(0, 1, 0, 1)),

bigtable-client-core-parent/bigtable-hbase-integration-tests-common/src/test/java/com/google/cloud/bigtable/hbase/AbstractTestModifyTable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
import static org.junit.Assert.assertEquals;
1919
import static org.junit.Assert.assertTrue;
2020

21-
import com.google.common.base.Function;
2221
import java.io.IOException;
22+
import java.util.function.Function;
2323
import org.apache.hadoop.hbase.HColumnDescriptor;
2424
import org.apache.hadoop.hbase.HTableDescriptor;
2525
import org.apache.hadoop.hbase.TableName;

bigtable-client-core-parent/bigtable-hbase-integration-tests-common/src/test/java/com/google/cloud/bigtable/hbase/TestAdminOps.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919
import static org.junit.Assert.assertNotNull;
2020
import static org.junit.Assert.assertTrue;
2121

22-
import com.google.common.collect.ImmutableList;
2322
import java.io.IOException;
24-
import org.apache.hadoop.hbase.TableName;
23+
import java.util.Collections;
2524
import org.apache.hadoop.hbase.client.Admin;
2625
import org.junit.Test;
2726
import org.junit.runner.RunWith;
@@ -88,7 +87,7 @@ public void testGetTableDescriptorsByTableNameWithNullAndEmptyList() throws IOEx
8887
try (Admin admin = getConnection().getAdmin()) {
8988
assertTrue(admin.getTableDescriptorsByTableName(null).length > 0);
9089

91-
assertTrue(admin.getTableDescriptorsByTableName(ImmutableList.<TableName>of()).length > 0);
90+
assertTrue(admin.getTableDescriptorsByTableName(Collections.emptyList()).length > 0);
9291
}
9392
}
9493

@@ -104,7 +103,7 @@ public void testGetTableDescriptorsWithNullAndEmptyList() throws IOException {
104103
assertNotNull(actualError);
105104
assertTrue(actualError instanceof NullPointerException);
106105

107-
assertTrue(admin.getTableDescriptors(ImmutableList.<String>of()).length > 0);
106+
assertTrue(admin.getTableDescriptors(Collections.emptyList()).length > 0);
108107
}
109108
}
110109
}

bigtable-client-core-parent/bigtable-hbase-integration-tests-common/src/test/java/com/google/cloud/bigtable/hbase/TestBufferedMutator.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
import static org.junit.Assert.assertNotNull;
2222
import static org.junit.Assert.assertNull;
2323

24-
import com.google.common.collect.ImmutableList;
24+
import java.util.ArrayList;
25+
import java.util.Collections;
2526
import java.util.List;
2627
import org.apache.commons.lang.RandomStringUtils;
2728
import org.apache.hadoop.hbase.client.BufferedMutator;
@@ -120,7 +121,7 @@ public void testBufferedMutatorWithNullAndEmptyValues() throws Exception {
120121
actualError = null;
121122

122123
try {
123-
bm.mutate(ImmutableList.<Mutation>of());
124+
bm.mutate(Collections.emptyList());
124125
} catch (Exception ex) {
125126
actualError = ex;
126127
}
@@ -176,13 +177,12 @@ public void testBulkMutation() throws Exception {
176177
getConnection().getBufferedMutator(sharedTestEnv.getDefaultTableName());
177178
Table tableForRead = getConnection().getTable(sharedTestEnv.getDefaultTableName())) {
178179

179-
ImmutableList.Builder<Put> builder = ImmutableList.builder();
180+
List<Put> mutations = new ArrayList<>();
180181
for (int i = 0; i < 10; i++) {
181-
builder.add(
182+
mutations.add(
182183
new Put(Bytes.toBytes(rowKeyPrefix + i))
183184
.addColumn(COLUMN_FAMILY, qualifier, 10_001L, value));
184185
}
185-
List<Put> mutations = builder.build();
186186

187187
mutator.mutate(mutations);
188188
// force bufferedMutator to apply mutation

bigtable-client-core-parent/bigtable-hbase-integration-tests-common/src/test/java/com/google/cloud/bigtable/hbase/TestScan.java

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

1818
import static com.google.cloud.bigtable.hbase.test_env.SharedTestEnvRule.COLUMN_FAMILY;
1919
import static com.google.cloud.bigtable.hbase.test_env.SharedTestEnvRule.COLUMN_FAMILY2;
20-
import static com.google.common.truth.Truth.*;
20+
import static com.google.common.truth.Truth.assertThat;
2121

22-
import com.google.common.collect.ImmutableList;
23-
import com.google.common.collect.Lists;
2422
import java.io.IOException;
2523
import java.util.ArrayList;
2624
import java.util.Arrays;
@@ -346,7 +344,7 @@ public void testBasicReverseScan() throws IOException {
346344
.collect(Collectors.toList());
347345

348346
List<String> expectedRowKeys =
349-
ImmutableList.of(
347+
Arrays.asList(
350348
new String(rowKeys[6]),
351349
new String(rowKeys[5]),
352350
new String(rowKeys[4]),
@@ -387,7 +385,7 @@ public void testReverseScanWithFilter() throws IOException {
387385
.setReversed(true)
388386
.setFilter(
389387
new MultiRowRangeFilter(
390-
Lists.newArrayList(
388+
Arrays.asList(
391389
new RowRange(rowKeys[3], false, rowKeys[4], true),
392390
new RowRange(rowKeys[6], true, rowKeys[8], false))));
393391

@@ -398,7 +396,7 @@ public void testReverseScanWithFilter() throws IOException {
398396
.collect(Collectors.toList());
399397

400398
List<String> expectedRowKeys =
401-
ImmutableList.of(new String(rowKeys[7]), new String(rowKeys[6]), new String(rowKeys[4]));
399+
Arrays.asList(new String(rowKeys[7]), new String(rowKeys[6]), new String(rowKeys[4]));
402400

403401
assertThat(actualRowKeys).containsExactlyElementsIn(expectedRowKeys).inOrder();
404402
}
@@ -437,7 +435,7 @@ public void testReverseScanWithFilterAndRange() throws IOException {
437435
.withStopRow(rowKeys[1])
438436
.setFilter(
439437
new MultiRowRangeFilter(
440-
Lists.newArrayList(
438+
Arrays.asList(
441439
new RowRange(rowKeys[3], true, rowKeys[4], true),
442440
new RowRange(rowKeys[6], true, rowKeys[8], false))));
443441

@@ -448,7 +446,7 @@ public void testReverseScanWithFilterAndRange() throws IOException {
448446
.collect(Collectors.toList());
449447

450448
List<String> expectedRowKeys =
451-
ImmutableList.of(new String(rowKeys[6]), new String(rowKeys[4]), new String(rowKeys[3]));
449+
Arrays.asList(new String(rowKeys[6]), new String(rowKeys[4]), new String(rowKeys[3]));
452450

453451
assertThat(actualRowKeys).containsExactlyElementsIn(expectedRowKeys).inOrder();
454452
}

bigtable-client-core-parent/bigtable-hbase-integration-tests-common/src/test/java/com/google/cloud/bigtable/hbase/TestSingleColumnValueFilter.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
import static com.google.cloud.bigtable.hbase.test_env.SharedTestEnvRule.COLUMN_FAMILY;
2020

2121
import com.google.cloud.bigtable.hbase.test_env.SharedTestEnvRule;
22-
import com.google.common.collect.ImmutableSet;
2322
import java.io.IOException;
2423
import java.util.ArrayList;
2524
import java.util.HashMap;
25+
import java.util.HashSet;
2626
import java.util.List;
2727
import java.util.Map;
2828
import java.util.Map.Entry;
@@ -57,10 +57,10 @@ public static void fillTable() throws IOException {
5757
table = SharedTestEnvRule.getInstance().getDefaultTable();
5858

5959
List<Put> puts = new ArrayList<>();
60-
ImmutableSet.Builder<String> keyBuilder = ImmutableSet.builder();
60+
keys = new HashSet<>();
6161
for (long i = 0; i < count; i++) {
6262
byte[] row = dataHelper.randomData(PREFIX);
63-
keyBuilder.add(Bytes.toString(row));
63+
keys.add(Bytes.toString(row));
6464
int randomValue = (int) Math.floor(count * Math.random());
6565
puts.add(
6666
new Put(row)
@@ -72,7 +72,6 @@ public static void fillTable() throws IOException {
7272
byte[] stringVal = Bytes.toBytes("Not a number");
7373
puts.add(new Put(otheRow).addColumn(COLUMN_FAMILY, OTHER_QUALIFIER, stringVal));
7474

75-
keys = keyBuilder.build();
7675
table.put(puts);
7776
}
7877

0 commit comments

Comments
 (0)