Search in sources :

Example 16 with NoHostAvailableException

use of com.datastax.driver.core.exceptions.NoHostAvailableException in project cassandra by apache.

the class AuditLoggerTest method testCqlPrepareQueryError.

@Test
public void testCqlPrepareQueryError() {
    createTable("CREATE TABLE %s (id int primary key, v1 text, v2 text)");
    String cql = "INSERT INTO " + KEYSPACE + '.' + currentTable() + " (id, v1, v2) VALUES (?,?,?)";
    try {
        Session session = sessionNet();
        PreparedStatement pstmt = session.prepare(cql);
        AuditLogEntry logEntry = ((InMemoryAuditLogger) AuditLogManager.instance.getLogger()).inMemQueue.poll();
        assertLogEntry(cql, AuditLogEntryType.PREPARE_STATEMENT, logEntry, false);
        dropTable("DROP TABLE %s");
        ResultSet rs = session.execute(pstmt.bind(1, "insert_audit", "test"));
        Assert.fail("should not succeed");
    } catch (NoHostAvailableException e) {
    // nop
    }
    AuditLogEntry logEntry = ((InMemoryAuditLogger) AuditLogManager.instance.getLogger()).inMemQueue.poll();
    assertLogEntry(logEntry, null);
    logEntry = ((InMemoryAuditLogger) AuditLogManager.instance.getLogger()).inMemQueue.poll();
    assertLogEntry(logEntry, cql);
    assertEquals(0, ((InMemoryAuditLogger) AuditLogManager.instance.getLogger()).inMemQueue.size());
}
Also used : NoHostAvailableException(com.datastax.driver.core.exceptions.NoHostAvailableException) ResultSet(com.datastax.driver.core.ResultSet) PreparedStatement(com.datastax.driver.core.PreparedStatement) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Session(com.datastax.driver.core.Session) Test(org.junit.Test)

Example 17 with NoHostAvailableException

use of com.datastax.driver.core.exceptions.NoHostAvailableException in project cassandra by apache.

the class BulkLoaderTest method testBulkLoader_WithArgs.

@Test
public void testBulkLoader_WithArgs() throws Exception {
    ToolResult tool = ToolRunner.invokeClass(BulkLoader.class, "-d", "127.9.9.1", OfflineToolUtils.sstableDirName("legacy_sstables", "legacy_ma_simple"));
    assertEquals(-1, tool.getExitCode());
    if (!(tool.getException().getCause() instanceof BulkLoadException))
        throw tool.getException();
    if (!(tool.getException().getCause().getCause() instanceof NoHostAvailableException))
        throw tool.getException();
    assertNoUnexpectedThreadsStarted(new String[] { "ObjectCleanerThread", "globalEventExecutor-[1-9]-[1-9]", "globalEventExecutor-[1-9]-[1-9]", "Shutdown-checker", "cluster[0-9]-connection-reaper-[0-9]" });
    assertSchemaNotLoaded();
    assertCLSMNotLoaded();
    assertSystemKSNotLoaded();
    assertKeyspaceNotLoaded();
    assertServerNotLoaded();
}
Also used : NoHostAvailableException(com.datastax.driver.core.exceptions.NoHostAvailableException) ToolResult(org.apache.cassandra.tools.ToolRunner.ToolResult) Test(org.junit.Test)

Example 18 with NoHostAvailableException

use of com.datastax.driver.core.exceptions.NoHostAvailableException in project storm by apache.

the class BaseCassandraBolt method prepare.

/**
 * {@inheritDoc}
 */
@Override
public void prepare(Map<String, Object> topoConfig, TopologyContext topologyContext, OutputCollector outputCollector) {
    this.outputCollector = outputCollector;
    this.topoConfig = topoConfig;
    Map<String, Object> cassandraClientConfig = cassandraConfig != null ? cassandraConfig : topoConfig;
    this.cassandraConf = new CassandraConf(cassandraClientConfig);
    this.client = clientProvider.getClient(cassandraClientConfig);
    try {
        session = client.connect();
    } catch (NoHostAvailableException e) {
        outputCollector.reportError(e);
        throw e;
    }
}
Also used : NoHostAvailableException(com.datastax.driver.core.exceptions.NoHostAvailableException) CassandraConf(org.apache.storm.cassandra.client.CassandraConf)

Aggregations

NoHostAvailableException (com.datastax.driver.core.exceptions.NoHostAvailableException)18 Test (org.junit.Test)8 ProcessException (org.apache.nifi.processor.exception.ProcessException)5 InetSocketAddress (java.net.InetSocketAddress)4 Session (com.datastax.driver.core.Session)3 HashMap (java.util.HashMap)3 TimeoutException (java.util.concurrent.TimeoutException)3 ToolResult (org.apache.cassandra.tools.ToolRunner.ToolResult)3 ComponentLog (org.apache.nifi.logging.ComponentLog)3 PreparedStatement (com.datastax.driver.core.PreparedStatement)2 ResultSet (com.datastax.driver.core.ResultSet)2 ResultSetFuture (com.datastax.driver.core.ResultSetFuture)2 InvalidQueryException (com.datastax.driver.core.exceptions.InvalidQueryException)2 QueryExecutionException (com.datastax.driver.core.exceptions.QueryExecutionException)2 QueryValidationException (com.datastax.driver.core.exceptions.QueryValidationException)2 ReadTimeoutException (com.datastax.driver.core.exceptions.ReadTimeoutException)2 Charset (java.nio.charset.Charset)2 FlowFile (org.apache.nifi.flowfile.FlowFile)2 ProcessSession (org.apache.nifi.processor.ProcessSession)2 CassandraConf (org.apache.storm.cassandra.client.CassandraConf)2