Skip to content

Commit

Permalink
Merge pull request #2338 from chrisdennis/issue-2337
Browse files Browse the repository at this point in the history
Fix #2337 : Ensure we break out of reconnect loop when the entity does not exist
  • Loading branch information
cljohnso authored Mar 16, 2018
2 parents f0c9eac + 8c92f91 commit 48b4d66
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public ClusterTierClientEntity createClusterTierClientEntity(String cacheId,
} catch (EntityNotFoundException e) {
throw new CachePersistenceException("Cluster tier proxy '" + cacheId + "' for entity '" + entityIdentifier + "' does not exist.", e);
} catch (ConnectionClosedException | ConnectionShutdownException e) {
LOGGER.info("Disconnected to the server", e);
LOGGER.info("Disconnected from the server", e);
handleConnectionClosedException();
}
}
Expand Down Expand Up @@ -240,13 +240,14 @@ public void destroy(String name) throws CachePersistenceException {
entity = entityFactory.retrieve(entityIdentifier, serviceConfiguration.getServerConfiguration());
} catch (EntityNotFoundException e) {
// No entity on the server, so no need to destroy anything
break;
} catch (TimeoutException e) {
throw new CachePersistenceException("Could not connect to the cluster tier manager '" + entityIdentifier
+ "'; retrieve operation timed out", e);
} catch (DestroyInProgressException e) {
silentDestroy();
// Nothing left to do
return;
break;
} catch (ConnectionClosedException | ConnectionShutdownException e) {
reconnect();
}
Expand All @@ -260,6 +261,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 All @@ -275,7 +277,7 @@ private void autoCreateEntity() throws ClusterTierManagerValidationException, Il
} catch (EntityAlreadyExistsException | EntityBusyException e) {
//ignore - entity already exists - try to retrieve
} catch (ConnectionClosedException | ConnectionShutdownException e) {
LOGGER.info("Disconnected to the server", e);
LOGGER.info("Disconnected from the server", e);
reconnect();
continue;
}
Expand All @@ -291,22 +293,24 @@ private void autoCreateEntity() throws ClusterTierManagerValidationException, Il
throw new RuntimeException("Could not connect to the cluster tier manager '" + entityIdentifier
+ "'; retrieve operation timed out", e);
} catch (ConnectionClosedException | ConnectionShutdownException e) {
LOGGER.info("Disconnected to the server", e);
LOGGER.info("Disconnected from the server", e);
reconnect();
}
}

}

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();
break;
} catch (ConnectionClosedException | ConnectionShutdownException e) {
LOGGER.info("Disconnected from 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,23 @@ 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 testDestroyCacheOnNonExistentCacheManager() throws CachePersistenceException {
PersistentCacheManager persistentCacheManager = clusteredCacheManagerBuilder.build(true);
persistentCacheManager.close();
persistentCacheManager.destroy();

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 48b4d66

Please sign in to comment.