use of org.eclipse.hono.connection.ConnectionFactory 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 org.eclipse.hono.connection.ConnectionFactory in project hono by eclipse.
the class StandaloneAuthServerTest method prepareServer.
/**
* Sets up the server.
*
* @param ctx The vertx test context.
*/
@BeforeClass
public static void prepareServer(final TestContext ctx) {
AuthTokenHelper tokenHelper = AuthTokenHelperImpl.forSharedSecret(SIGNING_SECRET, 5);
ServiceConfigProperties props = new ServiceConfigProperties();
props.setInsecurePortEnabled(true);
props.setInsecurePort(0);
server = new SimpleAuthenticationServer();
server.setConfig(props);
server.setSaslAuthenticatorFactory(new HonoSaslAuthenticatorFactory(vertx, tokenHelper));
server.addEndpoint(new AuthenticationEndpoint(vertx));
AuthenticationServerConfigProperties serviceProps = new AuthenticationServerConfigProperties();
serviceProps.getSigning().setTokenExpiration(5);
serviceProps.getSigning().setSharedSecret(SIGNING_SECRET);
serviceProps.setPermissionsPath(new ClassPathResource("authentication-service-test-permissions.json"));
FileBasedAuthenticationService authServiceImpl = new FileBasedAuthenticationService();
authServiceImpl.setConfig(serviceProps);
authServiceImpl.setTokenFactory(tokenHelper);
Async startup = ctx.async();
Future<String> serverTracker = Future.future();
serverTracker.setHandler(ctx.asyncAssertSuccess(s -> startup.complete()));
Future<String> serviceTracker = Future.future();
vertx.deployVerticle(authServiceImpl, serviceTracker.completer());
serviceTracker.compose(s -> {
vertx.deployVerticle(server, ctx.asyncAssertSuccess(d -> serverTracker.complete(d)));
}, serverTracker);
startup.await(2000);
AuthenticationServerClientConfigProperties clientProps = new AuthenticationServerClientConfigProperties();
clientProps.setHost("127.0.0.1");
clientProps.setName("test-client");
clientProps.setPort(server.getInsecurePort());
clientProps.getValidation().setSharedSecret(SIGNING_SECRET);
ConnectionFactory clientFactory = new ConnectionFactoryImpl(vertx, clientProps);
client = new AuthenticationServerClient(vertx, clientFactory);
}
use of org.eclipse.hono.connection.ConnectionFactory in project hono by eclipse.
the class HonoClientImplTest method testDownstreamDisconnectClearsSenderCreationLocks.
/**
* Verifies that all sender creation locks are cleared when the connection to the server fails.
*
* @param ctx The Vertx test context.
*/
@Test
public void testDownstreamDisconnectClearsSenderCreationLocks(final TestContext ctx) {
// expect the connection factory to be invoked twice
// first on initial connection
// second on reconnect
connectionFactory = new DisconnectHandlerProvidingConnectionFactory(con);
// GIVEN a client trying to create a sender to a peer
final ProtonClientOptions options = new ProtonClientOptions().setReconnectInterval(50).setReconnectAttempts(3);
client = new HonoClientImpl(vertx, connectionFactory, props);
client.connect(options).setHandler(ctx.asyncAssertSuccess());
assertTrue(connectionFactory.await(1, TimeUnit.SECONDS));
connectionFactory.setExpectedSucceedingConnectionAttempts(1);
// WHEN the downstream connection fails just when the client wants to open a sender link
final Async senderCreationFailure = ctx.async();
client.getOrCreateSender("telemetry/tenant", () -> {
connectionFactory.getDisconnectHandler().handle(con);
return Future.future();
}).setHandler(ctx.asyncAssertFailure(cause -> senderCreationFailure.complete()));
// THEN the sender creation fails,
senderCreationFailure.await();
// the connection is re-established
assertTrue(connectionFactory.await(1, TimeUnit.SECONDS));
// and the next attempt to create a sender succeeds
client.getOrCreateSender("telemetry/tenant", () -> Future.succeededFuture(mock(MessageSender.class))).setHandler(ctx.asyncAssertSuccess());
}
use of org.eclipse.hono.connection.ConnectionFactory 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();
}
Aggregations