protected void checkCassandraException(Exception e) { _mexceptions.incr(); if (e instanceof AlreadyExistsException || e instanceof AuthenticationException || e instanceof DriverException || e instanceof DriverInternalError || e instanceof InvalidConfigurationInQueryException || e instanceof InvalidQueryException || e instanceof InvalidTypeException || e instanceof QueryExecutionException || e instanceof QueryTimeoutException || e instanceof QueryValidationException || e instanceof ReadTimeoutException || e instanceof SyntaxError || e instanceof TraceRetrievalException || e instanceof TruncateException || e instanceof UnauthorizedException || e instanceof UnavailableException || e instanceof ReadTimeoutException || e instanceof WriteTimeoutException) { throw new ReportedFailedException(e); } else { throw new RuntimeException(e); } }
@Test public void testShouldReturnConfigurationError() throws Exception { String message = "This is a config error"; server.prime(when(query).then(configurationError(message))); thrown.expect(InvalidConfigurationInQueryException.class); thrown.expectMessage(endsWith(message)); query(); }
@Test public void testInValidCreateIndex() { String createIndexQuery = "CREATE CUSTOM INDEX " + TestingConstants.INDEX_NAME_CONSTANT + " ON " + cassandraUtils.getKeyspace() + "." + cassandraUtils.getTable() + "(lucene) " + "USING 'com.stratio.cassandra.lucene.Index' " + "WITH OPTIONS = { " + "'refresh_seconds' : '1', " + "'schema' : '{ " + " fields : { " + " \"addres.inexistent.latitude\" : {type:\"string\"}}}'};"; try { cassandraUtils.executeQuery(createIndexQuery); assertFalse("Creating invalid index must throw an Exception but does not ", true); } catch (InvalidConfigurationInQueryException e) { String expectedMessage = "'schema' is invalid : No column definition 'addres.inexistent' for mapper 'addres.inexistent.latitude'"; assertEquals("Cretaing invalid index must return InvalidConfigurationInQueryException(" + expectedMessage + ") but returns InvalidConfigurationInQueryException(" + e.getMessage() + ")", expectedMessage, e.getMessage()); } }
@Test public void testInValidCreateIndex2() { String createIndexQuery = "CREATE CUSTOM INDEX " + TestingConstants.INDEX_NAME_CONSTANT + " ON " + cassandraUtils.getKeyspace() + "." + cassandraUtils.getTable() + "(lucene) " + "USING 'com.stratio.cassandra.lucene.Index' " + "WITH OPTIONS = { " + "'refresh_seconds' : '1', " + "'schema' : '{ " + " fields : { " + "\"addres.inexistent\" : {type:\"string\"}}}'};"; try { cassandraUtils.executeQuery(createIndexQuery); assertFalse("Creating invalid index must throw an Exception but does not ", true); } catch (InvalidConfigurationInQueryException e) { String expectedMessage = "'schema' is invalid : No column definition 'addres.inexistent' for mapper 'addres.inexistent'"; assertEquals("Cretaing invalid index must return InvalidConfigurationInQueryException(" + expectedMessage + ") but returns InvalidConfigurationInQueryException(" + e.getMessage() + ")", expectedMessage, e.getMessage()); } }
@Test public void testInValidCreateIndex3() { String createIndexQuery = "CREATE CUSTOM INDEX " + TestingConstants.INDEX_NAME_CONSTANT + " ON " + cassandraUtils.getKeyspace() + "." + cassandraUtils.getTable() + "(lucene) " + "USING 'com.stratio.cassandra.lucene.Index' " + "WITH OPTIONS = { " + "'refresh_seconds' : '1', " + "'schema' : '{ " + " fields : { " + "\"addres.city\" : {type:\"string\"}," + "\"addres.zip\" : {type:\"integer\"}," + "\"addres.bool\" : {type:\"boolean\"}," + "\"addres.hight\" : {type:\"float\"}," + "\"addres.point.latitude\" : {type:\"float\"}," + "\"addres.point.longitude\" : {type:\"bytes\"}," + "first_name : {type:\"string\"}}}'};"; try { cassandraUtils.executeQuery(createIndexQuery); assertFalse("Creating invalid index must throw an Exception but does not ", true); } catch (InvalidConfigurationInQueryException e) { String expectedMessage = "'schema' is invalid : 'org.apache.cassandra.db.marshal.FloatType' is not supported by mapper 'addres.point.longitude'"; assertEquals("Cretaing invalid index must return InvalidConfigurationInQueryException(" + expectedMessage + ") but returns InvalidConfigurationInQueryException(" + e.getMessage() + ")", expectedMessage, e.getMessage()); } }
@Test public void testInValidCreateIndex4() { String createIndexQuery = "CREATE CUSTOM INDEX " + TestingConstants.INDEX_NAME_CONSTANT + " ON " + cassandraUtils.getKeyspace() + "." + cassandraUtils.getTable() + "(lucene) " + "USING 'com.stratio.cassandra.lucene.Index' " + "WITH OPTIONS = { " + "'refresh_seconds' : '1', " + "'schema' : '{ " + " fields : { " + "\"addres.city\" : {type:\"string\"}," + "\"addres.zip\" : {type:\"integer\"}," + "\"addres.bool\" : {type:\"boolean\"}," + "\"addres.hight\" : {type:\"float\"}," + "\"addres.point.latitude\" : {type:\"float\"}," + "\"addres.point.longitude.inexistent\" : {type:\"float\"}," + "first_name : {type:\"string\"}}}'};"; try { cassandraUtils.executeQuery(createIndexQuery); assertFalse("Creating invalid index must throw an Exception but does not ", true); } catch (InvalidConfigurationInQueryException e) { String expectedMessage = "'schema' is invalid : No column definition 'addres.point.longitude.inexistent' for mapper 'addres.point.longitude.inexistent'"; assertEquals("Cretaing invalid index must return InvalidConfigurationInQueryException(" + expectedMessage + ") but returns InvalidConfigurationInQueryException(" + e.getMessage() + ")", expectedMessage, e.getMessage()); } }
private void revertCompressionChunkLength() throws Exception { try { // try with compression options for Cassandra 3.x // see https://docs.datastax.com/en/cql/3.3/cql/cql_reference/compressSubprop.html session.execute("alter table trace_entry with compression = {'class':" + " 'org.apache.cassandra.io.compress.LZ4Compressor', 'chunk_length_kb' :" + " 64};"); } catch (InvalidConfigurationInQueryException e) { logger.debug(e.getMessage(), e); // try with compression options for Cassandra 2.x // see https://docs.datastax.com/en/cql/3.1/cql/cql_reference/compressSubprop.html session.execute("alter table trace_entry with compression" + " = {'sstable_compression': 'SnappyCompressor', 'chunk_length_kb' : 64};"); } }
public void createTableWithTWCS(String createTableQuery, int expirationHours, boolean useAndInsteadOfWith, boolean fallbackToSTCS) { // as long as gc_grace_seconds is less than TTL, then tombstones can be collected // immediately (https://issues.apache.org/jira/browse/CASSANDRA-4917) // // not using gc_grace_seconds of 0 since that disables hinted handoff // (http://www.uberobert.com/cassandra_gc_grace_disables_hinted_handoff) // // it seems any value over max_hint_window_in_ms (which defaults to 3 hours) is good long gcGraceSeconds = HOURS.toSeconds(4); // using unchecked_tombstone_compaction=true for better tombstone purging // see http://thelastpickle.com/blog/2016/12/08/TWCS-part1.html String term = useAndInsteadOfWith ? "and" : "with"; try { wrappedSession.execute(createTableQuery + " " + term + " compaction = { 'class' :" + " 'TimeWindowCompactionStrategy', 'compaction_window_unit' : 'HOURS'," + " 'compaction_window_size' : '" + getCompactionWindowSizeHours(expirationHours) + "', 'unchecked_tombstone_compaction' : true } and gc_grace_seconds = " + gcGraceSeconds); } catch (InvalidConfigurationInQueryException e) { logger.debug(e.getMessage(), e); if (fallbackToSTCS) { wrappedSession.execute(createTableQuery + " " + term + " compaction = { 'class' : 'SizeTieredCompactionStrategy'," + " 'unchecked_tombstone_compaction' : true } and gc_grace_seconds = " + gcGraceSeconds); } else { wrappedSession.execute(createTableQuery + " " + term + " compaction = { 'class' : 'DateTieredCompactionStrategy'," + " 'unchecked_tombstone_compaction' : true } and gc_grace_seconds = " + gcGraceSeconds); } } }
public Response toResponse(InvalidConfigurationInQueryException exception) { LOG.error("foo", exception); return Response.status(Status.NOT_FOUND).entity(exception.getCause()).build(); }