当前位置: 首页>>代码示例>>Java>>正文


Java Proton.connection方法代码示例

本文整理汇总了Java中org.apache.qpid.proton.Proton.connection方法的典型用法代码示例。如果您正苦于以下问题:Java Proton.connection方法的具体用法?Java Proton.connection怎么用?Java Proton.connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.qpid.proton.Proton的用法示例。


在下文中一共展示了Proton.connection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testOpenSessionBeforeOpenConnection

import org.apache.qpid.proton.Proton; //导入方法依赖的package包/类
@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);
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:24,代码来源:TransportImplTest.java

示例2: testTickRemoteTimeout

import org.apache.qpid.proton.Proton; //导入方法依赖的package包/类
@Test
public void testTickRemoteTimeout()
{
    MockTransportImpl transport = new MockTransportImpl();
    Connection connection = Proton.connection();
    transport.bind(connection);

    int timeout = 4000;
    Open open = new Open();
    open.setIdleTimeOut(new UnsignedInteger(4000));
    TransportFrame openFrame = new TransportFrame(CHANNEL_ID, open, null);
    transport.handleFrame(openFrame);
    pumpMockTransport(transport);

    long deadline = transport.tick(0);
    assertEquals("Expected to be returned a deadline of 2000",  2000, deadline);  // deadline = 4000 / 2

    deadline = transport.tick(1000);    // Wait for less than the deadline with no data - get the same value
    assertEquals("When the deadline hasn't been reached tick() should return the previous deadline",  2000, deadline);
    assertEquals("When the deadline hasn't been reached tick() shouldn't write data", 0, transport.writes.size());

    deadline = transport.tick(timeout/2); // Wait for the deadline - next deadline should be (4000/2)*2
    assertEquals("When the deadline has been reached expected a new deadline to be returned 4000",  4000, deadline);
    assertEquals("tick() should have written data", 1, transport.writes.size());
    assertEquals("tick() should have written an empty frame", null, transport.writes.get(0));

    transport.writeFrame(CHANNEL_ID, new Begin(), null, null);
    while(transport.pending() > 0) transport.pop(transport.head().remaining());
    int framesWrittenBeforeTick = transport.writes.size();
    deadline = transport.tick(3000);
    assertEquals("Writing data resets the deadline",  5000, deadline);
    assertEquals("When the deadline is reset tick() shouldn't write an empty frame", 0, transport.writes.size() - framesWrittenBeforeTick);

    transport.writeFrame(CHANNEL_ID, new Attach(), null, null);
    assertTrue(transport.pending() > 0);
    framesWrittenBeforeTick = transport.writes.size();
    deadline = transport.tick(4000);
    assertEquals("Having pending data does not reset the deadline",  5000, deadline);
    assertEquals("Having pending data prevents tick() from sending an empty frame", 0, transport.writes.size() - framesWrittenBeforeTick);
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:41,代码来源:TransportImplTest.java

示例3: testTickLocalTimeout

import org.apache.qpid.proton.Proton; //导入方法依赖的package包/类
@Test
public void testTickLocalTimeout()
{
    MockTransportImpl transport = new MockTransportImpl();
    transport.setIdleTimeout(4000);
    Connection connection = Proton.connection();
    transport.bind(connection);

    transport.handleFrame(TRANSPORT_FRAME_OPEN);
    connection.open();
    pumpMockTransport(transport);

    long deadline = transport.tick(0);
    assertEquals("Expected to be returned a deadline of 4000",  4000, deadline);

    int framesWrittenBeforeTick = transport.writes.size();
    deadline = transport.tick(1000);    // Wait for less than the deadline with no data - get the same value
    assertEquals("When the deadline hasn't been reached tick() should return the previous deadline",  4000, deadline);
    assertEquals("Reading data should never result in a frame being written", 0, transport.writes.size() - framesWrittenBeforeTick);

    // Protocol header + empty frame
    ByteBuffer data = ByteBuffer.wrap(new byte[] {'A', 'M', 'Q', 'P', 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x02, 0x00, 0x00, 0x00});
    processInput(transport, data);
    framesWrittenBeforeTick = transport.writes.size();
    deadline = transport.tick(2000);
    assertEquals("Reading data data resets the deadline",  6000, deadline);
    assertEquals("Reading data should never result in a frame being written", 0, transport.writes.size() - framesWrittenBeforeTick);
    assertEquals("Reading data before the deadline should keep the connection open", EndpointState.ACTIVE, connection.getLocalState());

    framesWrittenBeforeTick = transport.writes.size();
    deadline = transport.tick(7000);
    assertEquals("Calling tick() after the deadline should result in the connection being closed", EndpointState.CLOSED, connection.getLocalState());
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:34,代码来源:TransportImplTest.java

示例4: doOpenLinkBeforeOpenConnectionTestImpl

import org.apache.qpid.proton.Proton; //导入方法依赖的package包/类
void doOpenLinkBeforeOpenConnectionTestImpl(boolean receiverLink)
{
    MockTransportImpl transport = new MockTransportImpl();
    Connection connection = Proton.connection();
    transport.bind(connection);

    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), 0, transport.writes.size());

    // Now open the connection, expect the Open, Begin, and Attach frames
    connection.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);
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:36,代码来源:TransportImplTest.java

示例5: testSessionBeginAfterCloseSent

import org.apache.qpid.proton.Proton; //导入方法依赖的package包/类
/**
 * 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());
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:41,代码来源:TransportImplTest.java

示例6: MockNetworkChannel

import org.apache.qpid.proton.Proton; //导入方法依赖的package包/类
public MockNetworkChannel(NetworkListener listener, Handler handler) {
    this.listener = listener;
    this.handler = handler;
    collector = Proton.collector();
    connection = Proton.connection();
    transport = Proton.transport();
    connection.collect(collector);
    connection.setHostname("localhost");
    connection.setContainer("some container");
    transport.bind(connection);
    Sasl sasl = transport.sasl();
    sasl.server();
    sasl.setMechanisms("ANONYMOUS");
    sasl.done(Sasl.SaslOutcome.PN_SASL_OK);
}
 
开发者ID:mqlight,项目名称:java-mqlight,代码行数:16,代码来源:MockNetworkChannel.java

示例7: testProperties

import org.apache.qpid.proton.Proton; //导入方法依赖的package包/类
@Test
public void testProperties() throws Exception
{
    final Symbol clientPropName = Symbol.valueOf("ClientPropName");
    final Integer clientPropValue = 1234;
    final Symbol serverPropName = Symbol.valueOf("ServerPropName");
    final Integer serverPropValue = 5678;

    Map<Symbol, Object> clientProps = new HashMap<>();
    clientProps.put(clientPropName, clientPropValue);

    Map<Symbol, Object> serverProps = new HashMap<>();
    serverProps.put(serverPropName, serverPropValue);

    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 sessions"));
    getClient().session = getClient().connection.session();

    // Set the client session properties
    getClient().session.setProperties(clientProps);

    getClient().session.open();

    pumpClientToServer();

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

    // Set the server session properties
    getServer().session.setProperties(serverProps);

    getServer().session.open();

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

    pumpServerToClient();

    assertEndpointState(getClient().session, ACTIVE, ACTIVE);

    // Verify server side got the clients session properties as expected
    Map<Symbol, Object> serverRemoteProperties = getServer().session.getRemoteProperties();
    assertNotNull("Server had no remote properties", serverRemoteProperties);
    assertEquals("Server remote properties not expected size", 1, serverRemoteProperties.size());
    assertTrue("Server remote properties lack expected key: " + clientPropName, serverRemoteProperties.containsKey(clientPropName));
    assertEquals("Server remote properties contain unexpected value for key: " + clientPropName, clientPropValue, serverRemoteProperties.get(clientPropName));

    // Verify the client side got the servers session properties as expected
    Map<Symbol, Object> clientRemoteProperties = getClient().session.getRemoteProperties();
    assertNotNull("Client had no remote properties", clientRemoteProperties);
    assertEquals("Client remote properties not expected size", 1, clientRemoteProperties.size());
    assertTrue("Client remote properties lack expected key: " + serverPropName, clientRemoteProperties.containsKey(serverPropName));
    assertEquals("Client remote properties contain unexpected value for key: " + serverPropName, serverPropValue, clientRemoteProperties.get(serverPropName));
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:75,代码来源:SessionTest.java

示例8: doOpenLinkBeforeOpenSessionTestImpl

import org.apache.qpid.proton.Proton; //导入方法依赖的package包/类
void doOpenLinkBeforeOpenSessionTestImpl(boolean receiverLink)
{
    MockTransportImpl transport = new MockTransportImpl();
    Connection connection = Proton.connection();
    transport.bind(connection);

    // Open the connection
    connection.open();

    // Create but don't open the session
    Session session = connection.session();

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

    pumpMockTransport(transport);

    // Expect only an Open frame, no attach should be sent as the session isn't open
    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 1, transport.writes.size());
    assertTrue("Unexpected frame type", transport.writes.get(0) instanceof Open);

    // Now open the session, expect the Begin
    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);
    // Note: an Attach wasn't sent because link is no longer 'modified' after earlier pump. It
    // could easily be argued it should, given how the engine generally handles things. Seems
    // unlikely to be of much real world concern.
    //assertTrue("Unexpected frame type", transport.writes.get(2) instanceof Attach);
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:44,代码来源:TransportImplTest.java

示例9: doLinkAttachAfterEndSentTestImpl

import org.apache.qpid.proton.Proton; //导入方法依赖的package包/类
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());
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:52,代码来源:TransportImplTest.java

示例10: doLinkDetachAfterEndSentTestImpl

import org.apache.qpid.proton.Proton; //导入方法依赖的package包/类
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());
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:54,代码来源:TransportImplTest.java

示例11: testSenderSendBeforeOpenConnection

import org.apache.qpid.proton.Proton; //导入方法依赖的package包/类
@Test
public void testSenderSendBeforeOpenConnection()
{
    MockTransportImpl transport = new MockTransportImpl();

    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());

    // Now open the connection, expect the Open and Begin and Attach frames but
    // nothing else as we the sender wont have credit yet.
    connection.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 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));

    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);
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:70,代码来源:TransportImplTest.java

示例12: testSessionEndAfterCloseSent

import org.apache.qpid.proton.Proton; //导入方法依赖的package包/类
/**
 * 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());
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:47,代码来源:TransportImplTest.java

示例13: doLinkAttachAfterCloseSentTestImpl

import org.apache.qpid.proton.Proton; //导入方法依赖的package包/类
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());
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:52,代码来源:TransportImplTest.java

示例14: testReceiverFlowAfterCloseSent

import org.apache.qpid.proton.Proton; //导入方法依赖的package包/类
/**
 * 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());
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:59,代码来源:TransportImplTest.java

示例15: testNoReceiverFlowAfterDetachSentWhileDraining

import org.apache.qpid.proton.Proton; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:57,代码来源:TransportImplTest.java


注:本文中的org.apache.qpid.proton.Proton.connection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。