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));
}
}
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"));
}
}
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"));
}
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"));
}
Aggregations