@Test public void testPutIfAbsent() throws Exception { assertThat(store.putIfAbsent(1L, "one"), nullValue()); validateStats(store, EnumSet.of(StoreOperationOutcomes.PutIfAbsentOutcome.PUT)); assertThat(store.putIfAbsent(1L, "another one").value(), is("one")); validateStats( store, EnumSet.of( StoreOperationOutcomes.PutIfAbsentOutcome.PUT, StoreOperationOutcomes.PutIfAbsentOutcome.HIT)); }
@Test(expected = StoreAccessException.class) public void testPutIfAbsentThrowsOnlySAE() 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.putIfAbsent(1L, "one"); }