Program: 41067
Project: 41067
Buggy source:
@Test(timeout=20000) public void testAsyncDeliveryOrder() throws Exception {
  try (TestAmqpPeer testPeer=new TestAmqpPeer()){
    Connection connection=testFixture.establishConnecton(testPeer);
    connection.start();
    testPeer.expectBegin();
    CoordinatorMatcher txCoordinatorMatcher=new CoordinatorMatcher();
    testPeer.expectSenderAttach(txCoordinatorMatcher,false,false);
    Session session=connection.createSession(true,Session.SESSION_TRANSACTED);
    testPeer.expectReceiverAttach();
    int messageCount=10;
    testPeer.expectLinkFlowRespondWithTransfer(null,null,null,null,new AmqpValueDescribedType("String_Node_Str"),messageCount,false,false,equalTo(UnsignedInteger.valueOf(messageCount)),1,true);
    Queue queue=session.createQueue("String_Node_Str");
    MessageConsumer consumer=session.createConsumer(queue);
    testPeer.waitForAllHandlersToComplete(3000);
    Binary txnId=new Binary(new byte[]{(byte)5,(byte)6,(byte)7,(byte)8});
    TransferPayloadCompositeMatcher declareMatcher=new TransferPayloadCompositeMatcher();
    declareMatcher.setMessageContentMatcher(new EncodedAmqpValueMatcher(new Declare()));
    testPeer.expectTransfer(declareMatcher,nullValue(),false,new Declared().setTxnId(txnId),true);
    for (int i=1; i <= messageCount; i++) {
      TransactionalStateMatcher stateMatcher=new TransactionalStateMatcher();
      stateMatcher.withTxnId(equalTo(txnId));
      stateMatcher.withOutcome(new AcceptedMatcher());
      testPeer.expectDisposition(true,stateMatcher);
    }
    final CountDownLatch done=new CountDownLatch(messageCount);
    final AtomicInteger index=new AtomicInteger(-1);
    consumer.setMessageListener(new DeliveryOrderListener(done,index));
    testPeer.waitForAllHandlersToComplete(3000);
    assertTrue("String_Node_Str",done.await(10,TimeUnit.SECONDS));
    assertEquals("String_Node_Str",messageCount - 1,index.get());
  }
 }

Fixed version (ground truth):
@Test(timeout=20000) public void testAsyncDeliveryOrder() throws Exception {
  try (TestAmqpPeer testPeer=new TestAmqpPeer()){
    Connection connection=testFixture.establishConnecton(testPeer);
    connection.start();
    testPeer.expectBegin();
    CoordinatorMatcher txCoordinatorMatcher=new CoordinatorMatcher();
    testPeer.expectSenderAttach(txCoordinatorMatcher,false,false);
    Session session=connection.createSession(true,Session.SESSION_TRANSACTED);
    testPeer.expectReceiverAttach();
    int messageCount=10;
    testPeer.expectLinkFlowRespondWithTransfer(null,null,null,null,new AmqpValueDescribedType("String_Node_Str"),messageCount,false,false,equalTo(UnsignedInteger.valueOf(JmsPrefetchPolicy.DEFAULT_QUEUE_PREFETCH)),1,true);
    Queue queue=session.createQueue("String_Node_Str");
    MessageConsumer consumer=session.createConsumer(queue);
    testPeer.waitForAllHandlersToComplete(3000);
    Binary txnId=new Binary(new byte[]{(byte)5,(byte)6,(byte)7,(byte)8});
    TransferPayloadCompositeMatcher declareMatcher=new TransferPayloadCompositeMatcher();
    declareMatcher.setMessageContentMatcher(new EncodedAmqpValueMatcher(new Declare()));
    testPeer.expectTransfer(declareMatcher,nullValue(),false,new Declared().setTxnId(txnId),true);
    for (int i=1; i <= messageCount; i++) {
      TransactionalStateMatcher stateMatcher=new TransactionalStateMatcher();
      stateMatcher.withTxnId(equalTo(txnId));
      stateMatcher.withOutcome(new AcceptedMatcher());
      testPeer.expectDisposition(true,stateMatcher);
    }
    final CountDownLatch done=new CountDownLatch(messageCount);
    final AtomicInteger index=new AtomicInteger(-1);
    consumer.setMessageListener(new DeliveryOrderListener(done,index));
    testPeer.waitForAllHandlersToComplete(3000);
    assertTrue("String_Node_Str",done.await(10,TimeUnit.SECONDS));
    assertEquals("String_Node_Str",messageCount - 1,index.get());
  }
 }