You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
These are tests made following the suggestion of using HealthChecker to monitor the connection. It partially works but the following problems were identified. They are particularly important for integration tests and batch applications.
Also, it seems impossible to have a sane application without HealthChecker. It should be documented as a mandatory system or be launched under the hood. And it should be an entity installed by default.
Here are the flaws encountered:
There is no way to know a connection was already closed by the client itself. Calling close twice will raise an exception. We should have a isClosed method or at least close should be reentrant
HealthChecker should import SLF4J. It needs it to run
If the server is dead when retrieving the HealthChecker entity, it get stuck. This can be really frequent during testing
HealthChecker entity is not by default in the kit. So it needs some Maven magic to work during testing
There are now way to stop the HealthChecker
The test code (the map can be replaced by any other entity):
publicclassInterruptibleGetEntity {
privateConnectionconnection;
@RulepublicClustervoltron = newBasicExternalCluster(newFile("target/galvan"), 1,
Arrays.asList(
newFile("../maps/server/target/maps-server-plugin.jar"),
newFile("target/entities/healthcheck-server.jar")),
"", "", "");
@BeforepublicvoidsetUp() throwsException {
voltron.getClusterControl().waitForActive();
Propertiesproperties = newProperties();
properties.setProperty(ConnectionPropertyNames.CONNECTION_NAME, getClass().getSimpleName());
properties.setProperty(ConnectionPropertyNames.CONNECTION_TIMEOUT, "10000");
// Get a valid connectionconnection = ConnectionFactory.connect(voltron.getConnectionURI(), properties);
}
@AfterpublicvoidtearDown() throwsException {
try {
connection.close();
} catch(IllegalStateExceptione) {
// Problem #1: Here, I have no way to know that the connection was already closed in the test// Since the connection was opened in setUp(), it makes sense to close it in tearDown(). And I// don't know if the test have closed it or notif(!e.getMessage().equals("Already shut down")) {
throwe;
}
}
voltron.getClusterControl().terminateAllServers();
}
@TestpublicvoidcanRetrieveEntity() throwsException {
// Get a valid entity factoryEntityFactory<ClusteredMapEntity, MapConfig> entityFactory = newEntityFactory<>(connection, ClusteredMapEntity.class);
// Try to retrieve the entityClusteredMapEntityentity = entityFactory.getOrCreateEntity("map", newMapConfig("map"));
assertThat(entity).isNotNull();
}
@TestpublicvoidcanCloseMultipleTimes() throwsException {
connection.close();
}
@TestpublicvoiddontGetStuckWhenAskingAnEntityWhenServerDown() throwsException {
// Get a valid entity factoryEntityFactory<ClusteredMapEntity, MapConfig> entityFactory = newEntityFactory<>(connection, ClusteredMapEntity.class);
// Close the connectionconnection.close();
// Try to retrieve the entityentityFactory.getOrCreateEntity("map", newMapConfig("map"));
}
@TestpublicvoidgettingAnEntityWhenConnectionClosedShouldFail() throwsException {
// Get a valid entity factoryEntityFactory<ClusteredMapEntity, MapConfig> entityFactory = newEntityFactory<>(connection, ClusteredMapEntity.class);
// Close the connectionconnection.close();
// Try to retrieve the entity. Should throw an exceptionassertThatExceptionOfType(IllegalStateException.class)
.isThrownBy(() -> { entityFactory.getOrCreateEntity("map", newMapConfig("map")); })
.withMessage("Already shut down");
}
@Test@IgnorepublicvoidhealthCheckerDontGetStuckWhenRetrievingItsEntity() throwsException {
// Kill the servervoltron.getClusterControl().terminateActive();
// Problem #2: NoClassDefFoundError is SLF4J is not in the classpath. I guess it should be a dependency of healthchecker-api// Problem #3: This test fails because it gets stuck on the health entity retrievalHealthCheckerFactory.startHealthChecker(connection, 60, 2000);
}
@TestpublicvoiddontGetStuckWhenThereIsNoServer() throwsException {
// Get a valid entity factoryEntityFactory<ClusteredMapEntity, MapConfig> entityFactory = newEntityFactory<>(connection, ClusteredMapEntity.class);
// Problem #4: The entity is not by default in the kit so it needs to be added manually. I'm using the maven-dependency-plugin for that// Problem #5: No way to stop itHealthCheckerFactory.startHealthChecker(connection, 60, 2000);
// Kill the servervoltron.getClusterControl().terminateActive();
// Try to retrieve the entity. It should stop and fail. And it does perfectlyassertThatExceptionOfType(ConnectionClosedException.class)
.isThrownBy(() -> { entityFactory.getOrCreateEntity("map", newMapConfig("map")); });
}
}
The text was updated successfully, but these errors were encountered:
These are tests made following the suggestion of using
HealthChecker
to monitor the connection. It partially works but the following problems were identified. They are particularly important for integration tests and batch applications.Also, it seems impossible to have a sane application without
HealthChecker
. It should be documented as a mandatory system or be launched under the hood. And it should be an entity installed by default.Here are the flaws encountered:
isClosed
method or at leastclose
should be reentrantHealthChecker
should import SLF4J. It needs it to runHealthChecker
entity, it get stuck. This can be really frequent during testingHealthChecker
entity is not by default in the kit. So it needs some Maven magic to work during testingHealthChecker
The test code (the map can be replaced by any other entity):
The text was updated successfully, but these errors were encountered: