Exemple #1
0
 @Test
 public void setTimeToLiveZero() throws InterruptedException {
   Cache cache = application().cache();
   assertFalse(cache.has(FOO));
   cache.set(0, FOO, BAR);
   assertThat(cache.get(FOO), equalTo(BAR));
   Thread.sleep(1100);
   assertTrue(cache.has(FOO));
 }
Exemple #2
0
 @Test
 public void hasSetHasGetRemoveHas() {
   Cache cache = application().cache();
   assertFalse(cache.has(FOO));
   cache.set(FOO, BAR);
   assertTrue(cache.has(FOO));
   assertThat(cache.get(FOO), equalTo(BAR));
   cache.remove(FOO);
   assertFalse(cache.has(FOO));
 }
Exemple #3
0
 @Test
 public void getOrSetDefaultTimeToZero() throws InterruptedException {
   Cache cache = application().cache();
   assertFalse(cache.has(FOO));
   assertThat(cache.getOrSetDefault(FOO, 0, BAR), equalTo(BAR));
   Thread.sleep(1100);
   assertTrue(cache.has(FOO));
   cache.set(0, FOO, "bazar");
   assertThat(cache.getOrSetDefault(FOO, 0, BAR), equalTo("bazar"));
   Thread.sleep(1100);
   assertThat(cache.get(FOO), equalTo("bazar"));
 }
Exemple #4
0
 @Test
 public void getOrSetDefault() {
   Cache cache = application().cache();
   assertFalse(cache.has(FOO));
   assertThat(cache.getOrSetDefault(FOO, BAR), equalTo(BAR));
   assertTrue(cache.has(FOO));
   cache.set(FOO, "bazar");
   assertThat(cache.getOrSetDefault(FOO, BAR), equalTo("bazar"));
 }
Exemple #5
0
 @Test
 public void getOptional() {
   Cache cache = application().cache();
   assertFalse(cache.getOptional(FOO).isPresent());
   cache.set(FOO, BAR);
   assertTrue(cache.getOptional(FOO).isPresent());
   assertThat(cache.getOptional(FOO).get(), equalTo(BAR));
   cache.remove(FOO);
   assertFalse(cache.getOptional(FOO).isPresent());
 }
Exemple #6
0
 @Test
 public void removeAbsent() {
   Cache cache = application().cache();
   assertFalse(cache.has(FOO));
   cache.remove(FOO);
 }