use of com.swiftmq.amqp.v100.client.Connection in project qpid-protonj2 by apache.
the class SaslConnectionTest method testSaslExternalConnection.
@Test
public void testSaslExternalConnection() throws Exception {
ProtonTestServerOptions serverOptions = serverOptions();
serverOptions.setKeyStoreLocation(BROKER_JKS_KEYSTORE);
serverOptions.setKeyStorePassword(PASSWORD);
serverOptions.setVerifyHost(false);
serverOptions.setTrustStoreLocation(BROKER_JKS_TRUSTSTORE);
serverOptions.setTrustStorePassword(PASSWORD);
serverOptions.setNeedClientAuth(true);
serverOptions.setSecure(true);
try (ProtonTestServer peer = new ProtonTestServer(serverOptions)) {
peer.expectSaslExternalConnect();
peer.expectOpen().respond();
peer.expectClose().respond();
peer.start();
URI remoteURI = peer.getServerURI();
ConnectionOptions clientOptions = connectionOptions();
clientOptions.sslOptions().sslEnabled(true).keyStoreLocation(CLIENT_JKS_KEYSTORE).keyStorePassword(PASSWORD).trustStoreLocation(CLIENT_JKS_TRUSTSTORE).trustStorePassword(PASSWORD);
Client container = Client.create();
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort(), clientOptions);
connection.openFuture().get(10, TimeUnit.SECONDS);
assertTrue(peer.hasSecureConnection());
assertTrue(peer.isConnectionVerified());
connection.closeAsync().get(10, TimeUnit.SECONDS);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of com.swiftmq.amqp.v100.client.Connection in project qpid-protonj2 by apache.
the class SenderTest method testRemotelyCloseSenderLinkWithRedirect.
@Test
public void testRemotelyCloseSenderLinkWithRedirect() throws Exception {
final String redirectVhost = "vhost";
final String redirectNetworkHost = "localhost";
final String redirectAddress = "redirect-queue";
final int redirectPort = 5677;
final String redirectScheme = "wss";
final String redirectPath = "/websockets";
// Tell the test peer to close the connection when executing its last handler
final Map<String, Object> errorInfo = new HashMap<>();
errorInfo.put(ClientConstants.OPEN_HOSTNAME.toString(), redirectVhost);
errorInfo.put(ClientConstants.NETWORK_HOST.toString(), redirectNetworkHost);
errorInfo.put(ClientConstants.PORT.toString(), redirectPort);
errorInfo.put(ClientConstants.SCHEME.toString(), redirectScheme);
errorInfo.put(ClientConstants.PATH.toString(), redirectPath);
errorInfo.put(ClientConstants.ADDRESS.toString(), redirectAddress);
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender().respond().withNullTarget();
peer.remoteDetach().withClosed(true).withErrorCondition(LinkError.REDIRECT.toString(), "Not accepting links here", errorInfo).queue();
peer.expectDetach();
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();
Sender sender = session.openSender("test-queue");
try {
sender.openFuture().get();
fail("Should not be able to create sender since the remote is redirecting.");
} catch (Exception ex) {
LOG.debug("Received expected exception from sender open: {}", ex.getMessage());
Throwable cause = ex.getCause();
assertTrue(cause instanceof ClientLinkRedirectedException);
ClientLinkRedirectedException linkRedirect = (ClientLinkRedirectedException) ex.getCause();
assertEquals(redirectVhost, linkRedirect.getHostname());
assertEquals(redirectNetworkHost, linkRedirect.getNetworkHost());
assertEquals(redirectPort, linkRedirect.getPort());
assertEquals(redirectScheme, linkRedirect.getScheme());
assertEquals(redirectPath, linkRedirect.getPath());
assertEquals(redirectAddress, linkRedirect.getAddress());
URI redirect = linkRedirect.getRedirectionURI();
assertEquals(redirectNetworkHost, redirect.getHost());
assertEquals(redirectPort, redirect.getPort());
assertEquals(redirectScheme, redirect.getScheme());
assertEquals(redirectPath, redirect.getPath());
}
connection.close();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of com.swiftmq.amqp.v100.client.Connection in project qpid-protonj2 by apache.
the class SenderTest method testAutoFlushDuringWriteThatExceedConfiguredBufferLimitSessionCreditLimitOnTransfer.
@Test
void testAutoFlushDuringWriteThatExceedConfiguredBufferLimitSessionCreditLimitOnTransfer() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().withNextOutgoingId(0).respond();
peer.expectAttach().ofSender().respond();
peer.start();
URI remoteURI = peer.getServerURI();
LOG.info("Test started, peer listening on: {}", remoteURI);
Client container = Client.create();
ConnectionOptions options = new ConnectionOptions().maxFrameSize(1024);
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort(), options);
Sender sender = connection.openSender("test-queue");
final byte[] payload = new byte[4800];
Arrays.fill(payload, (byte) 1);
final AtomicBoolean sendFailed = new AtomicBoolean();
ForkJoinPool.commonPool().execute(() -> {
try {
sender.send(Message.create(payload));
} catch (Exception e) {
LOG.info("send failed with error: ", e);
sendFailed.set(true);
}
});
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.expectTransfer().withNonNullPayload().withMore(true).withFrameSize(1024);
peer.remoteFlow().withIncomingWindow(1).withNextIncomingId(1).withLinkCredit(10).queue();
peer.expectTransfer().withNonNullPayload().withMore(true).withFrameSize(1024);
peer.remoteFlow().withIncomingWindow(1).withNextIncomingId(2).withLinkCredit(10).queue();
peer.expectTransfer().withNonNullPayload().withMore(true).withFrameSize(1024);
peer.remoteFlow().withIncomingWindow(1).withNextIncomingId(3).withLinkCredit(10).queue();
peer.expectTransfer().withNonNullPayload().withMore(true).withFrameSize(1024);
peer.remoteFlow().withIncomingWindow(1).withNextIncomingId(4).withLinkCredit(10).queue();
peer.expectTransfer().withNonNullPayload().withMore(false).accept();
// Grant the credit to start meeting the above expectations
peer.remoteFlow().withIncomingWindow(1).withNextIncomingId(0).withLinkCredit(10).now();
peer.waitForScriptToComplete(500, TimeUnit.SECONDS);
peer.expectDetach().respond();
peer.expectClose().respond();
assertFalse(sendFailed.get());
sender.closeAsync().get();
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of com.swiftmq.amqp.v100.client.Connection in project qpid-protonj2 by apache.
the class SenderTest method testAutoFlushDuringWriteWithRollingIncomingWindowUpdates.
@Test
void testAutoFlushDuringWriteWithRollingIncomingWindowUpdates() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().withNextOutgoingId(0).respond();
peer.expectAttach().ofSender().respond();
peer.start();
URI remoteURI = peer.getServerURI();
LOG.info("Test started, peer listening on: {}", remoteURI);
Client container = Client.create();
ConnectionOptions options = new ConnectionOptions().maxFrameSize(1024);
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort(), options);
Sender sender = connection.openSender("test-queue");
final byte[] payload = new byte[4800];
Arrays.fill(payload, (byte) 1);
final AtomicBoolean sendFailed = new AtomicBoolean();
ForkJoinPool.commonPool().execute(() -> {
try {
sender.send(Message.create(payload));
} catch (Exception e) {
LOG.info("send failed with error: ", e);
sendFailed.set(true);
}
});
// Credit should will be refilling as transfers arrive vs being exhausted on each
// incoming transfer and the send awaiting more credit.
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.expectTransfer().withNonNullPayload().withMore(true);
peer.remoteFlow().withIncomingWindow(1).withNextIncomingId(2).withLinkCredit(10).queue();
peer.expectTransfer().withNonNullPayload().withMore(true);
peer.remoteFlow().withIncomingWindow(1).withNextIncomingId(3).withLinkCredit(10).queue();
peer.expectTransfer().withNonNullPayload().withMore(true);
peer.remoteFlow().withIncomingWindow(1).withNextIncomingId(4).withLinkCredit(10).queue();
peer.expectTransfer().withNonNullPayload().withMore(true);
peer.expectTransfer().withNonNullPayload().withMore(false).accept();
// Grant the credit to start meeting the above expectations
peer.remoteFlow().withIncomingWindow(2).withNextIncomingId(0).withLinkCredit(10).now();
peer.waitForScriptToComplete(500, TimeUnit.SECONDS);
peer.expectDetach().respond();
peer.expectClose().respond();
assertFalse(sendFailed.get());
sender.closeAsync().get();
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of com.swiftmq.amqp.v100.client.Connection in project qpid-protonj2 by apache.
the class SenderTest method doTestCloseOrDetachWithErrorCondition.
public void doTestCloseOrDetachWithErrorCondition(boolean close) throws Exception {
final String condition = "amqp:link:detach-forced";
final String description = "something bad happened.";
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender().respond();
peer.expectDetach().withClosed(close).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();
Sender sender = session.openSender("test-sender");
sender.openFuture().get();
if (close) {
sender.closeAsync(ErrorCondition.create(condition, description, null));
} else {
sender.detachAsync(ErrorCondition.create(condition, description, null));
}
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
Aggregations