Source:
<code>public void recreateCacheOnRestartedCluster_whenMaxConcurrentInvocationLow() { HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(); ClientConfig clientConfig = new ClientConfig(); clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(Long.MAX_VALUE); clientConfig.setProperty(ClientProperty.MAX_CONCURRENT_INVOCATIONS.getName(), "1"); clientConfig.getMetricsConfig().setEnabled(false); clientConfig.setBackupAckToClientEnabled(false); HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig); HazelcastClientCachingProvider cachingProvider = createClientCachingProvider(client); final CacheManager cacheManager = cachingProvider.getCacheManager(); MutableConfiguration configuration = new MutableConfiguration(); <START> while (true) { <END> try { cacheManager.createCache("xmlCache", configuration); break; } catch (HazelcastOverloadException e) { sleepMillis(30); } } IExecutorService executorService = client.getExecutorService("exec"); CountDownLatch testFinished = new CountDownLatch(1); executorService.submit(new ExecutorServiceTestSupport.SleepingTask(0), new ExecutionCallback<Boolean>() { @Override public void onResponse(Boolean response) { try { testFinished.await(); } catch (InterruptedException e) { e.printStackTrace(); } } @Override public void onFailure(Throwable t) { try { testFinished.await(); } catch (InterruptedException e) { e.printStackTrace(); } } }); hazelcastInstance.shutdown(); HazelcastInstance instance = Hazelcast.newHazelcastInstance(); assertTrueEventually(new AssertTask() { @Override public void run() { try { instance.getCacheManager().getCache("xmlCache"); } catch (Exception e) { fail(); } } }); testFinished.countDown(); }</code><technical_language>convert assertTrueEventually avoid possibility of infinite wait? (practically more test timeout anyway)</technical_language>

Target:
public void recreateCacheOnRestartedCluster_whenMaxConcurrentInvocationLow() { HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(); ClientConfig clientConfig = new ClientConfig(); clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(Long.MAX_VALUE); clientConfig.setProperty(ClientProperty.MAX_CONCURRENT_INVOCATIONS.getName(), "1"); clientConfig.getMetricsConfig().setEnabled(false); clientConfig.setBackupAckToClientEnabled(false); HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig); HazelcastClientCachingProvider cachingProvider = createClientCachingProvider(client); final CacheManager cacheManager = cachingProvider.getCacheManager(); MutableConfiguration configuration = new MutableConfiguration(); assertTrueEventually(() -> { try { cacheManager.createCache("xmlCache", configuration); } catch (HazelcastOverloadException e) { throw new AssertionError("Could not create cache due to " + "low concurrent invocation count."); } }); IExecutorService executorService = client.getExecutorService("exec"); CountDownLatch testFinished = new CountDownLatch(1); executorService.submit(new ExecutorServiceTestSupport.SleepingTask(0), new ExecutionCallback<Boolean>() { @Override public void onResponse(Boolean response) { try { testFinished.await(); } catch (InterruptedException e) { e.printStackTrace(); } } @Override public void onFailure(Throwable t) { try { testFinished.await(); } catch (InterruptedException e) { e.printStackTrace(); } } }); hazelcastInstance.shutdown(); HazelcastInstance instance = Hazelcast.newHazelcastInstance(); assertTrueEventually(new AssertTask() { @Override public void run() { try { instance.getCacheManager().getCache("xmlCache"); } catch (Exception e) { fail(); } } }); testFinished.countDown(); }