Source:
<code>public void leaseExpiry() throws Exception { URI connectionURI = TCPProxyUtil.getProxyURI(CLUSTER.getConnectionURI(), proxies); CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder = CacheManagerBuilder.newCacheManagerBuilder() .with(ClusteringServiceConfigurationBuilder.cluster(connectionURI.resolve("/crud-cm")) .timeouts(TimeoutsBuilder.timeouts() .connection(Duration.ofSeconds(20))) .autoCreate() .defaultServerResource("primary-server-resource")); PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(false); cacheManager.init(); CacheConfiguration<Long, String> config = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, resourcePoolsBuilder).build(); Cache<Long, String> cache = cacheManager.createCache("clustered-cache", config); cache.put(1L, "The one"); cache.put(2L, "The two"); cache.put(3L, "The three"); assertThat(cache.get(1L), equalTo("The one")); assertThat(cache.get(2L), equalTo("The two")); assertThat(cache.get(3L), equalTo("The three")); setDelay(6000, proxies); Thread.sleep(6000); setDelay(0L, proxies); CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> { <START> while (true) { <END> try { Thread.sleep(200); } catch (InterruptedException e) { } String result = cache.get(1L); if (result != null) { return result; } } }); assertThat(future.get(50, TimeUnit.SECONDS), is("The one")); assertThat(cache.get(2L), equalTo("The two")); assertThat(cache.get(3L), equalTo("The three")); }</code><technical_language>In case of error, need able get out of loop some point. 20 seconds something</technical_language>

Target:
public void leaseExpiry() throws Exception { URI connectionURI = TCPProxyUtil.getProxyURI(CLUSTER.getConnectionURI(), proxies); CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder = CacheManagerBuilder.newCacheManagerBuilder() .with(ClusteringServiceConfigurationBuilder.cluster(connectionURI.resolve("/crud-cm")) .timeouts(TimeoutsBuilder.timeouts() .connection(Duration.ofSeconds(20))) .autoCreate() .defaultServerResource("primary-server-resource")); PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(false); cacheManager.init(); CacheConfiguration<Long, String> config = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, resourcePoolsBuilder).build(); Cache<Long, String> cache = cacheManager.createCache("clustered-cache", config); cache.put(1L, "The one"); cache.put(2L, "The two"); cache.put(3L, "The three"); assertThat(cache.get(1L), equalTo("The one")); assertThat(cache.get(2L), equalTo("The two")); assertThat(cache.get(3L), equalTo("The three")); setDelay(6000, proxies); Thread.sleep(6000); setDelay(0L, proxies); AtomicBoolean timedout = new AtomicBoolean(false); CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> { while (!timedout.get()) { try { Thread.sleep(200); } catch (InterruptedException e) { throw new AssertionError(e); } String result = cache.get(1L); if (result != null) { return result; } } return null; }); assertThat(future.get(5, TimeUnit.SECONDS), is("The one")); timedout.set(true); assertThat(cache.get(2L), equalTo("The two")); assertThat(cache.get(3L), equalTo("The three")); }