@Override protected Host computeNext() { while (childIterator.hasNext()) { Host host = childIterator.next(); if (host.isUp() && replicas.contains(host) && childPolicy.distance(host) == HostDistance.LOCAL) { // UP replicas should be prioritized, retaining order from childPolicy return host; } else { // save for later if (nonReplicas == null) nonReplicas = new ArrayList<Host>(); nonReplicas.add(host); } } // This should only engage if all local replicas are DOWN if (nonReplicas != null) { if (nonReplicasIterator == null) nonReplicasIterator = nonReplicas.iterator(); if (nonReplicasIterator.hasNext()) return nonReplicasIterator.next(); } return endOfData(); } };
public HostAssert isUp() { assertThat(actual.isUp()).isTrue(); return this; }
public HostAssert isDown() { assertThat(actual.isUp()).isFalse(); return this; }
@Override protected Host computeNext() { while (replicasIterator.hasNext()) { Host host = replicasIterator.next(); if (host.isUp() && childPolicy.distance(host) == HostDistance.LOCAL) return host; } if (childIterator == null) childIterator = childPolicy.newQueryPlan(loggedKeyspace, statement); while (childIterator.hasNext()) { Host host = childIterator.next(); // Skip it if it was already a local replica if (!replicas.contains(host) || childPolicy.distance(host) != HostDistance.LOCAL) return host; } return endOfData(); } };
@Override public Boolean call() throws Exception { final Host host = findHost(cluster, ip); return host == null || !host.isUp(); } }
@Override public Boolean call() throws Exception { final Host host = findHost(cluster, ip); return host != null && host.isUp(); } }
private static int countUpHosts(Cluster cluster) { int ups = 0; for (Host host : cluster.getMetadata().getAllHosts()) { if (host.isUp()) ups += 1; } return ups; }
@BeforeMethod(groups = "unit") public void initMocks() { CodecRegistry codecRegistry = new CodecRegistry(); cluster = mock(Cluster.class); Configuration configuration = mock(Configuration.class); ProtocolOptions protocolOptions = mock(ProtocolOptions.class); Metadata metadata = mock(Metadata.class); childPolicy = mock(LoadBalancingPolicy.class); when(cluster.getConfiguration()).thenReturn(configuration); when(configuration.getCodecRegistry()).thenReturn(codecRegistry); when(configuration.getProtocolOptions()).thenReturn(protocolOptions); when(protocolOptions.getProtocolVersion()).thenReturn(ProtocolVersion.NEWEST_SUPPORTED); when(cluster.getMetadata()).thenReturn(metadata); when(metadata.getReplicas(Metadata.quote("keyspace"), routingKey)) .thenReturn(Sets.newLinkedHashSet(host1, host2)); when(childPolicy.newQueryPlan("keyspace", statement)) .thenReturn(Sets.newLinkedHashSet(host4, host3, host2, host1).iterator()); when(childPolicy.distance(any(Host.class))).thenReturn(HostDistance.LOCAL); when(host1.isUp()).thenReturn(true); when(host2.isUp()).thenReturn(true); when(host3.isUp()).thenReturn(true); when(host4.isUp()).thenReturn(true); }
boolean wasUp = host.isUp(); host.setDown();
void startSingleReconnectionAttempt(final Host host) { if (isClosed() || host.isUp()) return;
if (previous == null) { futures.add(schedule(hostAdded(newHost))); } else if (!previous.isUp()) { futures.add(schedule(hostUp(previous)));
private static boolean checkSchemaAgreement(Connection connection, Cluster.Manager cluster) throws InterruptedException, ExecutionException { DefaultResultSetFuture peersFuture = new DefaultResultSetFuture( null, cluster.protocolVersion(), new Requests.Query(SELECT_SCHEMA_PEERS)); DefaultResultSetFuture localFuture = new DefaultResultSetFuture( null, cluster.protocolVersion(), new Requests.Query(SELECT_SCHEMA_LOCAL)); connection.write(peersFuture); connection.write(localFuture); Set<UUID> versions = new HashSet<UUID>(); Row localRow = localFuture.get().one(); if (localRow != null && !localRow.isNull("schema_version")) versions.add(localRow.getUUID("schema_version")); for (Row row : peersFuture.get()) { InetSocketAddress addr = nativeAddressForPeerHost(row, connection.address, cluster); if (addr == null || row.isNull("schema_version")) continue; Host peer = cluster.metadata.getHost(addr); if (peer != null && peer.isUp()) versions.add(row.getUUID("schema_version")); } logger.debug("Checking for schema agreement: versions are {}", versions); return versions.size() <= 1; }
public HostAssert comesUpWithin(long duration, TimeUnit unit) { final CountDownLatch upSignal = new CountDownLatch(1); StateListener upListener = new StateListenerBase() { @Override public void onUp(Host host) { upSignal.countDown(); } @Override public void onAdd(Host host) { // Special case, cassandra will sometimes not send an 'UP' topology change event // for a new node, because of this we also listen for add events. upSignal.countDown(); } }; cluster.register(upListener); try { // If the host is already up or if we receive the UP signal within given time if (actual.isUp() || upSignal.await(duration, unit)) { return this; } } catch (InterruptedException e) { fail("Got interrupted while waiting for host to come up"); } finally { cluster.unregister(upListener); } fail(actual + " did not come up within " + duration + " " + unit); return this; }
public HostAssert isUp() { assertThat(actual.isUp()).isTrue(); return this; }
public HostAssert isDown() { assertThat(actual.isUp()).isFalse(); return this; }
@Override protected Host computeNext() { while (iter.hasNext()) { Host host = iter.next(); if (host.isUp() && childPolicy.distance(host) == HostDistance.LOCAL) return host; } if (childIterator == null) childIterator = childPolicy.newQueryPlan(loggedKeyspace, statement); while (childIterator.hasNext()) { Host host = childIterator.next(); // Skip it if it was already a local replica if (!replicas.contains(host) || childPolicy.distance(host) != HostDistance.LOCAL) return host; } return endOfData(); } };
@Override public Boolean call() throws Exception { final Host host = findHost(cluster, ip); return host != null && host.isUp(); } }
private int getNumberOfUpNodes() { int count = 0; for (Host host : session.getCluster().getMetadata().getAllHosts()) { if (host.isUp()) { ++count; } } return count; }
@Override public Boolean call() throws Exception { final Host host = findHost(cluster, ip); return host == null || !host.isUp(); } }
private static int countUpHosts(Cluster cluster) { int ups = 0; for (Host host : cluster.getMetadata().getAllHosts()) { if (host.isUp()) ups += 1; } return ups; }