Skip to content

Commit

Permalink
Fix ehcache#2337 : Ensure we break out of reconnect loop when the ent…
Browse files Browse the repository at this point in the history
…ity does not exist
  • Loading branch information
chrisdennis committed Mar 16, 2018
1 parent f0c9eac commit f1538d2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ public void destroy(String name) throws CachePersistenceException {
} catch (EntityNotFoundException e) {
// Ignore - does not exist, nothing to destroy
LOGGER.debug("Destruction of cluster tier {} failed as it does not exist", name);
break;
} catch (ConnectionClosedException | ConnectionShutdownException e) {
handleConnectionClosedException();
}
Expand Down Expand Up @@ -299,14 +300,16 @@ private void autoCreateEntity() throws ClusterTierManagerValidationException, Il
}

private void handleConnectionClosedException() {
try {
destroyState();
reconnect();
retrieveEntity();
connectionRecoveryListener.run();
} catch (ConnectionClosedException | ConnectionShutdownException e) {
LOGGER.info("Disconnected to the server", e);
handleConnectionClosedException();
while (true) {
try {
destroyState();
reconnect();
retrieveEntity();
connectionRecoveryListener.run();
return;
} catch (ConnectionClosedException | ConnectionShutdownException e) {
LOGGER.info("Disconnected to the server", e);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ public void testDestroyUnknownCacheAlias() throws Exception {
cacheManager.close();
}

@Test
public void testDestroyNonExistentCache() throws CachePersistenceException {
PersistentCacheManager persistentCacheManager = clusteredCacheManagerBuilder.build(true);

String nonExistent = "this-is-not-the-cache-you-are-looking-for";
assertThat(persistentCacheManager.getCache(nonExistent, Long.class, String.class), nullValue());
persistentCacheManager.destroyCache(nonExistent);
persistentCacheManager.close();
}

@Test
public void testDestroyCacheWhenMultipleClientsConnected() {
PersistentCacheManager persistentCacheManager1 = clusteredCacheManagerBuilder.build(true);
Expand Down Expand Up @@ -181,6 +191,14 @@ public void testDestroyCacheWithCacheManagerStopped() throws CachePersistenceExc
assertThat(persistentCacheManager.getStatus(), is(Status.UNINITIALIZED));
}

@Test
public void testDestroyNonExistentCacheWIthCacheManagerStopped() throws CachePersistenceException {
PersistentCacheManager persistentCacheManager = clusteredCacheManagerBuilder.build(true);
persistentCacheManager.close();
persistentCacheManager.destroyCache("this-is-not-the-cache-you-are-looking-for");
assertThat(persistentCacheManager.getStatus(), is(Status.UNINITIALIZED));
}

@Test
public void testDestroyCacheWithTwoCacheManagerOnSameCache_forbiddenWhenInUse() throws CachePersistenceException {
PersistentCacheManager persistentCacheManager1 = clusteredCacheManagerBuilder.build(true);
Expand Down

0 comments on commit f1538d2

Please sign in to comment.