Skip to content

Commit

Permalink
fix testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
BarDweller committed Jun 28, 2022
1 parent 3f95420 commit 54cbd91
Showing 1 changed file with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.junit.Test;

import mockit.Mocked;
import mockit.Verifications;

public class SignedRequestTimedCacheTest {

Expand All @@ -50,7 +49,6 @@ public void testIsDuplicate(@Mocked ManagedExecutorService executor) {
public void testTrigger(@Mocked ManagedExecutorService executor) {

SignedRequestTimedCache cache = new SignedRequestTimedCache();
cache.managedExecutorService = executor;

// executor not called for this one
cache.triggerCount.set(1);
Expand All @@ -63,16 +61,11 @@ public void testTrigger(@Mocked ManagedExecutorService executor) {
// executor triggered to clean up for this one
cache.triggerCount.set(SignedRequestTimedCache.TRIGGER_CLEANUP_DEPTH + 1);
cache.isDuplicate("fred", SignedRequestHmac.EXPIRES_REPLAY_MS);

new Verifications() {{
executor.execute(cache); times = 2;
}};
}

@Test
public void testCacheExpiration(@Mocked ManagedExecutorService executor) {
SignedRequestTimedCache cache = new SignedRequestTimedCache();
cache.managedExecutorService = executor;

cache.requests.put("A", new TimestampedKey("A", Duration.ofMillis(1)));
cache.requests.put("B", new TimestampedKey("B", SignedRequestHmac.EXPIRES_REPLAY_MS));
Expand All @@ -81,7 +74,10 @@ public void testCacheExpiration(@Mocked ManagedExecutorService executor) {
snooze(3); // make sure "A" has expired
Assert.assertTrue("'A' should be expired", cache.requests.get("A").hasExpired());

cache.run();
//calls to isduplicate flush the cache of expired keys.
cache.triggerCount.set(SignedRequestTimedCache.TRIGGER_CLEANUP_DEPTH + 1);
cache.isDuplicate("B", SignedRequestHmac.EXPIRES_REPLAY_MS);

Assert.assertEquals(1, cache.requests.size());
Assert.assertNull("'A' should have been deleted: " + cache.requests, cache.requests.get("A"));
Assert.assertNotNull("'B' should remain: " + cache.requests, cache.requests.get("B"));
Expand Down

0 comments on commit 54cbd91

Please sign in to comment.