use of com.datastax.oss.driver.internal.core.adminrequest.AdminRow in project java-driver by datastax.
the class SchemaParserTestBase method mockLegacyKeyspaceRow.
protected static AdminRow mockLegacyKeyspaceRow(String keyspaceName) {
AdminRow row = mock(AdminRow.class);
when(row.getString("keyspace_name")).thenReturn(keyspaceName);
when(row.getBoolean("durable_writes")).thenReturn(true);
when(row.contains("strategy_class")).thenReturn(true);
when(row.getString("strategy_class")).thenReturn("org.apache.cassandra.locator.SimpleStrategy");
when(row.getString("strategy_options")).thenReturn("{\"replication_factor\":\"1\"}");
return row;
}
use of com.datastax.oss.driver.internal.core.adminrequest.AdminRow in project java-driver by datastax.
the class DefaultTopologyMonitorTest method should_refresh_node_list_from_local_and_peers.
@Test
public void should_refresh_node_list_from_local_and_peers() {
// Given
AdminRow local = mockLocalRow(1, node1.getHostId());
AdminRow peer3 = mockPeersRow(3, UUID.randomUUID());
AdminRow peer2 = mockPeersRow(2, node2.getHostId());
topologyMonitor.stubQueries(new StubbedQuery("SELECT * FROM system.local", mockResult(local)), new StubbedQuery("SELECT * FROM system.peers_v2", Collections.emptyMap(), null, true), new StubbedQuery("SELECT * FROM system.peers", mockResult(peer3, peer2)));
// When
CompletionStage<Iterable<NodeInfo>> futureInfos = topologyMonitor.refreshNodeList();
// Then
assertThatStage(futureInfos).isSuccess(infos -> {
Iterator<NodeInfo> iterator = infos.iterator();
NodeInfo info1 = iterator.next();
assertThat(info1.getEndPoint()).isEqualTo(node1.getEndPoint());
assertThat(info1.getDatacenter()).isEqualTo("dc1");
NodeInfo info3 = iterator.next();
assertThat(info3.getEndPoint().resolve()).isEqualTo(new InetSocketAddress("127.0.0.3", 9042));
assertThat(info3.getDatacenter()).isEqualTo("dc3");
NodeInfo info2 = iterator.next();
assertThat(info2.getEndPoint()).isEqualTo(node2.getEndPoint());
assertThat(info2.getDatacenter()).isEqualTo("dc2");
});
}
use of com.datastax.oss.driver.internal.core.adminrequest.AdminRow in project java-driver by datastax.
the class DefaultTopologyMonitorTest method should_get_new_node_from_peers.
@Test
public void should_get_new_node_from_peers() {
// Given
AdminRow peer3 = mockPeersRow(4, UUID.randomUUID());
AdminRow peer2 = mockPeersRow(3, node2.getHostId());
AdminRow peer1 = mockPeersRow(2, node1.getHostId());
topologyMonitor.isSchemaV2 = false;
topologyMonitor.stubQueries(new StubbedQuery("SELECT * FROM system.peers", mockResult(peer3, peer2, peer1)));
// When
CompletionStage<Optional<NodeInfo>> futureInfo = topologyMonitor.getNewNodeInfo(ADDRESS2);
// Then
assertThatStage(futureInfo).isSuccess(maybeInfo -> {
assertThat(maybeInfo.isPresent()).isTrue();
NodeInfo info = maybeInfo.get();
assertThat(info.getDatacenter()).isEqualTo("dc2");
});
// The rpc_address in each row should have been tried, only the last row should have been
// converted
verify(peer3).getInetAddress("rpc_address");
verify(peer3, never()).getString(anyString());
verify(peer2).getInetAddress("rpc_address");
verify(peer2, never()).getString(anyString());
verify(peer1).getInetAddress("rpc_address");
verify(peer1).getString("data_center");
}
use of com.datastax.oss.driver.internal.core.adminrequest.AdminRow in project java-driver by datastax.
the class DefaultTopologyMonitorTest method should_warn_when_control_host_found_in_system_peers_v2.
@Test
public void should_warn_when_control_host_found_in_system_peers_v2() {
// Given
AdminRow local = mockLocalRow(1, node1.getHostId());
AdminRow peer3 = mockPeersRow(3, UUID.randomUUID());
AdminRow peer2 = mockPeersRow(2, node2.getHostId());
// invalid
AdminRow peer1 = mockPeersRow(1, node2.getHostId());
topologyMonitor.stubQueries(new StubbedQuery("SELECT * FROM system.local", mockResult(local)), new StubbedQuery("SELECT * FROM system.peers_v2", mockResult(peer3, peer2, peer1)));
// When
CompletionStage<Iterable<NodeInfo>> futureInfos = topologyMonitor.refreshNodeList();
// Then
assertThatStage(futureInfos).isSuccess(infos -> assertThat(infos).hasSize(3).extractingResultOf("getEndPoint").containsOnlyOnce(node1.getEndPoint()));
assertLog(Level.WARN, "[null] Control node /127.0.0.1:9042 has an entry for itself in system.peers_v2: " + "this entry will be ignored. This is likely due to a misconfiguration; " + "please verify your rpc_address configuration in cassandra.yaml on " + "all nodes in your cluster.");
}
use of com.datastax.oss.driver.internal.core.adminrequest.AdminRow in project java-driver by datastax.
the class PeerRowValidatorTest method mockRowV2.
private AdminRow mockRowV2(String nullColumn) {
AdminRow peerRow = mock(AdminRow.class);
when(peerRow.isNull("host_id")).thenReturn(nullColumn.equals("host_id"));
when(peerRow.isNull("native_address")).thenReturn(nullColumn.equals("native_address"));
when(peerRow.isNull("native_port")).thenReturn(nullColumn.equals("native_port"));
when(peerRow.isNull("rpc_address")).thenReturn(true);
when(peerRow.isNull("data_center")).thenReturn(nullColumn.equals("data_center"));
when(peerRow.isNull("rack")).thenReturn(nullColumn.equals("rack"));
when(peerRow.isNull("tokens")).thenReturn(nullColumn.equals("tokens"));
when(peerRow.isNull("schema_version")).thenReturn(nullColumn.equals("schema_version"));
return peerRow;
}
Aggregations