use of org.apache.qpid.server.protocol.v1_0.type.transport.Error in project qpid-broker-j by apache.
the class Session_1_0Test method assertDetachSent.
private void assertDetachSent(final AMQPConnection_1_0 connection, final Session_1_0 session, final ErrorCondition expectedError, final int invocationOffset) {
ArgumentCaptor<FrameBody> frameCapture = ArgumentCaptor.forClass(FrameBody.class);
verify(connection, times(invocationOffset + 1)).sendFrame(eq(session.getChannelId()), frameCapture.capture());
List<FrameBody> sentFrames = frameCapture.getAllValues();
assertTrue("unexpected Frame sent", sentFrames.get(invocationOffset) instanceof Detach);
Detach sentDetach = (Detach) sentFrames.get(invocationOffset);
assertTrue("Unexpected closed state", sentDetach.getClosed());
assertEquals("Closed with unexpected error condition", expectedError, sentDetach.getError().getCondition());
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Error in project qpid-broker-j by apache.
the class ValueHandlerTest method performTest.
private void performTest(final byte type, final byte[] encodedBytes, ValueHandler valueHandler) {
QpidByteBuffer qbb = QpidByteBuffer.wrap(encodedBytes);
try {
valueHandler.parse(qbb);
fail(String.format("AmqpErrorException is expected for %#02x", type));
} catch (AmqpErrorException e) {
assertEquals(String.format("Unexpected error code for %#02x", type), AmqpError.DECODE_ERROR, e.getError().getCondition());
} catch (Exception e) {
fail(String.format("Unexpected exception for %#02x: %s", type, e));
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Error in project qpid-broker-j by apache.
the class FrameHandlerTest method testOversizedFrame.
public void testOversizedFrame() {
ConnectionHandler connectionHandler = mock(ConnectionHandler.class);
when(connectionHandler.getMaxFrameSize()).thenReturn(MAX_FRAME_SIZE);
FrameHandler handler = new FrameHandler(_valueHandler, connectionHandler, true);
QpidByteBuffer body = QpidByteBuffer.allocate(false, MAX_FRAME_SIZE + 8);
// size
body.putInt(body.capacity());
// DOFF
body.put((byte) 2);
// AMQP Frame Type
body.put((byte) 1);
// channel
body.putShort(UnsignedShort.ZERO.shortValue());
body.position(body.capacity());
body.flip();
handler.parse(body);
ArgumentCaptor<Error> errorCaptor = ArgumentCaptor.forClass(Error.class);
verify(connectionHandler).handleError(errorCaptor.capture());
Error error = errorCaptor.getValue();
assertNotNull(error);
assertEquals(ConnectionError.FRAMING_ERROR, error.getCondition());
assertEquals(String.format("specified frame size %s larger than maximum frame header size %s", body.capacity(), MAX_FRAME_SIZE), error.getDescription());
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Error in project qpid-broker-j by apache.
the class ResumeDeliveriesTest method rejectNewDeliveryWhilstUnsettledIncomplete.
@Ignore("QPID-7845")
@Test
@SpecificationTest(section = "2.7.3", description = "If set to true [incomplete-unsettled] indicates that the unsettled map provided is not complete. " + "When the map is incomplete the recipient of the map cannot take the absence of a delivery tag from " + "the map as evidence of settlement. On receipt of an incomplete unsettled map a sending endpoint MUST " + "NOT send any new deliveries (i.e. deliveries where resume is not set to true) to its partner (and " + "a receiving endpoint which sent an incomplete unsettled map MUST detach with an error on " + "receiving a transfer which does not have the resume flag set to true).")
public void rejectNewDeliveryWhilstUnsettledIncomplete() throws Exception {
final String destination = BrokerAdmin.TEST_QUEUE_NAME;
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
interaction.negotiateProtocol().consumeResponse();
// 0. Open connection with small max-frame-size
final Open open = interaction.openMaxFrameSize(UnsignedInteger.valueOf(MIN_MAX_FRAME_SIZE)).open().consumeResponse().getLatestResponse(Open.class);
interaction.begin().consumeResponse(Begin.class);
// 1. attach with ReceiverSettleMode.SECOND
final UnsignedInteger linkHandle1 = UnsignedInteger.ZERO;
interaction.attachHandle(linkHandle1).attachRole(Role.SENDER).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachTargetAddress(destination).attach().consumeResponse(Attach.class).consumeResponse(Flow.class);
// 2. send enough unsettled deliverys to cause incomplete-unsettled to be true
// assume each delivery requires at least 1 byte, therefore max-frame-size deliveries should be enough
interaction.transferHandle(linkHandle1).transferPayloadData(TEST_MESSAGE_CONTENT);
Map<Binary, DeliveryState> localUnsettled = new HashMap<>(open.getMaxFrameSize().intValue());
for (int i = 0; i < open.getMaxFrameSize().intValue(); ++i) {
final Binary deliveryTag = new Binary(String.valueOf(i).getBytes(StandardCharsets.UTF_8));
final Disposition responseDisposition = interaction.transferDeliveryId(UnsignedInteger.valueOf(i)).transferDeliveryTag(deliveryTag).transfer().consumeResponse(Disposition.class).getLatestResponse(Disposition.class);
assertThat(responseDisposition.getRole(), is(Role.RECEIVER));
assertThat(responseDisposition.getSettled(), is(Boolean.FALSE));
localUnsettled.put(deliveryTag, null);
}
// 3. detach the link
interaction.detach().consumeResponse(Detach.class);
// 4. resume the link
final UnsignedInteger linkHandle2 = UnsignedInteger.ONE;
final Binary sampleLocalUnsettled = localUnsettled.keySet().iterator().next();
Map<Binary, DeliveryState> unsettled = Collections.singletonMap(sampleLocalUnsettled, localUnsettled.get(sampleLocalUnsettled));
final Response<?> latestResponse = interaction.attachHandle(linkHandle2).attachUnsettled(unsettled).attachIncompleteUnsettled(true).attach().consumeResponse(End.class, Attach.class).getLatestResponse();
assumeThat(latestResponse.getBody(), is(instanceOf(Attach.class)));
// 5. ensure attach has incomplete-unsettled
final Attach responseAttach = (Attach) latestResponse.getBody();
assertThat(responseAttach.getIncompleteUnsettled(), is(equalTo(true)));
// 6. send new transfer
final Binary newDeliveryTag = new Binary("newTransfer".getBytes(StandardCharsets.UTF_8));
final Detach detachWithError = interaction.transferHandle(linkHandle2).transferDeliveryId(UnsignedInteger.ONE).transferDeliveryTag(newDeliveryTag).transfer().consumeResponse().getLatestResponse(Detach.class);
assertThat(detachWithError.getError(), is(notNullValue()));
final Error detachError = detachWithError.getError();
assertThat(detachError.getCondition(), is(equalTo(AmqpError.ILLEGAL_STATE)));
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Error in project qpid-broker-j by apache.
the class BeginTest method emptyBegin.
@Test
@SpecificationTest(section = "1.3.4", description = "Begin without mandatory fields should result in a decoding error.")
public void emptyBegin() throws Exception {
final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
try (FrameTransport transport = new FrameTransport(addr).connect()) {
Close responseClose = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).beginNextOutgoingId(null).beginIncomingWindow(null).beginOutgoingWindow(null).begin().consumeResponse().getLatestResponse(Close.class);
assertThat(responseClose.getError(), is(notNullValue()));
assertThat(responseClose.getError().getCondition(), equalTo(AmqpError.DECODE_ERROR));
}
}
Aggregations