use of com.datastax.oss.driver.internal.core.adminrequest.AdminResult in project java-driver by datastax.
the class Cassandra3SchemaQueriesTest method should_ignore_malformed_rows.
@Test
public void should_ignore_malformed_rows() {
SchemaQueriesWithMockedChannel queries = new SchemaQueriesWithMockedChannel(driverChannel, node, config, "test");
CompletionStage<SchemaRows> result = queries.execute();
// Keyspace
Call call = queries.calls.poll();
assertThat(call.query).isEqualTo("SELECT * FROM system_schema.keyspaces");
call.result.complete(mockResult(mockRow("keyspace_name", "ks1")));
// No types
call = queries.calls.poll();
assertThat(call.query).isEqualTo("SELECT * FROM system_schema.types");
call.result.complete(mockResult());
// Tables
call = queries.calls.poll();
assertThat(call.query).isEqualTo("SELECT * FROM system_schema.tables");
call.result.complete(mockResult(mockRow("keyspace_name", "ks", "table_name", "foo"), // Missing keyspace name:
mockRow("table_name", "foo")));
// Columns
call = queries.calls.poll();
call.result.complete(mockResult(mockRow("keyspace_name", "ks", "table_name", "foo", "column_name", "k"), // Missing keyspace name:
mockRow("table_name", "foo", "column_name", "k"), // Missing table name:
mockRow("keyspace_name", "ks", "column_name", "k")));
AdminResult page2 = mockResult(mockRow("keyspace_name", "ks1", "table_name", "foo", "column_name", "v"));
AdminResult page1 = mockResult(page2, mockRow("keyspace_name", "ks1", "table_name", "foo", "column_name", "k"));
call.result.complete(page1);
// No indexes
call = queries.calls.poll();
assertThat(call.query).isEqualTo("SELECT * FROM system_schema.indexes");
call.result.complete(mockResult());
// No views
call = queries.calls.poll();
assertThat(call.query).isEqualTo("SELECT * FROM system_schema.views");
call.result.complete(mockResult());
// No functions
call = queries.calls.poll();
assertThat(call.query).isEqualTo("SELECT * FROM system_schema.functions");
call.result.complete(mockResult());
// No aggregates
call = queries.calls.poll();
assertThat(call.query).isEqualTo("SELECT * FROM system_schema.aggregates");
call.result.complete(mockResult());
channel.runPendingTasks();
assertThatStage(result).isSuccess(rows -> {
assertThat(rows.tables().keySet()).containsOnly(KS_ID);
assertThat(rows.tables().get(KS_ID)).hasSize(1);
assertThat(rows.tables().get(KS_ID).iterator().next().getString("table_name")).isEqualTo("foo");
assertThat(rows.columns().keySet()).containsOnly(KS_ID);
assertThat(rows.columns().get(KS_ID).keySet()).containsOnly(FOO_ID);
assertThat(rows.columns().get(KS_ID).get(FOO_ID).iterator().next().getString("column_name")).isEqualTo("k");
});
}
use of com.datastax.oss.driver.internal.core.adminrequest.AdminResult in project java-driver by datastax.
the class DefaultTopologyMonitor method refreshNode.
@Override
public CompletionStage<Optional<NodeInfo>> refreshNode(Node node) {
if (closeFuture.isDone()) {
return CompletableFutures.failedFuture(new IllegalStateException("closed"));
}
LOG.debug("[{}] Refreshing info for {}", logPrefix, node);
DriverChannel channel = controlConnection.channel();
EndPoint localEndPoint = channel.getEndPoint();
if (node.getEndPoint().equals(channel.getEndPoint())) {
// refreshNode is called for nodes that just came up. If the control node just came up, it
// means the control connection just reconnected, which means we did a full node refresh. So
// we don't need to process this call.
LOG.debug("[{}] Ignoring refresh of control node", logPrefix);
return CompletableFuture.completedFuture(Optional.empty());
} else if (node.getBroadcastAddress().isPresent()) {
CompletionStage<AdminResult> query;
if (isSchemaV2) {
query = query(channel, "SELECT * FROM " + getPeerTableName() + " WHERE peer = :address and peer_port = :port", ImmutableMap.of("address", node.getBroadcastAddress().get().getAddress(), "port", node.getBroadcastAddress().get().getPort()));
} else {
query = query(channel, "SELECT * FROM " + getPeerTableName() + " WHERE peer = :address", ImmutableMap.of("address", node.getBroadcastAddress().get().getAddress()));
}
return query.thenApply(result -> firstPeerRowAsNodeInfo(result, localEndPoint));
} else {
return query(channel, "SELECT * FROM " + getPeerTableName()).thenApply(result -> findInPeers(result, node.getHostId(), localEndPoint));
}
}
use of com.datastax.oss.driver.internal.core.adminrequest.AdminResult in project java-driver by datastax.
the class Cassandra3SchemaQueriesTest method should_query_with_paging.
@Test
public void should_query_with_paging() {
SchemaQueriesWithMockedChannel queries = new SchemaQueriesWithMockedChannel(driverChannel, node, config, "test");
CompletionStage<SchemaRows> result = queries.execute();
// Keyspace
Call call = queries.calls.poll();
assertThat(call.query).isEqualTo("SELECT * FROM system_schema.keyspaces");
call.result.complete(mockResult(mockRow("keyspace_name", "ks1")));
// No types
call = queries.calls.poll();
assertThat(call.query).isEqualTo("SELECT * FROM system_schema.types");
call.result.complete(mockResult());
// Tables
call = queries.calls.poll();
assertThat(call.query).isEqualTo("SELECT * FROM system_schema.tables");
call.result.complete(mockResult(mockRow("keyspace_name", "ks1", "table_name", "foo")));
// Columns: paged
call = queries.calls.poll();
assertThat(call.query).isEqualTo("SELECT * FROM system_schema.columns");
AdminResult page2 = mockResult(mockRow("keyspace_name", "ks1", "table_name", "foo", "column_name", "v"));
AdminResult page1 = mockResult(page2, mockRow("keyspace_name", "ks1", "table_name", "foo", "column_name", "k"));
call.result.complete(page1);
// No indexes
call = queries.calls.poll();
assertThat(call.query).isEqualTo("SELECT * FROM system_schema.indexes");
call.result.complete(mockResult());
// No views
call = queries.calls.poll();
assertThat(call.query).isEqualTo("SELECT * FROM system_schema.views");
call.result.complete(mockResult());
// No functions
call = queries.calls.poll();
assertThat(call.query).isEqualTo("SELECT * FROM system_schema.functions");
call.result.complete(mockResult());
// No aggregates
call = queries.calls.poll();
assertThat(call.query).isEqualTo("SELECT * FROM system_schema.aggregates");
call.result.complete(mockResult());
channel.runPendingTasks();
assertThatStage(result).isSuccess(rows -> {
assertThat(rows.columns().keySet()).containsOnly(KS1_ID);
assertThat(rows.columns().get(KS1_ID).keySet()).containsOnly(FOO_ID);
assertThat(rows.columns().get(KS1_ID).get(FOO_ID)).extracting(r -> r.getString("column_name")).containsExactly("k", "v");
});
}
use of com.datastax.oss.driver.internal.core.adminrequest.AdminResult in project java-driver by datastax.
the class SchemaQueriesTest method mockResult.
protected static AdminResult mockResult(AdminResult next, AdminRow... rows) {
AdminResult result = mock(AdminResult.class);
if (next == null) {
when(result.hasNextPage()).thenReturn(false);
} else {
when(result.hasNextPage()).thenReturn(true);
when(result.nextPage()).thenReturn(CompletableFuture.completedFuture(next));
}
when(result.iterator()).thenReturn(Iterators.forArray(rows));
return result;
}
use of com.datastax.oss.driver.internal.core.adminrequest.AdminResult in project java-driver by datastax.
the class ReprepareOnUpTest method should_limit_number_of_statements_to_reprepare.
@Test
public void should_limit_number_of_statements_to_reprepare() {
when(defaultProfile.getInt(DefaultDriverOption.REPREPARE_MAX_STATEMENTS)).thenReturn(3);
MockReprepareOnUp reprepareOnUp = new MockReprepareOnUp("test", pool, ImmediateEventExecutor.INSTANCE, getMockPayloads('a', 'b', 'c', 'd', 'e', 'f'), context, whenPrepared);
reprepareOnUp.start();
MockAdminQuery adminQuery = reprepareOnUp.queries.poll();
assertThat(adminQuery).isNotNull();
assertThat(adminQuery.request).isInstanceOf(Query.class);
assertThat(((Query) adminQuery.request).query).isEqualTo("SELECT prepared_id FROM system.prepared_statements");
// server knows no ids:
adminQuery.resultFuture.complete(new AdminResult(preparedIdRows(), null, DefaultProtocolVersion.DEFAULT));
for (char c = 'a'; c <= 'c'; c++) {
adminQuery = reprepareOnUp.queries.poll();
assertThat(adminQuery).isNotNull();
assertThat(adminQuery.request).isInstanceOf(Prepare.class);
assertThat(((Prepare) adminQuery.request).cqlQuery).isEqualTo("mock query " + c);
adminQuery.resultFuture.complete(null);
}
assertThatStage(done).isSuccess(v -> assertThat(reprepareOnUp.queries).isEmpty());
}
Aggregations