org.apache.qpid.proton.engine.Collector Java Examples
The following examples show how to use
org.apache.qpid.proton.engine.Collector.
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: Drain.java From qpid-proton-j with Apache License 2.0 | 6 votes |
public static void main(String[] argv) throws Exception { List<String> switches = new ArrayList<String>(); List<String> args = new ArrayList<String>(); for (String s : argv) { if (s.startsWith("-")) { switches.add(s); } else { args.add(s); } } boolean quiet = switches.contains("-q"); String address = args.isEmpty() || !args.get(0).startsWith("/") ? "//localhost" : args.remove(0); int count = args.isEmpty() ? 1 : Integer.parseInt(args.remove(0)); boolean block = switches.contains("-b"); Collector collector = Collector.Factory.create(); Drain drain = new Drain(count, block, quiet); Driver driver = new Driver(collector, drain); Pool pool = new Pool(collector); pool.incoming(address, null); driver.run(); }
Example #2
Source File: Server.java From qpid-proton-j with Apache License 2.0 | 6 votes |
public static final void main(String[] argv) throws IOException { List<String> switches = new ArrayList<String>(); List<String> args = new ArrayList<String>(); for (String s : argv) { if (s.startsWith("-")) { switches.add(s); } else { args.add(s); } } boolean quiet = switches.contains("-q"); String host = !args.isEmpty() && !Character.isDigit(args.get(0).charAt(0)) ? args.remove(0) : "localhost"; int port = !args.isEmpty() ? Integer.parseInt(args.remove(0)) : 5672; Collector collector = Collector.Factory.create(); Router router = new Router(); Driver driver = new Driver(collector, new Handshaker(), new FlowController(1024), router, new Server(router, quiet)); driver.listen(host, port); driver.run(); }
Example #3
Source File: Pool.java From qpid-proton-j with Apache License 2.0 | 6 votes |
public Pool(Collector collector, final Router router) { this.collector = collector; connections = new HashMap<String,Connection>(); if (router != null) { outgoingResolver = new LinkResolver<Sender>() { public Sender resolve(String address) { return router.getOutgoing(address).choose(); } }; incomingResolver = new LinkResolver<Receiver>() { public Receiver resolve(String address) { return router.getIncoming(address).choose(); } }; } else { outgoingResolver = new LinkResolver<Sender>() { public Sender resolve(String address) { return null; } }; incomingResolver = new LinkResolver<Receiver>() { public Receiver resolve(String address) { return null; } }; } }
Example #4
Source File: ConnectionImpl.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Override public void collect(Collector collector) { _collector = (CollectorImpl) collector; put(Event.Type.CONNECTION_INIT, this); LinkNode<SessionImpl> ssn = _sessionHead; while (ssn != null) { put(Event.Type.SESSION_INIT, ssn.getValue()); ssn = ssn.getNext(); } LinkNode<LinkImpl> lnk = _linkHead; while (lnk != null) { put(Event.Type.LINK_INIT, lnk.getValue()); lnk = lnk.getNext(); } }
Example #5
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 6 votes |
private void assertEvents(Collector collector, Event.Type... expectedEventTypes) { if(expectedEventTypes.length == 0) { assertNull("Expected no events, but at least one was present: " + collector.peek(), collector.peek()); } else { ArrayList<Event.Type> eventTypesList = new ArrayList<Event.Type>(); Event event = null; while ((event = collector.peek()) != null) { eventTypesList.add(event.getType()); collector.pop(); } assertArrayEquals("Unexpected event types: " + eventTypesList, expectedEventTypes, eventTypesList.toArray(new Event.Type[0])); } }
Example #6
Source File: Spout.java From qpid-proton-j with Apache License 2.0 | 5 votes |
public static void main(String[] argv) throws Exception { List<String> switches = new ArrayList<String>(); List<String> args = new ArrayList<String>(); for (String s : argv) { if (s.startsWith("-")) { switches.add(s); } else { args.add(s); } } boolean quiet = switches.contains("-q"); String address = !args.isEmpty() && args.get(0).startsWith("/") ? args.remove(0) : "//localhost"; int count = !args.isEmpty() ? Integer.parseInt(args.remove(0)) : 1; Collector collector = Collector.Factory.create(); Spout spout = new Spout(count, quiet); Driver driver = new Driver(collector, spout); Pool pool = new Pool(collector); pool.outgoing(address, null); driver.run(); }
Example #7
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 4 votes |
private void doInvalidDispositionProvokesDecodeErrorTestImpl(byte[] bytes, String description) { MockTransportImpl transport = new MockTransportImpl(); Connection connection = Proton.connection(); Collector collector = Collector.Factory.create(); connection.collect(collector); transport.bind(connection); connection.open(); Session session = connection.session(); session.open(); String linkName = "mySender"; 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); // Provide the response bytes for the header transport.tail().put(AmqpHeader.HEADER); transport.process(); // Send the necessary response to Open/Begin/Attach plus some credit 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)); 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)); 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); int capacity = transport.capacity(); assertTrue("Unexpected transport capacity: " + capacity, capacity > bytes.length); transport.tail().put(bytes); transport.process(); pumpMockTransport(transport); assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 5, transport.writes.size()); FrameBody frameBody = transport.writes.get(4); assertTrue("Unexpected frame type", frameBody instanceof Close); // Expect the close frame generated to contain a decode error condition referencing the missing container-id. ErrorCondition expectedCondition = new ErrorCondition(); expectedCondition.setCondition(AmqpError.DECODE_ERROR); expectedCondition.setDescription(description); assertEquals("Unexpected condition", expectedCondition, ((Close) frameBody).getError()); }
Example #8
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 4 votes |
private void doInvalidTransferProvokesDecodeErrorTestImpl(byte[] bytes, String description) { MockTransportImpl transport = new MockTransportImpl(); Connection connection = Proton.connection(); Collector collector = Collector.Factory.create(); connection.collect(collector); 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); // Provide the response bytes for the header transport.tail().put(AmqpHeader.HEADER); transport.process(); // Send the necessary response 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 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)); int capacity = transport.capacity(); assertTrue("Unexpected transport capacity: " + capacity, capacity > bytes.length); transport.tail().put(bytes); transport.process(); pumpMockTransport(transport); assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 5, transport.writes.size()); FrameBody frameBody = transport.writes.get(4); assertTrue("Unexpected frame type", frameBody instanceof Close); // Expect the close frame generated to contain a decode error condition referencing the missing container-id. ErrorCondition expectedCondition = new ErrorCondition(); expectedCondition.setCondition(AmqpError.DECODE_ERROR); expectedCondition.setDescription(description); assertEquals("Unexpected condition", expectedCondition, ((Close) frameBody).getError()); }
Example #9
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 4 votes |
private void doInvalidFlowProvokesDecodeErrorTestImpl(byte[] bytes, String description) { MockTransportImpl transport = new MockTransportImpl(); Connection connection = Proton.connection(); Collector collector = Collector.Factory.create(); connection.collect(collector); 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); // Provide the response bytes for the header transport.tail().put(AmqpHeader.HEADER); transport.process(); // Send the necessary response to Open/Begin 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)); int capacity = transport.capacity(); assertTrue("Unexpected transport capacity: " + capacity, capacity > bytes.length); transport.tail().put(bytes); transport.process(); pumpMockTransport(transport); assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size()); FrameBody frameBody = transport.writes.get(2); assertTrue("Unexpected frame type", frameBody instanceof Close); // Expect the close frame generated to contain a decode error condition referencing the missing container-id. ErrorCondition expectedCondition = new ErrorCondition(); expectedCondition.setCondition(AmqpError.DECODE_ERROR); expectedCondition.setDescription(description); assertEquals("Unexpected condition", expectedCondition, ((Close) frameBody).getError()); }
Example #10
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 4 votes |
private void doInvalidBeginProvokesDecodeErrorTestImpl(byte[] bytes, String description) { MockTransportImpl transport = new MockTransportImpl(); Connection connection = Proton.connection(); Collector collector = Collector.Factory.create(); connection.collect(collector); transport.bind(connection); connection.open(); pumpMockTransport(transport); assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 1, transport.writes.size()); assertTrue("Unexpected frame type", transport.writes.get(0) instanceof Open); // Provide the response bytes for the header transport.tail().put(AmqpHeader.HEADER); transport.process(); // Send the necessary response to open transport.handleFrame(new TransportFrame(0, new Open(), null)); int capacity = transport.capacity(); assertTrue("Unexpected transport capacity: " + capacity, capacity > bytes.length); transport.tail().put(bytes); transport.process(); pumpMockTransport(transport); assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 2, transport.writes.size()); FrameBody frameBody = transport.writes.get(1); assertTrue("Unexpected frame type", frameBody instanceof Close); // Expect the close frame generated to contain a decode error condition referencing the missing container-id. ErrorCondition expectedCondition = new ErrorCondition(); expectedCondition.setCondition(AmqpError.DECODE_ERROR); expectedCondition.setDescription(description); assertEquals("Unexpected condition", expectedCondition, ((Close) frameBody).getError()); }
Example #11
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 4 votes |
@Test public void testCloseFrameErrorAfterDecodeError() { MockTransportImpl transport = new MockTransportImpl(); Connection connection = Proton.connection(); Collector collector = Collector.Factory.create(); connection.collect(collector); transport.bind(connection); connection.open(); pumpMockTransport(transport); assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 1, transport.writes.size()); assertTrue("Unexpected frame type", transport.writes.get(0) instanceof Open); assertEvents(collector, Event.Type.CONNECTION_INIT, Event.Type.CONNECTION_BOUND, Event.Type.CONNECTION_LOCAL_OPEN, Event.Type.TRANSPORT); // Provide the response bytes for the header transport.tail().put(AmqpHeader.HEADER); transport.process(); // Provide the bytes for Open, but omit the mandatory container-id to provoke a decode error. byte[] bytes = new byte[] { 0x00, 0x00, 0x00, 0x0C, // Frame size = 12 bytes. 0x02, 0x00, 0x00, 0x00, // DOFF, TYPE, 2x CHANNEL 0x00, 0x53, 0x10, 0x45};// Described-type, ulong type, open descriptor, list0. int capacity = transport.capacity(); assertTrue("Unexpected transport capacity: " + capacity, capacity > bytes.length); transport.tail().put(bytes); transport.process(); assertEvents(collector, Event.Type.TRANSPORT_ERROR, Event.Type.TRANSPORT_TAIL_CLOSED); pumpMockTransport(transport); assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 2, transport.writes.size()); FrameBody frameBody = transport.writes.get(1); assertTrue("Unexpected frame type", frameBody instanceof Close); // Expect the close frame generated to contain a decode error condition referencing the missing container-id. ErrorCondition expectedCondition = new ErrorCondition(); expectedCondition.setCondition(AmqpError.DECODE_ERROR); expectedCondition.setDescription("The container-id field cannot be omitted"); assertEquals("Unexpected condition", expectedCondition, ((Close) frameBody).getError()); }
Example #12
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 4 votes |
@Test public void testEndpointOpenAndCloseAreIdempotent() { MockTransportImpl transport = new MockTransportImpl(); Connection connection = Proton.connection(); transport.bind(connection); Collector collector = Collector.Factory.create(); connection.collect(collector); connection.open(); connection.open(); Session session = connection.session(); session.open(); String linkName = "mySender"; Sender sender = session.sender(linkName); sender.open(); pumpMockTransport(transport); assertEvents(collector, Event.Type.CONNECTION_INIT, Event.Type.CONNECTION_LOCAL_OPEN, Event.Type.TRANSPORT, Event.Type.SESSION_INIT, Event.Type.SESSION_LOCAL_OPEN, Event.Type.TRANSPORT, Event.Type.LINK_INIT, Event.Type.LINK_LOCAL_OPEN, Event.Type.TRANSPORT); pumpMockTransport(transport); connection.open(); session.open(); sender.open(); assertNoEvents(collector); 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)); assertEvents(collector, Event.Type.CONNECTION_REMOTE_OPEN, Event.Type.SESSION_REMOTE_OPEN, Event.Type.LINK_REMOTE_OPEN); assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size()); // Now close the link and expect one event sender.close(); sender.close(); assertEvents(collector, Event.Type.LINK_LOCAL_CLOSE, Event.Type.TRANSPORT); pumpMockTransport(transport); sender.close(); assertNoEvents(collector); pumpMockTransport(transport); assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 4, transport.writes.size()); assertTrue("Unexpected frame type", transport.writes.get(3) instanceof Detach); }
Example #13
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 4 votes |
private void assertNoEvents(Collector collector) { assertEvents(collector); }
Example #14
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 4 votes |
/** * Verify that no Transfer frame is emitted by the Transport should a Delivery * be sendable after the Close frame was sent. */ @Test public void testTransferAfterCloseSent() { MockTransportImpl transport = new MockTransportImpl(); Connection connection = Proton.connection(); transport.bind(connection); connection.open(); Collector collector = Collector.Factory.create(); connection.collect(collector); Session session = connection.session(); session.open(); String linkName = "mySender"; 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 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()); // 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); // Send a new message and verify the transport doesn't // send any Transfer frame, as a Close frame was sent already. sendMessage(sender, "tag1", "content1"); pumpMockTransport(transport); assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 4, transport.writes.size()); }
Example #15
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 4 votes |
/** * Verify that no Flow frame is emitted by the Transport should a Sender * have credit drained added after the Close frame was sent. */ @Test public void testSenderFlowAfterCloseSent() { MockTransportImpl transport = new MockTransportImpl(); Connection connection = Proton.connection(); transport.bind(connection); connection.open(); Collector collector = Collector.Factory.create(); connection.collect(collector); Session session = connection.session(); session.open(); String linkName = "mySender"; 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); assertFalse("Should not be in drain yet", sender.getDrain()); // Send the necessary responses to open/begin/attach then give sender credit and drain 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)); int credit = 10; 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)); assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size()); assertTrue("Should not be in drain", sender.getDrain()); assertEquals("Should have credit", credit, sender.getCredit()); // 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); // Drain the credit and verify the transport doesn't // send any Flow frame, as a Close frame was sent already. int drained = sender.drained(); assertEquals("Should have drained all credit", credit, drained); pumpMockTransport(transport); assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 4, transport.writes.size()); }
Example #16
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 4 votes |
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 #17
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 4 votes |
@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); }
Example #18
Source File: Timer.java From qpid-proton-j with Apache License 2.0 | 4 votes |
public Timer(Collector collector) { this.collector = (CollectorImpl)collector; }
Example #19
Source File: ReactorImpl.java From qpid-proton-j with Apache License 2.0 | 4 votes |
@Override public Collector collector() { return collector; }
Example #20
Source File: Proton.java From qpid-proton-j with Apache License 2.0 | 4 votes |
public static Collector collector() { return Engine.collector(); }
Example #21
Source File: Pool.java From qpid-proton-j with Apache License 2.0 | 4 votes |
public Pool(Collector collector) { this(collector, null); }
Example #22
Source File: Driver.java From qpid-proton-j with Apache License 2.0 | 4 votes |
public Driver(Collector collector, Handler ... handlers) throws IOException { this.collector = collector; this.handlers = handlers; this.selector = Selector.open(); }
Example #23
Source File: Selectable.java From qpid-proton-j with Apache License 2.0 | 2 votes |
/** * Configure a selectable with a set of callbacks that emit readable, * writable, and expired events into the supplied collector. * @param collector */ void setCollector(final Collector collector);
Example #24
Source File: Reactor.java From qpid-proton-j with Apache License 2.0 | 2 votes |
/** * @return the Collector used to gather events generated by this reactor. */ Collector collector();