use of akka.testkit.javadsl.TestKit in project controller by opendaylight.
the class ShardTransactionTest method testOnReceiveBatchedModificationsFailure.
@Test(expected = TestException.class)
public void testOnReceiveBatchedModificationsFailure() throws Exception {
new TestKit(getSystem()) {
{
ShardDataTreeTransactionParent parent = Mockito.mock(ShardDataTreeTransactionParent.class);
DataTreeModification mockModification = Mockito.mock(DataTreeModification.class);
ReadWriteShardDataTreeTransaction mockWriteTx = new ReadWriteShardDataTreeTransaction(parent, nextTransactionId(), mockModification);
final ActorRef transaction = newTransactionActor(RW, mockWriteTx, "testOnReceiveBatchedModificationsFailure");
TestKit watcher = new TestKit(getSystem());
watcher.watch(transaction);
YangInstanceIdentifier path = TestModel.TEST_PATH;
ContainerNode node = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
doThrow(new TestException()).when(mockModification).write(path, node);
final TransactionIdentifier tx1 = nextTransactionId();
BatchedModifications batched = new BatchedModifications(tx1, DataStoreVersions.CURRENT_VERSION);
batched.addModification(new WriteModification(path, node));
transaction.tell(batched, getRef());
expectMsgClass(duration("5 seconds"), akka.actor.Status.Failure.class);
batched = new BatchedModifications(tx1, DataStoreVersions.CURRENT_VERSION);
batched.setReady(true);
batched.setTotalMessagesSent(2);
transaction.tell(batched, getRef());
Failure failure = expectMsgClass(duration("5 seconds"), akka.actor.Status.Failure.class);
watcher.expectMsgClass(duration("5 seconds"), Terminated.class);
if (failure != null) {
Throwables.propagateIfPossible(failure.cause(), Exception.class);
throw new RuntimeException(failure.cause());
}
}
};
}
use of akka.testkit.javadsl.TestKit in project controller by opendaylight.
the class ShardTransactionTest method testReadWriteTxOnReceiveCloseTransaction.
@Test
public void testReadWriteTxOnReceiveCloseTransaction() throws Exception {
new TestKit(getSystem()) {
{
final ActorRef transaction = newTransactionActor(RW, readWriteTransaction(), "testReadWriteTxOnReceiveCloseTransaction");
watch(transaction);
transaction.tell(new CloseTransaction().toSerializable(), getRef());
expectMsgClass(duration("3 seconds"), CloseTransactionReply.class);
expectTerminated(duration("3 seconds"), transaction);
}
};
}
use of akka.testkit.javadsl.TestKit in project controller by opendaylight.
the class ShardTransactionTest method testWriteOnlyTxOnReceiveCloseTransaction.
@Test
public void testWriteOnlyTxOnReceiveCloseTransaction() throws Exception {
new TestKit(getSystem()) {
{
final ActorRef transaction = newTransactionActor(WO, readWriteTransaction(), "testWriteTxOnReceiveCloseTransaction");
watch(transaction);
transaction.tell(new CloseTransaction().toSerializable(), getRef());
expectMsgClass(duration("3 seconds"), CloseTransactionReply.class);
expectTerminated(duration("3 seconds"), transaction);
}
};
}
use of akka.testkit.javadsl.TestKit in project controller by opendaylight.
the class ShardTransactionTest method testOnReceiveBatchedModificationsReadyWithoutImmediateCommit.
@Test
public void testOnReceiveBatchedModificationsReadyWithoutImmediateCommit() throws Exception {
new TestKit(getSystem()) {
{
final ActorRef transaction = newTransactionActor(WO, readWriteTransaction(), "testOnReceiveBatchedModificationsReadyWithoutImmediateCommit");
TestKit watcher = new TestKit(getSystem());
watcher.watch(transaction);
YangInstanceIdentifier writePath = TestModel.TEST_PATH;
NormalizedNode<?, ?> writeData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
final TransactionIdentifier tx1 = nextTransactionId();
BatchedModifications batched = new BatchedModifications(tx1, DataStoreVersions.CURRENT_VERSION);
batched.addModification(new WriteModification(writePath, writeData));
transaction.tell(batched, getRef());
BatchedModificationsReply reply = expectMsgClass(duration("5 seconds"), BatchedModificationsReply.class);
assertEquals("getNumBatched", 1, reply.getNumBatched());
batched = new BatchedModifications(tx1, DataStoreVersions.CURRENT_VERSION);
batched.setReady(true);
batched.setTotalMessagesSent(2);
transaction.tell(batched, getRef());
expectMsgClass(duration("5 seconds"), ReadyTransactionReply.class);
watcher.expectMsgClass(duration("5 seconds"), Terminated.class);
}
};
}
use of akka.testkit.javadsl.TestKit 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());
}
};
}
Aggregations