Skip to content

Commit b59eb96

Browse files
authored
HBASE-27822 TestFromClientSide5.testAppendWithoutWAL is flaky (#5211)
Signed-off-by: Liangjun He <heliangjun@apache.org>
1 parent 4e69921 commit b59eb96

File tree

3 files changed

+31
-18
lines changed

3 files changed

+31
-18
lines changed

hbase-server/src/test/java/org/apache/hadoop/hbase/client/FromClientSideBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ protected static boolean isSameParameterizedCluster(Class<?> registryImpl, int n
9898
return confClass.getName().equals(registryImpl.getName()) && numHedgedReqs == hedgedReqConfig;
9999
}
100100

101-
protected static final void initialize(Class<?> registryImpl, int numHedgedReqs, Class<?>... cps)
102-
throws Exception {
101+
protected static final void initialize(Class<? extends ConnectionRegistry> registryImpl,
102+
int numHedgedReqs, Class<?>... cps) throws Exception {
103103
// initialize() is called for every unit test, however we only want to reset the cluster state
104104
// at the end of every parameterized run.
105105
if (isSameParameterizedCluster(registryImpl, numHedgedReqs)) {

hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide5.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.io.IOException;
2929
import java.util.ArrayList;
3030
import java.util.Arrays;
31-
import java.util.Collection;
3231
import java.util.LinkedList;
3332
import java.util.List;
3433
import java.util.Map;
@@ -91,6 +90,7 @@
9190
import org.junit.experimental.categories.Category;
9291
import org.junit.runner.RunWith;
9392
import org.junit.runners.Parameterized;
93+
import org.junit.runners.Parameterized.Parameters;
9494
import org.slf4j.Logger;
9595
import org.slf4j.LoggerFactory;
9696

@@ -115,21 +115,23 @@ public class TestFromClientSide5 extends FromClientSideBase {
115115
@ClassRule
116116
public static final HBaseClassTestRule CLASS_RULE =
117117
HBaseClassTestRule.forClass(TestFromClientSide5.class);
118+
118119
@Rule
119120
public TableNameTestRule name = new TableNameTestRule();
120121

121122
// To keep the child classes happy.
122123
TestFromClientSide5() {
123124
}
124125

125-
public TestFromClientSide5(Class registry, int numHedgedReqs) throws Exception {
126+
public TestFromClientSide5(Class<? extends ConnectionRegistry> registry, int numHedgedReqs)
127+
throws Exception {
126128
initialize(registry, numHedgedReqs, MultiRowMutationEndpoint.class);
127129
}
128130

129-
@Parameterized.Parameters
130-
public static Collection parameters() {
131-
return Arrays.asList(new Object[][] { { MasterRegistry.class, 1 }, { MasterRegistry.class, 2 },
132-
{ ZKConnectionRegistry.class, 1 } });
131+
@Parameters(name = "{index}: registry={0}, numHedgedReqs={1}")
132+
public static List<Object[]> parameters() {
133+
return Arrays.asList(new Object[] { MasterRegistry.class, 1 },
134+
new Object[] { MasterRegistry.class, 2 }, new Object[] { ZKConnectionRegistry.class, 1 });
133135
}
134136

135137
@AfterClass
@@ -771,10 +773,20 @@ private List<Result> doAppend(final boolean walUsed) throws IOException {
771773
t.put(put_1);
772774
List<Result> results = new LinkedList<>();
773775
try (ResultScanner scanner = t.getScanner(s)) {
776+
// get one row(should be row3) from the scanner to make sure that we have send a request to
777+
// region server, which means we have already set the read point, so later we should not see
778+
// the new appended values.
779+
Result r = scanner.next();
780+
assertNotNull(r);
781+
results.add(r);
774782
t.append(append_1);
775783
t.append(append_2);
776784
t.append(append_3);
777-
for (Result r : scanner) {
785+
for (;;) {
786+
r = scanner.next();
787+
if (r == null) {
788+
break;
789+
}
778790
results.add(r);
779791
}
780792
}
@@ -788,11 +800,11 @@ public void testAppendWithoutWAL() throws Exception {
788800
List<Result> resultsWithWal = doAppend(true);
789801
List<Result> resultsWithoutWal = doAppend(false);
790802
assertEquals(resultsWithWal.size(), resultsWithoutWal.size());
791-
for (int i = 0; i != resultsWithWal.size(); ++i) {
803+
for (int i = 0; i < resultsWithWal.size(); ++i) {
792804
Result resultWithWal = resultsWithWal.get(i);
793805
Result resultWithoutWal = resultsWithoutWal.get(i);
794806
assertEquals(resultWithWal.rawCells().length, resultWithoutWal.rawCells().length);
795-
for (int j = 0; j != resultWithWal.rawCells().length; ++j) {
807+
for (int j = 0; j < resultWithWal.rawCells().length; ++j) {
796808
Cell cellWithWal = resultWithWal.rawCells()[j];
797809
Cell cellWithoutWal = resultWithoutWal.rawCells()[j];
798810
assertArrayEquals(CellUtil.cloneRow(cellWithWal), CellUtil.cloneRow(cellWithoutWal));

hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSideWithCoprocessor5.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package org.apache.hadoop.hbase.client;
1919

2020
import java.util.Arrays;
21-
import java.util.Collection;
21+
import java.util.List;
2222
import org.apache.hadoop.hbase.HBaseClassTestRule;
2323
import org.apache.hadoop.hbase.coprocessor.MultiRowMutationEndpoint;
2424
import org.apache.hadoop.hbase.regionserver.NoOpScanPolicyObserver;
@@ -27,7 +27,7 @@
2727
import org.junit.AfterClass;
2828
import org.junit.ClassRule;
2929
import org.junit.experimental.categories.Category;
30-
import org.junit.runners.Parameterized;
30+
import org.junit.runners.Parameterized.Parameters;
3131

3232
/**
3333
* Test all client operations with a coprocessor that just implements the default flush/compact/scan
@@ -41,18 +41,19 @@ public class TestFromClientSideWithCoprocessor5 extends TestFromClientSide5 {
4141

4242
// Override the parameters from the parent class. We just want to run it for the default
4343
// param combination.
44-
@Parameterized.Parameters
45-
public static Collection parameters() {
46-
return Arrays
47-
.asList(new Object[][] { { MasterRegistry.class, 1 }, { ZKConnectionRegistry.class, 1 } });
44+
@Parameters(name = "{index}: registry={0}, numHedgedReqs={1}")
45+
public static List<Object[]> parameters() {
46+
return Arrays.asList(new Object[] { MasterRegistry.class, 1 },
47+
new Object[] { ZKConnectionRegistry.class, 1 });
4848
}
4949

5050
@AfterClass
5151
public static void tearDownAfterClass() throws Exception {
5252
afterClass();
5353
}
5454

55-
public TestFromClientSideWithCoprocessor5(Class registry, int numHedgedReqs) throws Exception {
55+
public TestFromClientSideWithCoprocessor5(Class<? extends ConnectionRegistry> registry,
56+
int numHedgedReqs) throws Exception {
5657
initialize(registry, numHedgedReqs, NoOpScanPolicyObserver.class,
5758
MultiRowMutationEndpoint.class);
5859
}

0 commit comments

Comments
 (0)