Search in sources :

Example 36 with NamedCache

use of com.tangosol.net.NamedCache in project oracle-bedrock by coherence-community.

the class AbstractCoherenceCacheServerTest method shouldAccessNamedCache.

/**
 * Ensure that we can create and use a NamedCache via a CoherenceCacheServer.
 */
@Test
public void shouldAccessNamedCache() {
    Platform platform = getPlatform();
    try (CoherenceCacheServer server = platform.launch(CoherenceCacheServer.class, ClusterPort.automatic(), LocalHost.only(), Console.system())) {
        assertThat(server, new GetLocalMemberId(), is(1));
        assertThat(server, new GetClusterSize(), is(1));
        NamedCache namedCache = server.getCache("dist-example");
        // ----- use NamedCache.clear -----
        namedCache.clear();
        assertThat(namedCache.size(), is(0));
        // ----- use NamedCache.put and NamedCache.get -----
        namedCache.put("key", "hello");
        assertThat(namedCache.size(), is(1));
        assertThat((String) namedCache.get("key"), is("hello"));
        // ----- use NamedCache.invokeAll -----
        Map map = namedCache.invokeAll(PresentFilter.INSTANCE, new GetProcessor());
        assertThat(map, notNullValue());
        assertThat(map.size(), is(1));
        assertThat((String) map.get("key"), is("hello"));
        // ----- use NamedCache.keySet -----
        Set keySet = namedCache.keySet();
        assertThat(keySet, notNullValue());
        assertThat(keySet.size(), is(1));
        assertThat(keySet.contains("key"), is(true));
        // ----- use NamedCache.entrySet -----
        Set entrySet = namedCache.entrySet();
        assertThat(entrySet, notNullValue());
        assertThat(entrySet.size(), is(1));
        assertThat(entrySet.contains(new AbstractMap.SimpleEntry("key", "hello")), is(true));
        // ----- use NamedCache.values -----
        Collection values = namedCache.values();
        assertThat(values, notNullValue());
        assertThat(values.size(), is(1));
        assertThat(values.contains("hello"), is(true));
        namedCache.clear();
        assertThat(invoking(namedCache).size(), is(0));
        namedCache.put("key", "hello");
        assertThat(namedCache.size(), is(1));
        assertThat((String) namedCache.get("key"), is("hello"));
        // ----- use NamedCache.remove -----
        namedCache.remove("key");
        assertThat(namedCache.size(), is(0));
        // ----- use NamedCache.putAll -----
        HashMap<String, Integer> putAllMap = new HashMap<>();
        long sum = 0;
        for (int i = 1; i < 5; i++) {
            String key = Integer.toString(i);
            putAllMap.put(key, new Integer(i));
            sum += i;
        }
        namedCache.putAll(putAllMap);
        assertThat(namedCache.size(), is(putAllMap.size()));
        // ----- use NamedCache.getAll -----
        Map<String, Integer> getAllResults = namedCache.getAll(putAllMap.keySet());
        assertThat(getAllResults, MapMatcher.sameAs(putAllMap));
        Map<String, Integer> otherGetAllResults = namedCache.getAll(namedCache.keySet());
        assertThat(otherGetAllResults, MapMatcher.sameAs(putAllMap));
        // ----- use NamedCache.aggregate -----
        long longSum = (Long) namedCache.aggregate(PresentFilter.INSTANCE, new LongSum(IdentityExtractor.INSTANCE));
        assertThat(longSum, is(sum));
        long anotherLongSum = (Long) namedCache.aggregate(putAllMap.keySet(), new LongSum(IdentityExtractor.INSTANCE));
        assertThat(anotherLongSum, is(sum));
    }
}
Also used : Set(java.util.Set) LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) Platform(com.oracle.bedrock.runtime.Platform) HashMap(java.util.HashMap) LongSum(com.tangosol.util.aggregator.LongSum) NamedCache(com.tangosol.net.NamedCache) GetLocalMemberId(com.oracle.bedrock.runtime.coherence.callables.GetLocalMemberId) GetClusterSize(com.oracle.bedrock.runtime.coherence.callables.GetClusterSize) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map) AbstractMap(java.util.AbstractMap) AbstractTest(com.oracle.bedrock.testsupport.junit.AbstractTest) Test(org.junit.Test)

Example 37 with NamedCache

use of com.tangosol.net.NamedCache in project oracle-bedrock by coherence-community.

the class AbstractCoherenceClusterBuilderTest method shouldAccessNamedCache.

/**
 * Ensure that we can create and use a NamedCache via a CoherenceCacheServer.
 */
@Test
public void shouldAccessNamedCache() {
    Capture<Integer> wkaPort = new Capture<>(LocalPlatform.get().getAvailablePorts());
    final int CLUSTER_SIZE = 3;
    String localHost = System.getProperty("tangosol.coherence.localhost", "127.0.0.1");
    AvailablePortIterator availablePorts = LocalPlatform.get().getAvailablePorts();
    ClusterPort clusterPort = ClusterPort.of(new Capture<>(availablePorts));
    CoherenceClusterBuilder builder = new CoherenceClusterBuilder();
    builder.include(CLUSTER_SIZE, CoherenceClusterMember.class, WellKnownAddress.of(localHost, wkaPort), clusterPort, LocalHost.of(localHost, wkaPort), ClusterName.of("Access"));
    try (CoherenceCluster cluster = builder.build(getPlatform(), Console.system())) {
        assertThat(invoking(cluster).getClusterSize(), is(CLUSTER_SIZE));
        NamedCache namedCache = cluster.getCache("dist-example");
        assertThat(namedCache.size(), is(0));
        namedCache.put("key", "hello");
        assertThat(namedCache.size(), is(1));
        assertThat((String) namedCache.get("key"), is("hello"));
    }
}
Also used : AvailablePortIterator(com.oracle.bedrock.runtime.network.AvailablePortIterator) ClusterPort(com.oracle.bedrock.runtime.coherence.options.ClusterPort) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Capture(com.oracle.bedrock.util.Capture) NamedCache(com.tangosol.net.NamedCache) AbstractTest(com.oracle.bedrock.testsupport.junit.AbstractTest) Test(org.junit.Test)

Example 38 with NamedCache

use of com.tangosol.net.NamedCache in project oracle-bedrock by coherence-community.

the class CoherenceClusterExtensionTest method shouldCreateExtendClientSession.

/**
 * Ensure that a {@link ExtendClient} session can be created against the {@link CoherenceClusterResource}.
 */
@Test
public void shouldCreateExtendClientSession() {
    ConfigurableCacheFactory session = coherenceResource.createSession(SessionBuilders.extendClient("client-cache-config.xml"));
    NamedCache cache = session.ensureCache("dist-example", null);
    assertThat(coherenceResource.getCluster().getClusterSize(), is(greaterThanOrEqualTo(3)));
    cache.put("message", "hello world");
    Eventually.assertThat(invoking(coherenceResource.getCluster().getCache("dist-example")).get("message"), is((Object) "hello world"));
}
Also used : ConfigurableCacheFactory(com.tangosol.net.ConfigurableCacheFactory) NamedCache(com.tangosol.net.NamedCache) Test(org.junit.jupiter.api.Test)

Example 39 with NamedCache

use of com.tangosol.net.NamedCache in project oracle-bedrock by coherence-community.

the class CoherenceClusterExtensionTest method shouldCreateStorageDisabledMemberSession.

/**
 * Ensure that a {@link StorageDisabledMember} session can be created against the {@link CoherenceClusterResource}.
 */
@Test
public void shouldCreateStorageDisabledMemberSession() {
    ConfigurableCacheFactory session = coherenceResource.createSession(SessionBuilders.storageDisabledMember());
    NamedCache cache = session.ensureCache("dist-example", null);
    Eventually.assertThat(coherenceResource.getCluster().getClusterSize(), is(4));
    cache.put("message", "hello world");
    Eventually.assertThat(invoking(coherenceResource.getCluster().getCache("dist-example")).get("message"), is((Object) "hello world"));
}
Also used : ConfigurableCacheFactory(com.tangosol.net.ConfigurableCacheFactory) NamedCache(com.tangosol.net.NamedCache) Test(org.junit.jupiter.api.Test)

Aggregations

NamedCache (com.tangosol.net.NamedCache)39 Test (org.junit.jupiter.api.Test)19 Map (java.util.Map)11 Test (org.junit.Test)6 BeanFactory (org.springframework.beans.factory.BeanFactory)6 ConfigurableCacheFactory (com.tangosol.net.ConfigurableCacheFactory)5 CacheMap (com.tangosol.net.cache.CacheMap)4 AbstractTest (com.oracle.bedrock.testsupport.junit.AbstractTest)3 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