Skip to content

Commit 3e1de74

Browse files
authored
fix: bidirectional replication flakey test (#4130)
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ x] Make sure to open an issue as a [bug/issue](https://togithub.com/googleapis/java-bigtable-hbase/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ x] Ensure the tests and linter pass - [ x] Code coverage does not decrease (if any source code was changed) - [ x] Appropriate docs were updated (if necessary) Fixes #4116 If you write sample code, please follow the [samples format]( https://togithub.com/GoogleCloudPlatform/java-docs-samples/blob/main/SAMPLE_FORMAT.md).
1 parent 65fe341 commit 3e1de74

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

hbase-migration-tools/bigtable-hbase-replication/bigtable-hbase-1.x-replication/src/test/java/com/google/cloud/bigtable/hbase1_x/replication/HbaseToCloudBigtableBidirectionalReplicationEndpointTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import org.apache.hadoop.hbase.client.RowMutations;
3838
import org.apache.hadoop.hbase.client.Table;
3939
import org.apache.hadoop.hbase.client.replication.ReplicationAdmin;
40-
import org.apache.hadoop.hbase.replication.ReplicationEndpoint.ReplicateContext;
4140
import org.apache.hadoop.hbase.replication.ReplicationPeerConfig;
4241
import org.junit.After;
4342
import org.junit.AfterClass;
@@ -60,12 +59,12 @@ public class HbaseToCloudBigtableBidirectionalReplicationEndpointTest {
6059

6160
public static class TestReplicationEndpoint extends HbaseToCloudBigtableReplicationEndpoint {
6261

63-
static AtomicInteger replicatedEntries = new AtomicInteger();
62+
static AtomicInteger replicatingEntries = new AtomicInteger();
6463

6564
@Override
6665
public boolean replicate(ReplicateContext replicateContext) {
6766
boolean result = super.replicate(replicateContext);
68-
replicatedEntries.getAndAdd(replicateContext.getEntries().size());
67+
replicatingEntries.getAndAdd(replicateContext.getEntries().size());
6968
return result;
7069
}
7170
}
@@ -141,7 +140,7 @@ public void setupTestCase() throws IOException {
141140
hbaseTable = hbaseConnection.getTable(table1);
142141

143142
// Reset the entry counts for TestReplicationEndpoint
144-
TestReplicationEndpoint.replicatedEntries.set(0);
143+
TestReplicationEndpoint.replicatingEntries.set(0);
145144
}
146145

147146
private void createTables(TableName tableName, int cf1Scope, int cf2Scope) throws IOException {
@@ -185,15 +184,16 @@ public void testDropsReplicatedEntry() throws IOException, InterruptedException
185184
// Wait for replication
186185
TestUtils.waitForReplication(
187186
() -> {
188-
// Only one entry should've been replicated
189-
return TestReplicationEndpoint.replicatedEntries.get() >= 1;
187+
// Both entries should've gone through the replication process
188+
// However, one would've been filtered out during this process
189+
return TestReplicationEndpoint.replicatingEntries.get() >= 2;
190190
});
191191

192192
// Hbase table should have both mutations
193-
Assert.assertTrue(hbaseTable.get(new Get(TestUtils.ROW_KEY)).size() == 1);
194-
Assert.assertTrue(hbaseTable.get(new Get(TestUtils.ROW_KEY_2)).size() == 1);
193+
Assert.assertEquals(1, hbaseTable.get(new Get(TestUtils.ROW_KEY)).size());
194+
Assert.assertEquals(1, hbaseTable.get(new Get(TestUtils.ROW_KEY_2)).size());
195195
// Cbt table should have only one mutation
196196
Assert.assertTrue(cbtTable.get(new Get(TestUtils.ROW_KEY)).isEmpty());
197-
Assert.assertTrue(cbtTable.get(new Get(TestUtils.ROW_KEY_2)).size() == 1);
197+
Assert.assertEquals(1, cbtTable.get(new Get(TestUtils.ROW_KEY_2)).size());
198198
}
199199
}

hbase-migration-tools/bigtable-hbase-replication/bigtable-hbase-2.x-replication/src/test/java/com/google/cloud/bigtable/hbase2_x/replication/HbaseToCloudBigtableBidirectionalReplicationEndpointTest.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.apache.hadoop.hbase.client.RowMutations;
3939
import org.apache.hadoop.hbase.client.Table;
4040
import org.apache.hadoop.hbase.client.replication.ReplicationAdmin;
41-
import org.apache.hadoop.hbase.replication.ReplicationEndpoint.ReplicateContext;
4241
import org.apache.hadoop.hbase.replication.ReplicationPeerConfig;
4342
import org.junit.After;
4443
import org.junit.AfterClass;
@@ -61,12 +60,13 @@ public class HbaseToCloudBigtableBidirectionalReplicationEndpointTest {
6160

6261
public static class TestReplicationEndpoint extends HbaseToCloudBigtableReplicationEndpoint {
6362

64-
static AtomicInteger replicatedEntries = new AtomicInteger();
63+
static AtomicInteger replicatingEntries = new AtomicInteger();
6564

6665
@Override
6766
public boolean replicate(ReplicateContext replicateContext) {
6867
boolean result = super.replicate(replicateContext);
69-
replicatedEntries.getAndAdd(replicateContext.getEntries().size());
68+
replicatingEntries.getAndAdd(replicateContext.getEntries().size());
69+
7070
return result;
7171
}
7272
}
@@ -144,9 +144,7 @@ public void setupTestCase() throws IOException {
144144
hbaseTable = hbaseConnection.getTable(table1);
145145

146146
// Reset the entry counts for TestReplicationEndpoint
147-
HbaseToCloudBigtableBidirectionalReplicationEndpointTest.TestReplicationEndpoint
148-
.replicatedEntries
149-
.set(0);
147+
TestReplicationEndpoint.replicatingEntries.set(0);
150148
}
151149

152150
private void createTables(TableName tableName, int cf1Scope, int cf2Scope) throws IOException {
@@ -191,18 +189,16 @@ public void testDropsReplicatedEntry() throws IOException, InterruptedException
191189
// Wait for replication
192190
TestUtils.waitForReplication(
193191
() -> {
194-
// Only one entry should've been replicated
195-
return HbaseToCloudBigtableBidirectionalReplicationEndpointTest.TestReplicationEndpoint
196-
.replicatedEntries
197-
.get()
198-
>= 1;
192+
// Both entries should've gone through the replication process
193+
// However, one would've been filtered out during this process
194+
return TestReplicationEndpoint.replicatingEntries.get() >= 2;
199195
});
200196

201197
// Hbase table should have both mutations
202-
Assert.assertTrue(hbaseTable.get(new Get(TestUtils.ROW_KEY)).size() == 1);
203-
Assert.assertTrue(hbaseTable.get(new Get(TestUtils.ROW_KEY_2)).size() == 1);
198+
Assert.assertEquals(1, hbaseTable.get(new Get(TestUtils.ROW_KEY)).size());
199+
Assert.assertEquals(1, hbaseTable.get(new Get(TestUtils.ROW_KEY_2)).size());
204200
// Cbt table should have only one mutation
205201
Assert.assertTrue(cbtTable.get(new Get(TestUtils.ROW_KEY)).isEmpty());
206-
Assert.assertTrue(cbtTable.get(new Get(TestUtils.ROW_KEY_2)).size() == 1);
202+
Assert.assertEquals(1, cbtTable.get(new Get(TestUtils.ROW_KEY_2)).size());
207203
}
208204
}

0 commit comments

Comments
 (0)