/*
* Copyright Terracotta, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.ehcache.core;
import org.ehcache.Status;
import org.ehcache.config.CacheConfiguration;
import org.ehcache.core.config.BaseCacheConfiguration;
import org.ehcache.core.config.ResourcePoolsHelper;
import org.ehcache.core.statistics.CacheOperationOutcomes;
import org.ehcache.core.spi.store.StoreAccessException;
import org.ehcache.spi.loaderwriter.CacheWritingException;
import org.ehcache.expiry.Duration;
import org.ehcache.expiry.Expirations;
import org.ehcache.expiry.Expiry;
import org.ehcache.spi.loaderwriter.CacheLoaderWriter;
import org.hamcrest.CoreMatchers;
import org.junit.Test;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.slf4j.LoggerFactory;
import java.util.Collections;
import java.util.EnumSet;
import static org.ehcache.core.util.Matchers.holding;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.argThat;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
/**
* Provides testing of basic REPLACE(key, value) operations on an {@code EhcacheWithLoaderWriter}.
*
* @author Clifford W. Johnson
*/
public class EhcacheWithLoaderWriterBasicReplaceTest extends EhcacheBasicCrudBase {
@Mock
protected CacheLoaderWriter<String, String> cacheLoaderWriter;
@Test
public void testReplaceNullNull() {
final EhcacheWithLoaderWriter<String, String> ehcache = this.getEhcache(this.cacheLoaderWriter);
try {
ehcache.replace(null, null);
fail();
} catch (NullPointerException e) {
// expected
}
}
@Test
public void testReplaceKeyNull() {
final EhcacheWithLoaderWriter<String, String> ehcache = this.getEhcache(this.cacheLoaderWriter);
try {
ehcache.replace("key", null);
fail();
} catch (NullPointerException e) {
// expected
}
}
@Test
public void testReplaceNullValue() {
final EhcacheWithLoaderWriter<String, String> ehcache = this.getEhcache(this.cacheLoaderWriter);
try {
ehcache.replace(null, "value");
fail();
} catch (NullPointerException e) {
// expected
}
}
/**
* Tests the effect of a {@link EhcacheWithLoaderWriter#replace(Object, Object)} for
* <ul>
* <li>key not present in {@code Store}</li>
* </ul>
*/
@Test
public void testReplaceNoStoreEntry() throws Exception {
final FakeStore fakeStore = new FakeStore(Collections.<String, String>emptyMap());
this.store = spy(fakeStore);
final EhcacheWithLoaderWriter<String, String> ehcache = this.getEhcache(this.cacheLoaderWriter);
assertNull(ehcache.replace("key", "value"));
verify(this.store).compute(eq("key"), getAnyBiFunction());
verifyZeroInteractions(this.spiedResilienceStrategy);
assertThat(fakeStore.getEntryMap().containsKey("key"), is(false));
validateStats(ehcache, EnumSet.of(CacheOperationOutcomes.ReplaceOutcome.MISS_NOT_PRESENT));
}
/**
* Tests the effect of a {@link EhcacheWithLoaderWriter#replace(Object, Object)} for
* <ul>
* <li>key not present in {@code Store}</li>
* <li>key not present via {@code CacheLoaderWriter}</li>
* </ul>
*/
@Test
public void testReplaceNoStoreEntryNoCacheLoaderWriterEntry() throws Exception {
final FakeStore fakeStore = new FakeStore(Collections.<String, String>emptyMap());
this.store = spy(fakeStore);
final FakeCacheLoaderWriter fakeLoaderWriter = new FakeCacheLoaderWriter(Collections.<String, String>emptyMap());
final EhcacheWithLoaderWriter<String, String> ehcache = this.getEhcache(fakeLoaderWriter);
assertNull(ehcache.replace("key", "value"));
verify(this.store).compute(eq("key"), getAnyBiFunction());
verifyZeroInteractions(this.spiedResilienceStrategy);
assertThat(fakeStore.getEntryMap().containsKey("key"), is(false));
assertThat(fakeLoaderWriter.getEntryMap().containsKey("key"), is(false));
validateStats(ehcache, EnumSet.of(CacheOperationOutcomes.ReplaceOutcome.MISS_NOT_PRESENT));
}
/**
* Tests the effect of a {@link EhcacheWithLoaderWriter#replace(Object, Object)} for
* <ul>
* <li>key not present in {@code Store}</li>
* <li>key present via {@code CacheLoaderWriter}</li>
* </ul>
*/
@Test
public void testReplaceNoStoreEntryHasCacheLoaderWriterEntry() throws Exception {
final FakeStore fakeStore = new FakeStore(Collections.<String, String>emptyMap());
this.store = spy(fakeStore);
final FakeCacheLoaderWriter fakeLoaderWriter = new FakeCacheLoaderWriter(Collections.singletonMap("key", "oldValue"));
final EhcacheWithLoaderWriter<String, String> ehcache = this.getEhcache(fakeLoaderWriter);
assertThat(ehcache.replace("key", "value"), is("oldValue"));
verify(this.store).compute(eq("key"), getAnyBiFunction());
verifyZeroInteractions(this.spiedResilienceStrategy);
assertThat(fakeStore.getEntryMap().containsKey("key"), is(true));
assertThat(fakeLoaderWriter.getEntryMap().get("key"), is(equalTo("value")));
validateStats(ehcache, EnumSet.of(CacheOperationOutcomes.ReplaceOutcome.HIT));
}
/**
* Tests the effect of a {@link EhcacheWithLoaderWriter#replace(Object, Object)} for
* <ul>
* <li>key not present in {@code Store}</li>
* <li>{@code CacheLoaderWriter.write} throws</li>
* </ul>
*/
@Test
public void testReplaceNoStoreEntryCacheWritingException() throws Exception {
final FakeStore fakeStore = new FakeStore(Collections.<String, String>emptyMap());
this.store = spy(fakeStore);
final FakeCacheLoaderWriter fakeLoaderWriter = new FakeCacheLoaderWriter(Collections.singletonMap("key", "oldValue"));
this.cacheLoaderWriter = spy(fakeLoaderWriter);
doThrow(new Exception()).when(this.cacheLoaderWriter).write("key", "value");
final EhcacheWithLoaderWriter<String, String> ehcache = this.getEhcache(cacheLoaderWriter);
try {
ehcache.replace("key", "value");
fail();
} catch (CacheWritingException e) {
e.printStackTrace();
}
verify(this.store).compute(eq("key"), getAnyBiFunction());
verifyZeroInteractions(this.spiedResilienceStrategy);
assertThat(fakeStore.getEntryMap().containsKey("key"), is(false));
validateStats(ehcache, EnumSet.noneOf(CacheOperationOutcomes.ReplaceOutcome.class));
}
/**
* Tests the effect of a {@link EhcacheWithLoaderWriter#replace(Object, Object)} for
* <ul>
* <li>key not present in {@code Store}</li>
* <li>{@code Store.compute} throws</li>
* </ul>
*/
@Test
public void testReplaceNoStoreEntryStoreAccessException() throws Exception {
final FakeStore fakeStore = new FakeStore(Collections.<String, String>emptyMap());
this.store = spy(fakeStore);
doThrow(new StoreAccessException("")).when(this.store).compute(eq("key"), getAnyBiFunction());
final EhcacheWithLoaderWriter<String, String> ehcache = this.getEhcache(this.cacheLoaderWriter);
ehcache.replace("key", "value");
verify(this.store).compute(eq("key"), getAnyBiFunction());
verify(this.spiedResilienceStrategy).replaceFailure(eq("key"), eq("value"), any(StoreAccessException.class));
validateStats(ehcache, EnumSet.of(CacheOperationOutcomes.ReplaceOutcome.FAILURE));
}
/**
* Tests the effect of a {@link EhcacheWithLoaderWriter#replace(Object, Object)} for
* <ul>
* <li>key not present in {@code Store}</li>
* <li>{@code Store.compute} throws</li>
* <li>key not present via {@code CacheLoaderWriter}</li>
* </ul>
*/
@Test
public void testReplaceNoStoreEntryStoreAccessExceptionNoCacheLoaderWriterEntry() throws Exception {
final FakeStore fakeStore = new FakeStore(Collections.<String, String>emptyMap());
this.store = spy(fakeStore);
doThrow(new StoreAccessException("")).when(this.store).compute(eq("key"), getAnyBiFunction());
final FakeCacheLoaderWriter fakeLoaderWriter = new FakeCacheLoaderWriter(Collections.<String, String>emptyMap());
this.cacheLoaderWriter = spy(fakeLoaderWriter);
final EhcacheWithLoaderWriter<String, String> ehcache = this.getEhcache(this.cacheLoaderWriter);
final InOrder ordered = inOrder(this.cacheLoaderWriter, this.spiedResilienceStrategy);
ehcache.replace("key", "value");
verify(this.store).compute(eq("key"), getAnyBiFunction());
ordered.verify(this.cacheLoaderWriter).load("key");
ordered.verify(this.spiedResilienceStrategy).replaceFailure(eq("key"), eq("value"), any(StoreAccessException.class));
assertThat(fakeLoaderWriter.getEntryMap().containsKey("key"), is(false));
validateStats(ehcache, EnumSet.of(CacheOperationOutcomes.ReplaceOutcome.FAILURE));
}
/**
* Tests the effect of a {@link EhcacheWithLoaderWriter#replace(Object, Object)} for
* <ul>
* <li>key not present in {@code Store}</li>
* <li>{@code Store.compute} throws</li>
* <li>key present via {@code CacheLoaderWriter}</li>
* </ul>
*/
@Test
public void testReplaceNoStoreEntryStoreAccessExceptionHasCacheLoaderWriterEntry() throws Exception {
final FakeStore fakeStore = new FakeStore(Collections.<String, String>emptyMap());
this.store = spy(fakeStore);
doThrow(new StoreAccessException("")).when(this.store).compute(eq("key"), getAnyBiFunction());
final FakeCacheLoaderWriter fakeLoaderWriter = new FakeCacheLoaderWriter(Collections.singletonMap("key", "oldValue"));
this.cacheLoaderWriter = spy(fakeLoaderWriter);
final EhcacheWithLoaderWriter<String, String> ehcache = this.getEhcache(this.cacheLoaderWriter);
final InOrder ordered = inOrder(this.cacheLoaderWriter, this.spiedResilienceStrategy);
ehcache.replace("key", "value");
verify(this.store).compute(eq("key"), getAnyBiFunction());
ordered.verify(this.cacheLoaderWriter).write(eq("key"), any(String.class));
ordered.verify(this.spiedResilienceStrategy).replaceFailure(eq("key"), eq("value"), any(StoreAccessException.class));
assertThat(fakeLoaderWriter.getEntryMap().get("key"), is(equalTo("value")));
validateStats(ehcache, EnumSet.of(CacheOperationOutcomes.ReplaceOutcome.FAILURE));
}
/**
* Tests the effect of a {@link EhcacheWithLoaderWriter#replace(Object, Object)} for
* <ul>
* <li>key not present in {@code Store}</li>
* <li>{@code Store.compute} throws</li>
* <li>{@code CacheLoaderWriter.write} throws</li>
* </ul>
*/
@Test
public void testReplaceNoStoreEntryStoreAccessExceptionCacheWritingException() throws Exception {
final FakeStore fakeStore = new FakeStore(Collections.<String, String>emptyMap());
this.store = spy(fakeStore);
doThrow(new StoreAccessException("")).when(this.store).compute(eq("key"), getAnyBiFunction());
final FakeCacheLoaderWriter fakeLoaderWriter = new FakeCacheLoaderWriter(Collections.singletonMap("key", "oldValue"));
this.cacheLoaderWriter = spy(fakeLoaderWriter);
doThrow(new Exception()).when(this.cacheLoaderWriter).write("key", "value");
final EhcacheWithLoaderWriter<String, String> ehcache = this.getEhcache(this.cacheLoaderWriter);
final InOrder ordered = inOrder(this.cacheLoaderWriter, this.spiedResilienceStrategy);
try {
ehcache.replace("key", "value");
fail();
} catch (CacheWritingException e) {
// Expected
}
verify(this.store).compute(eq("key"), getAnyBiFunction());
ordered.verify(this.cacheLoaderWriter).write(eq("key"), any(String.class));
ordered.verify(this.spiedResilienceStrategy)
.replaceFailure(eq("key"), eq("value"), any(StoreAccessException.class), any(CacheWritingException.class));
validateStats(ehcache, EnumSet.of(CacheOperationOutcomes.ReplaceOutcome.FAILURE));
}
/**
* Tests the effect of a {@link EhcacheWithLoaderWriter#replace(Object, Object)} for
* <ul>
* <li>key present in {@code Store}</li>
* </ul>
*/
@Test
public void testReplaceHasStoreEntry() throws Exception {
final FakeStore fakeStore = new FakeStore(Collections.singletonMap("key", "oldValue"));
this.store = spy(fakeStore);
final EhcacheWithLoaderWriter<String, String> ehcache = this.getEhcache(this.cacheLoaderWriter);
assertThat(ehcache.replace("key", "value"), is(equalTo("oldValue")));
verify(this.store).compute(eq("key"), getAnyBiFunction());
verifyZeroInteractions(this.spiedResilienceStrategy);
assertThat(fakeStore.getEntryMap().get("key"), is(equalTo("value")));
validateStats(ehcache, EnumSet.of(CacheOperationOutcomes.ReplaceOutcome.HIT));
}
/**
* Tests the effect of a {@link EhcacheWithLoaderWriter#replace(Object, Object)} for
* <ul>
* <li>key present in {@code Store}</li>
* <li>key not present via {@code CacheLoaderWriter}</li>
* </ul>
*/
@Test
public void testReplaceHasStoreEntryNoCacheLoaderWriterEntry() throws Exception {
final FakeStore fakeStore = new FakeStore(Collections.singletonMap("key", "oldValue"));
this.store = spy(fakeStore);
final FakeCacheLoaderWriter fakeLoaderWriter = new FakeCacheLoaderWriter(Collections.<String, String>emptyMap());
final EhcacheWithLoaderWriter<String, String> ehcache = this.getEhcache(fakeLoaderWriter);
assertThat(ehcache.replace("key", "value"), is(equalTo("oldValue")));
verify(this.store).compute(eq("key"), getAnyBiFunction());
verifyZeroInteractions(this.spiedResilienceStrategy);
assertThat(fakeStore.getEntryMap().get("key"), is(equalTo("value")));
assertThat(fakeLoaderWriter.getEntryMap().get("key"), equalTo("value"));
validateStats(ehcache, EnumSet.of(CacheOperationOutcomes.ReplaceOutcome.HIT));
}
/**
* Tests the effect of a {@link EhcacheWithLoaderWriter#replace(Object, Object)} for
* <ul>
* <li>key present in {@code Store}</li>
* <li>key present via {@code CacheLoaderWriter}</li>
* </ul>
*/
@Test
public void testReplaceHasStoreEntryHasCacheLoaderWriterEntry() throws Exception {
final FakeStore fakeStore = new FakeStore(Collections.singletonMap("key", "oldValue"));
this.store = spy(fakeStore);
final FakeCacheLoaderWriter fakeLoaderWriter = new FakeCacheLoaderWriter(Collections.singletonMap("key", "oldValue"));
final EhcacheWithLoaderWriter<String, String> ehcache = this.getEhcache(fakeLoaderWriter);
assertThat(ehcache.replace("key", "value"), is(equalTo("oldValue")));
verify(this.store).compute(eq("key"), getAnyBiFunction());
verifyZeroInteractions(this.spiedResilienceStrategy);
assertThat(fakeStore.getEntryMap().get("key"), is(equalTo("value")));
assertThat(fakeLoaderWriter.getEntryMap().get("key"), equalTo("value"));
validateStats(ehcache, EnumSet.of(CacheOperationOutcomes.ReplaceOutcome.HIT));
}
/**
* Tests the effect of a {@link EhcacheWithLoaderWriter#replace(Object, Object)} for
* <ul>
* <li>key present in {@code Store}</li>
* <li>{@code CacheLoaderWriter.write} throws</li>
* </ul>
*/
@Test
public void testReplaceHasStoreEntryCacheWritingException() throws Exception {
final FakeStore fakeStore = new FakeStore(Collections.singletonMap("key", "oldValue"));
this.store = spy(fakeStore);
final FakeCacheLoaderWriter fakeLoaderWriter = new FakeCacheLoaderWriter(Collections.singletonMap("key", "oldValue"));
this.cacheLoaderWriter = spy(fakeLoaderWriter);
doThrow(new Exception()).when(this.cacheLoaderWriter).write("key", "value");
final EhcacheWithLoaderWriter<String, String> ehcache = this.getEhcache(this.cacheLoaderWriter);
try {
ehcache.replace("key", "value");
fail();
} catch (CacheWritingException e) {
// Expected
}
verify(this.store).compute(eq("key"), getAnyBiFunction());
verifyZeroInteractions(this.spiedResilienceStrategy);
validateStats(ehcache, EnumSet.noneOf(CacheOperationOutcomes.ReplaceOutcome.class));
}
/**
* Tests the effect of a {@link EhcacheWithLoaderWriter#replace(Object, Object)} for
* <ul>
* <li>key present in {@code Store}</li>
* <li>{@code Store.compute} throws</li>
* </ul>
*/
@Test
public void testReplaceHasStoreEntryStoreAccessException() throws Exception {
final FakeStore fakeStore = new FakeStore(Collections.singletonMap("key", "oldValue"));
this.store = spy(fakeStore);
doThrow(new StoreAccessException("")).when(this.store).compute(eq("key"), getAnyBiFunction());
final EhcacheWithLoaderWriter<String, String> ehcache = this.getEhcache(this.cacheLoaderWriter);
ehcache.replace("key", "value");
verify(this.store).compute(eq("key"), getAnyBiFunction());
verify(this.spiedResilienceStrategy).replaceFailure(eq("key"), eq("value"), any(StoreAccessException.class));
validateStats(ehcache, EnumSet.of(CacheOperationOutcomes.ReplaceOutcome.FAILURE));
}
/**
* Tests the effect of a {@link EhcacheWithLoaderWriter#replace(Object, Object)} for
* <ul>
* <li>key present in {@code Store}</li>
* <li>{@code Store.compute} throws</li>
* <li>key not present via {@code CacheLoaderWriter}</li>
* </ul>
*/
@Test
public void testReplaceHasStoreEntryStoreAccessExceptionNoCacheLoaderWriterEntry() throws Exception {
final FakeStore fakeStore = new FakeStore(Collections.singletonMap("key", "oldValue"));
this.store = spy(fakeStore);
doThrow(new StoreAccessException("")).when(this.store).compute(eq("key"), getAnyBiFunction());
final FakeCacheLoaderWriter fakeLoaderWriter = new FakeCacheLoaderWriter(Collections.<String, String>emptyMap());
this.cacheLoaderWriter = spy(fakeLoaderWriter);
final EhcacheWithLoaderWriter<String, String> ehcache = this.getEhcache(this.cacheLoaderWriter);
final InOrder ordered = inOrder(this.cacheLoaderWriter, this.spiedResilienceStrategy);
ehcache.replace("key", "value");
verify(this.store).compute(eq("key"), getAnyBiFunction());
verify(this.store, times(1)).remove("key");
ordered.verify(this.cacheLoaderWriter).load(eq("key"));
ordered.verify(this.spiedResilienceStrategy).replaceFailure(eq("key"), eq("value"), any(StoreAccessException.class));
assertThat(fakeLoaderWriter.getEntryMap().containsKey("key"), is(false));
validateStats(ehcache, EnumSet.of(CacheOperationOutcomes.ReplaceOutcome.FAILURE));
}
/**
* Tests the effect of a {@link EhcacheWithLoaderWriter#replace(Object, Object)} for
* <ul>
* <li>key present in {@code Store}</li>
* <li>{@code Store.compute} throws</li>
* <li>key present via {@code CacheLoaderWriter}</li>
* </ul>
*/
@Test
public void testReplaceHasStoreEntryStoreAccessExceptionHasCacheLoaderWriterEntry() throws Exception {
final FakeStore fakeStore = new FakeStore(Collections.singletonMap("key", "oldValue"));
this.store = spy(fakeStore);
doThrow(new StoreAccessException("")).when(this.store).compute(eq("key"), getAnyBiFunction());
final FakeCacheLoaderWriter fakeLoaderWriter = new FakeCacheLoaderWriter(Collections.singletonMap("key", "oldValue"));
this.cacheLoaderWriter = spy(fakeLoaderWriter);
final EhcacheWithLoaderWriter<String, String> ehcache = this.getEhcache(this.cacheLoaderWriter);
final InOrder ordered = inOrder(this.cacheLoaderWriter, this.spiedResilienceStrategy);
ehcache.replace("key", "value");
verify(this.store).compute(eq("key"), getAnyBiFunction());
ordered.verify(this.cacheLoaderWriter).write(eq("key"), any(String.class));
ordered.verify(this.spiedResilienceStrategy).replaceFailure(eq("key"), eq("value"), any(StoreAccessException.class));
assertThat(fakeLoaderWriter.getEntryMap().get("key"), is(equalTo("value")));
validateStats(ehcache, EnumSet.of(CacheOperationOutcomes.ReplaceOutcome.FAILURE));
}
/**
* Tests the effect of a {@link EhcacheWithLoaderWriter#replace(Object, Object)} for
* <ul>
* <li>key present in {@code Store}</li>
* <li>{@code Store.compute} throws</li>
* <li>{@code CacheLoaderWriter.write} throws</li>
* </ul>
*/
@Test
public void testReplaceHasStoreEntryStoreAccessExceptionCacheWritingException() throws Exception {
final FakeStore fakeStore = new FakeStore(Collections.singletonMap("key", "oldValue"));
this.store = spy(fakeStore);
doThrow(new StoreAccessException("")).when(this.store).compute(eq("key"), getAnyBiFunction());
final FakeCacheLoaderWriter fakeLoaderWriter = new FakeCacheLoaderWriter(Collections.singletonMap("key", "oldValue"));
this.cacheLoaderWriter = spy(fakeLoaderWriter);
doThrow(new Exception()).when(this.cacheLoaderWriter).write("key", "value");
final EhcacheWithLoaderWriter<String, String> ehcache = this.getEhcache(this.cacheLoaderWriter);
final InOrder ordered = inOrder(this.cacheLoaderWriter, this.spiedResilienceStrategy);
try {
ehcache.replace("key", "value");
fail();
} catch (CacheWritingException e) {
// Expected
}
verify(this.store).compute(eq("key"), getAnyBiFunction());
ordered.verify(this.cacheLoaderWriter).write(eq("key"), any(String.class));
ordered.verify(this.spiedResilienceStrategy)
.replaceFailure(eq("key"), eq("value"), any(StoreAccessException.class), any(CacheWritingException.class));
validateStats(ehcache, EnumSet.of(CacheOperationOutcomes.ReplaceOutcome.FAILURE));
}
@Test
public void testReplaceWithImmediatelyExpiredEntry() throws Exception {
final FakeStore fakeStore = new FakeStore(Collections.<String, String>singletonMap("key", "old-value"));
this.store = spy(fakeStore);
final FakeCacheLoaderWriter fakeWriter = new FakeCacheLoaderWriter(Collections.<String, String>singletonMap("key", "old-value"));
@SuppressWarnings("unchecked")
final Expiry<String, String> expiry = mock(Expiry.class);
when(expiry.getExpiryForUpdate(eq("key"), argThat(holding("old-value")), eq("value"))).thenReturn(Duration.ZERO);
final EhcacheWithLoaderWriter<String, String> ehcache = this.getEhcache(fakeWriter, expiry);
ehcache.replace("key", "value");
verify(this.store).compute(eq("key"), getAnyBiFunction());
verifyZeroInteractions(this.spiedResilienceStrategy);
assertThat(fakeStore.getEntryMap().get("key"), nullValue());
assertThat(fakeWriter.getEntryMap().get("key"), equalTo("value"));
validateStats(ehcache, EnumSet.of(CacheOperationOutcomes.ReplaceOutcome.HIT));
}
/**
* Gets an initialized {@link EhcacheWithLoaderWriter Ehcache} instance using the
* {@link CacheLoaderWriter} provided.
*
* @param cacheLoaderWriter the {@code CacheLoaderWriter} to use; may be {@code null}
*
* @return a new {@code EhcacheWithLoaderWriter} instance
*/
private EhcacheWithLoaderWriter<String, String> getEhcache(final CacheLoaderWriter<String, String> cacheLoaderWriter) {
return getEhcache(cacheLoaderWriter, Expirations.noExpiration());
}
private EhcacheWithLoaderWriter<String, String> getEhcache(final CacheLoaderWriter<String, String> cacheLoaderWriter, Expiry<? super String, ? super String> expiry) {
CacheConfiguration<String, String> config = new BaseCacheConfiguration<String, String>(String.class, String.class, null, null,
expiry, ResourcePoolsHelper.createHeapOnlyPools());
final EhcacheWithLoaderWriter<String, String> ehcache
= new EhcacheWithLoaderWriter<String, String>(config, this.store, cacheLoaderWriter, cacheEventDispatcher, LoggerFactory.getLogger(EhcacheWithLoaderWriter.class + "-" + "EhcacheWithLoaderWriterBasicReplaceTest"));
ehcache.init();
assertThat("cache not initialized", ehcache.getStatus(), CoreMatchers.is(Status.AVAILABLE));
this.spiedResilienceStrategy = this.setResilienceStrategySpy(ehcache);
return ehcache;
}
}