use of com.tangosol.net.NamedCache in project coherence-spring by coherence-community.
the class SpringNamespaceHandlerTests method testBackingMapManagerContextInjection.
/**
* Test the injection of a backing map manager context via
* the {manager-context} macro.
*/
@Test
public void testBackingMapManagerContextInjection() {
String[] asCacheNames = new String[] { "CacheBML", "CacheBMLPull" };
String[] asBeanNames = new String[] { "bml", "bmlPull" };
for (int i = 0; i < asCacheNames.length; ++i) {
NamedCache cache = getFactory().ensureCache(asCacheNames[i], null);
BeanFactory beanFactory = getFactory().getResourceRegistry().getResource(BeanFactory.class);
StubBackingMapListener bml = beanFactory.getBean(asBeanNames[i], StubBackingMapListener.class);
assertThat(bml.isContextConfigured()).isFalse();
cache.put("key", "value");
assertThat(bml.isContextConfigured()).isTrue();
}
}
use of com.tangosol.net.NamedCache in project coherence-spring by coherence-community.
the class SpringNamespaceHandlerTests method testManualRegistration.
/**
* Test the registration of a bean factory and injection of a backing map.
*/
@Test
public void testManualRegistration() {
// this local cache will be used as a backing map
LocalCache localCache = new LocalCache(100, 0, new AbstractCacheLoader() {
@Override
public Object load(Object oKey) {
return ExternalizableHelper.toBinary("mock");
}
});
// instead of creating a Spring application context, create
// a simple mock BeanFactory that returns the local cache
// created above
BeanFactory factory = mock(BeanFactory.class);
when(factory.getBean("localBackingMap")).thenReturn(localCache);
ConfigurableCacheFactory ccf = getFactory();
// register the mock BeanFactory with the cache factory so that
// it is used as the backing map (see the cache config file)
ccf.getResourceRegistry().registerResource(BeanFactory.class, "mock", factory);
NamedCache namedCache = ccf.ensureCache("CacheCustomBackingMap", null);
// cache loader always returns the same value
assertThat("mock").isEqualTo(namedCache.get("key"));
// assert backing map properties
Map mapBacking = namedCache.getCacheService().getBackingMapManager().getContext().getBackingMapContext("CacheCustomBackingMap").getBackingMap();
assertThat(LocalCache.class).isEqualTo(mapBacking.getClass());
assertThat(100).isEqualTo(((LocalCache) mapBacking).getHighUnits());
assertThat(localCache).isEqualTo(mapBacking);
}
use of com.tangosol.net.NamedCache in project coherence-spring by coherence-community.
the class CoherenceCacheManagerTests method getBasicCaches.
@Test
@Order(1)
public void getBasicCaches() throws Exception {
final NamedCache<String, String> fooCache = this.coherence.getSession().getCache("foo");
final NamedCache<String, String> barCache = this.coherence.getSession().getCache("bar");
assertThat(fooCache).isNotNull();
assertThat(barCache).isNotNull();
assertThat(fooCache).hasSize(0);
assertThat(barCache).hasSize(0);
final Cache springCache = this.cacheManager.getCache("spring");
final Cache anotherCache = this.cacheManager.getCache("cache");
assertThat(springCache instanceof CoherenceCache).isTrue();
assertThat(anotherCache instanceof CoherenceCache).isTrue();
final CoherenceCache springCoherenceCache = (CoherenceCache) springCache;
final CoherenceCache anotherCoherenceCache = (CoherenceCache) anotherCache;
final CoherenceCacheConfiguration springCoherenceCacheConfiguration = (CoherenceCacheConfiguration) ReflectionTestUtils.getField(springCoherenceCache, "cacheConfiguration");
final CoherenceCacheConfiguration anotherCoherenceCacheConfiguration = (CoherenceCacheConfiguration) ReflectionTestUtils.getField(anotherCoherenceCache, "cacheConfiguration");
assertThat(springCoherenceCacheConfiguration.getTimeToLive()).isEqualTo(Duration.ZERO);
assertThat(anotherCoherenceCacheConfiguration.getTimeToLive()).isEqualTo(Duration.ZERO);
assertThat(springCoherenceCache.size()).isEqualTo(0);
assertThat(anotherCoherenceCache.size()).isEqualTo(0);
}
Aggregations