Skip to content

Commit

Permalink
ISPN-6016 Unstable HotRodRemoteCacheIT testPutAsync test
Browse files Browse the repository at this point in the history
  • Loading branch information
mgencur authored and danberindei committed Jan 14, 2016
1 parent cae5de0 commit f49e7a3
Showing 1 changed file with 9 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public abstract class AbstractRemoteCacheIT {

protected RemoteCache remoteCache;
protected static RemoteCacheManager remoteCacheManager = null;
protected final int ASYNC_OPS_ENTRY_LOAD = 100;
protected final int ASYNC_OPS_ENTRY_LOAD = 10;

protected abstract List<RemoteInfinispanServer> getServers();

Expand All @@ -68,7 +68,7 @@ public void initialize() {
remoteCacheManager = new RemoteCacheManager(config, true);
}
remoteCache = remoteCacheManager.getCache(TEST_CACHE_NAME);
assertCacheEmpty();
remoteCache.clear();
}

@AfterClass
Expand Down Expand Up @@ -117,17 +117,6 @@ private boolean isDistributedMode() {
return "dist".equals(AbstractRemoteCacheManagerIT.getClusteringMode());
}

public void assertCacheEmpty() {
clearServer(0);
if (!AbstractRemoteCacheManagerIT.isLocalMode()) {
clearServer(1);
}
}

private void clearServer(int serverIndex) {
remoteCache.clear();
}

private long numEntriesOnServer(int serverIndex) {
return getServers().get(serverIndex).
getCacheManager(AbstractRemoteCacheManagerIT.isLocalMode() ? "local" : "clustered").
Expand Down Expand Up @@ -569,20 +558,17 @@ public void testClearAsync() throws Exception {

@Test
public void testPutAsync() throws Exception {
Set<Future<?>> futures = new HashSet<Future<?>>();
for (int i = 0; i != ASYNC_OPS_ENTRY_LOAD; i++) {
futures.add(remoteCache.putAsync("key" + i, "value" + i));
}
for (Future<?> f : futures) {
f.get();
}
assertEquals(ASYNC_OPS_ENTRY_LOAD, numEntriesOnServer(0));
assertEquals("value" + (ASYNC_OPS_ENTRY_LOAD - 1), remoteCache.get("key" + (ASYNC_OPS_ENTRY_LOAD - 1)));
assertNull(remoteCache.get("k"));
Future<String> f = remoteCache.putAsync("k", "v");
assertFalse(f.isCancelled());
assertNull(f.get());
assertTrue(f.isDone());
assertEquals("v", remoteCache.get("k"));
}

@Test
public void testPutWithLifespanAsync() throws Exception {
long lifespanInSecs = 10;
long lifespanInSecs = 2;
Set<Future<?>> futures = new HashSet<Future<?>>();
for (int i = 0; i != ASYNC_OPS_ENTRY_LOAD; i++) {
futures.add(remoteCache.putAsync("key" + i, "value" + i, lifespanInSecs, TimeUnit.SECONDS, -1, TimeUnit.SECONDS));
Expand Down

0 comments on commit f49e7a3

Please sign in to comment.