- shard.tell(new CommitTransaction(transactionID, CURRENT_VERSION).toSerializable(), getRef());
- expectMsgClass(duration, CommitTransactionReply.class);
-
- final InOrder inOrder = inOrder(cohort);
- inOrder.verify(cohort).canCommit();
- inOrder.verify(cohort).preCommit();
- inOrder.verify(cohort).commit();
-
- final NormalizedNode<?, ?> actualNode = readStore(shard, TestModel.TEST_PATH);
- assertEquals(TestModel.TEST_QNAME.getLocalName(), containerNode, actualNode);
- }};
- }
-
- @Test
- public void testReadWriteCommitWhenTransactionHasNoModifications() {
- testCommitWhenTransactionHasNoModifications(true);
- }
-
- @Test
- public void testWriteOnlyCommitWhenTransactionHasNoModifications() {
- testCommitWhenTransactionHasNoModifications(false);
- }
-
- private void testCommitWhenTransactionHasNoModifications(final boolean readWrite){
- // Note that persistence is enabled which would normally result in the entry getting written to the journal
- // but here that need not happen
- new ShardTestKit(getSystem()) {
- {
- final TestActorRef<Shard> shard = actorFactory.createTestActor(
- newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()),
- "testCommitWhenTransactionHasNoModifications-" + readWrite);
-
- waitUntilLeader(shard);
-
- final String transactionID = "tx1";
- final MutableCompositeModification modification = new MutableCompositeModification();
- final ShardDataTreeCohort cohort = mock(ShardDataTreeCohort.class, "cohort1");
- doReturn(Futures.immediateFuture(Boolean.TRUE)).when(cohort).canCommit();
- doReturn(Futures.immediateFuture(Boolean.TRUE)).when(cohort).preCommit();
- doReturn(Futures.immediateFuture(Boolean.TRUE)).when(cohort).commit();
- doReturn(mockUnmodifiedCandidate("cohort1-candidate")).when(cohort).getCandidate();
-
- final FiniteDuration duration = duration("5 seconds");
-
- shard.tell(prepareReadyTransactionMessage(readWrite, shard.underlyingActor(), cohort, transactionID, modification), getRef());
- expectMsgClass(duration, ReadyTransactionReply.class);
-
- // Send the CanCommitTransaction message.
-
- shard.tell(new CanCommitTransaction(transactionID, CURRENT_VERSION).toSerializable(), getRef());
- final CanCommitTransactionReply canCommitReply = CanCommitTransactionReply.fromSerializable(
- expectMsgClass(duration, CanCommitTransactionReply.class));
- assertEquals("Can commit", true, canCommitReply.getCanCommit());
-
- shard.tell(new CommitTransaction(transactionID, CURRENT_VERSION).toSerializable(), getRef());
- expectMsgClass(duration, CommitTransactionReply.class);
-
- final InOrder inOrder = inOrder(cohort);
- inOrder.verify(cohort).canCommit();
- inOrder.verify(cohort).preCommit();
- inOrder.verify(cohort).commit();
-
- shard.tell(Shard.GET_SHARD_MBEAN_MESSAGE, getRef());
- final ShardStats shardStats = expectMsgClass(duration, ShardStats.class);
-
- // Use MBean for verification
- // Committed transaction count should increase as usual
- assertEquals(1,shardStats.getCommittedTransactionsCount());
-
- // Commit index should not advance because this does not go into the journal
- assertEquals(-1, shardStats.getCommitIndex());