Search in sources :

Example 26 with NamedCache

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();
    }
}
Also used : BeanFactory(org.springframework.beans.factory.BeanFactory) NamedCache(com.tangosol.net.NamedCache) Test(org.junit.jupiter.api.Test)

Example 27 with NamedCache

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);
}
Also used : LocalCache(com.tangosol.net.cache.LocalCache) AbstractCacheLoader(com.tangosol.net.cache.AbstractCacheLoader) BeanFactory(org.springframework.beans.factory.BeanFactory) ConfigurableCacheFactory(com.tangosol.net.ConfigurableCacheFactory) Map(java.util.Map) NamedCache(com.tangosol.net.NamedCache) Test(org.junit.jupiter.api.Test)

Example 28 with NamedCache

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);
}
Also used : Cache(org.springframework.cache.Cache) NamedCache(com.tangosol.net.NamedCache) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Aggregations

NamedCache (com.tangosol.net.NamedCache)28 Test (org.junit.jupiter.api.Test)14 Map (java.util.Map)10 BeanFactory (org.springframework.beans.factory.BeanFactory)6 VisualVMModel (com.oracle.coherence.plugin.visualvm.VisualVMModel)3 RequestSender (com.oracle.coherence.plugin.visualvm.helper.RequestSender)3 CacheData (com.oracle.coherence.plugin.visualvm.tablemodel.model.CacheData)3 CacheDetailData (com.oracle.coherence.plugin.visualvm.tablemodel.model.CacheDetailData)3 ClusterData (com.oracle.coherence.plugin.visualvm.tablemodel.model.ClusterData)3 Data (com.oracle.coherence.plugin.visualvm.tablemodel.model.Data)3 FederationData (com.oracle.coherence.plugin.visualvm.tablemodel.model.FederationData)3 FederationDestinationDetailsData (com.oracle.coherence.plugin.visualvm.tablemodel.model.FederationDestinationDetailsData)3 FederationOriginDetailsData (com.oracle.coherence.plugin.visualvm.tablemodel.model.FederationOriginDetailsData)3 MemberData (com.oracle.coherence.plugin.visualvm.tablemodel.model.MemberData)3 PersistenceData (com.oracle.coherence.plugin.visualvm.tablemodel.model.PersistenceData)3 ProxyData (com.oracle.coherence.plugin.visualvm.tablemodel.model.ProxyData)3 RamJournalData (com.oracle.coherence.plugin.visualvm.tablemodel.model.RamJournalData)3 ServiceData (com.oracle.coherence.plugin.visualvm.tablemodel.model.ServiceData)3 ServiceMemberData (com.oracle.coherence.plugin.visualvm.tablemodel.model.ServiceMemberData)3 ExtensibleConfigurableCacheFactory (com.tangosol.net.ExtensibleConfigurableCacheFactory)3