use of com.linkedin.pinot.routing.builder.BalancedRandomRoutingTableBuilder in project pinot by linkedin.
the class RandomRoutingTableTest method testHelixExternalViewBasedRoutingTable.
@Test
public void testHelixExternalViewBasedRoutingTable() throws Exception {
URL resourceUrl = getClass().getClassLoader().getResource("SampleExternalView.json");
Assert.assertNotNull(resourceUrl);
String fileName = resourceUrl.getFile();
String tableName = "testTable_OFFLINE";
InputStream evInputStream = new FileInputStream(fileName);
ZNRecordSerializer znRecordSerializer = new ZNRecordSerializer();
ZNRecord externalViewRecord = (ZNRecord) znRecordSerializer.deserialize(IOUtils.toByteArray(evInputStream));
int totalRuns = 10000;
RoutingTableBuilder routingStrategy = new BalancedRandomRoutingTableBuilder(10);
HelixExternalViewBasedRouting routingTable = new HelixExternalViewBasedRouting(null, new PercentageBasedRoutingTableSelector(), null, new BaseConfiguration());
routingTable.setSmallClusterRoutingTableBuilder(routingStrategy);
ExternalView externalView = new ExternalView(externalViewRecord);
routingTable.markDataResourceOnline(tableName, externalView, getInstanceConfigs(externalView));
double[] globalArrays = new double[9];
for (int numRun = 0; numRun < totalRuns; ++numRun) {
RoutingTableLookupRequest request = new RoutingTableLookupRequest(tableName, Collections.<String>emptyList());
Map<ServerInstance, SegmentIdSet> serversMap = routingTable.findServers(request);
TreeSet<ServerInstance> serverInstances = new TreeSet<ServerInstance>(serversMap.keySet());
int i = 0;
double[] arrays = new double[9];
for (ServerInstance serverInstance : serverInstances) {
globalArrays[i] += serversMap.get(serverInstance).getSegments().size();
arrays[i++] = serversMap.get(serverInstance).getSegments().size();
}
for (int j = 0; i < arrays.length; ++j) {
Assert.assertTrue(arrays[j] / totalRuns <= 31);
Assert.assertTrue(arrays[j] / totalRuns >= 28);
}
// System.out.println(Arrays.toString(arrays) + " : " + new StandardDeviation().evaluate(arrays) + " : " + new Mean().evaluate(arrays));
}
for (int i = 0; i < globalArrays.length; ++i) {
Assert.assertTrue(globalArrays[i] / totalRuns <= 31);
Assert.assertTrue(globalArrays[i] / totalRuns >= 28);
}
// System.out.println(Arrays.toString(globalArrays) + " : " + new StandardDeviation().evaluate(globalArrays) + " : "
// + new Mean().evaluate(globalArrays));
}
Aggregations