private void addKeyspace (Cluster cluster, String keyspaceName) throws Exception { try { keyspaces.put( keyspaceName, cluster.getKeyspace( keyspaceName ) ); } catch (ConnectionException e) { logger.error("Unable to get keyspace client for keyspace: {}, detail: {}", keyspaceName, e.getMessage()); throw e; } }
@Override public boolean failure(ConnectionException e) { LOG.error(e.getMessage(), e); return false; } });
@Override public boolean onException(ConnectionException e) { Assert.fail(e.getMessage()); return true; } }).execute();
@Test public void testGetSingleColumnNotExistsAsync() { Future<OperationResult<Column<String>>> future = null; try { future = keyspace.prepareQuery(CF_STANDARD1).getKey("A") .getColumn("DoesNotExist").executeAsync(); future.get(1000, TimeUnit.MILLISECONDS); } catch (ConnectionException e) { LOG.info("ConnectionException: " + e.getMessage()); Assert.fail(); } catch (InterruptedException e) { LOG.info(e.getMessage()); Assert.fail(); } catch (ExecutionException e) { if (e.getCause() instanceof NotFoundException) LOG.info(e.getCause().getMessage()); else { Assert.fail(e.getMessage()); } } catch (TimeoutException e) { future.cancel(true); LOG.info(e.getMessage()); Assert.fail(); } }
@Override public void dropStorage() throws MessageQueueException { try { keyspace.dropColumnFamily(this.queueColumnFamily); try { Thread.sleep(SCHEMA_CHANGE_DELAY); } catch (InterruptedException e) { } } catch (ConnectionException e) { if (!e.getMessage().contains("already exist")) throw new MessageQueueException("Failed to create column family for " + queueColumnFamily.getName(), e); } try { keyspace.dropColumnFamily(this.keyIndexColumnFamily); try { Thread.sleep(SCHEMA_CHANGE_DELAY); } catch (InterruptedException e) { } } catch (ConnectionException e) { if (!e.getMessage().contains("already exist")) throw new MessageQueueException("Failed to create column family for " + queueColumnFamily.getName(), e); } }
@Test public void testCompositeKey() { MockCompositeType key = new MockCompositeType("A", 1, 2, true, "B"); MutationBatch m = keyspace.prepareMutationBatch(); m.withRow(CF_COMPOSITE_KEY, key).putColumn("Test", "Value", null); try { m.execute(); } catch (ConnectionException e) { LOG.error(e.getMessage(), e); Assert.fail(); } try { ColumnList<String> row = keyspace.prepareQuery(CF_COMPOSITE_KEY) .getKey(key).execute().getResult(); Assert.assertFalse(row.isEmpty()); } catch (ConnectionException e) { LOG.error(e.getMessage(), e); Assert.fail(); } } }
/** * {@inheritDoc} */ @Override public Result check() { boolean res = false; String msg = ""; try { keyspace.prepareCqlStatement() .withCql("SELECT now() FROM system.local") .withConsistencyLevel(ConsistencyLevel.CL_QUORUM) .execute(); res = true; } catch (ConnectionException ex) { LOGGER.error("Unable to connect to cassandra", ex); msg = ex.getMessage(); } return res ? Result.healthy() : Result.unhealthy(msg); } }
/** * @return Result of healthy or unhealthy based on the cql statement */ @Override public Result check() { boolean res = false; String msg = ""; try { this.keyspace.prepareCqlStatement() .withCql(SELECT_NOW_FROM_SYSTEM_LOCAL) .withConsistencyLevel(ConsistencyLevel.CL_QUORUM) .execute(); res = true; } catch (ConnectionException ex) { LOGGER.trace("Health Check encountered exception: ", ex); msg = ex.getMessage(); } return res ? Result.healthy() : Result.unhealthy(msg); } }
} catch (ConnectionException e) { Assert.fail(); LOG.info(e.getMessage()); e.printStackTrace();