use of io.vertx.proton.ProtonClientOptions in project hono by eclipse.
the class StandaloneEventApiTest method prepareHonoServer.
/**
* Sets up Hono Messaging service.
*
* @param ctx The test context.
*/
@BeforeClass
public static void prepareHonoServer(final TestContext ctx) {
vertx = Vertx.vertx();
downstreamAdapter = new MessageDiscardingDownstreamAdapter(vertx);
final HonoMessagingConfigProperties configProperties = new HonoMessagingConfigProperties();
configProperties.setInsecurePort(0);
final EventEndpoint eventEndpoint = new EventEndpoint(vertx);
eventEndpoint.setMetrics(mock(MessagingMetrics.class));
eventEndpoint.setEventAdapter(downstreamAdapter);
eventEndpoint.setRegistrationAssertionValidator(assertionHelper);
eventEndpoint.setConfiguration(configProperties);
server = new HonoMessaging();
server.setSaslAuthenticatorFactory(new HonoSaslAuthenticatorFactory(TestSupport.createAuthenticationService(createUser())));
server.setConfig(configProperties);
server.addEndpoint(eventEndpoint);
Future<String> serverTracker = Future.future();
vertx.deployVerticle(server, serverTracker.completer());
serverTracker.compose(s -> {
final ClientConfigProperties clientProps = new ClientConfigProperties();
clientProps.setName("test");
clientProps.setHost(server.getInsecurePortBindAddress());
clientProps.setPort(server.getInsecurePort());
clientProps.setUsername(USER);
clientProps.setPassword(PWD);
client = new HonoClientImpl(vertx, clientProps);
return client.connect(new ProtonClientOptions());
}).setHandler(ctx.asyncAssertSuccess());
}
use of io.vertx.proton.ProtonClientOptions in project hono by eclipse.
the class ClientTestBase method connect.
/**
* Sets up the environment:
* <ol>
* <li>connect to the AMQP messaging network</li>
* <li>connects to the Hono Server</li>
* <li>connects to the Hono Device Registry</li>
* <li>creates a RegistrationClient for TEST_TENANT_ID</li>
* <li>creates a MessageSender for TEST_TENANT_ID</li>
* </ul>
*
* @param ctx The test context
*/
@Before
public void connect(final TestContext ctx) {
final ClientConfigProperties downstreamProps = new ClientConfigProperties();
downstreamProps.setHost(IntegrationTestSupport.DOWNSTREAM_HOST);
downstreamProps.setPort(IntegrationTestSupport.DOWNSTREAM_PORT);
downstreamProps.setPathSeparator(IntegrationTestSupport.PATH_SEPARATOR);
downstreamProps.setUsername(IntegrationTestSupport.RESTRICTED_CONSUMER_NAME);
downstreamProps.setPassword(IntegrationTestSupport.RESTRICTED_CONSUMER_PWD);
downstreamClient = new HonoClientImpl(vertx, ConnectionFactoryBuilder.newBuilder(downstreamProps).vertx(vertx).build(), downstreamProps);
final ClientConfigProperties honoProps = new ClientConfigProperties();
honoProps.setHost(IntegrationTestSupport.HONO_HOST);
honoProps.setPort(IntegrationTestSupport.HONO_PORT);
honoProps.setUsername(IntegrationTestSupport.HONO_USER);
honoProps.setPassword(IntegrationTestSupport.HONO_PWD);
honoClient = new HonoClientImpl(vertx, ConnectionFactoryBuilder.newBuilder(honoProps).vertx(vertx).build(), honoProps);
final ClientConfigProperties registryProps = new ClientConfigProperties();
registryProps.setHost(IntegrationTestSupport.HONO_DEVICEREGISTRY_HOST);
registryProps.setPort(IntegrationTestSupport.HONO_DEVICEREGISTRY_AMQP_PORT);
registryProps.setUsername(IntegrationTestSupport.HONO_USER);
registryProps.setPassword(IntegrationTestSupport.HONO_PWD);
honoDeviceRegistryClient = new HonoClientImpl(vertx, ConnectionFactoryBuilder.newBuilder(registryProps).vertx(vertx).build(), registryProps);
final ProtonClientOptions options = new ProtonClientOptions();
// connect to AMQP messaging network
final Future<HonoClient> downstreamTracker = downstreamClient.connect(options);
// create sender
final Future<MessageSender> senderTracker = honoClient.connect(options).compose(connectedClient -> createProducer(TEST_TENANT_ID)).map(s -> {
sender = s;
return s;
});
// create registration client
final Future<RegistrationClient> registrationClientTracker = honoDeviceRegistryClient.connect(options).compose(connectedClient -> connectedClient.getOrCreateRegistrationClient(TEST_TENANT_ID)).map(c -> {
registrationClient = c;
return c;
});
CompositeFuture.all(downstreamTracker, senderTracker, registrationClientTracker).setHandler(ctx.asyncAssertSuccess(s -> {
LOGGER.info("connections to Hono server, Hono device registry and AMQP messaging network established");
}));
}
use of io.vertx.proton.ProtonClientOptions in project hono by eclipse.
the class TenantAmqpIT method prepareDeviceRegistry.
/**
* Starts the device registry, connects a client and provides a tenant API client.
*
* @param ctx The vert.x test context.
*/
@BeforeClass
public static void prepareDeviceRegistry(final TestContext ctx) {
client = DeviceRegistryAmqpTestSupport.prepareDeviceRegistryClient(vertx);
client.connect(new ProtonClientOptions()).compose(c -> c.getOrCreateTenantClient()).setHandler(ctx.asyncAssertSuccess(r -> {
tenantClient = r;
}));
}
use of io.vertx.proton.ProtonClientOptions in project hono by eclipse.
the class HonoClientImplTest method testClientDoesNotTriggerReconnectionAfterShutdown.
/**
* Verifies that the client does not try to re-connect to a server instance if the client was shutdown.
*
* @param ctx The test context.
*/
@Test
public void testClientDoesNotTriggerReconnectionAfterShutdown(final TestContext ctx) {
// GIVEN a client that tries to connect to a server but does not succeed
final Async connectionHandlerInvocation = ctx.async();
connectionFactory = new DisconnectHandlerProvidingConnectionFactory(con, 0, Integer.MAX_VALUE);
client = new HonoClientImpl(vertx, connectionFactory, props);
client.connect(new ProtonClientOptions().setReconnectAttempts(1)).setHandler(ctx.asyncAssertFailure(cause -> connectionHandlerInvocation.complete()));
// WHEN client gets shutdown
client.shutdown();
// THEN reconnect gets stopped, i.e. connection fails
connectionHandlerInvocation.await();
}
use of io.vertx.proton.ProtonClientOptions in project hono by eclipse.
the class HonoClientImplTest method testGetOrCreateRequestResponseClientFailsIfInvokedConcurrently.
/**
* Verifies that a concurrent request to create a request-response client fails the given
* future for tracking the attempt.
*
* @param ctx The helper to use for running async tests.
*/
@Test
public void testGetOrCreateRequestResponseClientFailsIfInvokedConcurrently(final TestContext ctx) {
// GIVEN a client that already tries to create a registration client for "tenant"
final Async connected = ctx.async();
client.connect(new ProtonClientOptions()).setHandler(ctx.asyncAssertSuccess(ok -> connected.complete()));
connected.await();
client.getOrCreateRequestResponseClient("registration/tenant", () -> Future.future(), result -> {
});
// WHEN an additional, concurrent attempt is made to create a client for "tenant"
client.getOrCreateRequestResponseClient("registration/tenant", () -> {
ctx.fail("should not create concurrent client");
return Future.succeededFuture(mock(RegistrationClient.class));
}, ctx.<RequestResponseClient>asyncAssertFailure(t -> {
// THEN the concurrent attempt fails without any attempt being made to create another client
ctx.assertTrue(ServerErrorException.class.isInstance(t));
}));
}
Aggregations