org.apache.qpid.proton.amqp.UnsignedShort Java Examples
The following examples show how to use
org.apache.qpid.proton.amqp.UnsignedShort.
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: ServerJMSMapMessage.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override public void setObject(final String name, final Object value) throws JMSException { try { // primitives and String Object val = value; if (value instanceof UnsignedInteger) { val = ((UnsignedInteger) value).intValue(); } else if (value instanceof UnsignedShort) { val = ((UnsignedShort) value).shortValue(); } else if (value instanceof UnsignedByte) { val = ((UnsignedByte) value).byteValue(); } else if (value instanceof UnsignedLong) { val = ((UnsignedLong) value).longValue(); } TypedProperties.setObjectProperty(new SimpleString(name), val, map); } catch (ActiveMQPropertyConversionException e) { throw new MessageFormatException(e.getMessage()); } }
Example #2
Source File: AmqpManagementTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
/** * Some clients use Unsigned types from org.apache.qpid.proton.amqp * @throws Exception */ @Test(timeout = 60000) public void testUnsignedValues() throws Exception { int sequence = 42; LinkedHashMap<String, Object> map = new LinkedHashMap<>(); map.put("sequence", new UnsignedInteger(sequence)); ServerJMSMapMessage msg = createMapMessage(1, map, null); assertEquals(msg.getInt("sequence"), sequence); map.clear(); map.put("sequence", new UnsignedLong(sequence)); msg = createMapMessage(1, map, null); assertEquals(msg.getLong("sequence"), sequence); map.clear(); map.put("sequence", new UnsignedShort((short)sequence)); msg = createMapMessage(1, map, null); assertEquals(msg.getShort("sequence"), sequence); map.clear(); map.put("sequence", new UnsignedByte((byte) sequence)); msg = createMapMessage(1, map, null); assertEquals(msg.getByte("sequence"), sequence); }
Example #3
Source File: BeginTest.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Test public void testCopy() { Map<Symbol, Object> properties = new HashMap<>(); properties.put(Symbol.valueOf("x-opt"), "value"); Begin begin = new Begin(); begin.setRemoteChannel(UnsignedShort.valueOf((short) 2)); begin.setNextOutgoingId(UnsignedInteger.valueOf(10)); begin.setIncomingWindow(UnsignedInteger.valueOf(11)); begin.setOutgoingWindow(UnsignedInteger.valueOf(12)); begin.setHandleMax(UnsignedInteger.valueOf(13)); begin.setDesiredCapabilities(new Symbol[0]); begin.setOfferedCapabilities(new Symbol[] { Symbol.valueOf("anonymous-relay") }); begin.setProperties(properties); final Begin copyOf = begin.copy(); assertEquals(begin.getRemoteChannel(), copyOf.getRemoteChannel()); assertEquals(begin.getNextOutgoingId(), copyOf.getNextOutgoingId()); assertEquals(begin.getIncomingWindow(), copyOf.getIncomingWindow()); assertEquals(begin.getOutgoingWindow(), copyOf.getOutgoingWindow()); assertEquals(begin.getHandleMax(), copyOf.getHandleMax()); assertArrayEquals(begin.getDesiredCapabilities(), copyOf.getDesiredCapabilities()); assertArrayEquals(begin.getOfferedCapabilities(), copyOf.getOfferedCapabilities()); assertEquals(begin.getProperties(), copyOf.getProperties()); }
Example #4
Source File: OpenType.java From qpid-proton-j with Apache License 2.0 | 6 votes |
public int size() { return _open.getProperties() != null ? 10 : _open.getDesiredCapabilities() != null ? 9 : _open.getOfferedCapabilities() != null ? 8 : _open.getIncomingLocales() != null ? 7 : _open.getOutgoingLocales() != null ? 6 : _open.getIdleTimeOut() != null ? 5 : (_open.getChannelMax() != null && !_open.getChannelMax().equals(UnsignedShort.MAX_VALUE)) ? 4 : (_open.getMaxFrameSize() != null && !_open.getMaxFrameSize().equals(UnsignedInteger.MAX_VALUE)) ? 3 : _open.getHostname() != null ? 2 : 1; }
Example #5
Source File: Benchmark.java From qpid-proton-j with Apache License 2.0 | 6 votes |
private void benchmarkApplicationProperties() throws IOException { ApplicationProperties properties = new ApplicationProperties(new HashMap<String, Object>()); properties.getValue().put("test1", UnsignedByte.valueOf((byte) 128)); properties.getValue().put("test2", UnsignedShort.valueOf((short) 128)); properties.getValue().put("test3", UnsignedInteger.valueOf((byte) 128)); resultSet.start(); for (int i = 0; i < ITERATIONS; i++) { outputBuf.byteBuffer().clear(); encoder.writeObject(properties); } resultSet.encodesComplete(); CompositeReadableBuffer inputBuf = convertToComposite(outputBuf); decoder.setBuffer(inputBuf); resultSet.start(); for (int i = 0; i < ITERATIONS; i++) { decoder.readObject(); inputBuf.flip(); } resultSet.decodesComplete(); time("ApplicationProperties", resultSet); }
Example #6
Source File: Benchmark.java From qpid-proton-j with Apache License 2.0 | 6 votes |
private void benchmarkMessageAnnotations() throws IOException { MessageAnnotations annotations = new MessageAnnotations(new HashMap<Symbol, Object>()); annotations.getValue().put(Symbol.valueOf("test1"), UnsignedByte.valueOf((byte) 128)); annotations.getValue().put(Symbol.valueOf("test2"), UnsignedShort.valueOf((short) 128)); annotations.getValue().put(Symbol.valueOf("test3"), UnsignedInteger.valueOf((byte) 128)); resultSet.start(); for (int i = 0; i < ITERATIONS; i++) { outputBuf.byteBuffer().clear(); encoder.writeObject(annotations); } resultSet.encodesComplete(); CompositeReadableBuffer inputBuf = convertToComposite(outputBuf); decoder.setBuffer(inputBuf); resultSet.start(); for (int i = 0; i < ITERATIONS; i++) { decoder.readObject(); inputBuf.flip(); } resultSet.decodesComplete(); time("MessageAnnotations", resultSet); }
Example #7
Source File: AMQPMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public final Object getObjectProperty(String key) { if (key.equals(MessageUtil.TYPE_HEADER_NAME.toString())) { if (properties != null) { return properties.getSubject(); } } else if (key.equals(MessageUtil.CONNECTION_ID_PROPERTY_NAME.toString())) { return getConnectionID(); } else if (key.equals(MessageUtil.JMSXGROUPID)) { return getGroupID(); } else if (key.equals(MessageUtil.JMSXGROUPSEQ)) { return getGroupSequence(); } else if (key.equals(MessageUtil.JMSXUSERID)) { return getAMQPUserID(); } else if (key.equals(MessageUtil.CORRELATIONID_HEADER_NAME.toString())) { if (properties != null && properties.getCorrelationId() != null) { return AMQPMessageIdHelper.INSTANCE.toCorrelationIdString(properties.getCorrelationId()); } } else { Object value = getApplicationPropertiesMap(false).get(key); if (value instanceof UnsignedInteger || value instanceof UnsignedByte || value instanceof UnsignedLong || value instanceof UnsignedShort) { return ((Number)value).longValue(); } else { return value; } } return null; }
Example #8
Source File: DecoderImpl.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Override public UnsignedShort readUnsignedShort(final UnsignedShort defaultVal) { byte encodingCode = _buffer.get(); switch (encodingCode) { case EncodingCodes.USHORT: return UnsignedShort.valueOf(readRawShort()); case EncodingCodes.NULL: return defaultVal; default: throw new ProtonException("Expected UnsignedShort type but found encoding: " + EncodingCodes.toString(encodingCode)); } }
Example #9
Source File: MessageAnnotationsBenchmark.java From qpid-proton-j with Apache License 2.0 | 5 votes |
private void initMessageAnnotations() { annotations = new MessageAnnotations(new HashMap<Symbol, Object>()); annotations.getValue().put(Symbol.valueOf("test1"), UnsignedByte.valueOf((byte) 128)); annotations.getValue().put(Symbol.valueOf("test2"), UnsignedShort.valueOf((short) 128)); annotations.getValue().put(Symbol.valueOf("test3"), UnsignedInteger.valueOf((byte) 128)); }
Example #10
Source File: EncoderImpl.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Override public void writeUnsignedShort(final UnsignedShort ushort) { if(ushort == null) { writeNull(); } else { _unsignedShortType.fastWrite(this, ushort); } }
Example #11
Source File: ApplicationPropertiesBenchmark.java From qpid-proton-j with Apache License 2.0 | 5 votes |
private void initApplicationProperties() { properties = new ApplicationProperties(new HashMap<String, Object>()); properties.getValue().put("test1", UnsignedByte.valueOf((byte) 128)); properties.getValue().put("test2", UnsignedShort.valueOf((short) 128)); properties.getValue().put("test3", UnsignedInteger.valueOf((byte) 128)); }
Example #12
Source File: OpenTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Test public void testCopy() { Map<Symbol, Object> properties = new HashMap<>(); properties.put(Symbol.valueOf("x-opt"), "value"); Open open = new Open(); open.setContainerId("test"); open.setHostname("host"); open.setMaxFrameSize(UnsignedInteger.valueOf(42)); open.setChannelMax(UnsignedShort.MAX_VALUE); open.setIdleTimeOut(UnsignedInteger.valueOf(111)); open.setOfferedCapabilities(new Symbol[] { Symbol.valueOf("anonymous-relay") }); open.setDesiredCapabilities(new Symbol[0]); open.setProperties(properties); Open copyOf = open.copy(); assertEquals(open.getContainerId(), copyOf.getContainerId()); assertEquals(open.getHostname(), copyOf.getHostname()); assertEquals(open.getMaxFrameSize(), copyOf.getMaxFrameSize()); assertEquals(open.getChannelMax(), copyOf.getChannelMax()); assertEquals(open.getIdleTimeOut(), copyOf.getIdleTimeOut()); assertArrayEquals(open.getDesiredCapabilities(), copyOf.getDesiredCapabilities()); assertArrayEquals(open.getOfferedCapabilities(), copyOf.getOfferedCapabilities()); assertEquals(open.getProperties(), copyOf.getProperties()); }
Example #13
Source File: MessageAnnotationsTypeCodecTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
private void doTestDecodeMessageAnnotationsSeries(int size) throws IOException { final Symbol SYMBOL_1 = Symbol.valueOf("test1"); final Symbol SYMBOL_2 = Symbol.valueOf("test2"); final Symbol SYMBOL_3 = Symbol.valueOf("test3"); MessageAnnotations annotations = new MessageAnnotations(new HashMap<>()); annotations.getValue().put(SYMBOL_1, UnsignedByte.valueOf((byte) 128)); annotations.getValue().put(SYMBOL_2, UnsignedShort.valueOf((short) 128)); annotations.getValue().put(SYMBOL_3, UnsignedInteger.valueOf(128)); for (int i = 0; i < size; ++i) { encoder.writeObject(annotations); } buffer.clear(); for (int i = 0; i < size; ++i) { final Object result = decoder.readObject(); assertNotNull(result); assertTrue(result instanceof MessageAnnotations); MessageAnnotations readAnnotations = (MessageAnnotations) result; Map<Symbol, Object> resultMap = readAnnotations.getValue(); assertEquals(annotations.getValue().size(), resultMap.size()); assertEquals(resultMap.get(SYMBOL_1), UnsignedByte.valueOf((byte) 128)); assertEquals(resultMap.get(SYMBOL_2), UnsignedShort.valueOf((short) 128)); assertEquals(resultMap.get(SYMBOL_3), UnsignedInteger.valueOf(128)); } }
Example #14
Source File: TransportImpl.java From qpid-proton-j with Apache License 2.0 | 5 votes |
private void processOpen() { if (!_isOpenSent && (_conditionSet || (_connectionEndpoint != null && _connectionEndpoint.getLocalState() != EndpointState.UNINITIALIZED))) { Open open = new Open(); if (_connectionEndpoint != null) { String cid = _connectionEndpoint.getLocalContainerId(); open.setContainerId(cid == null ? "" : cid); open.setHostname(_connectionEndpoint.getHostname()); open.setDesiredCapabilities(_connectionEndpoint.getDesiredCapabilities()); open.setOfferedCapabilities(_connectionEndpoint.getOfferedCapabilities()); open.setProperties(_connectionEndpoint.getProperties()); } else { open.setContainerId(""); } if (_maxFrameSize > 0) { open.setMaxFrameSize(UnsignedInteger.valueOf(_maxFrameSize)); } if (_channelMax > 0) { open.setChannelMax(UnsignedShort.valueOf((short) _channelMax)); } // as per the recommendation in the spec, advertise half our // actual timeout to the remote if (_localIdleTimeout > 0) { open.setIdleTimeOut(new UnsignedInteger(_localIdleTimeout / 2)); } _isOpenSent = true; writeFrame(0, open, null, null); } }
Example #15
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 4 votes |
@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 #16
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 #17
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 4 votes |
@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 #18
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 4 votes |
@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 #19
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 4 votes |
/** * 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 testNoDispositionUpdatesAfterSettlementProceessedSender() { 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); 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 #20
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 #21
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 4 votes |
/** * 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 #22
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 #23
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 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 #24
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 4 votes |
@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 #25
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 4 votes |
@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 #26
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 4 votes |
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 #27
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 #28
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 #29
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 #30
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 4 votes |
/** * 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()); }