use of akka.actor.Status.Failure in project controller by opendaylight.
the class RemoteTransactionContextTest method testLimiterOnFailure.
/**
* OperationLimiter should be correctly released when a failure, like AskTimeoutException occurs. Future reads
* need to complete immediately with the failure and modifications should not be throttled and thrown away
* immediately.
*/
@Test
public void testLimiterOnFailure() throws TimeoutException, InterruptedException {
txContext.executeModification(DELETE);
txContext.executeModification(DELETE);
assertEquals(2, limiter.availablePermits());
Future<Object> future = txContext.sendBatchedModifications();
assertEquals(2, limiter.availablePermits());
BatchedModifications msg = kit.expectMsgClass(BatchedModifications.class);
assertEquals(2, msg.getModifications().size());
assertEquals(1, msg.getTotalMessagesSent());
sendReply(new Failure(new NullPointerException()));
assertFuture(future, new OnComplete<Object>() {
@Override
public void onComplete(final Throwable failure, final Object success) {
assertTrue(failure instanceof NullPointerException);
assertEquals(4, limiter.availablePermits());
// The transaction has failed, no throttling should occur
txContext.executeModification(DELETE);
assertEquals(4, limiter.availablePermits());
// Executing a read should result in immediate failure
final SettableFuture<Boolean> readFuture = SettableFuture.create();
txContext.executeRead(new DataExists(), readFuture);
assertTrue(readFuture.isDone());
try {
readFuture.get();
fail("Read future did not fail");
} catch (ExecutionException | InterruptedException e) {
assertTrue(e.getCause() instanceof NullPointerException);
}
}
});
future = txContext.directCommit();
msg = kit.expectMsgClass(BatchedModifications.class);
// Modification should have been thrown away by the dropped transmit induced by executeRead()
assertEquals(0, msg.getModifications().size());
assertTrue(msg.isDoCommitOnReady());
assertTrue(msg.isReady());
assertEquals(2, msg.getTotalMessagesSent());
sendReply(new Failure(new IllegalStateException()));
assertFuture(future, new OnComplete<Object>() {
@Override
public void onComplete(final Throwable failure, final Object success) {
assertTrue(failure instanceof IllegalStateException);
}
});
kit.expectNoMsg();
}
Aggregations