/** * Get configured Cluster * * Can be used to obtain connections to Cassandra in the container */ public Cluster getCluster() { return getCluster(this); }
@Override protected Session createNewConnection() { try { return CassandraContainer.getCluster(container) .newSession(); } catch (DriverException e) { log.error("Could not obtain cassandra connection"); throw new ConnectionCreationException("Could not obtain cassandra connection", e); } }
@Test public void testCassandraGetCluster() { try (CassandraContainer cassandraContainer = new CassandraContainer<>()) { cassandraContainer.start(); ResultSet resultSet = performQuery(cassandraContainer.getCluster(), "SELECT release_version FROM system.local"); assertTrue("Query was not applied", resultSet.wasApplied()); assertNotNull("Result set has no release_version", resultSet.one().getString(0)); } }