use of org.apache.qpid.protonj2.client.exceptions.ClientUnsupportedOperationException in project qpid-protonj2 by apache.
the class SenderTest method testCreateAnonymousSenderWhenRemoteDoesNotOfferSupportForIt.
@Test
public void testCreateAnonymousSenderWhenRemoteDoesNotOfferSupportForIt() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().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().openFuture().get();
try {
session.openAnonymousSender();
fail("Should not be able to open an anonymous sender when remote does not offer anonymous relay");
} catch (ClientUnsupportedOperationException unsupported) {
LOG.info("Caught expected error: ", unsupported);
}
connection.closeAsync();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of org.apache.qpid.protonj2.client.exceptions.ClientUnsupportedOperationException in project qpid-protonj2 by apache.
the class ConnectionTest method doTestOpenAnonymousSenderFailsWhenAnonymousRelayNotAdvertisedByRemote.
private void doTestOpenAnonymousSenderFailsWhenAnonymousRelayNotAdvertisedByRemote(boolean openWait) throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().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());
// Ensures that the Begin arrives regard of a race on open without anonymous relay support
connection.defaultSession();
if (openWait) {
connection.openFuture().get();
}
try {
connection.openAnonymousSender().openFuture().get();
fail("Open of Sender should fail as remote did not advertise anonymous relay support: ");
} catch (ClientUnsupportedOperationException ex) {
} catch (ExecutionException ex) {
assertTrue(ex.getCause() instanceof ClientUnsupportedOperationException);
}
connection.close();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of org.apache.qpid.protonj2.client.exceptions.ClientUnsupportedOperationException in project qpid-protonj2 by apache.
the class ConnectionTest method testCreateDefaultSenderFailsOnConnectionWithoutSupportForAnonymousRelay.
@Test
public void testCreateDefaultSenderFailsOnConnectionWithoutSupportForAnonymousRelay() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer(testServerOptions())) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectClose().respond();
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(), connectionOptions()).openFuture().get();
try {
connection.defaultSender();
fail("Should not be able to get the default sender when remote does not offer anonymous relay");
} catch (ClientUnsupportedOperationException unsupported) {
LOG.info("Caught expected error: ", unsupported);
}
connection.close();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of org.apache.qpid.protonj2.client.exceptions.ClientUnsupportedOperationException in project qpid-protonj2 by apache.
the class ConnectionTest method doTestConnectionLevelSendFailsWhenAnonymousRelayNotAdvertisedByRemote.
private void doTestConnectionLevelSendFailsWhenAnonymousRelayNotAdvertisedByRemote(boolean openWait) throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().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());
// Ensures that the Begin arrives regard of a race on open without anonymous relay support
connection.defaultSession();
if (openWait) {
connection.openFuture().get();
}
try {
connection.send(Message.create("Hello World"));
fail("Open of Sender should fail as remote did not advertise anonymous relay support: ");
} catch (ClientUnsupportedOperationException ex) {
}
connection.close();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of org.apache.qpid.protonj2.client.exceptions.ClientUnsupportedOperationException in project qpid-protonj2 by apache.
the class StreamSenderTest method testCannotAssignAnOutputStreamToTheMessageBody.
@Test
public void testCannotAssignAnOutputStreamToTheMessageBody() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
// Hidden session for stream sender
peer.expectBegin().respond();
peer.expectAttach().ofSender().respond();
peer.remoteFlow().withLinkCredit(10).queue();
peer.expectDetach().respond();
peer.expectEnd().respond();
peer.expectClose().respond();
peer.start();
URI remoteURI = peer.getServerURI();
LOG.info("Sender test started, peer listening on: {}", remoteURI);
Client container = Client.create();
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort()).openFuture().get();
StreamSender sender = connection.openStreamSender("test-qos").openFuture().get();
StreamSenderMessage message = sender.beginMessage();
try {
message.body(new ByteArrayOutputStream());
fail("Should not be able assign an output stream to the message body");
} catch (ClientUnsupportedOperationException ex) {
// Expected
}
message.abort();
assertThrows(ClientIllegalStateException.class, () -> message.complete());
sender.closeAsync().get(10, TimeUnit.SECONDS);
connection.closeAsync().get(10, TimeUnit.SECONDS);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
Aggregations