SearchCluster implements NodeManager<Node> { public Optional<Node> localCorpusDispatchTarget() { if ( localCorpusDispatchTarget.isEmpty()) return Optional.empty(); Group localSearchGroup = groups().get(localCorpusDispatchTarget.get().group()); if ( ! localSearchGroup.hasSufficientCoverage()) return Optional.empty(); if ( localCorpusDispatchTarget.get().isWorking() == Boolean.FALSE) return Optional.empty(); return localCorpusDispatchTarget; } SearchCluster(String clusterId, DispatchConfig dispatchConfig, int containerClusterSize,
                         VipStatus vipStatus, PingFactory pingFactory);  SearchCluster(String clusterId, DispatchConfig dispatchConfig,
                         VipStatus vipStatus, PingFactory pingFactory); void addMonitoring(ClusterMonitor clusterMonitor); DispatchConfig dispatchConfig(); int size(); ImmutableMap<Integer, Group> groups(); ImmutableList<Group> orderedGroups(); Optional<Group> group(int n); int groupSize(); int groupsWithSufficientCoverage(); Optional<Node> localCorpusDispatchTarget(); @Override void working(Node node); @Override void failed(Node node); int estimateHitsToFetch(int wantedHits, int numPartitions); int estimateHitsToFetch(int wantedHits, int numPartitions, double topKProbability); boolean hasInformationAboutAllNodes(); @Override void ping(ClusterMonitor clusterMonitor, Node node, Executor executor); @Override void pingIterationCompleted(); boolean isPartialGroupCoverageSufficient(OptionalInt knownGroupId, List<Node> nodes);  }
@Test public void requireThatVipStatusIsDefaultDownButComesUpAfterPinging() { try (State test = new State("cluster.1", 2, "a", "b")) { assertTrue(test.searchCluster.localCorpusDispatchTarget().isEmpty()); assertFalse(test.vipStatus.isInRotation()); test.waitOneFullPingRound(); assertTrue(test.vipStatus.isInRotation()); } }
@Test public void requireThatZeroDocsAreFine() { try (State test = new State("cluster.1", 2, "a", "b")) { test.waitOneFullPingRound(); assertTrue(test.vipStatus.isInRotation()); assertTrue(test.searchCluster.localCorpusDispatchTarget().isEmpty()); test.numDocsPerNode.get(0).set(-1); test.numDocsPerNode.get(1).set(-1); test.waitOneFullPingRound(); assertFalse(test.vipStatus.isInRotation()); test.numDocsPerNode.get(0).set(0); test.waitOneFullPingRound(); assertTrue(test.vipStatus.isInRotation()); } }
@Test public void requireThatVipStatusIsDefaultDownWithLocalDispatch() { try (State test = new State("cluster.1", 1, HostName.getLocalhost(), "b")) { assertTrue(test.searchCluster.localCorpusDispatchTarget().isPresent()); assertFalse(test.vipStatus.isInRotation()); test.waitOneFullPingRound(); assertTrue(test.vipStatus.isInRotation()); } }
@Test public void requireThatVipStatusStaysUpWithLocalDispatchAndClusterSize1() { try (State test = new State("cluster.1", 1, HostName.getLocalhost())) { assertTrue(test.searchCluster.localCorpusDispatchTarget().isPresent()); assertFalse(test.vipStatus.isInRotation()); test.waitOneFullPingRound(); assertTrue(test.vipStatus.isInRotation()); test.numDocsPerNode.get(0).set(-1); test.waitOneFullPingRound(); assertTrue(test.vipStatus.isInRotation()); } }
@Test public void requireThatVipStatusIsDefaultDownWithLocalDispatchAndClusterSize2() { try (State test = new State("cluster.1", 1, HostName.getLocalhost(), "otherhost")) { assertTrue(test.searchCluster.localCorpusDispatchTarget().isPresent()); assertFalse(test.vipStatus.isInRotation()); test.waitOneFullPingRound(); assertTrue(test.vipStatus.isInRotation()); test.numDocsPerNode.get(0).set(-1); test.waitOneFullPingRound(); assertFalse(test.vipStatus.isInRotation()); } }
@Test public void requireThatVipStatusDownWhenLocalIsDown() { try (State test = new State("cluster.1",1,HostName.getLocalhost(), "b")) { test.waitOneFullPingRound(); assertTrue(test.vipStatus.isInRotation()); assertTrue(test.searchCluster.localCorpusDispatchTarget().isPresent()); test.waitOneFullPingRound(); assertTrue(test.vipStatus.isInRotation()); test.numDocsPerNode.get(0).set(-1); test.waitOneFullPingRound(); assertFalse(test.vipStatus.isInRotation()); test.numDocsPerNode.get(0).set(1); test.waitOneFullPingRound(); assertTrue(test.vipStatus.isInRotation()); test.numDocsPerNode.get(1).set(-1); test.waitOneFullPingRound(); assertTrue(test.vipStatus.isInRotation()); test.numDocsPerNode.get(0).set(-1); test.numDocsPerNode.get(1).set(-1); test.waitOneFullPingRound(); assertFalse(test.vipStatus.isInRotation()); test.numDocsPerNode.get(1).set(1); test.waitOneFullPingRound(); assertFalse(test.vipStatus.isInRotation()); test.numDocsPerNode.get(0).set(1); test.waitOneFullPingRound(); assertTrue(test.vipStatus.isInRotation()); } }