Search in sources :

Example 11 with AdminRow

use of com.datastax.oss.driver.internal.core.adminrequest.AdminRow in project java-driver by datastax.

the class PeerRowValidatorTest method mockRowV1.

private AdminRow mockRowV1(String nullColumn) {
    AdminRow peerRow = mock(AdminRow.class);
    when(peerRow.isNull("host_id")).thenReturn(nullColumn.equals("host_id"));
    when(peerRow.isNull("rpc_address")).thenReturn(nullColumn.equals("rpc_address"));
    when(peerRow.isNull("native_address")).thenReturn(true);
    when(peerRow.isNull("native_port")).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;
}
Also used : AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow)

Example 12 with AdminRow

use of com.datastax.oss.driver.internal.core.adminrequest.AdminRow in project java-driver by datastax.

the class DefaultTopologyMonitorTest method should_skip_invalid_peers_row_v2.

@Test
@UseDataProvider("columnsToCheckV2")
public void should_skip_invalid_peers_row_v2(String columnToCheck) {
    // Given
    topologyMonitor.isSchemaV2 = true;
    node2.broadcastAddress = ADDRESS2;
    AdminRow peer2 = mockPeersV2Row(2, node2.getHostId());
    when(peer2.isNull(columnToCheck)).thenReturn(true);
    topologyMonitor.stubQueries(new StubbedQuery("SELECT * FROM system.peers_v2 WHERE peer = :address and peer_port = :port", ImmutableMap.of("address", ADDRESS2.getAddress(), "port", 9042), mockResult(peer2)));
    // When
    CompletionStage<Optional<NodeInfo>> futureInfo = topologyMonitor.refreshNode(node2);
    // Then
    assertThatStage(futureInfo).isSuccess(maybeInfo -> assertThat(maybeInfo).isEmpty());
    assertThat(node2.broadcastAddress).isNotNull().isEqualTo(ADDRESS2);
    assertLog(Level.WARN, "[null] Found invalid row in system.peers_v2 for peer: /127.0.0.2. " + "This is likely a gossip or snitch issue, this node will be ignored.");
}
Also used : Optional(java.util.Optional) AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 13 with AdminRow

use of com.datastax.oss.driver.internal.core.adminrequest.AdminRow in project java-driver by datastax.

the class DefaultTopologyMonitorTest method should_refresh_node_from_peers_if_broadcast_address_is_not_present_V2.

@Test
public void should_refresh_node_from_peers_if_broadcast_address_is_not_present_V2() {
    // Given
    topologyMonitor.isSchemaV2 = true;
    node2.broadcastAddress = null;
    AdminRow peer3 = mockPeersV2Row(3, UUID.randomUUID());
    AdminRow peer2 = mockPeersV2Row(2, node2.getHostId());
    topologyMonitor.stubQueries(new StubbedQuery("SELECT * FROM system.peers_v2", mockResult(peer3, peer2)));
    // When
    CompletionStage<Optional<NodeInfo>> futureInfo = topologyMonitor.refreshNode(node2);
    // Then
    assertThatStage(futureInfo).isSuccess(maybeInfo -> {
        assertThat(maybeInfo.isPresent()).isTrue();
        NodeInfo info = maybeInfo.get();
        assertThat(info.getDatacenter()).isEqualTo("dc2");
    });
    // The host_id in each row should have been tried, only the last row should have been
    // converted
    verify(peer3).getUuid("host_id");
    verify(peer3, never()).getString(anyString());
    verify(peer2, times(2)).getUuid("host_id");
    verify(peer2).getString("data_center");
}
Also used : Optional(java.util.Optional) AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow) Test(org.junit.Test)

Example 14 with AdminRow

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_v2.

@Test
public void should_get_new_node_from_peers_v2() {
    // Given
    AdminRow peer3 = mockPeersV2Row(4, UUID.randomUUID());
    AdminRow peer2 = mockPeersV2Row(3, node2.getHostId());
    AdminRow peer1 = mockPeersV2Row(2, node1.getHostId());
    topologyMonitor.isSchemaV2 = true;
    topologyMonitor.stubQueries(new StubbedQuery("SELECT * FROM system.peers_v2", 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 natove in each row should have been tried, only the last row should have been
    // converted
    verify(peer3).getInetAddress("native_address");
    verify(peer3, never()).getString(anyString());
    verify(peer2).getInetAddress("native_address");
    verify(peer2, never()).getString(anyString());
    verify(peer1).getInetAddress("native_address");
    verify(peer1).getString("data_center");
}
Also used : Optional(java.util.Optional) AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow) Test(org.junit.Test)

Example 15 with AdminRow

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.

@Test
public void should_warn_when_control_host_found_in_system_peers() {
    // 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", Collections.emptyMap(), null, true), new StubbedQuery("SELECT * FROM system.peers", 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: " + "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.");
}
Also used : AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow) Test(org.junit.Test)

Aggregations

AdminRow (com.datastax.oss.driver.internal.core.adminrequest.AdminRow)43 Test (org.junit.Test)12 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)7 Optional (java.util.Optional)6 ImmutableMap (com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap)5 UnknownHostException (java.net.UnknownHostException)3 UUID (java.util.UUID)3 ClusteringOrder (com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder)2 ColumnMetadata (com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata)2 IndexMetadata (com.datastax.oss.driver.api.core.metadata.schema.IndexMetadata)2 KeyspaceMetadata (com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata)2 TableMetadata (com.datastax.oss.driver.api.core.metadata.schema.TableMetadata)2 DataType (com.datastax.oss.driver.api.core.type.DataType)2 SchemaRefresh (com.datastax.oss.driver.internal.core.metadata.schema.refresh.SchemaRefresh)2 ImmutableList (com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList)2 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2 InetSocketAddress (java.net.InetSocketAddress)2 DseColumnMetadata (com.datastax.dse.driver.api.core.metadata.schema.DseColumnMetadata)1 DseIndexMetadata (com.datastax.dse.driver.api.core.metadata.schema.DseIndexMetadata)1 DseKeyspaceMetadata (com.datastax.dse.driver.api.core.metadata.schema.DseKeyspaceMetadata)1