- 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());
- }};
- }
-
- 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() throws Exception {
- new JavaTestKit(getSystem()) {{
- final ActorRef transaction = newTransactionActor(store.newWriteOnlyTransaction(),
- "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);
- }};
- }
-
- @Test
- public void testOnReceiveHeliumR1WriteData() throws Exception {
- new JavaTestKit(getSystem()) {{
- final ActorRef transaction = newTransactionActor(store.newWriteOnlyTransaction(),
- "testOnReceiveHeliumR1WriteData", DataStoreVersions.HELIUM_1_VERSION);
-
- Encoded encoded = new NormalizedNodeToNodeCodec(null).encode(TestModel.TEST_PATH,
- ImmutableNodes.containerNode(TestModel.TEST_QNAME));
- ShardTransactionMessages.WriteData serialized = ShardTransactionMessages.WriteData.newBuilder()
- .setInstanceIdentifierPathArguments(encoded.getEncodedPath())
- .setNormalizedNode(encoded.getEncodedNode().getNormalizedNode()).build();
-
- transaction.tell(serialized, getRef());