@Test
public void testTransactionCommitWithSubsequentExpiredCohortEntry() {

    dataStoreContextBuilder.shardTransactionCommitTimeoutInSeconds(1);
    final ShardTestKit testKit = new ShardTestKit(getSystem());
    final TestActorRef<Shard> shard = actorFactory.createTestActor(
        newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()),
        "testTransactionCommitWithSubsequentExpiredCohortEntry");
    ShardTestKit.waitUntilLeader(shard);
    final Duration duration = Duration.ofSeconds(5);
    final ShardDataTree dataStore = shard.underlyingActor().getDataStore();
    final TransactionIdentifier transactionID1 = nextTransactionId();
    shard.tell(prepareBatchedModifications(transactionID1, TestModel.TEST_PATH,
        ImmutableNodes.containerNode(TestModel.TEST_QNAME), false), testKit.getRef());
    testKit.expectMsgClass(duration, ReadyTransactionReply.class);
    // CanCommit the first Tx so it's the current in-progress Tx.
    shard.tell(new CanCommitTransaction(transactionID1, CURRENT_VERSION).toSerializable(), testKit.getRef());
    testKit.expectMsgClass(duration, CanCommitTransactionReply.class);
    // Ready the second Tx.
    final TransactionIdentifier transactionID2 = nextTransactionId();
    shard.tell(prepareBatchedModifications(transactionID2, TestModel.TEST_PATH,
        ImmutableNodes.containerNode(TestModel.TEST_QNAME), false), testKit.getRef());
    testKit.expectMsgClass(duration, ReadyTransactionReply.class);
    // Ready the third Tx.
    final TransactionIdentifier transactionID3 = nextTransactionId();
    final DataTreeModification modification3 = dataStore.newModification();
    new WriteModification(TestModel.TEST2_PATH, ImmutableNodes.containerNode(TestModel.TEST2_QNAME))
        .apply(modification3);
    modification3.ready();
    final ReadyLocalTransaction readyMessage = new ReadyLocalTransaction(transactionID3, modification3,
        true, Optional.empty());
    shard.tell(readyMessage, testKit.getRef());
    // Commit the first Tx. After completing, the second should
    // expire from the queue and the third
    // Tx committed.
    shard.tell(new CommitTransaction(transactionID1, CURRENT_VERSION).toSerializable(), testKit.getRef());
    testKit.expectMsgClass(duration, CommitTransactionReply.class);
    // Expect commit reply from the third Tx.
    testKit.expectMsgClass(duration, CommitTransactionReply.class);
    final NormalizedNode<?, ?> node = readStore(shard, TestModel.TEST2_PATH);
    assertNotNull(TestModel.TEST2_PATH + " not found", node);
}