- return store.newReadWriteTransaction("test-rw-" + String.valueOf(txCounter++), null);
- }
-
- @Test
- public void testOnReceiveReadData() throws Exception {
- new JavaTestKit(getSystem()) {{
- final ActorRef shard = createShard();
-
- testOnReceiveReadData(newTransactionActor(RO, readOnlyTransaction(), shard, "testReadDataRO"));
-
- testOnReceiveReadData(newTransactionActor(RW, readWriteTransaction(), shard, "testReadDataRW"));
- }
-
- private void testOnReceiveReadData(final ActorRef transaction) {
- //serialized read
- transaction.tell(new ReadData(YangInstanceIdentifier.builder().build()).toSerializable(),
- getRef());
-
- Object replySerialized =
- expectMsgClass(duration("5 seconds"), ReadDataReply.SERIALIZABLE_CLASS);
-
- assertNotNull(ReadDataReply.fromSerializable(replySerialized).getNormalizedNode());
-
- // unserialized read
- transaction.tell(new ReadData(YangInstanceIdentifier.builder().build()),getRef());
-
- ReadDataReply reply = expectMsgClass(duration("5 seconds"), ReadDataReply.class);
-
- assertNotNull(reply.getNormalizedNode());
- }};
- }
-
- @Test
- public void testOnReceiveReadDataWhenDataNotFound() throws Exception {
- new JavaTestKit(getSystem()) {{
- final ActorRef shard = createShard();
-
- testOnReceiveReadDataWhenDataNotFound(newTransactionActor(
- RO, readOnlyTransaction(), shard, "testReadDataWhenDataNotFoundRO"));
-
- testOnReceiveReadDataWhenDataNotFound(newTransactionActor(
- RW, readWriteTransaction(), shard, "testReadDataWhenDataNotFoundRW"));
- }
-
- private void testOnReceiveReadDataWhenDataNotFound(final ActorRef transaction) {
- // serialized read
- transaction.tell(new ReadData(TestModel.TEST_PATH).toSerializable(), getRef());
-
- Object replySerialized =
- expectMsgClass(duration("5 seconds"), ReadDataReply.SERIALIZABLE_CLASS);
-
- assertTrue(ReadDataReply.fromSerializable(replySerialized).getNormalizedNode() == null);
-
- // unserialized read
- transaction.tell(new ReadData(TestModel.TEST_PATH),getRef());
-
- ReadDataReply reply = expectMsgClass(duration("5 seconds"), ReadDataReply.class);
-
- assertTrue(reply.getNormalizedNode() == null);
- }};
- }
-
- @Test
- public void testOnReceiveReadDataHeliumR1() throws Exception {
- new JavaTestKit(getSystem()) {{
- ActorRef transaction = newTransactionActor(RO, readOnlyTransaction(),
- "testOnReceiveReadDataHeliumR1", DataStoreVersions.HELIUM_1_VERSION);
-
- transaction.tell(new ReadData(YangInstanceIdentifier.builder().build()).toSerializable(),
- getRef());
-
- ShardTransactionMessages.ReadDataReply replySerialized =
- expectMsgClass(duration("5 seconds"), ShardTransactionMessages.ReadDataReply.class);
-
- assertNotNull(ReadDataReply.fromSerializable(replySerialized).getNormalizedNode());
- }};
- }
-
- @Test
- public void testOnReceiveDataExistsPositive() throws Exception {
- new JavaTestKit(getSystem()) {{
- final ActorRef shard = createShard();
-
- testOnReceiveDataExistsPositive(newTransactionActor(RO, readOnlyTransaction(), shard,
- "testDataExistsPositiveRO"));
-
- testOnReceiveDataExistsPositive(newTransactionActor(RW, readWriteTransaction(), shard,
- "testDataExistsPositiveRW"));
- }
-
- private void testOnReceiveDataExistsPositive(final ActorRef transaction) {
- transaction.tell(new DataExists(YangInstanceIdentifier.builder().build()).toSerializable(),
- getRef());
-
- ShardTransactionMessages.DataExistsReply replySerialized =
- expectMsgClass(duration("5 seconds"), ShardTransactionMessages.DataExistsReply.class);
-
- assertTrue(DataExistsReply.fromSerializable(replySerialized).exists());
-
- // unserialized read
- transaction.tell(new DataExists(YangInstanceIdentifier.builder().build()),getRef());
-
- DataExistsReply reply = expectMsgClass(duration("5 seconds"), DataExistsReply.class);
-
- assertTrue(reply.exists());
- }};
- }
-
- @Test
- public void testOnReceiveDataExistsNegative() throws Exception {
- new JavaTestKit(getSystem()) {{
- final ActorRef shard = createShard();
-
- testOnReceiveDataExistsNegative(newTransactionActor(RO, readOnlyTransaction(), shard,
- "testDataExistsNegativeRO"));
-
- testOnReceiveDataExistsNegative(newTransactionActor(RW, readWriteTransaction(), shard,
- "testDataExistsNegativeRW"));
- }
-
- private void testOnReceiveDataExistsNegative(final ActorRef transaction) {
- transaction.tell(new DataExists(TestModel.TEST_PATH).toSerializable(), getRef());
-
- ShardTransactionMessages.DataExistsReply replySerialized =
- expectMsgClass(duration("5 seconds"), ShardTransactionMessages.DataExistsReply.class);
-
- assertFalse(DataExistsReply.fromSerializable(replySerialized).exists());
-
- // unserialized read
- transaction.tell(new DataExists(TestModel.TEST_PATH),getRef());
-
- DataExistsReply reply = expectMsgClass(duration("5 seconds"), DataExistsReply.class);
-
- assertFalse(reply.exists());
- }};
- }
-
- private void assertModification(final ActorRef subject,
- final Class<? extends Modification> modificationType) {
- new JavaTestKit(getSystem()) {{
- subject.tell(new ShardWriteTransaction.GetCompositedModification(), getRef());
-
- CompositeModification compositeModification = expectMsgClass(duration("3 seconds"),
- GetCompositeModificationReply.class).getModification();
-
- assertTrue(compositeModification.getModifications().size() == 1);
- assertEquals(modificationType, compositeModification.getModifications().get(0).getClass());
- }};
- }
-
- @Test
- public void testOnReceiveWriteData() {
- new JavaTestKit(getSystem()) {{
- final ActorRef transaction = newTransactionActor(WO, readWriteTransaction(),
- "testOnReceiveWriteData");
-
- transaction.tell(new WriteData(TestModel.TEST_PATH,
- ImmutableNodes.containerNode(TestModel.TEST_QNAME), DataStoreVersions.HELIUM_2_VERSION).
- toSerializable(), getRef());
-
- expectMsgClass(duration("5 seconds"), ShardTransactionMessages.WriteDataReply.class);
-
- assertModification(transaction, WriteModification.class);
-
- // unserialized write
- transaction.tell(new WriteData(TestModel.TEST_PATH,
- ImmutableNodes.containerNode(TestModel.TEST_QNAME), DataStoreVersions.CURRENT_VERSION),
- getRef());
-
- expectMsgClass(duration("5 seconds"), WriteDataReply.class);
- }};