@Test
public void testTransactionCommitTimeout() throws Exception {

    dataStoreContextBuilder.shardTransactionCommitTimeoutInSeconds(1);
    final ShardTestKit testKit = new ShardTestKit(getSystem());
    final TestActorRef<Shard> shard = actorFactory.createTestActor(
        newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()),
        "testTransactionCommitTimeout");
    ShardTestKit.waitUntilLeader(shard);
    final Duration duration = Duration.ofSeconds(5);
    writeToStore(shard, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
    writeToStore(shard, TestModel.OUTER_LIST_PATH,
        ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
    // Ready 2 Tx's - the first will timeout
    final TransactionIdentifier transactionID1 = nextTransactionId();
    shard.tell(
        prepareBatchedModifications(transactionID1,
            YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH)
            .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1).build(),
            ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1), false),
        testKit.getRef());
    testKit.expectMsgClass(duration, ReadyTransactionReply.class);
    final TransactionIdentifier transactionID2 = nextTransactionId();
    final YangInstanceIdentifier listNodePath = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH)
            .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2).build();
    shard.tell(
        prepareBatchedModifications(transactionID2, listNodePath,
            ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2), false), testKit.getRef());
    testKit.expectMsgClass(duration, ReadyTransactionReply.class);
    // canCommit 1st Tx. We don't send the commit so it should
    // timeout.
    shard.tell(new CanCommitTransaction(transactionID1, CURRENT_VERSION).toSerializable(), testKit.getRef());
    testKit.expectMsgClass(duration, CanCommitTransactionReply.class);
    // canCommit the 2nd Tx - it should complete after the 1st Tx
    // times out.
    shard.tell(new CanCommitTransaction(transactionID2, CURRENT_VERSION).toSerializable(), testKit.getRef());
    testKit.expectMsgClass(duration, CanCommitTransactionReply.class);
    // Try to commit the 1st Tx - should fail as it's not the
    // current Tx.
    shard.tell(new CommitTransaction(transactionID1, CURRENT_VERSION).toSerializable(), testKit.getRef());
    testKit.expectMsgClass(duration, akka.actor.Status.Failure.class);
    // Commit the 2nd Tx.
    shard.tell(new CommitTransaction(transactionID2, CURRENT_VERSION).toSerializable(), testKit.getRef());
    testKit.expectMsgClass(duration, CommitTransactionReply.class);
    final NormalizedNode<?, ?> node = readStore(shard, listNodePath);
    assertNotNull(listNodePath + " not found", node);
}