HADOOP-15098. TestClusterTopology#testChooseRandom fails intermittently. Contributed by Zsolt Venczel.

This commit is contained in:
Sean Mackrory 2017-12-07 10:52:02 -07:00
parent 67662e2ac9
commit acb92904d0

View File

@ -139,9 +139,15 @@ public void testChooseRandom() {
NodeElement node4 = getNewNode("node4", "/d1/r3");
cluster.add(node4);
// Number of test runs
int numTestRuns = 3;
int chiSquareTestRejectedCounter = 0;
// Number of iterations to do the test
int numIterations = 100;
for (int testRun = 0; testRun < numTestRuns; ++testRun) {
// Pick random nodes
HashMap<String, Integer> histogram = new HashMap<String, Integer>();
for (int i = 0; i < numIterations; i++) {
@ -153,7 +159,7 @@ public void testChooseRandom() {
}
assertEquals("Random is not selecting all nodes", 4, histogram.size());
// Check with 99% confidence (alpha=0.01 as confidence = (100 * (1 - alpha)
// Check with 99% confidence alpha=0.01 as confidence = 100 * (1 - alpha)
ChiSquareTest chiSquareTest = new ChiSquareTest();
double[] expected = new double[histogram.size()];
long[] observed = new long[histogram.size()];
@ -166,11 +172,17 @@ public void testChooseRandom() {
boolean chiSquareTestRejected =
chiSquareTest.chiSquareTest(expected, observed, 0.01);
if (chiSquareTestRejected) {
++chiSquareTestRejectedCounter;
}
}
// Check that they have the proper distribution
assertFalse("Not choosing nodes randomly", chiSquareTestRejected);
assertFalse("Random not choosing nodes with proper distribution",
chiSquareTestRejectedCounter==3);
// Pick random nodes excluding the 2 nodes in /d1/r3
histogram = new HashMap<String,Integer>();
HashMap<String, Integer> histogram = new HashMap<String, Integer>();
for (int i=0; i<numIterations; i++) {
String randomNode = cluster.chooseRandom("~/d1/r3").getName();
if (!histogram.containsKey(randomNode)) {