use of com.hazelcast.cache.ICache in project hazelcast by hazelcast.
the class SourcesTest method remoteCacheWithUnknownValueClass.
@Test
public void remoteCacheWithUnknownValueClass() throws Exception {
// Given
URL jarResource = Thread.currentThread().getContextClassLoader().getResource("deployment/sample-pojo-1.0-car.jar");
assertNotNull("jar not found", jarResource);
ClassLoader cl = new URLClassLoader(new URL[] { jarResource });
Class<?> personClz = cl.loadClass("com.sample.pojo.car.Car");
Object person = personClz.getConstructor(String.class, String.class).newInstance("make", "model");
ICache<String, Object> cache = remoteHz.getCacheManager().getCache(srcName);
// the class of the value is unknown to the remote IMDG member, it will be only known to Jet
cache.put("key", person);
// When
BatchSource<Entry<String, Object>> source = Sources.remoteCache(srcName, clientConfig);
// Then
p.readFrom(source).map(en -> en.getValue().toString()).writeTo(sink);
JobConfig jobConfig = new JobConfig();
jobConfig.addJar(jarResource);
hz().getJet().newJob(p, jobConfig).join();
List<Object> expected = singletonList(person.toString());
List<Object> actual = new ArrayList<>(sinkList);
assertEquals(expected, actual);
}
use of com.hazelcast.cache.ICache in project hazelcast by hazelcast.
the class Sources_withEventJournalTest method remoteCacheJournal_withUnknownValueClass.
@Test
public void remoteCacheJournal_withUnknownValueClass() throws Exception {
// Given
URL jarResource = Thread.currentThread().getContextClassLoader().getResource("deployment/sample-pojo-1.0-car.jar");
assertNotNull("jar not found", jarResource);
ClassLoader cl = new URLClassLoader(new URL[] { jarResource });
Class<?> carClz = cl.loadClass("com.sample.pojo.car.Car");
Object car = carClz.getConstructor(String.class, String.class).newInstance("make", "model");
String cacheName = JOURNALED_CACHE_PREFIX + randomName();
ICache<String, Object> cache = remoteHz.getCacheManager().getCache(cacheName);
// the class of the value is unknown to the remote IMDG member, it will be only known to Jet
cache.put("key", car);
// When
StreamSource<Entry<Object, Object>> source = Sources.remoteCacheJournal(cacheName, clientConfig, START_FROM_OLDEST);
// Then
p.readFrom(source).withoutTimestamps().map(en -> en.getValue().toString()).writeTo(sink);
JobConfig jobConfig = new JobConfig();
jobConfig.addJar(jarResource);
Job job = hz().getJet().newJob(p, jobConfig);
List<Object> expected = singletonList(car.toString());
assertTrueEventually(() -> assertEquals(expected, new ArrayList<>(sinkList)), 10);
job.cancel();
}
use of com.hazelcast.cache.ICache in project hazelcast by hazelcast.
the class HazelcastConnectorTest method when_streamCache_withFilterAndProjection.
@Test
public void when_streamCache_withFilterAndProjection() {
DAG dag = new DAG();
Vertex source = dag.newVertex("source", SourceProcessors.<Integer, Integer, Integer>streamCacheP(streamSourceName, event -> !event.getKey().equals(0), EventJournalCacheEvent::getKey, START_FROM_OLDEST, eventTimePolicy(i -> i, limitingLag(0), 1, 0, 10_000)));
Vertex sink = dag.newVertex("sink", writeListP(streamSinkName));
dag.edge(between(source, sink));
Job job = instance().getJet().newJob(dag);
ICache<Integer, Integer> sourceCache = instance().getCacheManager().getCache(streamSourceName);
range(0, ENTRY_COUNT).forEach(i -> sourceCache.put(i, i));
assertSizeEventually(ENTRY_COUNT - 1, instance().getList(streamSinkName));
assertFalse(instance().getList(streamSinkName).contains(0));
assertTrue(instance().getList(streamSinkName).contains(1));
job.cancel();
}
use of com.hazelcast.cache.ICache in project hazelcast by hazelcast.
the class CacheExpirationManagerTest method expiration_task_starts_on_new_node_after_migration_when_there_is_expirable_entry.
@Test
public void expiration_task_starts_on_new_node_after_migration_when_there_is_expirable_entry() {
Config config = getConfig();
config.setProperty(taskPeriodSecondsPropName(), "1");
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
final HazelcastInstance node1 = factory.newHazelcastInstance(config);
CacheManager cacheManager = createCacheManager(node1);
Cache cache = cacheManager.createCache("test", new CacheConfig());
((ICache) cache).put(1, 1, new HazelcastExpiryPolicy(ONE_HOUR, ONE_HOUR, ONE_HOUR));
final HazelcastInstance node2 = factory.newHazelcastInstance(config);
node1.shutdown();
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertTrue("There should be one ClearExpiredRecordsTask started", hasClearExpiredRecordsTaskStarted(node2));
}
});
}
use of com.hazelcast.cache.ICache in project hazelcast by hazelcast.
the class TimedMemberStateTest method testOnlyCachesWithStatsEnabled_areReportedInTimedMemberState.
@Test
public void testOnlyCachesWithStatsEnabled_areReportedInTimedMemberState() {
// create 100 caches with stats enabled
for (int i = 0; i < 100; i++) {
hz.getCacheManager().getCache(CACHE_WITH_STATS_PREFIX + i);
}
// create 50 caches with stats disabled
for (int i = 0; i < 50; i++) {
ICache cacheWithoutStats = hz.getCacheManager().getCache(CACHE_WITHOUT_STATS_PREFIX + i);
// explicitly request local stats -> this registers an empty stats object in CacheService
cacheWithoutStats.getLocalCacheStatistics();
}
MemberStateImpl memberState = createState().getMemberState();
for (int i = 0; i < 100; i++) {
assertContains(memberState.getCachesWithStats(), getDistributedObjectName(CACHE_WITH_STATS_PREFIX + i));
assertNotContains(memberState.getCachesWithStats(), getDistributedObjectName(CACHE_WITHOUT_STATS_PREFIX + i));
}
}
Aggregations