use of com.datastax.oss.driver.api.core.metadata.Node in project spring-boot by spring-projects.
the class CassandraDriverHealthIndicatorTests method mockCqlSessionWithNodeState.
private CqlSession mockCqlSessionWithNodeState(NodeState... nodeStates) {
CqlSession session = mock(CqlSession.class);
Metadata metadata = mock(Metadata.class);
List<Node> nodes = new ArrayList<>();
for (NodeState nodeState : nodeStates) {
Node node = mock(Node.class);
given(node.getState()).willReturn(nodeState);
nodes.add(node);
}
given(session.getMetadata()).willReturn(metadata);
given(metadata.getNodes()).willReturn(createNodesWithRandomUUID(nodes));
return session;
}
use of com.datastax.oss.driver.api.core.metadata.Node in project spring-boot by spring-projects.
the class CassandraDriverReactiveHealthIndicatorTests method mockCqlSessionWithNodeState.
private CqlSession mockCqlSessionWithNodeState(NodeState... nodeStates) {
CqlSession session = mock(CqlSession.class);
Metadata metadata = mock(Metadata.class);
List<Node> nodes = new ArrayList<>();
for (NodeState nodeState : nodeStates) {
Node node = mock(Node.class);
given(node.getState()).willReturn(nodeState);
nodes.add(node);
}
given(session.getMetadata()).willReturn(metadata);
given(metadata.getNodes()).willReturn(createNodesWithRandomUUID(nodes));
return session;
}
use of com.datastax.oss.driver.api.core.metadata.Node in project zipkin by openzipkin.
the class CassandraStorageExtension method poolInFlight.
// Use metrics to wait for in-flight requests to settle per
// https://groups.google.com/a/lists.datastax.com/g/java-driver-user/c/5um_yGNynow/m/cInH5I5jBgAJ
static boolean poolInFlight(CqlSession session) {
Collection<Node> nodes = session.getMetadata().getNodes().values();
Optional<Metrics> metrics = session.getMetrics();
for (Node node : nodes) {
int inFlight = metrics.flatMap(m -> m.getNodeMetric(node, DefaultNodeMetric.IN_FLIGHT)).map(m -> ((Gauge<Integer>) m).getValue()).orElse(0);
if (inFlight > 0)
return true;
}
return false;
}
use of com.datastax.oss.driver.api.core.metadata.Node in project zipkin by openzipkin.
the class InternalForTests method mockSession.
static CqlSession mockSession() {
CqlSession session = mock(CqlSession.class);
Metadata metadata = mock(Metadata.class);
Node node = mock(Node.class);
when(session.getMetadata()).thenReturn(metadata);
when(metadata.getNodes()).thenReturn(Collections.singletonMap(UUID.fromString("11111111-1111-1111-1111-111111111111"), node));
when(node.getCassandraVersion()).thenReturn(Version.parse("3.11.9"));
KeyspaceMetadata keyspaceMetadata = mock(KeyspaceMetadata.class);
when(session.getMetadata()).thenReturn(metadata);
when(metadata.getKeyspace("zipkin2")).thenReturn(Optional.of(keyspaceMetadata));
when(keyspaceMetadata.getTable(TABLE_SERVICE_REMOTE_SERVICES)).thenReturn(Optional.of(mock(TableMetadata.class)));
return session;
}
use of com.datastax.oss.driver.api.core.metadata.Node in project zipkin by openzipkin.
the class SchemaTest method ensureKeyspaceMetadata_failsWhenKeyspaceMetadataIsNotNull.
@Test
public void ensureKeyspaceMetadata_failsWhenKeyspaceMetadataIsNotNull() {
CqlSession session = mock(CqlSession.class);
Metadata metadata = mock(Metadata.class);
Node node = mock(Node.class);
when(session.getMetadata()).thenReturn(metadata);
when(metadata.getNodes()).thenReturn(Collections.singletonMap(UUID.fromString("11111111-1111-1111-1111-111111111111"), node));
when(node.getCassandraVersion()).thenReturn(Version.parse("3.11.3"));
assertThatThrownBy(() -> Schema.ensureKeyspaceMetadata(session, "zipkin2")).isInstanceOf(RuntimeException.class).hasMessageStartingWith("Cannot read keyspace metadata for keyspace");
}
Aggregations