use of io.vertx.proton.ProtonClientOptions in project hono by eclipse.
the class HonoClientImplTest method testGetOrCreateRequestResponseClientFailsOnConnectionFailure.
/**
* Verifies that a request to create a request-response client is failed immediately when the
* underlying connection to the server fails.
*
* @param ctx The Vertx test context.
*/
@Test
public void testGetOrCreateRequestResponseClientFailsOnConnectionFailure(final TestContext ctx) {
// GIVEN a client that 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();
final Async creationFailure = ctx.async();
final Async supplierInvocation = ctx.async();
client.getOrCreateRequestResponseClient("registration/tenant", () -> {
ctx.assertFalse(creationFailure.isCompleted());
supplierInvocation.complete();
return Future.future();
}, ctx.asyncAssertFailure(cause -> creationFailure.complete()));
// WHEN the underlying connection fails
supplierInvocation.await();
connectionFactory.getDisconnectHandler().handle(con);
// THEN all creation requests are failed
creationFailure.await();
}
use of io.vertx.proton.ProtonClientOptions in project hono by eclipse.
the class HonoClientImplTest method testConnectTriesToReconnectOnFailedConnectAttempt.
/**
* Verifies that the client repeatedly tries to connect until a connection is established.
*
* @param ctx The test context.
*/
@Test
public void testConnectTriesToReconnectOnFailedConnectAttempt(final TestContext ctx) {
// GIVEN a client that is configured to connect to a peer
// to which the connection can be established on the third attempt only
connectionFactory = new DisconnectHandlerProvidingConnectionFactory(con, 1, 2);
client = new HonoClientImpl(vertx, connectionFactory, props);
// WHEN trying to connect
final ProtonClientOptions options = new ProtonClientOptions().setReconnectInterval(50).setReconnectAttempts(3);
final Async disconnectHandlerInvocation = ctx.async();
client.connect(options, failedCon -> disconnectHandlerInvocation.complete()).setHandler(ctx.asyncAssertSuccess());
// THEN the client succeeds to connect on the third attempt
assertTrue(connectionFactory.await(1, TimeUnit.SECONDS));
// and sets the disconnect handler provided as a parameter to the connect method
connectionFactory.getDisconnectHandler().handle(con);
disconnectHandlerInvocation.await();
}
use of io.vertx.proton.ProtonClientOptions in project hono by eclipse.
the class HonoClientImplTest method testConnectFailsAfterMaxConnectionAttempts.
/**
* Verifies that the client tries to connect a limited
* number of times only.
*
* @param ctx The vert.x test client.
*/
@Test
public void testConnectFailsAfterMaxConnectionAttempts(final TestContext ctx) {
// GIVEN a client that is configured to connect
// to a peer that is not listening
props.setHost(InetAddress.getLoopbackAddress().getHostAddress());
props.setPort(45000);
client = new HonoClientImpl(vertx, props);
final ProtonClientOptions options = new ProtonClientOptions().setConnectTimeout(50).setReconnectAttempts(3).setReconnectInterval(50);
// WHEN the client tries to connect
client.connect(options).setHandler(ctx.asyncAssertFailure(t -> {
// THEN the connection attempt fails
ctx.assertEquals(HttpURLConnection.HTTP_UNAVAILABLE, ((ServerErrorException) t).getErrorCode());
}));
}
use of io.vertx.proton.ProtonClientOptions in project hono by eclipse.
the class ConnectionFactoryImplTest method testConnectEnablesSslIfTrustStoreIsConfigured.
/**
* Verifies that the factory uses TLS when connecting to the peer if a trust store
* is configured but TLS has not been enabled explicitly.
*/
@SuppressWarnings("unchecked")
@Test
public void testConnectEnablesSslIfTrustStoreIsConfigured() {
// GIVEN a factory configured to use a specific trust store
final ClientConfigProperties config = new ClientConfigProperties();
config.setHost("remote.host");
config.setTrustStorePath("/tmp/trusted-ca.p12");
final ProtonClient client = mock(ProtonClient.class);
final ConnectionFactoryImpl factory = new ConnectionFactoryImpl(vertx, config);
factory.setProtonClient(client);
// WHEN connecting to the server
factory.connect(null, null, null, c -> {
});
// THEN the factory uses TLS when establishing the connection
final ArgumentCaptor<ProtonClientOptions> optionsCaptor = ArgumentCaptor.forClass(ProtonClientOptions.class);
verify(client).connect(optionsCaptor.capture(), eq("remote.host"), anyInt(), any(), any(), any(Handler.class));
assertTrue(optionsCaptor.getValue().isSsl());
}
use of io.vertx.proton.ProtonClientOptions in project hono by eclipse.
the class ConnectionFactoryImplTest method testConnectDoesNotUseSaslPlainForEmptyUsernameAndPassword.
/**
* Verifies that the factory does not enable SASL_PLAIN if the username and password are empty
* strings.
*
* @param ctx The vert.x test context.
*/
@SuppressWarnings("unchecked")
@Test
public void testConnectDoesNotUseSaslPlainForEmptyUsernameAndPassword(final TestContext ctx) {
// GIVEN a factory configured to connect to a server
final ProtonClientOptions options = new ProtonClientOptions();
final ProtonClient client = mock(ProtonClient.class);
final ConnectionFactoryImpl factory = new ConnectionFactoryImpl(vertx, props);
factory.setProtonClient(client);
// WHEN connecting to the server using empty strings for username and password
factory.connect(options, "", "", null, null, c -> {
});
// THEN the factory does not enable the SASL_PLAIN mechanism when establishing
// the connection
ArgumentCaptor<ProtonClientOptions> optionsCaptor = ArgumentCaptor.forClass(ProtonClientOptions.class);
verify(client).connect(optionsCaptor.capture(), anyString(), anyInt(), eq(""), eq(""), any(Handler.class));
assertFalse(optionsCaptor.getValue().getEnabledSaslMechanisms().contains("PLAIN"));
}
Aggregations