コード例 #1
0
 @Test
 public void testGet() throws Exception {
   assertThat(store.get(1L), nullValue());
   validateStats(store, EnumSet.of(StoreOperationOutcomes.GetOutcome.MISS));
   store.put(1L, "one");
   assertThat(store.get(1L).value(), is("one"));
   validateStats(
       store,
       EnumSet.of(StoreOperationOutcomes.GetOutcome.MISS, StoreOperationOutcomes.GetOutcome.HIT));
 }
コード例 #2
0
  @Test
  public void testBulkComputeIfAbsentGetAll() throws Exception {
    store.put(1L, "one");
    store.put(2L, "two");
    Ehcache.GetAllFunction<Long, String> getAllAllFunction =
        new Ehcache.GetAllFunction<Long, String>();
    Map<Long, Store.ValueHolder<String>> valueHolderMap =
        store.bulkComputeIfAbsent(new HashSet<Long>(Arrays.asList(1L, 2L)), getAllAllFunction);

    assertThat(valueHolderMap.get(1L).value(), is("one"));
    assertThat(store.get(1L).value(), is("one"));
    assertThat(valueHolderMap.get(2L).value(), is("two"));
    assertThat(store.get(2L).value(), is("two"));
  }
コード例 #3
0
  @Test
  public void testBulkComputeRemoveAll() throws Exception {
    store.put(1L, "one");
    store.put(2L, "two");
    store.put(3L, "three");
    Ehcache.RemoveAllFunction<Long, String> removeAllFunction =
        new Ehcache.RemoveAllFunction<Long, String>();
    Map<Long, Store.ValueHolder<String>> valueHolderMap =
        store.bulkCompute(new HashSet<Long>(Arrays.asList(1L, 2L, 4L)), removeAllFunction);

    assertThat(valueHolderMap.get(1L), nullValue());
    assertThat(store.get(1L), nullValue());
    assertThat(valueHolderMap.get(2L), nullValue());
    assertThat(store.get(2L), nullValue());
    assertThat(valueHolderMap.get(4L), nullValue());
    assertThat(store.get(4L), nullValue());
    validateStats(store, EnumSet.noneOf(StoreOperationOutcomes.RemoveOutcome.class));
  }
コード例 #4
0
  @Test
  public void testBulkComputePutAll() throws Exception {
    store.put(1L, "another one");
    Map<Long, String> map = new HashMap<Long, String>();
    map.put(1L, "one");
    map.put(2L, "two");
    Ehcache.PutAllFunction<Long, String> putAllFunction =
        new Ehcache.PutAllFunction<Long, String>(null, map, null);
    Map<Long, Store.ValueHolder<String>> valueHolderMap =
        store.bulkCompute(new HashSet<Long>(Arrays.asList(1L, 2L)), putAllFunction);

    assertThat(valueHolderMap.get(1L).value(), is(map.get(1L)));
    assertThat(store.get(1L).value(), is(map.get(1L)));
    assertThat(valueHolderMap.get(2L).value(), is(map.get(2L)));
    assertThat(store.get(2L).value(), is(map.get(2L)));
    assertThat(putAllFunction.getActualPutCount().get(), is(2));
    validateStats(
        store,
        EnumSet.of(StoreOperationOutcomes.PutOutcome.PUT)); // outcome of the initial store put
  }
コード例 #5
0
 @Test(expected = StoreAccessException.class)
 public void testGetThrowsOnlySAE() throws Exception {
   OperationsCodec<Long, String> codec = mock(OperationsCodec.class);
   ChainResolver chainResolver = mock(ChainResolver.class);
   ServerStoreProxy serverStoreProxy = mock(ServerStoreProxy.class);
   when(serverStoreProxy.get(anyLong())).thenThrow(new RuntimeException());
   TestTimeSource testTimeSource = mock(TestTimeSource.class);
   ClusteredStore<Long, String> store =
       new ClusteredStore<Long, String>(codec, chainResolver, serverStoreProxy, testTimeSource);
   store.get(1L);
 }