- final ActorRef shard = getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP));
- final Props props =
- ShardTransaction.props( store.newReadOnlyTransaction(), shard, testSchemaContext);
- final ActorRef subject = getSystem().actorOf(props, "testReadDataWhenDataNotFound");
-
- new Within(duration("1 seconds")) {
- @Override
- protected void run() {
-
- subject.tell(
- new ReadData(TestModel.TEST_PATH).toSerializable(),
- getRef());
-
- final String out = new ExpectMsg<String>(duration("1 seconds"), "match hint") {
- // do not put code outside this method, will run afterwards
- @Override
- protected String match(Object in) {
- if (in.getClass().equals(ReadDataReply.SERIALIZABLE_CLASS)) {
- if (ReadDataReply.fromSerializable(testSchemaContext,TestModel.TEST_PATH, in)
- .getNormalizedNode()
- == null) {
- return "match";
- }
- return null;
- } else {
- throw noMatch();
- }
- }
- }.get(); // this extracts the received message
-
- assertEquals("match", out);
-
- expectNoMsg();
- }
-
-
- };
+ final ActorRef shard = createShard();
+
+ testOnReceiveReadDataWhenDataNotFound(newTransactionActor(
+ store.newReadOnlyTransaction(), shard, "testReadDataWhenDataNotFoundRO"));
+
+ testOnReceiveReadDataWhenDataNotFound(newTransactionActor(
+ store.newReadWriteTransaction(), 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(store.newReadOnlyTransaction(),
+ "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(store.newReadOnlyTransaction(), shard,
+ "testDataExistsPositiveRO"));
+
+ testOnReceiveDataExistsPositive(newTransactionActor(store.newReadWriteTransaction(), 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(store.newReadOnlyTransaction(), shard,
+ "testDataExistsNegativeRO"));
+
+ testOnReceiveDataExistsNegative(newTransactionActor(store.newReadWriteTransaction(), 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());