use of com.swiftmq.amqp.v100.client.Connection in project qpid-protonj2 by apache.
the class SslConnectionTest method doTestCreateSslConnectionWithServerSendingPreemptiveData.
private void doTestCreateSslConnectionWithServerSendingPreemptiveData(boolean openSSL) throws Exception {
ProtonTestServerOptions serverOptions = serverOptions();
serverOptions.setSecure(true);
serverOptions.setKeyStoreLocation(BROKER_JKS_KEYSTORE);
serverOptions.setKeyStorePassword(PASSWORD);
serverOptions.setVerifyHost(false);
try (ProtonTestServer peer = new ProtonTestServer(serverOptions)) {
peer.remoteHeader(AMQPHeader.getSASLHeader().toArray()).queue();
peer.expectSASLHeader();
peer.remoteSaslMechanisms().withMechanisms("ANONYMOUS").queue();
peer.expectSaslInit().withMechanism("ANONYMOUS");
peer.remoteSaslOutcome().withCode(SaslCode.OK.byteValue()).queue();
peer.expectAMQPHeader().respondWithAMQPHeader();
peer.expectOpen().respond();
peer.expectClose().respond();
peer.start();
URI remoteURI = peer.getServerURI();
ConnectionOptions clientOptions = connectionOptions();
clientOptions.sslOptions().trustStoreLocation(CLIENT_JKS_TRUSTSTORE).trustStorePassword(PASSWORD).allowNativeSSL(openSSL);
Client container = Client.create();
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort(), clientOptions);
connection.openFuture().get(10, TimeUnit.SECONDS);
assertTrue(peer.hasSecureConnection());
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 SslConnectionTest method testCreateAndCloseSslConnection.
private void testCreateAndCloseSslConnection(boolean openSSL) throws Exception {
ProtonTestServerOptions serverOptions = serverOptions();
serverOptions.setSecure(true);
serverOptions.setKeyStoreLocation(BROKER_JKS_KEYSTORE);
serverOptions.setKeyStorePassword(PASSWORD);
serverOptions.setVerifyHost(false);
try (ProtonTestServer peer = new ProtonTestServer(serverOptions)) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectClose().respond();
peer.start();
URI remoteURI = peer.getServerURI();
ConnectionOptions clientOptions = connectionOptions();
clientOptions.sslOptions().trustStoreLocation(CLIENT_JKS_TRUSTSTORE).trustStorePassword(PASSWORD).allowNativeSSL(openSSL);
Client container = Client.create();
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort(), clientOptions);
connection.openFuture().get(10, TimeUnit.SECONDS);
assertTrue(peer.hasSecureConnection());
assertFalse(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 StreamReceiverTest method doTestCreateReceiverAndCloseOrDetachWithErrorSync.
private void doTestCreateReceiverAndCloseOrDetachWithErrorSync(boolean close) throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofReceiver().respond();
peer.expectFlow();
peer.expectDetach().withError("amqp-resource-deleted", "an error message").withClosed(close).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());
StreamReceiver receiver = connection.openStreamReceiver("test-queue");
receiver.openFuture().get(10, TimeUnit.SECONDS);
if (close) {
receiver.close(ErrorCondition.create("amqp-resource-deleted", "an error message", null));
} else {
receiver.detach(ErrorCondition.create("amqp-resource-deleted", "an error message", null));
}
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 StreamReceiverTest method doTestCreateReceiverAndCloseOrDetachLink.
private void doTestCreateReceiverAndCloseOrDetachLink(boolean close) throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofReceiver().respond();
peer.expectFlow().withLinkCredit(10);
peer.expectDetach().withClosed(close).respond();
peer.expectEnd().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());
StreamReceiver receiver = connection.openStreamReceiver("test-queue");
receiver.openFuture().get(10, TimeUnit.SECONDS);
assertSame(container, receiver.client());
assertSame(connection, receiver.connection());
if (close) {
receiver.closeAsync().get(10, TimeUnit.SECONDS);
} else {
receiver.detachAsync().get(10, TimeUnit.SECONDS);
}
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 StreamReceiverTest method testStreamDeliveryRawInputStreamReadBytesSignalsEOFOnEmptyCompleteTransfer.
@Test
public void testStreamDeliveryRawInputStreamReadBytesSignalsEOFOnEmptyCompleteTransfer() throws Exception {
final byte[] payload1 = createEncodedMessage(new Data(new byte[] { 0, 1, 2, 3, 4, 5 }));
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().withRole(Role.RECEIVER.getValue()).respond();
peer.expectFlow();
peer.remoteTransfer().withHandle(0).withDeliveryId(0).withDeliveryTag(new byte[] { 1 }).withMore(true).withMessageFormat(0).withPayload(payload1).queue();
peer.expectDisposition().withState().accepted().withSettled(true);
peer.start();
URI remoteURI = peer.getServerURI();
LOG.info("Test started, peer listening on: {}", remoteURI);
final Client container = Client.create();
final Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
final StreamReceiver receiver = connection.openStreamReceiver("test-queue");
final StreamDelivery delivery = receiver.receive();
assertNotNull(delivery);
assertFalse(delivery.completed());
assertFalse(delivery.aborted());
final InputStream stream = delivery.rawInputStream();
assertNotNull(stream);
assertEquals(payload1.length, stream.available());
final byte[] deliveryBytes1 = new byte[payload1.length];
stream.read(deliveryBytes1);
assertArrayEquals(payload1, deliveryBytes1);
assertEquals(0, stream.available());
peer.remoteTransfer().withHandle(0).withDeliveryId(0).withDeliveryTag(new byte[] { 1 }).withMore(false).later(50);
// Should block until more data arrives.
final byte[] deliveryBytes2 = new byte[payload1.length];
assertEquals(-1, stream.read(deliveryBytes2));
assertEquals(0, stream.available());
assertTrue(delivery.completed());
assertFalse(delivery.aborted());
stream.close();
peer.expectDetach().respond();
peer.expectEnd().respond();
peer.expectClose().respond();
receiver.close();
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
Aggregations