use of org.apache.helix.HelixManager in project pinot by linkedin.
the class BaseClusterIntegrationTest method setupSegmentCountCountDownLatch.
protected CountDownLatch setupSegmentCountCountDownLatch(final String tableName, final int expectedSegmentCount) throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
HelixManager manager = HelixManagerFactory.getZKHelixManager(getHelixClusterName(), "test_instance", InstanceType.SPECTATOR, ZkStarter.DEFAULT_ZK_STR);
manager.connect();
manager.addExternalViewChangeListener(new ExternalViewChangeListener() {
private boolean _hasBeenTriggered = false;
@Override
public void onExternalViewChange(List<ExternalView> externalViewList, NotificationContext changeContext) {
// Nothing to do?
if (_hasBeenTriggered) {
return;
}
for (ExternalView externalView : externalViewList) {
if (externalView.getId().contains(tableName)) {
Set<String> partitionSet = externalView.getPartitionSet();
if (partitionSet.size() == expectedSegmentCount) {
int onlinePartitionCount = 0;
for (String partitionId : partitionSet) {
Map<String, String> partitionStateMap = externalView.getStateMap(partitionId);
if (partitionStateMap.containsValue("ONLINE")) {
onlinePartitionCount++;
}
}
if (onlinePartitionCount == expectedSegmentCount) {
// System.out.println("Got " + expectedSegmentCount + " online tables, unlatching the main thread");
latch.countDown();
_hasBeenTriggered = true;
}
}
}
}
}
});
return latch;
}
Aggregations