Search in sources :

Example 1 with DataExists

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));
}
Also used : TestActorRef(akka.testkit.TestActorRef) ActorRef(akka.actor.ActorRef) DataExists(org.opendaylight.controller.cluster.datastore.messages.DataExists) Props(akka.actor.Props) Test(org.junit.Test)

Example 2 with DataExists

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());
        }
    };
}
Also used : ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) DataExists(org.opendaylight.controller.cluster.datastore.messages.DataExists) DataExistsReply(org.opendaylight.controller.cluster.datastore.messages.DataExistsReply) TestKit(akka.testkit.javadsl.TestKit) Test(org.junit.Test)

Example 3 with DataExists

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);
}
Also used : DataExists(org.opendaylight.controller.cluster.datastore.messages.DataExists) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 4 with DataExists

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());
        }
    };
}
Also used : ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) DataExists(org.opendaylight.controller.cluster.datastore.messages.DataExists) DataExistsReply(org.opendaylight.controller.cluster.datastore.messages.DataExistsReply) TestKit(akka.testkit.javadsl.TestKit) Test(org.junit.Test)

Example 5 with DataExists

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();
}
Also used : SettableFuture(com.google.common.util.concurrent.SettableFuture) DataExists(org.opendaylight.controller.cluster.datastore.messages.DataExists) Failure(akka.actor.Status.Failure) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 DataExists (org.opendaylight.controller.cluster.datastore.messages.DataExists)5 ActorRef (akka.actor.ActorRef)3 TestActorRef (akka.testkit.TestActorRef)3 TestKit (akka.testkit.javadsl.TestKit)2 DataExistsReply (org.opendaylight.controller.cluster.datastore.messages.DataExistsReply)2 Props (akka.actor.Props)1 Failure (akka.actor.Status.Failure)1 SettableFuture (com.google.common.util.concurrent.SettableFuture)1 BatchedModifications (org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)1 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)1