Java Code Examples for org.apache.qpid.proton.Proton#connection()

The following examples show how to use org.apache.qpid.proton.Proton#connection() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransportImplTest.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
@Test
public void testOpenSessionBeforeOpenConnection()
{
    MockTransportImpl transport = new MockTransportImpl();
    Connection connection = Proton.connection();
    transport.bind(connection);

    Session session = connection.session();
    session.open();

    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 0, transport.writes.size());

    connection.open();

    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 2, transport.writes.size());

    assertTrue("Unexpected frame type", transport.writes.get(0) instanceof Open);
    assertTrue("Unexpected frame type", transport.writes.get(1) instanceof Begin);
}
 
Example 2
Source File: TransportImplTest.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Test
public void testReceiverFlowBeforeOpenConnection()
{
    MockTransportImpl transport = new MockTransportImpl();
    Connection connection = Proton.connection();
    transport.bind(connection);

    Session session = connection.session();
    session.open();

    Receiver reciever = session.receiver("myReceiver");
    reciever.flow(5);

    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 0, transport.writes.size());

    // Now open the connection, expect the Open and Begin frames but
    // nothing else as we haven't opened the receiver itself yet.
    connection.open();

    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 2, transport.writes.size());

    assertTrue("Unexpected frame type", transport.writes.get(0) instanceof Open);
    assertTrue("Unexpected frame type", transport.writes.get(1) instanceof Begin);
}
 
Example 3
Source File: TransportImplTest.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
/**
 * Verify that no Begin frame is emitted by the Transport should a Session open
 * after the Close frame was sent.
 */
@Test
public void testSessionBeginAfterCloseSent()
{
    MockTransportImpl transport = new MockTransportImpl();
    Connection connection = Proton.connection();
    transport.bind(connection);

    connection.open();

    Session session = connection.session();

    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 1, transport.writes.size());

    assertTrue("Unexpected frame type", transport.writes.get(0) instanceof Open);

    // Send the necessary response to Open
    transport.handleFrame(new TransportFrame(0, new Open(), null));

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 1, transport.writes.size());

    // Cause a Close frame to be sent
    connection.close();
    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 2, transport.writes.size());
    assertTrue("Unexpected frame type", transport.writes.get(1) instanceof Close);

    // Open the session and verify the transport doesn't
    // send any Begin frame, as a Close frame was sent already.
    session.open();
    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 2, transport.writes.size());
}
 
Example 4
Source File: TransportImplTest.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Test
public void testDeliveryIdOutOfSequenceCausesISE() {
    MockTransportImpl transport = new MockTransportImpl();
    transport.setEmitFlowEventOnSend(false);
    Connection connection = Proton.connection();
    transport.bind(connection);

    connection.open();

    Session session = connection.session();
    session.open();

    String linkName1 = "myReceiver1";
    Receiver receiver1 = session.receiver(linkName1);
    receiver1.flow(5);
    receiver1.open();

    String linkName2 = "myReceiver2";
    Receiver receiver2 = session.receiver(linkName2);
    receiver2.flow(5);
    receiver2.open();

    pumpMockTransport(transport);

    final UnsignedInteger r1handle = UnsignedInteger.ZERO;
    final UnsignedInteger r2handle = UnsignedInteger.ONE;

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 6, transport.writes.size());

    // Give the necessary responses to open/begin/attach
    transport.handleFrame(new TransportFrame(0, new Open(), null));

    Begin begin = new Begin();
    begin.setRemoteChannel(UnsignedShort.valueOf((short) 0));
    begin.setNextOutgoingId(UnsignedInteger.ONE);
    begin.setIncomingWindow(UnsignedInteger.valueOf(1024));
    begin.setOutgoingWindow(UnsignedInteger.valueOf(1024));
    transport.handleFrame(new TransportFrame(0, begin, null));

    Attach attach1 = new Attach();
    attach1.setHandle(r1handle);
    attach1.setRole(Role.SENDER);
    attach1.setName(linkName1);
    attach1.setInitialDeliveryCount(UnsignedInteger.ZERO);
    transport.handleFrame(new TransportFrame(0, attach1, null));

    Attach attach2 = new Attach();
    attach2.setHandle(r2handle);
    attach2.setRole(Role.SENDER);
    attach2.setName(linkName2);
    attach2.setInitialDeliveryCount(UnsignedInteger.ZERO);
    transport.handleFrame(new TransportFrame(0, attach2, null));

    String deliveryTag1 = "tag1";
    String deliveryTag2 = "tag2";

    handlePartialTransfer(transport, r2handle, 2, deliveryTag2, new byte[]{ 2 }, false);
    try {
        handlePartialTransfer(transport, r1handle, 1, deliveryTag1, new byte[]{ 1 }, false);
        fail("Expected an ISE");
    } catch(IllegalStateException ise) {
        // Expected
        assertTrue("Unexpected exception:" + ise, ise.getMessage().contains("Expected delivery-id 3, got 1"));
    }
}
 
Example 5
Source File: TransportImplTest.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Test
public void testDeliveryIdMissingOnInitialTransferCausesISE() {
    MockTransportImpl transport = new MockTransportImpl();
    transport.setEmitFlowEventOnSend(false);
    Connection connection = Proton.connection();
    transport.bind(connection);

    connection.open();

    Session session = connection.session();
    session.open();

    String linkName1 = "myReceiver1";
    Receiver receiver1 = session.receiver(linkName1);
    receiver1.flow(5);
    receiver1.open();

    pumpMockTransport(transport);

    final UnsignedInteger r1handle = UnsignedInteger.ZERO;

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 4, transport.writes.size());

    // Give the necessary responses to open/begin/attach
    transport.handleFrame(new TransportFrame(0, new Open(), null));

    Begin begin = new Begin();
    begin.setRemoteChannel(UnsignedShort.valueOf((short) 0));
    begin.setNextOutgoingId(UnsignedInteger.ONE);
    begin.setIncomingWindow(UnsignedInteger.valueOf(1024));
    begin.setOutgoingWindow(UnsignedInteger.valueOf(1024));
    transport.handleFrame(new TransportFrame(0, begin, null));

    Attach attach1 = new Attach();
    attach1.setHandle(r1handle);
    attach1.setRole(Role.SENDER);
    attach1.setName(linkName1);
    attach1.setInitialDeliveryCount(UnsignedInteger.ZERO);
    transport.handleFrame(new TransportFrame(0, attach1, null));

    // Receive a delivery without any delivery-id on the [first] transfer frame, expect it to fail.
    try {
        handlePartialTransfer(transport, r1handle, null, "tag1", new byte[]{ 1 }, false);
        fail("Expected an ISE");
    } catch(IllegalStateException ise) {
        // Expected
        assertEquals("Unexpected message", "No delivery-id specified on first Transfer of new delivery", ise.getMessage());
    }
}
 
Example 6
Source File: TransportImplTest.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
private void doDeliveryIdThresholdsWrapsTestImpl(UnsignedInteger deliveryId1, UnsignedInteger deliveryId2, UnsignedInteger deliveryId3) {
    MockTransportImpl transport = new MockTransportImpl();
    transport.setEmitFlowEventOnSend(false);
    Connection connection = Proton.connection();
    transport.bind(connection);

    connection.open();

    Session session = connection.session();
    session.open();

    String linkName1 = "myReceiver1";
    Receiver receiver1 = session.receiver(linkName1);
    receiver1.flow(5);
    receiver1.open();

    pumpMockTransport(transport);

    final UnsignedInteger r1handle = UnsignedInteger.ZERO;

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 4, transport.writes.size());

    // Give the necessary responses to open/begin/attach
    transport.handleFrame(new TransportFrame(0, new Open(), null));

    Begin begin = new Begin();
    begin.setRemoteChannel(UnsignedShort.valueOf((short) 0));
    begin.setNextOutgoingId(UnsignedInteger.ONE);
    begin.setIncomingWindow(UnsignedInteger.valueOf(1024));
    begin.setOutgoingWindow(UnsignedInteger.valueOf(1024));
    transport.handleFrame(new TransportFrame(0, begin, null));

    Attach attach1 = new Attach();
    attach1.setHandle(r1handle);
    attach1.setRole(Role.SENDER);
    attach1.setName(linkName1);
    attach1.setInitialDeliveryCount(UnsignedInteger.ZERO);
    transport.handleFrame(new TransportFrame(0, attach1, null));

    String deliveryTag1 = "tag1";
    String deliveryTag2 = "tag2";
    String deliveryTag3 = "tag3";

    // Send deliveries with the given delivery-id
    handlePartialTransfer(transport, r1handle, deliveryId1, deliveryTag1, new byte[]{ 1 }, false);
    handlePartialTransfer(transport, r1handle, deliveryId2, deliveryTag2, new byte[]{ 2 }, false);
    handlePartialTransfer(transport, r1handle, deliveryId3, deliveryTag3, new byte[]{ 3 }, false);

    // Verify deliveries arrived with expected payload
    verifyDeliveryRawPayload(receiver1, deliveryTag1, new byte[] { 1 });
    verifyDeliveryRawPayload(receiver1, deliveryTag2, new byte[] { 2 });
    verifyDeliveryRawPayload(receiver1, deliveryTag3, new byte[] { 3 });
}
 
Example 7
Source File: TransportImplTest.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Test
public void testDeliveryWithIdOmittedOnContinuationTransfers() {
    MockTransportImpl transport = new MockTransportImpl();
    transport.setEmitFlowEventOnSend(false);
    Connection connection = Proton.connection();
    transport.bind(connection);

    connection.open();

    Session session = connection.session();
    session.open();

    String linkName1 = "myReceiver1";
    Receiver receiver1 = session.receiver(linkName1);
    receiver1.flow(5);
    receiver1.open();

    String linkName2 = "myReceiver2";
    Receiver receiver2 = session.receiver(linkName2);
    receiver2.flow(5);
    receiver2.open();

    pumpMockTransport(transport);

    final UnsignedInteger r1handle = UnsignedInteger.ZERO;
    final UnsignedInteger r2handle = UnsignedInteger.ONE;

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 6, transport.writes.size());

    // Give the necessary responses to open/begin/attach
    transport.handleFrame(new TransportFrame(0, new Open(), null));

    Begin begin = new Begin();
    begin.setRemoteChannel(UnsignedShort.valueOf((short) 0));
    begin.setNextOutgoingId(UnsignedInteger.ONE);
    begin.setIncomingWindow(UnsignedInteger.valueOf(1024));
    begin.setOutgoingWindow(UnsignedInteger.valueOf(1024));
    transport.handleFrame(new TransportFrame(0, begin, null));

    Attach attach1 = new Attach();
    attach1.setHandle(r1handle);
    attach1.setRole(Role.SENDER);
    attach1.setName(linkName1);
    attach1.setInitialDeliveryCount(UnsignedInteger.ZERO);
    transport.handleFrame(new TransportFrame(0, attach1, null));

    Attach attach2 = new Attach();
    attach2.setHandle(r2handle);
    attach2.setRole(Role.SENDER);
    attach2.setName(linkName2);
    attach2.setInitialDeliveryCount(UnsignedInteger.ZERO);
    transport.handleFrame(new TransportFrame(0, attach2, null));

    String deliveryTag1 = "tag1";
    String deliveryTag2 = "tag2";

    // Send multi-frame deliveries for each link, multiplexed together, and omit
    // the delivery-id on the continuation frames as allowed for by the spec.
    handlePartialTransfer(transport, r1handle, 1, deliveryTag1, new byte[]{ 1 }, true);
    handlePartialTransfer(transport, r2handle, 2, deliveryTag2, new byte[]{ 101 }, true);
    handlePartialTransfer(transport, r2handle, null, deliveryTag2, new byte[]{ 102 }, true);
    handlePartialTransfer(transport, r1handle, null, deliveryTag1, new byte[]{ 2 }, true);
    handlePartialTransfer(transport, r1handle, null, deliveryTag1, new byte[]{ 3 }, false);
    handlePartialTransfer(transport, r2handle, null, deliveryTag2, new byte[]{ 103 }, true);
    handlePartialTransfer(transport, r2handle, null, deliveryTag2, new byte[]{ 104 }, false);

    // Verify the transfer frames were all matched to compose the expected delivery payload.
    verifyDeliveryRawPayload(receiver1, deliveryTag1, new byte[] { 1, 2, 3 });
    verifyDeliveryRawPayload(receiver2, deliveryTag2, new byte[] { 101, 102, 103, 104 });
}
 
Example 8
Source File: TransportImplTest.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
/**
 * Verify that no Disposition frame is emitted by the Transport should a Delivery
 * have disposition applied after the Close frame was sent.
 */
@Test
public void testDispositionAfterCloseSent()
{
    MockTransportImpl transport = new MockTransportImpl();
    Connection connection = Proton.connection();
    transport.bind(connection);

    connection.open();

    Session session = connection.session();
    session.open();

    String linkName = "myReceiver";
    Receiver receiver = session.receiver(linkName);
    receiver.flow(5);
    receiver.open();

    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 4, transport.writes.size());

    assertTrue("Unexpected frame type", transport.writes.get(0) instanceof Open);
    assertTrue("Unexpected frame type", transport.writes.get(1) instanceof Begin);
    assertTrue("Unexpected frame type", transport.writes.get(2) instanceof Attach);
    assertTrue("Unexpected frame type", transport.writes.get(3) instanceof Flow);

    Delivery delivery = receiver.current();
    assertNull("Should not yet have a delivery", delivery);

    // Send the necessary responses to open/begin/attach as well as a transfer
    transport.handleFrame(new TransportFrame(0, new Open(), null));

    Begin begin = new Begin();
    begin.setRemoteChannel(UnsignedShort.valueOf((short) 0));
    begin.setNextOutgoingId(UnsignedInteger.ONE);
    begin.setIncomingWindow(UnsignedInteger.valueOf(1024));
    begin.setOutgoingWindow(UnsignedInteger.valueOf(1024));
    transport.handleFrame(new TransportFrame(0, begin, null));

    Attach attach = new Attach();
    attach.setHandle(UnsignedInteger.ZERO);
    attach.setRole(Role.SENDER);
    attach.setName(linkName);
    attach.setInitialDeliveryCount(UnsignedInteger.ZERO);
    transport.handleFrame(new TransportFrame(0, attach, null));

    String deliveryTag = "tag1";
    String messageContent = "content1";
    handleTransfer(transport, 1, deliveryTag, messageContent);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 4, transport.writes.size());

    delivery = verifyDelivery(receiver, deliveryTag, messageContent);
    assertNotNull("Should now have a delivery", delivery);

    // Cause the Close frame to be sent
    connection.close();
    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 5, transport.writes.size());
    assertTrue("Unexpected frame type", transport.writes.get(4) instanceof Close);

    delivery.disposition(Released.getInstance());
    delivery.settle();

    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 5, transport.writes.size());
}
 
Example 9
Source File: TransportImplTest.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Test
public void testDeliveryIdTrackingHandlesAbortedDelivery() {
    MockTransportImpl transport = new MockTransportImpl();
    transport.setEmitFlowEventOnSend(false);
    Connection connection = Proton.connection();
    transport.bind(connection);

    connection.open();

    Session session = connection.session();
    session.open();

    String linkName1 = "myReceiver1";
    Receiver receiver1 = session.receiver(linkName1);
    receiver1.flow(5);
    receiver1.open();

    pumpMockTransport(transport);

    final UnsignedInteger r1handle = UnsignedInteger.ZERO;

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 4, transport.writes.size());

    // Give the necessary responses to open/begin/attach
    transport.handleFrame(new TransportFrame(0, new Open(), null));

    Begin begin = new Begin();
    begin.setRemoteChannel(UnsignedShort.valueOf((short) 0));
    begin.setNextOutgoingId(UnsignedInteger.ONE);
    begin.setIncomingWindow(UnsignedInteger.valueOf(1024));
    begin.setOutgoingWindow(UnsignedInteger.valueOf(1024));
    transport.handleFrame(new TransportFrame(0, begin, null));

    Attach attach1 = new Attach();
    attach1.setHandle(r1handle);
    attach1.setRole(Role.SENDER);
    attach1.setName(linkName1);
    attach1.setInitialDeliveryCount(UnsignedInteger.ZERO);
    transport.handleFrame(new TransportFrame(0, attach1, null));

    // Receive first transfer for a multi-frame delivery
    assertEquals("Unexpected queued count", 0, receiver1.getQueued());
    handlePartialTransfer(transport, r1handle, UnsignedInteger.ZERO, "tag1", new byte[]{ 1 }, true);
    assertEquals("Unexpected queued count", 1, receiver1.getQueued());
    // Receive second transfer for a multi-frame delivery, indicating it is aborted
    handlePartialTransfer(transport, r1handle, UnsignedInteger.ZERO, "tag1", new byte[]{ 2 }, true, true);
    assertEquals("Unexpected queued count", 1, receiver1.getQueued());

    // Receive first transfer for ANOTHER delivery, expect it not to fail, since the earlier delivery aborted
    handlePartialTransfer(transport, r1handle, UnsignedInteger.ONE, "tag2", new byte[]{ 3 }, false);
    assertEquals("Unexpected queued count", 2, receiver1.getQueued());

    receiver1.advance();
    verifyDeliveryRawPayload(receiver1, "tag2", new byte[] { 3 });
}
 
Example 10
Source File: TransportImplTest.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
/**
 * Verify that no Flow frame is emitted by the Transport should a Receiver
 * have pending drain when a detach is sent for that receiver.
 */
@Test
public void testNoReceiverFlowAfterDetachSentWhileDraining()
{
    MockTransportImpl transport = new MockTransportImpl();
    Connection connection = Proton.connection();
    transport.bind(connection);

    connection.open();

    Session session = connection.session();
    session.open();

    String linkName = "myReceiver";
    Receiver receiver = session.receiver(linkName);
    receiver.open();

    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size());

    assertTrue("Unexpected frame type", transport.writes.get(0) instanceof Open);
    assertTrue("Unexpected frame type", transport.writes.get(1) instanceof Begin);
    assertTrue("Unexpected frame type", transport.writes.get(2) instanceof Attach);

    // Send the necessary responses to open/begin/attach
    transport.handleFrame(new TransportFrame(0, new Open(), null));

    Begin begin = new Begin();
    begin.setRemoteChannel(UnsignedShort.valueOf((short) 0));
    transport.handleFrame(new TransportFrame(0, begin, null));

    Attach attach = new Attach();
    attach.setHandle(UnsignedInteger.ZERO);
    attach.setRole(Role.RECEIVER);
    attach.setName(linkName);
    attach.setInitialDeliveryCount(UnsignedInteger.ZERO);
    transport.handleFrame(new TransportFrame(0, attach, null));

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size());

    // Start a drain for the Receiver and verify the transport doesn't
    // send any Flow frame, due to the detach being initiated.
    receiver.drain(10);
    pumpMockTransport(transport);

    // Cause the Detach frame to be sent
    receiver.detach();
    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 5, transport.writes.size());
    assertTrue("Unexpected frame type", transport.writes.get(4) instanceof Detach);
}
 
Example 11
Source File: TransportImplTest.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
/**
 * Verify that no Flow frame is emitted by the Transport should a Receiver
 * have credit added after the Close frame was sent.
 */
@Test
public void testReceiverFlowAfterCloseSent()
{
    MockTransportImpl transport = new MockTransportImpl();
    Connection connection = Proton.connection();
    transport.bind(connection);

    connection.open();

    Session session = connection.session();
    session.open();

    String linkName = "myReceiver";
    Receiver receiver = session.receiver(linkName);
    receiver.open();

    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size());

    assertTrue("Unexpected frame type", transport.writes.get(0) instanceof Open);
    assertTrue("Unexpected frame type", transport.writes.get(1) instanceof Begin);
    assertTrue("Unexpected frame type", transport.writes.get(2) instanceof Attach);

    // Send the necessary responses to open/begin/attach
    transport.handleFrame(new TransportFrame(0, new Open(), null));

    Begin begin = new Begin();
    begin.setRemoteChannel(UnsignedShort.valueOf((short) 0));
    transport.handleFrame(new TransportFrame(0, begin, null));

    Attach attach = new Attach();
    attach.setHandle(UnsignedInteger.ZERO);
    attach.setRole(Role.RECEIVER);
    attach.setName(linkName);
    attach.setInitialDeliveryCount(UnsignedInteger.ZERO);
    transport.handleFrame(new TransportFrame(0, attach, null));

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size());

    // Cause the Close frame to be sent
    connection.close();
    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 4, transport.writes.size());
    assertTrue("Unexpected frame type", transport.writes.get(3) instanceof Close);

    // Grant new credit for the Receiver and verify the transport doesn't
    // send any Flow frame, as a Close frame was sent already.
    receiver.flow(1);
    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 4, transport.writes.size());
}
 
Example 12
Source File: TransportImplTest.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
void doLinkAttachAfterCloseSentTestImpl(boolean receiverLink)
{
    MockTransportImpl transport = new MockTransportImpl();
    Connection connection = Proton.connection();
    transport.bind(connection);

    connection.open();

    Session session = connection.session();
    session.open();

    Link link = null;
    if(receiverLink)
    {
        link = session.receiver("myReceiver");
    }
    else
    {
        link = session.sender("mySender");
    }

    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 2, transport.writes.size());

    assertTrue("Unexpected frame type", transport.writes.get(0) instanceof Open);
    assertTrue("Unexpected frame type", transport.writes.get(1) instanceof Begin);

    // Send the necessary responses to open/begin
    transport.handleFrame(new TransportFrame(0, new Open(), null));

    Begin begin = new Begin();
    begin.setRemoteChannel(UnsignedShort.valueOf((short) 0));
    transport.handleFrame(new TransportFrame(0, begin, null));

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 2, transport.writes.size());

    // Cause a Close frame to be sent
    connection.close();
    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size());
    assertTrue("Unexpected frame type", transport.writes.get(2) instanceof Close);

    // Open the link and verify the transport doesn't
    // send any Attach frame, as a Close frame was sent already.
    link.open();
    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size());
}
 
Example 13
Source File: TransportImplTest.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
/**
 * Verify that no End frame is emitted by the Transport should a Session close
 * after the Close frame was sent.
 */
@Test
public void testSessionEndAfterCloseSent()
{
    MockTransportImpl transport = new MockTransportImpl();
    Connection connection = Proton.connection();
    transport.bind(connection);

    connection.open();

    Session session = connection.session();
    session.open();

    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 2, transport.writes.size());

    assertTrue("Unexpected frame type", transport.writes.get(0) instanceof Open);
    assertTrue("Unexpected frame type", transport.writes.get(1) instanceof Begin);

    // Send the necessary responses to open/begin
    transport.handleFrame(new TransportFrame(0, new Open(), null));

    Begin begin = new Begin();
    begin.setRemoteChannel(UnsignedShort.valueOf((short) 0));
    transport.handleFrame(new TransportFrame(0, begin, null));

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 2, transport.writes.size());

    // Cause a Close frame to be sent
    connection.close();
    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size());
    assertTrue("Unexpected frame type", transport.writes.get(2) instanceof Close);

    // Close the session and verify the transport doesn't
    // send any End frame, as a Close frame was sent already.
    session.close();
    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size());
}
 
Example 14
Source File: TransportImplTest.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
void doEmitFlowOnSendTestImpl(boolean emitFlowEventOnSend)
{
    MockTransportImpl transport = new MockTransportImpl();
    transport.setEmitFlowEventOnSend(emitFlowEventOnSend);

    Connection connection = Proton.connection();
    transport.bind(connection);

    Collector collector = Collector.Factory.create();
    connection.collect(collector);

    Session session = connection.session();
    session.open();

    String linkName = "mySender";
    Sender sender = session.sender(linkName);
    sender.open();

    sendMessage(sender, "tag1", "content1");

    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 0, transport.writes.size());

    assertEvents(collector, Event.Type.CONNECTION_INIT, Event.Type.SESSION_INIT, Event.Type.SESSION_LOCAL_OPEN,
                            Event.Type.TRANSPORT, Event.Type.LINK_INIT, Event.Type.LINK_LOCAL_OPEN, Event.Type.TRANSPORT);

    // Now open the connection, expect the Open and Begin frames but
    // nothing else as we haven't opened the receiver itself yet.
    connection.open();

    pumpMockTransport(transport);

    assertEvents(collector, Event.Type.CONNECTION_LOCAL_OPEN, Event.Type.TRANSPORT);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size());

    assertTrue("Unexpected frame type", transport.writes.get(0) instanceof Open);
    assertTrue("Unexpected frame type", transport.writes.get(1) instanceof Begin);
    assertTrue("Unexpected frame type", transport.writes.get(2) instanceof Attach);

    // Send the necessary responses to open/begin/attach then give sender credit
    transport.handleFrame(new TransportFrame(0, new Open(), null));

    Begin begin = new Begin();
    begin.setRemoteChannel(UnsignedShort.valueOf((short) 0));
    transport.handleFrame(new TransportFrame(0, begin, null));

    Attach attach = new Attach();
    attach.setHandle(UnsignedInteger.ZERO);
    attach.setRole(Role.RECEIVER);
    attach.setName(linkName);
    attach.setInitialDeliveryCount(UnsignedInteger.ZERO);
    transport.handleFrame(new TransportFrame(0, attach, null));

    Flow flow = new Flow();
    flow.setHandle(UnsignedInteger.ZERO);
    flow.setDeliveryCount(UnsignedInteger.ZERO);
    flow.setNextIncomingId(UnsignedInteger.ONE);
    flow.setNextOutgoingId(UnsignedInteger.ZERO);
    flow.setIncomingWindow(UnsignedInteger.valueOf(1024));
    flow.setOutgoingWindow(UnsignedInteger.valueOf(1024));
    flow.setLinkCredit(UnsignedInteger.valueOf(10));

    transport.handleFrame(new TransportFrame(0, flow, null));

    assertEvents(collector, Event.Type.CONNECTION_REMOTE_OPEN, Event.Type.SESSION_REMOTE_OPEN,
                            Event.Type.LINK_REMOTE_OPEN, Event.Type.LINK_FLOW);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size());

    // Now pump the transport again and expect a transfer for the message
    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 4, transport.writes.size());
    assertTrue("Unexpected frame type", transport.writes.get(3) instanceof Transfer);

    // Verify that we did, or did not, emit a flow event
    if(emitFlowEventOnSend)
    {
        assertEvents(collector, Event.Type.LINK_FLOW);
    }
    else
    {
        assertNoEvents(collector);
    }
}
 
Example 15
Source File: SslTest.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
private void doMultiplePemTrustCertificatesTestImpl(String serverKeystore) throws Exception {
    Transport clientTransport = Proton.transport();
    Transport serverTransport = Proton.transport();

    TransportPumper pumper = new TransportPumper(clientTransport, serverTransport);

    Connection clientConnection = Proton.connection();
    Connection serverConnection = Proton.connection();

    SslDomain clientSslDomain = SslDomain.Factory.create();
    clientSslDomain.init(Mode.CLIENT);
    clientSslDomain.setPeerAuthentication(VerifyMode.VERIFY_PEER);
    clientSslDomain.setTrustedCaDb(CA_CERTS);
    clientTransport.ssl(clientSslDomain);

    SslDomain serverSslDomain = SslDomain.Factory.create();
    serverSslDomain.init(Mode.SERVER);
    SSLContext serverSslContext = createSslContext(serverKeystore, PASSWORD, SERVER_JKS_TRUSTSTORE, PASSWORD);
    serverSslDomain.setSslContext(serverSslContext);
    serverTransport.ssl(serverSslDomain);

    clientConnection.setContainer(CLIENT_CONTAINER);
    serverConnection.setContainer(SERVER_CONTAINER);

    clientTransport.bind(clientConnection);
    serverTransport.bind(serverConnection);

    assertConditions(clientTransport);
    assertConditions(serverTransport);

    clientConnection.open();

    assertEndpointState(clientConnection, ACTIVE, UNINITIALIZED);
    assertEndpointState(serverConnection, UNINITIALIZED, UNINITIALIZED);

    assertConditions(clientTransport);
    assertConditions(serverTransport);

    pumper.pumpAll();

    assertEndpointState(clientConnection, ACTIVE, UNINITIALIZED);
    assertEndpointState(serverConnection, UNINITIALIZED, ACTIVE);

    assertConditions(clientTransport);
    assertConditions(serverTransport);

    serverConnection.open();

    assertEndpointState(clientConnection, ACTIVE, UNINITIALIZED);
    assertEndpointState(serverConnection, ACTIVE, ACTIVE);

    assertConditions(clientTransport);
    assertConditions(serverTransport);

    pumper.pumpAll();

    assertEndpointState(clientConnection, ACTIVE, ACTIVE);
    assertEndpointState(serverConnection, ACTIVE, ACTIVE);

    assertConditions(clientTransport);
    assertConditions(serverTransport);
}
 
Example 16
Source File: TransportImplTest.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
void doLinkDetachAfterEndSentTestImpl(boolean receiverLink)
{
    MockTransportImpl transport = new MockTransportImpl();
    Connection connection = Proton.connection();
    transport.bind(connection);

    connection.open();

    Session session = connection.session();
    session.open();

    Link link = null;
    if(receiverLink)
    {
        link = session.receiver("myReceiver");
    }
    else
    {
        link = session.sender("mySender");
    }
    link.open();

    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size());

    assertTrue("Unexpected frame type", transport.writes.get(0) instanceof Open);
    assertTrue("Unexpected frame type", transport.writes.get(1) instanceof Begin);
    assertTrue("Unexpected frame type", transport.writes.get(2) instanceof Attach);

    // Send the necessary responses to open/begin
    transport.handleFrame(new TransportFrame(0, new Open(), null));

    Begin begin = new Begin();
    begin.setRemoteChannel(UnsignedShort.valueOf((short) 0));
    transport.handleFrame(new TransportFrame(0, begin, null));

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size());

    // Cause an End frame to be sent
    session.close();
    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 4, transport.writes.size());
    assertTrue("Unexpected frame type", transport.writes.get(3) instanceof End);

    // Close the link and verify the transport doesn't
    // send any Detach frame, as an End frame was sent already.
    link.close();
    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 4, transport.writes.size());
}
 
Example 17
Source File: TransportImplTest.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
void doLinkAttachAfterEndSentTestImpl(boolean receiverLink)
{
    MockTransportImpl transport = new MockTransportImpl();
    Connection connection = Proton.connection();
    transport.bind(connection);

    connection.open();

    Session session = connection.session();
    session.open();

    Link link = null;
    if(receiverLink)
    {
        link = session.receiver("myReceiver");
    }
    else
    {
        link = session.sender("mySender");
    }

    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 2, transport.writes.size());

    assertTrue("Unexpected frame type", transport.writes.get(0) instanceof Open);
    assertTrue("Unexpected frame type", transport.writes.get(1) instanceof Begin);

    // Send the necessary responses to open/begin
    transport.handleFrame(new TransportFrame(0, new Open(), null));

    Begin begin = new Begin();
    begin.setRemoteChannel(UnsignedShort.valueOf((short) 0));
    transport.handleFrame(new TransportFrame(0, begin, null));

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 2, transport.writes.size());

    // Cause a End frame to be sent
    session.close();
    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size());
    assertTrue("Unexpected frame type", transport.writes.get(2) instanceof End);

    // Open the link and verify the transport doesn't
    // send any Attach frame, as an End frame was sent already.
    link.open();
    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size());
}
 
Example 18
Source File: TransportImplTest.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
/**
 * Verify that no Disposition frame is emitted by the Transport should a Delivery
 * have disposition applied after the delivery has been settled previously.
 */
@Test
public void testNoDispositionUpdatesAfterSettlementProceessedReceiver()
{
    MockTransportImpl transport = new MockTransportImpl();
    Connection connection = Proton.connection();
    transport.bind(connection);

    connection.open();

    Session session = connection.session();
    session.open();

    String linkName = "myReceiver";
    Sender sender = session.sender(linkName);
    sender.open();

    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size());

    assertTrue("Unexpected frame type", transport.writes.get(0) instanceof Open);
    assertTrue("Unexpected frame type", transport.writes.get(1) instanceof Begin);
    assertTrue("Unexpected frame type", transport.writes.get(2) instanceof Attach);

    // Send the necessary responses to open/begin/attach as well as a transfer
    transport.handleFrame(new TransportFrame(0, new Open(), null));

    Begin begin = new Begin();
    begin.setRemoteChannel(UnsignedShort.valueOf((short) 0));
    begin.setNextOutgoingId(UnsignedInteger.ONE);
    begin.setIncomingWindow(UnsignedInteger.valueOf(1024));
    begin.setOutgoingWindow(UnsignedInteger.valueOf(1024));
    transport.handleFrame(new TransportFrame(0, begin, null));

    Attach attach = new Attach();
    attach.setHandle(UnsignedInteger.ZERO);
    attach.setRole(Role.RECEIVER);
    attach.setName(linkName);
    attach.setInitialDeliveryCount(UnsignedInteger.ZERO);
    transport.handleFrame(new TransportFrame(0, attach, null));

    int credit = 1;
    Flow flow = new Flow();
    flow.setHandle(UnsignedInteger.ZERO);
    flow.setDeliveryCount(UnsignedInteger.ZERO);
    flow.setNextIncomingId(UnsignedInteger.ONE);
    flow.setNextOutgoingId(UnsignedInteger.ZERO);
    flow.setIncomingWindow(UnsignedInteger.valueOf(1024));
    flow.setOutgoingWindow(UnsignedInteger.valueOf(1024));
    flow.setDrain(true);
    flow.setLinkCredit(UnsignedInteger.valueOf(credit));
    transport.handleFrame(new TransportFrame(0, flow, null));

    Delivery delivery = sendMessage(sender, "tag1", "content1");

    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 4, transport.writes.size());
    assertTrue("Unexpected frame type", transport.writes.get(3) instanceof Transfer);

    delivery.disposition(Accepted.getInstance());
    delivery.settle();

    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 5, transport.writes.size());
    assertTrue("Unexpected frame type", transport.writes.get(4) instanceof Disposition);

    // Should not produce any new frames being written
    delivery.disposition(Accepted.getInstance());

    connection.close();
    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 6, transport.writes.size());
    assertTrue("Unexpected frame type", transport.writes.get(5) instanceof Close);
}
 
Example 19
Source File: TransportImplTest.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Test
public void testMultiplexDeliveriesOnSameReceiverLinkCausesISE() {
    MockTransportImpl transport = new MockTransportImpl();
    transport.setEmitFlowEventOnSend(false);
    Connection connection = Proton.connection();
    transport.bind(connection);

    connection.open();

    Session session = connection.session();
    session.open();

    String linkName1 = "myReceiver1";
    Receiver receiver1 = session.receiver(linkName1);
    receiver1.flow(5);
    receiver1.open();

    pumpMockTransport(transport);

    final UnsignedInteger r1handle = UnsignedInteger.ZERO;

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 4, transport.writes.size());

    // Give the necessary responses to open/begin/attach
    transport.handleFrame(new TransportFrame(0, new Open(), null));

    Begin begin = new Begin();
    begin.setRemoteChannel(UnsignedShort.valueOf((short) 0));
    begin.setNextOutgoingId(UnsignedInteger.ONE);
    begin.setIncomingWindow(UnsignedInteger.valueOf(1024));
    begin.setOutgoingWindow(UnsignedInteger.valueOf(1024));
    transport.handleFrame(new TransportFrame(0, begin, null));

    Attach attach1 = new Attach();
    attach1.setHandle(r1handle);
    attach1.setRole(Role.SENDER);
    attach1.setName(linkName1);
    attach1.setInitialDeliveryCount(UnsignedInteger.ZERO);
    transport.handleFrame(new TransportFrame(0, attach1, null));

    // Receive first transfer for a multi-frame delivery
    handlePartialTransfer(transport, r1handle, 1, "tag1", new byte[]{ 1 }, true);

    // Receive first transfer for ANOTHER multi-frame delivery, expect it to fail
    // as multiplexing deliveries on a single link is forbidden by the spec.
    try {
        handlePartialTransfer(transport, r1handle, 2, "tag2", new byte[]{ 2 }, true);
        fail("Expected an ISE");
    } catch(IllegalStateException ise) {
        // Expected
        assertEquals("Unexpected message", "Illegal multiplex of deliveries on same link with delivery-id 1 and 2", ise.getMessage());
    }
}
 
Example 20
Source File: ProtonEngineExampleTest.java    From qpid-proton-j with Apache License 2.0 2 votes vote down vote up
@Ignore("This test does not have a fix yet")
@Test
public void testPROTON_1017() throws Exception
{
    LOGGER.fine(bold("======== About to create transports"));

    getClient().transport = Proton.transport();
    ProtocolTracerEnabler.setProtocolTracer(getClient().transport, TestLoggingHelper.CLIENT_PREFIX);

    getServer().transport = Proton.transport();
    ProtocolTracerEnabler.setProtocolTracer(getServer().transport, "            " + TestLoggingHelper.SERVER_PREFIX);

    doOutputInputCycle();

    getClient().connection = Proton.connection();
    getClient().transport.bind(getClient().connection);

    getServer().connection = Proton.connection();
    getServer().transport.bind(getServer().connection);

    LOGGER.fine(bold("======== About to open connections"));
    getClient().connection.open();
    getServer().connection.open();

    doOutputInputCycle();

    LOGGER.fine(bold("======== About to open and close client session"));
    getClient().session = getClient().connection.session();
    getClient().session.open();
    getClient().session.close();
    pumpClientToServer();

    getServer().session = getServer().connection.sessionHead(of(UNINITIALIZED), of(CLOSED));
    assertEndpointState(getServer().session, UNINITIALIZED, CLOSED);

    getServer().session.open();
    assertEndpointState(getServer().session, ACTIVE, CLOSED);

    getServer().session.close();
    assertEndpointState(getServer().session, CLOSED, CLOSED);

    pumpServerToClient();
    assertEndpointState(getClient().session, CLOSED, CLOSED);

    LOGGER.fine(bold("======== About to close client's connection"));

    getClient().connection.close();

    pumpClientToServer();

    LOGGER.fine(bold("======== Server about to process client's connection closure"));

    assertEquals(CLOSED, getServer().connection.getRemoteState());
    getServer().connection.close();

    pumpServerToClient();

    LOGGER.fine(bold("======== Checking client has nothing more to pump"));

    assertClientHasNothingToOutput();

    LOGGER.fine(bold("======== Done!"));
}