use of com.datastax.oss.driver.api.core.CqlSession in project zipkin by openzipkin.
the class CassandraStorageExtension method clear.
void clear(CassandraStorage storage) {
// Clear any key cache
CassandraSpanConsumer spanConsumer = storage.spanConsumer;
if (spanConsumer != null)
spanConsumer.clear();
CqlSession session = storage.session.session;
if (session == null)
session = globalSession;
List<String> toTruncate = new ArrayList<>(SEARCH_TABLES);
toTruncate.add(TABLE_DEPENDENCY);
toTruncate.add(TABLE_SPAN);
for (String table : toTruncate) {
try {
session.execute("TRUNCATE " + storage.keyspace + "." + table);
} catch (InvalidQueryException e) {
assertThat(e).hasMessage("unconfigured table " + table);
}
}
blockWhileInFlight(storage);
}
use of com.datastax.oss.driver.api.core.CqlSession 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.CqlSession in project zipkin by openzipkin.
the class CassandraStorageExtension method tryToInitializeSession.
// Builds a session without trying to use a namespace or init UDTs
static CqlSession tryToInitializeSession(String contactPoint) {
CassandraStorage storage = newStorageBuilder(contactPoint).build();
CqlSession session = null;
try {
session = DefaultSessionFactory.buildSession(storage);
session.execute("SELECT now() FROM system.local");
} catch (Throwable e) {
propagateIfFatal(e);
if (session != null)
session.close();
assumeTrue(false, e.getMessage());
}
return session;
}
use of com.datastax.oss.driver.api.core.CqlSession in project zipkin by openzipkin.
the class InternalForTests method writeDependencyLinks.
static void writeDependencyLinks(CassandraStorage storage, List<DependencyLink> links, long midnightUTC) {
CqlSession session = storage.session();
PreparedStatement prepared = session.prepare("INSERT INTO " + Schema.TABLE_DEPENDENCY + " (day,parent,child,calls,errors)" + " VALUES (?,?,?,?,?)");
LocalDate day = Instant.ofEpochMilli(midnightUTC).atZone(ZoneOffset.UTC).toLocalDate();
for (DependencyLink link : links) {
int i = 0;
storage.session().execute(prepared.bind().setLocalDate(i++, day).setString(i++, link.parent()).setString(i++, link.child()).setLong(i++, link.callCount()).setLong(i, link.errorCount()));
}
}
use of com.datastax.oss.driver.api.core.CqlSession 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;
}
Aggregations