Skip to content

Commit e9ece82

Browse files
committed
Improve SimpleBalancerFairnessIT
1 parent 802b4d6 commit e9ece82

File tree

1 file changed

+47
-31
lines changed

1 file changed

+47
-31
lines changed

test/src/main/java/org/apache/accumulo/test/functional/SimpleBalancerFairnessIT.java

+47-31
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.apache.accumulo.test.functional;
2020

2121
import static java.util.concurrent.TimeUnit.SECONDS;
22-
import static org.junit.jupiter.api.Assertions.assertEquals;
2322
import static org.junit.jupiter.api.Assertions.assertTrue;
2423

2524
import java.util.ArrayList;
@@ -43,6 +42,7 @@
4342
import org.apache.accumulo.minicluster.ServerType;
4443
import org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl;
4544
import org.apache.accumulo.test.TestIngest;
45+
import org.apache.accumulo.test.util.Wait;
4646
import org.apache.hadoop.conf.Configuration;
4747
import org.apache.hadoop.io.Text;
4848
import org.junit.jupiter.api.Test;
@@ -61,53 +61,69 @@ public void configure(MiniAccumuloConfigImpl cfg, Configuration hadoopCoreSite)
6161
@Test
6262
public void simpleBalancerFairness() throws Exception {
6363
try (AccumuloClient c = Accumulo.newClient().from(getClientProperties()).build()) {
64-
c.tableOperations().create("test_ingest");
65-
c.tableOperations().setProperty("test_ingest", Property.TABLE_SPLIT_THRESHOLD.getKey(), "1K");
66-
c.tableOperations().create("unused");
67-
TreeSet<Text> splits = TestIngest.getSplitPoints(0, 10000000, NUM_SPLITS);
64+
final String ingestTable = "test_ingest";
65+
final String unusedTable = "unused";
66+
67+
c.tableOperations().create(ingestTable);
68+
c.tableOperations().setProperty(ingestTable, Property.TABLE_SPLIT_THRESHOLD.getKey(), "1K");
69+
c.tableOperations().create(unusedTable);
70+
TreeSet<Text> splits = TestIngest.getSplitPoints(0, 10_000_000, NUM_SPLITS);
6871
log.info("Creating {} splits", splits.size());
69-
c.tableOperations().addSplits("unused", splits);
72+
c.tableOperations().addSplits(unusedTable, splits);
7073
Set<ServerId> tservers = c.instanceOperations().getServers(ServerId.Type.TABLET_SERVER);
7174
TestIngest.IngestParams params = new TestIngest.IngestParams(getClientProperties());
7275
params.rows = 5000;
7376
TestIngest.ingest(c, params);
74-
c.tableOperations().flush("test_ingest", null, null, false);
75-
Thread.sleep(SECONDS.toMillis(45));
77+
c.tableOperations().flush(ingestTable, null, null, false);
7678
Credentials creds = new Credentials("root", new PasswordToken(ROOT_PASSWORD));
7779

78-
int unassignedTablets = 1;
79-
ManagerMonitorInfo stats = null;
8080
ClientContext context = (ClientContext) c;
81-
for (int i = 0; unassignedTablets > 0 && i < 20; i++) {
82-
stats = ThriftClientTypes.MANAGER.execute(context,
81+
82+
// wait for tablet assignment
83+
Wait.waitFor(() -> {
84+
ManagerMonitorInfo stats = ThriftClientTypes.MANAGER.execute(context,
8385
client -> client.getManagerStats(TraceUtil.traceInfo(),
8486
creds.toThrift(c.instanceOperations().getInstanceId())));
85-
unassignedTablets = stats.getUnassignedTablets();
87+
int unassignedTablets = stats.getUnassignedTablets();
8688
if (unassignedTablets > 0) {
8789
log.info("Found {} unassigned tablets, sleeping 3 seconds for tablet assignment",
8890
unassignedTablets);
89-
Thread.sleep(3000);
91+
return false;
92+
} else {
93+
return true;
9094
}
91-
}
95+
}, SECONDS.toMillis(45), SECONDS.toMillis(3));
9296

93-
assertEquals(0, unassignedTablets, "Unassigned tablets were not assigned within 60 seconds");
97+
// wait for tablets to be balanced
98+
Wait.waitFor(() -> {
99+
ManagerMonitorInfo stats = ThriftClientTypes.MANAGER.execute(context,
100+
client -> client.getManagerStats(TraceUtil.traceInfo(),
101+
creds.toThrift(c.instanceOperations().getInstanceId())));
94102

95-
// Compute online tablets per tserver
96-
List<Integer> counts = new ArrayList<>();
97-
for (TabletServerStatus server : stats.tServerInfo) {
98-
int count = 0;
99-
for (TableInfo table : server.tableMap.values()) {
100-
count += table.onlineTablets;
103+
List<Integer> counts = new ArrayList<>();
104+
for (TabletServerStatus server : stats.tServerInfo) {
105+
int count = 0;
106+
for (TableInfo table : server.tableMap.values()) {
107+
count += table.onlineTablets;
108+
}
109+
counts.add(count);
101110
}
102-
counts.add(count);
103-
}
104-
assertTrue(counts.size() > 1, "Expected to have at least two TabletServers");
105-
for (int i = 1; i < counts.size(); i++) {
106-
int diff = Math.abs(counts.get(0) - counts.get(i));
107-
assertTrue(diff <= tservers.size(),
108-
"Expected difference in tablets to be less than or equal to " + counts.size()
109-
+ " but was " + diff + ". Counts " + counts);
110-
}
111+
assertTrue(counts.size() >= 2,
112+
"Expected at least 2 tservers to have tablets, but found " + counts);
113+
114+
for (int i = 1; i < counts.size(); i++) {
115+
int diff = Math.abs(counts.get(0) - counts.get(i));
116+
log.info(" Counts: {}", counts);
117+
if (diff > tservers.size()) {
118+
log.info("Difference in tablets between tservers is greater than expected. Counts: {}",
119+
counts);
120+
return false;
121+
}
122+
}
123+
124+
// if diff is less than the number of tservers, then we are good
125+
return true;
126+
}, SECONDS.toMillis(60), SECONDS.toMillis(3));
111127
}
112128
}
113129

0 commit comments

Comments
 (0)