Search in sources :

Example 26 with AdminRow

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

the class SchemaAgreementCheckerTest method mockLocalRow.

private AdminRow mockLocalRow(@SuppressWarnings("SameParameterValue") UUID schemaVersion) {
    AdminRow row = mock(AdminRow.class);
    when(row.getUuid("host_id")).thenReturn(node1.getHostId());
    when(row.getUuid("schema_version")).thenReturn(schemaVersion);
    return row;
}
Also used : AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow)

Example 27 with AdminRow

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

the class SchemaAgreementCheckerTest method mockPeerRow.

private static AdminRow mockPeerRow(UUID hostId, UUID schemaVersion, boolean hasDatacenter, boolean hasRack, boolean hasRpcAddress, boolean hasTokens) {
    AdminRow row = mock(AdminRow.class);
    when(row.getUuid("host_id")).thenReturn(hostId);
    when(row.isNull("host_id")).thenReturn(hostId == null);
    when(row.getUuid("schema_version")).thenReturn(schemaVersion);
    when(row.isNull("schema_version")).thenReturn(schemaVersion == null);
    when(row.isNull("data_center")).thenReturn(!hasDatacenter);
    when(row.isNull("rack")).thenReturn(!hasRack);
    when(row.isNull("tokens")).thenReturn(!hasTokens);
    when(row.isNull("rpc_address")).thenReturn(!hasRpcAddress);
    when(row.isNull("native_address")).thenReturn(true);
    when(row.isNull("native_port")).thenReturn(true);
    return row;
}
Also used : AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow)

Example 28 with AdminRow

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

the class DefaultTopologyMonitorTest method mockLocalRow.

private AdminRow mockLocalRow(int i, UUID hostId) {
    try {
        AdminRow row = mock(AdminRow.class);
        when(row.isNull("host_id")).thenReturn(hostId == null);
        when(row.getUuid("host_id")).thenReturn(hostId);
        when(row.getInetAddress("broadcast_address")).thenReturn(InetAddress.getByName("127.0.0." + i));
        when(row.isNull("data_center")).thenReturn(false);
        when(row.getString("data_center")).thenReturn("dc" + i);
        when(row.getInetAddress("listen_address")).thenReturn(InetAddress.getByName("127.0.0." + i));
        when(row.isNull("rack")).thenReturn(false);
        when(row.getString("rack")).thenReturn("rack" + i);
        when(row.getString("release_version")).thenReturn("release_version" + i);
        // The driver should not use this column for the local row, because it can contain the
        // non-broadcast RPC address. Simulate the bug to ensure it's handled correctly.
        when(row.isNull("rpc_address")).thenReturn(false);
        when(row.getInetAddress("rpc_address")).thenReturn(InetAddress.getByName("0.0.0.0"));
        when(row.isNull("tokens")).thenReturn(false);
        when(row.getSetOfString("tokens")).thenReturn(ImmutableSet.of("token" + i));
        when(row.contains("peer")).thenReturn(false);
        return row;
    } catch (UnknownHostException e) {
        fail("unexpected", e);
        return null;
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow)

Example 29 with AdminRow

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

the class DefaultTopologyMonitorTest method mockPeersRow.

private AdminRow mockPeersRow(int i, UUID hostId) {
    try {
        AdminRow row = mock(AdminRow.class);
        when(row.isNull("host_id")).thenReturn(hostId == null);
        when(row.getUuid("host_id")).thenReturn(hostId);
        when(row.getInetAddress("peer")).thenReturn(InetAddress.getByName("127.0.0." + i));
        when(row.isNull("data_center")).thenReturn(false);
        when(row.getString("data_center")).thenReturn("dc" + i);
        when(row.isNull("rack")).thenReturn(false);
        when(row.getString("rack")).thenReturn("rack" + i);
        when(row.getString("release_version")).thenReturn("release_version" + i);
        when(row.isNull("rpc_address")).thenReturn(false);
        when(row.getInetAddress("rpc_address")).thenReturn(InetAddress.getByName("127.0.0." + i));
        when(row.isNull("tokens")).thenReturn(false);
        when(row.getSetOfString("tokens")).thenReturn(ImmutableSet.of("token" + i));
        when(row.contains("peer")).thenReturn(true);
        when(row.isNull("native_address")).thenReturn(true);
        when(row.isNull("native_port")).thenReturn(true);
        return row;
    } catch (UnknownHostException e) {
        fail("unexpected", e);
        return null;
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow)

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

@Test
@UseDataProvider("columnsToCheckV1")
public void should_skip_invalid_peers_row(String columnToCheck) {
    // Given
    topologyMonitor.isSchemaV2 = false;
    node2.broadcastAddress = ADDRESS2;
    AdminRow peer2 = mockPeersRow(2, node2.getHostId());
    when(peer2.isNull(columnToCheck)).thenReturn(true);
    topologyMonitor.stubQueries(new StubbedQuery("SELECT * FROM system.peers WHERE peer = :address", ImmutableMap.of("address", ADDRESS2.getAddress()), 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 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)

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