use of org.opendaylight.controller.cluster.datastore.messages.DataExists in project controller by opendaylight.
the class ShardTransactionFailureTest method testNegativeExistsWithReadWriteTransactionClosed.
@Test(expected = ReadFailedException.class)
public void testNegativeExistsWithReadWriteTransactionClosed() throws Exception {
final ActorRef shard = createShard();
final Props props = ShardTransaction.props(RW, STORE.newReadWriteTransaction(nextTransactionId()), shard, datastoreContext, shardStats);
final TestActorRef<ShardTransaction> subject = TestActorRef.create(getSystem(), props, "testNegativeExistsWithReadWriteTransactionClosed");
Future<Object> future = akka.pattern.Patterns.ask(subject, new DataExists(YangInstanceIdentifier.EMPTY, DataStoreVersions.CURRENT_VERSION), 3000);
Await.result(future, Duration.create(3, TimeUnit.SECONDS));
subject.underlyingActor().getDOMStoreTransaction().abortFromTransactionActor();
future = akka.pattern.Patterns.ask(subject, new DataExists(YangInstanceIdentifier.EMPTY, DataStoreVersions.CURRENT_VERSION), 3000);
Await.result(future, Duration.create(3, TimeUnit.SECONDS));
}
use of org.opendaylight.controller.cluster.datastore.messages.DataExists in project controller by opendaylight.
the class ShardTransactionTest method testOnReceiveDataExistsPositive.
@Test
public void testOnReceiveDataExistsPositive() throws Exception {
new TestKit(getSystem()) {
{
testOnReceiveDataExistsPositive(newTransactionActor(RO, readOnlyTransaction(), "testDataExistsPositiveRO"));
testOnReceiveDataExistsPositive(newTransactionActor(RW, readWriteTransaction(), "testDataExistsPositiveRW"));
}
private void testOnReceiveDataExistsPositive(final ActorRef transaction) {
transaction.tell(new DataExists(YangInstanceIdentifier.EMPTY, DataStoreVersions.CURRENT_VERSION), getRef());
DataExistsReply reply = expectMsgClass(duration("5 seconds"), DataExistsReply.class);
assertTrue(reply.exists());
}
};
}
use of org.opendaylight.controller.cluster.datastore.messages.DataExists in project controller by opendaylight.
the class LocalTransactionContextTest method testExists.
@Test
public void testExists() {
YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.EMPTY;
doReturn(Futures.immediateCheckedFuture(true)).when(readWriteTransaction).exists(yangInstanceIdentifier);
localTransactionContext.executeRead(new DataExists(yangInstanceIdentifier, DataStoreVersions.CURRENT_VERSION), SettableFuture.<Boolean>create());
verify(readWriteTransaction).exists(yangInstanceIdentifier);
}
use of org.opendaylight.controller.cluster.datastore.messages.DataExists in project controller by opendaylight.
the class ShardTransactionTest method testOnReceiveDataExistsNegative.
@Test
public void testOnReceiveDataExistsNegative() throws Exception {
new TestKit(getSystem()) {
{
testOnReceiveDataExistsNegative(newTransactionActor(RO, readOnlyTransaction(), "testDataExistsNegativeRO"));
testOnReceiveDataExistsNegative(newTransactionActor(RW, readWriteTransaction(), "testDataExistsNegativeRW"));
}
private void testOnReceiveDataExistsNegative(final ActorRef transaction) {
transaction.tell(new DataExists(TestModel.TEST_PATH, DataStoreVersions.CURRENT_VERSION), getRef());
DataExistsReply reply = expectMsgClass(duration("5 seconds"), DataExistsReply.class);
assertFalse(reply.exists());
}
};
}
use of org.opendaylight.controller.cluster.datastore.messages.DataExists 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