use of org.apache.cassandra.exceptions.ReadSizeAbortException in project cassandra by apache.
the class AbstractClientSizeWarning method failThreshold.
public void failThreshold(String cql) throws UnknownHostException {
ICoordinator node = CLUSTER.coordinator(1);
for (int i = 0; i < failThresholdRowCount(); i++) node.execute("INSERT INTO " + KEYSPACE + ".tbl (pk, ck, v) VALUES (1, ?, ?)", ConsistencyLevel.ALL, i + 1, bytes(512));
if (shouldFlush())
CLUSTER.stream().forEach(i -> i.flush(KEYSPACE));
enable(true);
checkpointHistogram();
List<String> warnings = CLUSTER.get(1).callsOnInstance(() -> {
ClientWarn.instance.captureWarnings();
CoordinatorWarnings.init();
try {
QueryProcessor.execute(cql, org.apache.cassandra.db.ConsistencyLevel.ALL, QueryState.forInternalCalls());
Assert.fail("Expected query failure");
} catch (ReadSizeAbortException e) {
// expected, client transport returns an error message and includes client warnings
}
CoordinatorWarnings.done();
CoordinatorWarnings.reset();
return ClientWarn.instance.getWarnings();
}).call();
assertAbortWarnings(warnings);
assertHistogramUpdated();
assertWarnAborts(0, 1, 1);
try {
driverQueryAll(cql);
Assert.fail("Query should have thrown ReadFailureException");
} catch (com.datastax.driver.core.exceptions.ReadFailureException e) {
// without changing the client can't produce a better message...
// client does NOT include the message sent from the server in the exception; so the message doesn't work
// well in this case
assertThat(e.getMessage()).contains("responses were required but only 0 replica responded");
ImmutableSet<InetAddress> expectedKeys = ImmutableSet.of(InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }), InetAddress.getByAddress(new byte[] { 127, 0, 0, 2 }), InetAddress.getByAddress(new byte[] { 127, 0, 0, 3 }));
assertThat(e.getFailuresMap()).hasSizeBetween(1, 3).containsValue(RequestFailureReason.READ_SIZE.code).hasKeySatisfying(new Condition<InetAddress>() {
public boolean matches(InetAddress value) {
return expectedKeys.contains(value);
}
});
}
assertHistogramUpdated();
assertWarnAborts(0, 2, 1);
// query should no longer fail
enable(false);
SimpleQueryResult result = node.executeWithResult(cql, ConsistencyLevel.ALL);
assertThat(result.warnings()).isEmpty();
assertHistogramNotUpdated();
assertThat(driverQueryAll(cql).getExecutionInfo().getWarnings()).isEmpty();
assertHistogramNotUpdated();
assertWarnAborts(0, 2, 0);
}
Aggregations