You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by or...@apache.org on 2019/08/21 16:35:55 UTC
[qpid-broker-j] 13/21: QPID-8350: [Tests][AMQP 1.0] Improve open
tests
This is an automated email from the ASF dual-hosted git repository.
orudyy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-broker-j.git
commit d67424a5171188295023b110c29b0bb9d0cf8f48
Author: Alex Rudyy <or...@apache.org>
AuthorDate: Mon Aug 19 14:31:09 2019 +0100
QPID-8350: [Tests][AMQP 1.0] Improve open tests
---
.../v1_0/transport/connection/OpenTest.java | 56 ++++++++++++----------
1 file changed, 32 insertions(+), 24 deletions(-)
diff --git a/systests/protocol-tests-amqp-1-0/src/test/java/org/apache/qpid/tests/protocol/v1_0/transport/connection/OpenTest.java b/systests/protocol-tests-amqp-1-0/src/test/java/org/apache/qpid/tests/protocol/v1_0/transport/connection/OpenTest.java
index a744cb1..17fdab0 100644
--- a/systests/protocol-tests-amqp-1-0/src/test/java/org/apache/qpid/tests/protocol/v1_0/transport/connection/OpenTest.java
+++ b/systests/protocol-tests-amqp-1-0/src/test/java/org/apache/qpid/tests/protocol/v1_0/transport/connection/OpenTest.java
@@ -20,13 +20,13 @@
package org.apache.qpid.tests.protocol.v1_0.transport.connection;
+import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.CoreMatchers.both;
-import static org.hamcrest.CoreMatchers.either;
+import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.hamcrest.Matchers.notNullValue;
@@ -39,6 +39,7 @@ import org.apache.qpid.server.protocol.v1_0.type.UnsignedShort;
import org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError;
import org.apache.qpid.server.protocol.v1_0.type.transport.Close;
import org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError;
+import org.apache.qpid.server.protocol.v1_0.type.transport.Error;
import org.apache.qpid.server.protocol.v1_0.type.transport.Open;
import org.apache.qpid.tests.utils.BrokerAdmin;
import org.apache.qpid.tests.protocol.v1_0.FrameTransport;
@@ -46,6 +47,7 @@ import org.apache.qpid.tests.protocol.v1_0.Interaction;
import org.apache.qpid.tests.protocol.v1_0.EmptyResponse;
import org.apache.qpid.tests.utils.BrokerAdminUsingTestBase;
import org.apache.qpid.tests.protocol.SpecificationTest;
+import org.apache.qpid.tests.utils.BrokerSpecific;
public class OpenTest extends BrokerAdminUsingTestBase
@@ -66,8 +68,14 @@ public class OpenTest extends BrokerAdminUsingTestBase
assertThat(responseOpen.getContainerId(), is(notNullValue()));
Close responseClose = interaction.consumeResponse().getLatestResponse(Close.class);
- assertThat(responseClose.getError(), is(notNullValue()));
- assertThat(responseClose.getError().getCondition(), equalTo(AmqpError.DECODE_ERROR));
+
+ // 2.7.9: If set, this field indicates that the connection is being closed due to an error condition.
+ // The value of the field SHOULD contain details on the cause of the error.
+ Error error = responseClose.getError();
+ if (error != null)
+ {
+ assertThat(error.getCondition(), equalTo(AmqpError.DECODE_ERROR));
+ }
}
}
@@ -88,9 +96,9 @@ public class OpenTest extends BrokerAdminUsingTestBase
.getLatestResponse(Open.class);
assertThat(responseOpen.getContainerId(), is(notNullValue()));
assertThat(responseOpen.getMaxFrameSize().longValue(),
- is(both(greaterThanOrEqualTo(0L)).and(lessThan(UnsignedInteger.MAX_VALUE.longValue()))));
+ is(both(greaterThanOrEqualTo(0L)).and(lessThanOrEqualTo(UnsignedInteger.MAX_VALUE.longValue()))));
assertThat(responseOpen.getChannelMax().intValue(),
- is(both(greaterThanOrEqualTo(0)).and(lessThan(UnsignedShort.MAX_VALUE.intValue()))));
+ is(both(greaterThanOrEqualTo(0)).and(lessThanOrEqualTo(UnsignedShort.MAX_VALUE.intValue()))));
interaction.doCloseConnection();
}
@@ -129,28 +137,21 @@ public class OpenTest extends BrokerAdminUsingTestBase
.open().consumeResponse()
.getLatestResponse(Open.class);
- final int peerIdleTimeOut = responseOpen.getIdleTimeOut().intValue();
- assertThat(peerIdleTimeOut, is(either(equalTo(0)).or(greaterThanOrEqualTo(idleTimeOut))));
+ final UnsignedInteger peerIdleTimeOut = responseOpen.getIdleTimeOut();
+ assertThat(peerIdleTimeOut, is(anyOf(nullValue(), greaterThanOrEqualTo(UnsignedInteger.ZERO))));
- final long startTime = System.currentTimeMillis();
+ final int timeout = peerIdleTimeOut == null || peerIdleTimeOut.intValue() == 0
+ ? idleTimeOut
+ : peerIdleTimeOut.intValue();
+ Thread.sleep(timeout);
interaction.consumeResponse(EmptyResponse.class);
- final long actualHeartbeatDelay = System.currentTimeMillis() - startTime;
- assertThat("Empty frame not received within expected time frame",
- ((int)actualHeartbeatDelay / 1000),
- is(both(greaterThanOrEqualTo(peerIdleTimeOut)).and(lessThanOrEqualTo(peerIdleTimeOut * 2))));
-
- if (peerIdleTimeOut > 0)
- {
- interaction.emptyFrame();
- }
-
- interaction.doCloseConnection();
}
}
@Test
@SpecificationTest(section = "2.4.1",
- description = "The open frame can only be sent on channel 0. §2.7.1: A peer that receives a channel number outside the supported range MUST close the connection with the framing-error error-code.")
+ description = "The open frame can only be sent on channel 0. §2.7.1: A peer that receives a channel number"
+ + " outside the supported range MUST close the connection with the framing-error error-code.")
public void failOpenOnChannelNotZero() throws Exception
{
final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
@@ -164,14 +165,21 @@ public class OpenTest extends BrokerAdminUsingTestBase
.getLatestResponse(Open.class);
assertThat(responseOpen.getContainerId(), is(notNullValue()));
- Close responseClose = interaction.consumeResponse().getLatestResponse(Close.class);
- assertThat(responseClose.getError(), is(notNullValue()));
- assertThat(responseClose.getError().getCondition(), equalTo(ConnectionError.FRAMING_ERROR));
+ Close responseClose = interaction.consumeResponse(Close.class).getLatestResponse(Close.class);
+
+ // 2.7.9: If set, this field indicates that the connection is being closed due to an error condition.
+ // The value of the field SHOULD contain details on the cause of the error.
+ Error error = responseClose.getError();
+ if (error != null)
+ {
+ assertThat(error.getCondition(), equalTo(ConnectionError.FRAMING_ERROR));
+ }
}
}
@Test
@SpecificationTest(section = "2.7.1", description = "The name of the host (either fully qualified or relative) to which the sending peer is connecting")
+ @BrokerSpecific(kind = BrokerAdmin.KIND_BROKER_J)
public void failOpenOnNonExistingHostname() throws Exception
{
final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org