use of com.datastax.driver.core.exceptions.NoHostAvailableException in project nifi by apache.
the class QueryCassandraTest method testProcessorNoInputFlowFileAndExceptions.
@Test
public void testProcessorNoInputFlowFileAndExceptions() {
setUpStandardProcessorConfig();
// Test no input flowfile
testRunner.setIncomingConnection(false);
testRunner.run(1, true, true);
testRunner.assertAllFlowFilesTransferred(QueryCassandra.REL_SUCCESS, 1);
testRunner.clearTransferState();
// Test exceptions
processor.setExceptionToThrow(new NoHostAvailableException(new HashMap<InetSocketAddress, Throwable>()));
testRunner.run(1, true, true);
testRunner.assertAllFlowFilesTransferred(QueryCassandra.REL_RETRY, 1);
testRunner.clearTransferState();
processor.setExceptionToThrow(new ReadTimeoutException(new InetSocketAddress("localhost", 9042), ConsistencyLevel.ANY, 0, 1, false));
testRunner.run(1, true, true);
testRunner.assertAllFlowFilesTransferred(QueryCassandra.REL_RETRY, 1);
testRunner.clearTransferState();
processor.setExceptionToThrow(new InvalidQueryException(new InetSocketAddress("localhost", 9042), "invalid query"));
testRunner.run(1, true, true);
// No files transferred to failure if there was no incoming connection
testRunner.assertAllFlowFilesTransferred(QueryCassandra.REL_FAILURE, 0);
testRunner.clearTransferState();
processor.setExceptionToThrow(new ProcessException());
testRunner.run(1, true, true);
// No files transferred to failure if there was no incoming connection
testRunner.assertAllFlowFilesTransferred(QueryCassandra.REL_FAILURE, 0);
testRunner.clearTransferState();
processor.setExceptionToThrow(null);
}
use of com.datastax.driver.core.exceptions.NoHostAvailableException in project nifi by apache.
the class QueryCassandraTest method testProcessorEmptyFlowFileAndExceptions.
@Test
public void testProcessorEmptyFlowFileAndExceptions() {
setUpStandardProcessorConfig();
// Run with empty flowfile
testRunner.setIncomingConnection(true);
processor.setExceptionToThrow(null);
testRunner.enqueue("".getBytes());
testRunner.run(1, true, true);
testRunner.assertAllFlowFilesTransferred(QueryCassandra.REL_SUCCESS, 1);
testRunner.clearTransferState();
// Test exceptions
processor.setExceptionToThrow(new NoHostAvailableException(new HashMap<InetSocketAddress, Throwable>()));
testRunner.enqueue("".getBytes());
testRunner.run(1, true, true);
testRunner.assertAllFlowFilesTransferred(QueryCassandra.REL_RETRY, 1);
testRunner.clearTransferState();
processor.setExceptionToThrow(new ReadTimeoutException(new InetSocketAddress("localhost", 9042), ConsistencyLevel.ANY, 0, 1, false));
testRunner.enqueue("".getBytes());
testRunner.run(1, true, true);
testRunner.assertAllFlowFilesTransferred(QueryCassandra.REL_RETRY, 1);
testRunner.clearTransferState();
processor.setExceptionToThrow(new InvalidQueryException(new InetSocketAddress("localhost", 9042), "invalid query"));
testRunner.enqueue("".getBytes());
testRunner.run(1, true, true);
testRunner.assertAllFlowFilesTransferred(QueryCassandra.REL_FAILURE, 1);
testRunner.clearTransferState();
processor.setExceptionToThrow(new ProcessException());
testRunner.enqueue("".getBytes());
testRunner.run(1, true, true);
testRunner.assertAllFlowFilesTransferred(QueryCassandra.REL_FAILURE, 1);
}
use of com.datastax.driver.core.exceptions.NoHostAvailableException in project java-driver by datastax.
the class ClusterInitTest method should_be_able_to_close_cluster_that_never_successfully_connected.
/**
* Validates that a Cluster that was never able to successfully establish connection a session can be closed
* properly.
*
* @test_category connection
* @expected_result Cluster closes within 1 second.
*/
@Test(groups = "short")
public void should_be_able_to_close_cluster_that_never_successfully_connected() throws Exception {
Cluster cluster = Cluster.builder().addContactPointsWithPorts(new InetSocketAddress("127.0.0.1", 65534)).withNettyOptions(nonQuietClusterCloseOptions).build();
try {
cluster.connect();
fail("Should not have been able to connect.");
} catch (NoHostAvailableException e) {
// Expected.
CloseFuture closeFuture = cluster.closeAsync();
try {
closeFuture.get(1, TimeUnit.SECONDS);
} catch (TimeoutException e1) {
fail("Close Future did not complete quickly.");
}
} finally {
cluster.close();
}
}
use of com.datastax.driver.core.exceptions.NoHostAvailableException in project presto by prestodb.
the class NativeCassandraSession method executeWithSession.
private <T> T executeWithSession(SessionCallable<T> sessionCallable) {
ReconnectionPolicy reconnectionPolicy = cluster.getConfiguration().getPolicies().getReconnectionPolicy();
ReconnectionSchedule schedule = reconnectionPolicy.newSchedule();
long deadline = System.currentTimeMillis() + noHostAvailableRetryTimeout.toMillis();
while (true) {
try {
return sessionCallable.executeWithSession(session.get());
} catch (NoHostAvailableException e) {
long timeLeft = deadline - System.currentTimeMillis();
if (timeLeft <= 0) {
throw e;
} else {
long delay = Math.min(schedule.nextDelayMs(), timeLeft);
log.warn(e.getCustomMessage(10, true, true));
log.warn("Reconnecting in %dms", delay);
try {
Thread.sleep(delay);
} catch (InterruptedException interrupted) {
Thread.currentThread().interrupt();
throw new RuntimeException("interrupted", interrupted);
}
}
}
}
}
use of com.datastax.driver.core.exceptions.NoHostAvailableException in project cassandra by apache.
the class ViewLongTest method testConflictResolution.
@Test
public void testConflictResolution() throws Throwable {
final int writers = 96;
final int insertsPerWriter = 50;
final Map<Integer, Exception> failedWrites = new ConcurrentHashMap<>();
createTable("CREATE TABLE %s (" + "a int," + "b int," + "c int," + "PRIMARY KEY (a, b))");
createView("CREATE MATERIALIZED VIEW %s AS SELECT * FROM %s " + "WHERE c IS NOT NULL AND a IS NOT NULL AND b IS NOT NULL " + "PRIMARY KEY (c, a, b)");
CyclicBarrier semaphore = new CyclicBarrier(writers);
Thread[] threads = new Thread[writers];
for (int i = 0; i < writers; i++) {
final int writer = i;
Thread t = NamedThreadFactory.createAnonymousThread(new WrappedRunnable() {
public void runMayThrow() {
try {
int writerOffset = writer * insertsPerWriter;
semaphore.await();
for (int i = 0; i < insertsPerWriter; i++) {
try {
executeNet("INSERT INTO %s (a, b, c) VALUES (?, ?, ?) USING TIMESTAMP 1", 1, 1, i + writerOffset);
} catch (NoHostAvailableException | WriteTimeoutException e) {
failedWrites.put(i + writerOffset, e);
}
}
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
});
t.start();
threads[i] = t;
}
for (int i = 0; i < writers; i++) threads[i].join();
for (int i = 0; i < writers * insertsPerWriter; i++) {
if (executeNet("SELECT COUNT(*) FROM system.batches").one().getLong(0) == 0)
break;
try {
// This will throw exceptions whenever there are exceptions trying to push the view values out, caused
// by the view becoming overwhelmed.
BatchlogManager.instance.startBatchlogReplay().get();
} catch (Throwable ignore) {
}
}
int value = executeNet("SELECT c FROM %s WHERE a = 1 AND b = 1").one().getInt("c");
List<Row> rows = executeNet("SELECT c FROM " + keyspace() + "." + currentView()).all();
boolean containsC = false;
StringBuilder others = new StringBuilder();
StringBuilder overlappingFailedWrites = new StringBuilder();
for (Row row : rows) {
int c = row.getInt("c");
if (c == value)
containsC = true;
else {
if (others.length() != 0)
others.append(' ');
others.append(c);
if (failedWrites.containsKey(c)) {
if (overlappingFailedWrites.length() != 0)
overlappingFailedWrites.append(' ');
overlappingFailedWrites.append(c).append(':').append(failedWrites.get(c).getMessage());
}
}
}
if (rows.size() > 1) {
throw new AssertionError(String.format("Expected 1 row, but found %d; %s c = %d, " + "and (%s) of which (%s) failed to insert", rows.size(), containsC ? "found row with" : "no rows contained", value, others, overlappingFailedWrites));
} else if (rows.isEmpty()) {
throw new AssertionError(String.format("Could not find row with c = %d", value));
} else if (!containsC) {
throw new AssertionError(String.format("Single row had c = %d, expected %d", rows.get(0).getInt("c"), value));
}
}
Aggregations