Program: 41150
Project: 41150
Buggy source:
/** 
 * Test that a message received from the test peer with a Data section and content type of  {@link AmqpMessageSupport#OCTET_STREAM_CONTENT_TYPE} is returned as a BytesMessage, verify itgives the expected data values when read, and when reset and left mid-stream before being resent that it results in the expected AMQP data body section and properties content type being received by the test peer.
 */
@Test(timeout=5000) public void testReceiveBytesMessageAndResendAfterResetAndPartialRead() throws Exception {
  try (TestAmqpPeer testPeer=new TestAmqpPeer(IntegrationTestFixture.PORT)){
    Connection connection=testFixture.establishConnecton(testPeer);
    connection.start();
    testPeer.expectBegin(true);
    Session session=connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
    Queue queue=session.createQueue("String_Node_Str");
    PropertiesDescribedType properties=new PropertiesDescribedType();
    Symbol contentType=Symbol.valueOf(AmqpMessageSupport.OCTET_STREAM_CONTENT_TYPE);
    properties.setContentType(contentType);
    MessageAnnotationsDescribedType msgAnnotations=new MessageAnnotationsDescribedType();
    msgAnnotations.setSymbolKeyedAnnotation(AmqpMessageSupport.JMS_MSG_TYPE,AmqpMessageSupport.JMS_BYTES_MESSAGE);
    boolean myBool=true;
    byte myByte=4;
    byte[] myBytes="String_Node_Str".getBytes();
    char myChar='d';
    double myDouble=1234567890123456789.1234;
    float myFloat=1.1F;
    int myInt=Integer.MAX_VALUE;
    long myLong=Long.MAX_VALUE;
    short myShort=25;
    String myUTF="String_Node_Str";
    ByteArrayOutputStream baos=new ByteArrayOutputStream();
    DataOutputStream dos=new DataOutputStream(baos);
    dos.writeBoolean(myBool);
    dos.writeByte(myByte);
    dos.write(myBytes);
    dos.writeChar(myChar);
    dos.writeDouble(myDouble);
    dos.writeFloat(myFloat);
    dos.writeInt(myInt);
    dos.writeLong(myLong);
    dos.writeShort(myShort);
    dos.writeUTF(myUTF);
    byte[] bytesPayload=baos.toByteArray();
    Binary binaryPayload=new Binary(bytesPayload);
    DescribedType dataSectionContent=new DataDescribedType(binaryPayload);
    testPeer.expectReceiverAttach();
    testPeer.expectLinkFlowRespondWithTransfer(null,msgAnnotations,properties,null,dataSectionContent);
    testPeer.expectDispositionThatIsAcceptedAndSettled();
    MessageConsumer messageConsumer=session.createConsumer(queue);
    Message receivedMessage=messageConsumer.receive(1000);
    testPeer.waitForAllHandlersToComplete(3000);
    assertNotNull("String_Node_Str",receivedMessage);
    assertTrue("String_Node_Str",receivedMessage instanceof BytesMessage);
    BytesMessage receivedBytesMessage=(BytesMessage)receivedMessage;
    assertEquals("String_Node_Str",myBool,receivedBytesMessage.readBoolean());
    assertEquals("String_Node_Str",myByte,receivedBytesMessage.readByte());
    byte[] readBytes=new byte[myBytes.length];
    assertEquals("String_Node_Str",myBytes.length,receivedBytesMessage.readBytes(readBytes));
    assertTrue("String_Node_Str" + Arrays.toString(readBytes),Arrays.equals(myBytes,readBytes));
    assertEquals("String_Node_Str",myChar,receivedBytesMessage.readChar());
    assertEquals("String_Node_Str",myDouble,receivedBytesMessage.readDouble(),0.0);
    assertEquals("String_Node_Str",myFloat,receivedBytesMessage.readFloat(),0.0);
    assertEquals("String_Node_Str",myInt,receivedBytesMessage.readInt());
    assertEquals("String_Node_Str",myLong,receivedBytesMessage.readLong());
    assertEquals("String_Node_Str",myShort,receivedBytesMessage.readShort());
    assertEquals("String_Node_Str",myUTF,receivedBytesMessage.readUTF());
    receivedBytesMessage.reset();
    assertEquals("String_Node_Str",myBool,receivedBytesMessage.readBoolean());
    testPeer.expectSenderAttach();
    MessageProducer producer=session.createProducer(queue);
    MessageHeaderSectionMatcher headersMatcher=new MessageHeaderSectionMatcher(true);
    MessageAnnotationsSectionMatcher msgAnnotationsMatcher=new MessageAnnotationsSectionMatcher(true);
    MessagePropertiesSectionMatcher propsMatcher=new MessagePropertiesSectionMatcher(true);
    propsMatcher.withContentType(equalTo(contentType));
    TransferPayloadCompositeMatcher messageMatcher=new TransferPayloadCompositeMatcher();
    messageMatcher.setHeadersMatcher(headersMatcher);
    messageMatcher.setMessageAnnotationsMatcher(msgAnnotationsMatcher);
    messageMatcher.setPropertiesMatcher(propsMatcher);
    messageMatcher.setMessageContentMatcher(new EncodedDataMatcher(binaryPayload));
    testPeer.expectTransfer(messageMatcher);
    producer.send(receivedBytesMessage);
    testPeer.waitForAllHandlersToComplete(3000);
  }
 }

Fixed version (ground truth):
/** 
 * Test that a message received from the test peer with a Data section and content type of  {@link AmqpMessageSupport#OCTET_STREAM_CONTENT_TYPE} is returned as a BytesMessage, verify itgives the expected data values when read, and when reset and left mid-stream before being resent that it results in the expected AMQP data body section and properties content type being received by the test peer.
 */
@Test(timeout=5000) public void testReceiveBytesMessageAndResendAfterResetAndPartialRead() throws Exception {
  try (TestAmqpPeer testPeer=new TestAmqpPeer(testFixture.getAvailablePort())){
    Connection connection=testFixture.establishConnecton(testPeer);
    connection.start();
    testPeer.expectBegin(true);
    Session session=connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
    Queue queue=session.createQueue("String_Node_Str");
    PropertiesDescribedType properties=new PropertiesDescribedType();
    Symbol contentType=Symbol.valueOf(AmqpMessageSupport.OCTET_STREAM_CONTENT_TYPE);
    properties.setContentType(contentType);
    MessageAnnotationsDescribedType msgAnnotations=new MessageAnnotationsDescribedType();
    msgAnnotations.setSymbolKeyedAnnotation(AmqpMessageSupport.JMS_MSG_TYPE,AmqpMessageSupport.JMS_BYTES_MESSAGE);
    boolean myBool=true;
    byte myByte=4;
    byte[] myBytes="String_Node_Str".getBytes();
    char myChar='d';
    double myDouble=1234567890123456789.1234;
    float myFloat=1.1F;
    int myInt=Integer.MAX_VALUE;
    long myLong=Long.MAX_VALUE;
    short myShort=25;
    String myUTF="String_Node_Str";
    ByteArrayOutputStream baos=new ByteArrayOutputStream();
    DataOutputStream dos=new DataOutputStream(baos);
    dos.writeBoolean(myBool);
    dos.writeByte(myByte);
    dos.write(myBytes);
    dos.writeChar(myChar);
    dos.writeDouble(myDouble);
    dos.writeFloat(myFloat);
    dos.writeInt(myInt);
    dos.writeLong(myLong);
    dos.writeShort(myShort);
    dos.writeUTF(myUTF);
    byte[] bytesPayload=baos.toByteArray();
    Binary binaryPayload=new Binary(bytesPayload);
    DescribedType dataSectionContent=new DataDescribedType(binaryPayload);
    testPeer.expectReceiverAttach();
    testPeer.expectLinkFlowRespondWithTransfer(null,msgAnnotations,properties,null,dataSectionContent);
    testPeer.expectDispositionThatIsAcceptedAndSettled();
    MessageConsumer messageConsumer=session.createConsumer(queue);
    Message receivedMessage=messageConsumer.receive(1000);
    testPeer.waitForAllHandlersToComplete(3000);
    assertNotNull("String_Node_Str",receivedMessage);
    assertTrue("String_Node_Str",receivedMessage instanceof BytesMessage);
    BytesMessage receivedBytesMessage=(BytesMessage)receivedMessage;
    assertEquals("String_Node_Str",myBool,receivedBytesMessage.readBoolean());
    assertEquals("String_Node_Str",myByte,receivedBytesMessage.readByte());
    byte[] readBytes=new byte[myBytes.length];
    assertEquals("String_Node_Str",myBytes.length,receivedBytesMessage.readBytes(readBytes));
    assertTrue("String_Node_Str" + Arrays.toString(readBytes),Arrays.equals(myBytes,readBytes));
    assertEquals("String_Node_Str",myChar,receivedBytesMessage.readChar());
    assertEquals("String_Node_Str",myDouble,receivedBytesMessage.readDouble(),0.0);
    assertEquals("String_Node_Str",myFloat,receivedBytesMessage.readFloat(),0.0);
    assertEquals("String_Node_Str",myInt,receivedBytesMessage.readInt());
    assertEquals("String_Node_Str",myLong,receivedBytesMessage.readLong());
    assertEquals("String_Node_Str",myShort,receivedBytesMessage.readShort());
    assertEquals("String_Node_Str",myUTF,receivedBytesMessage.readUTF());
    receivedBytesMessage.reset();
    assertEquals("String_Node_Str",myBool,receivedBytesMessage.readBoolean());
    testPeer.expectSenderAttach();
    MessageProducer producer=session.createProducer(queue);
    MessageHeaderSectionMatcher headersMatcher=new MessageHeaderSectionMatcher(true);
    MessageAnnotationsSectionMatcher msgAnnotationsMatcher=new MessageAnnotationsSectionMatcher(true);
    MessagePropertiesSectionMatcher propsMatcher=new MessagePropertiesSectionMatcher(true);
    propsMatcher.withContentType(equalTo(contentType));
    TransferPayloadCompositeMatcher messageMatcher=new TransferPayloadCompositeMatcher();
    messageMatcher.setHeadersMatcher(headersMatcher);
    messageMatcher.setMessageAnnotationsMatcher(msgAnnotationsMatcher);
    messageMatcher.setPropertiesMatcher(propsMatcher);
    messageMatcher.setMessageContentMatcher(new EncodedDataMatcher(binaryPayload));
    testPeer.expectTransfer(messageMatcher);
    producer.send(receivedBytesMessage);
    testPeer.waitForAllHandlersToComplete(3000);
  }
 }