Search in sources :

Example 6 with AdminRow

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;
}
Also used : AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow)

Example 7 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_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");
    });
}
Also used : InetSocketAddress(java.net.InetSocketAddress) AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow) Test(org.junit.Test)

Example 8 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.

@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");
}
Also used : Optional(java.util.Optional) AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow) Test(org.junit.Test)

Example 9 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_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.");
}
Also used : AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow) Test(org.junit.Test)

Example 10 with AdminRow

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;
}
Also used : AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow)

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