use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class SessionTest method tryReadSessionRemoteProperties.
private void tryReadSessionRemoteProperties(boolean beginResponse) throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin();
peer.start();
URI remoteURI = peer.getServerURI();
LOG.info("Connect test started, peer listening on: {}", remoteURI);
Client container = Client.create();
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
SessionOptions options = new SessionOptions().openTimeout(120, TimeUnit.MILLISECONDS);
Session session = connection.openSession(options);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
Map<String, Object> expectedProperties = new HashMap<>();
expectedProperties.put("TEST", "test-property");
if (beginResponse) {
peer.expectEnd().respond();
peer.respondToLastBegin().withProperties(expectedProperties).later(10);
} else {
peer.expectEnd();
}
if (beginResponse) {
assertNotNull(session.properties(), "Remote should have responded with a remote properties value");
assertEquals(expectedProperties, session.properties());
} else {
try {
session.properties();
fail("Should failed to get remote state due to no begin response");
} catch (ClientException ex) {
LOG.debug("Caught expected exception from blocking call", ex);
}
}
try {
session.closeAsync().get();
} catch (ExecutionException ex) {
LOG.debug("Caught unexpected exception from close call", ex);
fail("Should not fail to close when connection not closed and end was sent");
}
peer.expectClose().respond();
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class SessionTest method tryReadSessionRemoteOfferedCapabilities.
private void tryReadSessionRemoteOfferedCapabilities(boolean beginResponse) throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin();
peer.start();
URI remoteURI = peer.getServerURI();
LOG.info("Connect test started, peer listening on: {}", remoteURI);
Client container = Client.create();
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
connection.openFuture().get();
SessionOptions options = new SessionOptions().openTimeout(125);
Session session = connection.openSession(options);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
if (beginResponse) {
peer.expectEnd().respond();
peer.respondToLastBegin().withOfferedCapabilities("transactions").later(10);
} else {
peer.expectEnd();
}
if (beginResponse) {
assertNotNull(session.offeredCapabilities(), "Remote should have responded with a remote offered Capabilities value");
assertEquals(1, session.offeredCapabilities().length);
assertEquals("transactions", session.offeredCapabilities()[0]);
} else {
try {
session.offeredCapabilities();
fail("Should failed to get remote state due to no begin response");
} catch (ClientException ex) {
LOG.debug("Caught expected exception from blocking call", ex);
}
}
try {
session.closeAsync().get();
} catch (ExecutionException ex) {
LOG.debug("Caught unexpected exception from close call", ex);
fail("Should not fail to close when connection not closed and end was sent");
}
peer.expectClose().respond();
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class SessionTest method doTestSessionCloseGetsResponseWithErrorThrows.
protected void doTestSessionCloseGetsResponseWithErrorThrows(boolean timeout) throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectEnd().respond().withErrorCondition(AmqpError.INTERNAL_ERROR.toString(), "Something odd happened.");
peer.expectClose().respond();
peer.start();
URI remoteURI = peer.getServerURI();
LOG.info("Test started, peer listening on: {}", remoteURI);
Client container = Client.create();
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
Session session = connection.openSession().openFuture().get();
if (timeout) {
// Should close normally and not throw error as we initiated the close.
session.closeAsync().get(10, TimeUnit.SECONDS);
} else {
// Should close normally and not throw error as we initiated the close.
session.closeAsync().get();
}
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class SessionTest method tryReadSessionRemoteDesiredCapabilities.
private void tryReadSessionRemoteDesiredCapabilities(boolean beginResponse) throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin();
peer.start();
URI remoteURI = peer.getServerURI();
LOG.info("Connect test started, peer listening on: {}", remoteURI);
Client container = Client.create();
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
SessionOptions options = new SessionOptions().openTimeout(125);
Session session = connection.openSession(options);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
if (beginResponse) {
peer.expectEnd().respond();
peer.respondToLastBegin().withDesiredCapabilities("Error-Free").later(10);
} else {
peer.expectEnd();
}
if (beginResponse) {
assertNotNull(session.desiredCapabilities(), "Remote should have responded with a remote desired Capabilities value");
assertEquals(1, session.desiredCapabilities().length);
assertEquals("Error-Free", session.desiredCapabilities()[0]);
} else {
try {
session.desiredCapabilities();
fail("Should failed to get remote state due to no begin response");
} catch (ClientException ex) {
LOG.debug("Caught expected exception from blocking call", ex);
}
}
try {
session.closeAsync().get();
} catch (ExecutionException ex) {
LOG.debug("Caught unexpected exception from close call", ex);
fail("Should not fail to close when connection not closed and end sent");
}
peer.expectClose().respond();
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class SessionTest method doTestCloseWithErrorCondition.
private void doTestCloseWithErrorCondition(boolean sync) throws Exception {
final String condition = "amqp:precondition-failed";
final String description = "something bad happened.";
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectEnd().withError(condition, description).respond();
peer.expectClose().respond();
peer.start();
URI remoteURI = peer.getServerURI();
LOG.info("Test started, peer listening on: {}", remoteURI);
Client container = Client.create();
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
Session session = connection.openSession();
session.openFuture().get();
assertEquals(session.client(), container);
if (sync) {
session.close(ErrorCondition.create(condition, description, null));
} else {
session.closeAsync(ErrorCondition.create(condition, description, null));
}
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
Aggregations