use of org.apache.qpid.server.protocol.v0_8.transport in project qpid-broker-j by apache.
the class BasicTest method qosBytesPrefetch.
@Test
@SpecificationTest(section = "1.8.3.3", description = "This field specifies the prefetch window size in octets. The server will send a message " + "in advance if it is equal to or smaller in size than the available prefetch size (and " + "also falls into other prefetch limits).")
public void qosBytesPrefetch() throws Exception {
String messageContent1 = String.join("", Collections.nCopies(128, "1"));
String messageContent2 = String.join("", Collections.nCopies(128, "2"));
String messageContent3 = String.join("", Collections.nCopies(256, "3"));
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final Interaction interaction = transport.newInteraction();
String consumerTag = "A";
interaction.negotiateOpen().channel().open().consumeResponse(ChannelOpenOkBody.class).basic().publishExchange("").publishRoutingKey(BrokerAdmin.TEST_QUEUE_NAME).content(messageContent1).publishMessage().basic().content(messageContent2).publishMessage().basic().content(messageContent3).publishMessage().channel().flow(true).consumeResponse(ChannelFlowOkBody.class).basic().qosPrefetchSize(256).qos().consumeResponse(BasicQosOkBody.class).basic().consumeConsumerTag(consumerTag).consumeQueue(BrokerAdmin.TEST_QUEUE_NAME).consume().consumeResponse(BasicConsumeOkBody.class);
BasicDeliverBody delivery1 = interaction.consumeResponse().getLatestResponse(BasicDeliverBody.class);
ContentBody content1 = interaction.consumeResponse(ContentHeaderBody.class).consumeResponse().getLatestResponse(ContentBody.class);
BasicDeliverBody delivery2 = interaction.consumeResponse().getLatestResponse(BasicDeliverBody.class);
ContentBody content2 = interaction.consumeResponse(ContentHeaderBody.class).consumeResponse().getLatestResponse(ContentBody.class);
assertThat(getContent(content1), is(equalTo(messageContent1)));
assertThat(getContent(content2), is(equalTo(messageContent2)));
ensureSync(interaction);
// Ack first. There will be insufficient bytes credit for the third to be sent.
interaction.basic().ackDeliveryTag(delivery1.getDeliveryTag()).ack();
ensureSync(interaction);
// Ack second. Now there will be sufficient bytes credit so expect the third.
interaction.basic().ackDeliveryTag(delivery2.getDeliveryTag()).ack();
BasicDeliverBody delivery3 = interaction.consumeResponse().getLatestResponse(BasicDeliverBody.class);
ContentBody content3 = interaction.consumeResponse(ContentHeaderBody.class).consumeResponse().getLatestResponse(ContentBody.class);
assertThat(getContent(content3), is(equalTo(messageContent3)));
interaction.basic().ackDeliveryTag(delivery3.getDeliveryTag()).ack().channel().close().consumeResponse(ChannelCloseOkBody.class);
}
}
use of org.apache.qpid.server.protocol.v0_8.transport in project qpid-broker-j by apache.
the class BasicTest method ackWithInvalidDeliveryTag.
@Test
@SpecificationTest(section = "1.8.3.13", description = "The server MUST validate that a non-zero delivery-tag refers to a delivered message," + " and raise a channel exception if this is not the case. On a transacted channel," + " this check MUST be done immediately and not delayed until a Tx.Commit. Specifically," + " a client MUST not acknowledge the same message more than once." + "" + "Note current broker behaviour is spec incompliant: broker ignores not valid delivery tags")
public void ackWithInvalidDeliveryTag() throws Exception {
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final Interaction interaction = transport.newInteraction();
String consumerTag = "A";
final long deliveryTag = 12345L;
String queueName = BrokerAdmin.TEST_QUEUE_NAME;
interaction.negotiateOpen().channel().open().consumeResponse(ChannelOpenOkBody.class).basic().qosPrefetchCount(1).qos().consumeResponse(BasicQosOkBody.class).basic().consumeConsumerTag(consumerTag).consumeQueue(queueName).consume().consumeResponse(BasicConsumeOkBody.class).channel().flow(true).consumeResponse(ChannelFlowOkBody.class).basic().ackDeliveryTag(deliveryTag).ack().channel().close().consumeResponse(ChannelCloseOkBody.class);
}
}
use of org.apache.qpid.server.protocol.v0_8.transport in project qpid-broker-j by apache.
the class BasicTest method getNoAck.
@Test
@SpecificationTest(section = "1.8.3.10", description = "direct access to a queue")
public void getNoAck() throws Exception {
String messageContent = "message";
getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, messageContent);
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final Interaction interaction = transport.newInteraction();
interaction.negotiateOpen().channel().open().consumeResponse(ChannelOpenOkBody.class).basic().getQueueName(BrokerAdmin.TEST_QUEUE_NAME).getNoAck(true).get().consumeResponse(BasicGetOkBody.class);
ContentBody content = interaction.consumeResponse(ContentHeaderBody.class).consumeResponse().getLatestResponse(ContentBody.class);
String receivedContent = getContent(content);
assertThat(receivedContent, is(equalTo(messageContent)));
interaction.channel().close().consumeResponse(ChannelCloseOkBody.class);
assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(0)));
}
}
use of org.apache.qpid.server.protocol.v0_8.transport in project qpid-broker-j by apache.
the class BasicTest method pollingUsingFlow.
/**
* The Qpid JMS AMQP 0-x client is capable of polling fors message. It does this using a combination of
* basic.qos (count one) and regulating the flow using channel.flow. This test supports this use-case.
*/
@Test
public void pollingUsingFlow() throws Exception {
getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, "A", "B", "C");
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final Interaction interaction = transport.newInteraction();
String consumerTag = "A";
interaction.negotiateOpen().channel().open().consumeResponse(ChannelOpenOkBody.class).basic().qosPrefetchCount(1).qos().consumeResponse(BasicQosOkBody.class).channel().flow(false).consumeResponse(ChannelFlowOkBody.class).basic().consumeConsumerTag(consumerTag).consumeQueue(BrokerAdmin.TEST_QUEUE_NAME).consume().consumeResponse(BasicConsumeOkBody.class);
ensureSync(interaction);
interaction.channel().flow(true).consumeResponse(ChannelFlowOkBody.class);
long deliveryTagA = receiveDeliveryHeaderAndBody(interaction, "A");
interaction.channel().flow(false).consumeResponse(ChannelFlowOkBody.class).basic().ackDeliveryTag(deliveryTagA).ack();
ensureSync(interaction);
interaction.channel().flow(true).consumeResponse(ChannelFlowOkBody.class);
long deliveryTagB = receiveDeliveryHeaderAndBody(interaction, "B");
interaction.channel().flow(false).consumeResponse(ChannelFlowOkBody.class).basic().ackDeliveryTag(deliveryTagB).ack().channel().close().consumeResponse(ChannelCloseOkBody.class);
assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(1)));
}
}
use of org.apache.qpid.server.protocol.v0_8.transport in project qpid-broker-j by apache.
the class ConnectionTest method heartbeating.
@Test
@SpecificationTest(section = "4.2.7", description = "Heartbeat frames tell the recipient that the sender is still alive. The rate and timing of" + " heartbeat frames is negotiated during connection tuning.")
public void heartbeating() throws Exception {
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final Interaction interaction = transport.newInteraction();
ConnectionTuneBody response = interaction.authenticateConnection().getLatestResponse(ConnectionTuneBody.class);
final Long heartbeatPeriod = 1L;
interaction.connection().tuneOkChannelMax(response.getChannelMax()).tuneOkFrameMax(response.getFrameMax()).tuneOkHeartbeat(heartbeatPeriod.intValue()).tuneOk();
final long startTime = System.currentTimeMillis();
interaction.connection().open().consumeResponse(ConnectionOpenOkBody.class).consumeResponse().getLatestResponse(HeartbeatBody.class);
final long actualHeartbeatDelay = System.currentTimeMillis() - startTime;
// Includes wiggle room to allow for slow boxes.
final long maximumExpectedHeartbeatDelay = heartbeatPeriod * 2 * 2;
assertThat("Heartbeat not received within expected time frame", actualHeartbeatDelay / 1000, is(both(greaterThanOrEqualTo(heartbeatPeriod)).and(lessThanOrEqualTo(maximumExpectedHeartbeatDelay))));
interaction.sendPerformative(new HeartbeatBody());
interaction.consumeResponse(HeartbeatBody.class).sendPerformative(new HeartbeatBody());
}
}
Aggregations