Skip to content

Commit

Permalink
ISPN-5497 MetadataAPIDefaultExpiryTest random failures
Browse files Browse the repository at this point in the history
  • Loading branch information
danberindei authored and tristantarrant committed Sep 18, 2015
1 parent fc49711 commit 32eb0b1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
Expand Up @@ -5,7 +5,10 @@
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.metadata.EmbeddedMetadata;
import org.infinispan.test.SingleCacheManagerTest;
import org.infinispan.test.TestingUtil;
import org.infinispan.test.fwk.TestCacheManagerFactory;
import org.infinispan.util.ControlledTimeService;
import org.infinispan.util.TimeService;
import org.testng.annotations.Test;

import java.util.concurrent.TimeUnit;
Expand All @@ -17,14 +20,17 @@
@Test(groups = "functional", testName = "api.MetadataAPIDefaultExpiryTest")
public class MetadataAPIDefaultExpiryTest extends SingleCacheManagerTest {

public static final int EXPIRATION_TIMEOUT = 3000;
public static final int EVICTION_CHECK_TIMEOUT = 2000;
public static final int EXPIRATION_TIMEOUT = 1000;

private final ControlledTimeService controlledTimeService = new ControlledTimeService(0);

@Override
protected EmbeddedCacheManager createCacheManager() throws Exception {
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.expiration().lifespan(EXPIRATION_TIMEOUT);
return TestCacheManagerFactory.createCacheManager(builder);
EmbeddedCacheManager manager = TestCacheManagerFactory.createCacheManager(builder);
TestingUtil.replaceComponent(manager, TimeService.class, controlledTimeService, true);
return manager;
}

public void testDefaultLifespanPut() {
Expand Down Expand Up @@ -76,21 +82,13 @@ public void testDefaultLifespanPutAsync() throws Exception {
}

private void expectCachedThenExpired(Integer key, String value) {
final long startTime = now();
final long expiration = EXPIRATION_TIMEOUT;
while (true) {
String v = this.<Integer, String>cache().get(key);
if (moreThanDurationElapsed(startTime, expiration))
break;
assertEquals(value, v);
sleepThread(100);
}

// Make sure that in the next X secs data is removed
while (!moreThanDurationElapsed(startTime, expiration + EVICTION_CHECK_TIMEOUT)) {
if (cache.get(key) == null) return;
}
// Check that it doesn't expire too early
controlledTimeService.advance(EXPIRATION_TIMEOUT - 1);
String v = this.<Integer, String>cache().get(key);
assertEquals(value, v);

// But not too late either
controlledTimeService.advance(2);
assertNull(cache.get(key));
}
}
Expand Up @@ -17,7 +17,7 @@ public long wallClockTime() {

@Override
public long time() {
return currentMillis * 1000;
return currentMillis * 1000000;
}

public void advance(long time) {
Expand Down

0 comments on commit 32eb0b1

Please sign in to comment.