use of com.datastax.oss.driver.api.core.CqlSession 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.CqlSession in project spring-boot by spring-projects.
the class CassandraDriverReactiveHealthIndicatorTests method healthWithOneUnknownNodeShouldReturnDown.
@Test
void healthWithOneUnknownNodeShouldReturnDown() {
CqlSession session = mockCqlSessionWithNodeState(NodeState.UNKNOWN);
CassandraDriverReactiveHealthIndicator healthIndicator = new CassandraDriverReactiveHealthIndicator(session);
Mono<Health> health = healthIndicator.health();
StepVerifier.create(health).consumeNextWith((h) -> assertThat(h.getStatus()).isEqualTo(Status.DOWN)).verifyComplete();
}
use of com.datastax.oss.driver.api.core.CqlSession in project zeppelin by apache.
the class CassandraInterpreterTest method setUp.
@BeforeClass
public static synchronized void setUp() throws IOException, InterruptedException {
System.setProperty("cassandra.skip_wait_for_gossip_to_settle", "0");
System.setProperty("cassandra.load_ring_state", "false");
System.setProperty("cassandra.initial_token", "0");
System.setProperty("cassandra.num_tokens", "nil");
System.setProperty("cassandra.allocate_tokens_for_local_replication_factor", "nil");
EmbeddedCassandraServerHelper.startEmbeddedCassandra();
CqlSession session = EmbeddedCassandraServerHelper.getSession();
new CQLDataLoader(session).load(new ClassPathCQLDataSet("prepare_all.cql", "zeppelin"));
Properties properties = new Properties();
properties.setProperty(CASSANDRA_CLUSTER_NAME, EmbeddedCassandraServerHelper.getClusterName());
properties.setProperty(CASSANDRA_COMPRESSION_PROTOCOL, "NONE");
properties.setProperty(CASSANDRA_CREDENTIALS_USERNAME, "none");
properties.setProperty(CASSANDRA_CREDENTIALS_PASSWORD, "none");
properties.setProperty(CASSANDRA_LOAD_BALANCING_POLICY, "DEFAULT");
properties.setProperty(CASSANDRA_RETRY_POLICY, "DEFAULT");
properties.setProperty(CASSANDRA_RECONNECTION_POLICY, "DEFAULT");
properties.setProperty(CASSANDRA_SPECULATIVE_EXECUTION_POLICY, "DEFAULT");
properties.setProperty(CASSANDRA_POOLING_CONNECTION_PER_HOST_LOCAL, "2");
properties.setProperty(CASSANDRA_POOLING_CONNECTION_PER_HOST_REMOTE, "1");
properties.setProperty(CASSANDRA_POOLING_MAX_REQUESTS_PER_CONNECTION, "1024");
properties.setProperty(CASSANDRA_POOLING_POOL_TIMEOUT_MILLIS, "5000");
properties.setProperty(CASSANDRA_POOLING_HEARTBEAT_INTERVAL_SECONDS, "30");
properties.setProperty(CASSANDRA_QUERY_DEFAULT_CONSISTENCY, "ONE");
properties.setProperty(CASSANDRA_QUERY_DEFAULT_SERIAL_CONSISTENCY, "SERIAL");
properties.setProperty(CASSANDRA_QUERY_DEFAULT_FETCH_SIZE, "5000");
properties.setProperty(CASSANDRA_SOCKET_CONNECTION_TIMEOUT_MILLIS, "5000");
properties.setProperty(CASSANDRA_SOCKET_READ_TIMEOUT_MILLIS, "12000");
properties.setProperty(CASSANDRA_SOCKET_TCP_NO_DELAY, "true");
properties.setProperty(CASSANDRA_HOSTS, EmbeddedCassandraServerHelper.getHost());
properties.setProperty(CASSANDRA_PORT, Integer.toString(EmbeddedCassandraServerHelper.getNativeTransportPort()));
properties.setProperty("datastax-java-driver.advanced.connection.pool.local.size", "1");
interpreter = new CassandraInterpreter(properties);
interpreter.open();
}
use of com.datastax.oss.driver.api.core.CqlSession in project zeppelin by apache.
the class CassandraInterpreterTest method should_execute_statement_with_timestamp_option.
@Test
public void should_execute_statement_with_timestamp_option() throws Exception {
// Given
String statement1 = "INSERT INTO zeppelin.ts(key,val) VALUES('k','v1');";
String statement2 = "@timestamp=15\n" + "INSERT INTO zeppelin.ts(key,val) VALUES('k','v2');";
CqlSession session = EmbeddedCassandraServerHelper.getSession();
// Insert v1 with current timestamp
interpreter.interpret(statement1, intrContext);
System.out.println("going to read data from zeppelin.ts;");
session.execute("SELECT val FROM zeppelin.ts LIMIT 1").forEach(x -> System.out.println("row " + x));
Thread.sleep(1);
// When
// Insert v2 with past timestamp
interpreter.interpret(statement2, intrContext);
System.out.println("going to read data from zeppelin.ts;");
session.execute("SELECT val FROM zeppelin.ts LIMIT 1").forEach(x -> System.out.println("row " + x));
final String actual = session.execute("SELECT val FROM zeppelin.ts LIMIT 1").one().getString("val");
// Then
assertThat(actual).isEqualTo("v1");
}
use of com.datastax.oss.driver.api.core.CqlSession in project cas by apereo.
the class DefaultCassandraSessionFactory method initializeCassandraSession.
private CqlSession initializeCassandraSession(final BaseCassandraProperties cassandra) {
val builder = CqlSession.builder().withKeyspace(cassandra.getKeyspace());
if (StringUtils.isNotBlank(cassandra.getUsername()) && StringUtils.isNotBlank(cassandra.getPassword())) {
builder.withAuthCredentials(cassandra.getUsername(), cassandra.getPassword());
}
if (StringUtils.isNotBlank(cassandra.getLocalDc())) {
builder.withLocalDatacenter(cassandra.getLocalDc());
}
builder.withSslContext(this.sslContext);
cassandra.getContactPoints().stream().map(contactPoint -> {
val hostAndPort = Splitter.on(":").splitToList(contactPoint);
val host = hostAndPort.get(0).trim();
val port = Integer.parseInt(hostAndPort.get(1).trim());
return new InetSocketAddress(host, port);
}).forEach(builder::addContactPoint);
return builder.build();
}
Aggregations