use of com.hazelcast.config.Config in project hazelcast by hazelcast.
the class IssuesTest method testMapInterceptorInstanceAware.
@Test
public void testMapInterceptorInstanceAware() {
Config config = getConfig();
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance hz1 = factory.newHazelcastInstance(config);
HazelcastInstance hz2 = factory.newHazelcastInstance(config);
IMap<Object, Object> map = hz1.getMap("test");
InstanceAwareMapInterceptorImpl interceptor = new InstanceAwareMapInterceptorImpl();
map.addInterceptor(interceptor);
assertNotNull(interceptor.hazelcastInstance);
assertEquals(hz1, interceptor.hazelcastInstance);
for (int i = 0; i < 100; i++) {
map.put(i, i);
}
for (int i = 0; i < 100; i++) {
assertEquals("notNull", map.get(i));
}
}
use of com.hazelcast.config.Config in project hazelcast by hazelcast.
the class MapIndexBackupTest method createNode.
private HazelcastInstance createNode(TestHazelcastInstanceFactory instanceFactory) {
Config config = getConfig();
MapConfig mapConfig = config.getMapConfig("book");
mapConfig.addMapIndexConfig(new MapIndexConfig("author", false));
mapConfig.addMapIndexConfig(new MapIndexConfig("year", true));
mapConfig.setMapStoreConfig(new MapStoreConfig().setImplementation(new BookMapLoader()));
mapConfig.setBackupCount(1);
return instanceFactory.newHazelcastInstance(config);
}
use of com.hazelcast.config.Config in project hazelcast by hazelcast.
the class MapListenerTest method main.
public static void main(String[] args) throws InterruptedException {
// create Hazelcast instance
Config config = new Config();
config.setInstanceName("hz-maplistener");
config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
config.getNetworkConfig().getInterfaces().setInterfaces(Arrays.asList(new String[] { "127.0.0.1" }));
HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
IMap<String, Person> map = hz.getMap("map");
MapListener listener = new AllListener();
map.addEntryListener(listener, new SqlPredicate("age > " + AGE_THRESHOLD), true);
MapRandomizer mapRandomizer = new MapRandomizer(map);
Thread t = new Thread(mapRandomizer);
t.start();
// let it run for 1 minute
Thread.sleep(60000);
mapRandomizer.setRunning(false);
// assertions
assertCount(ENTRIES, ENTRIES_OBSERVED, "entries");
assertCount(EXITS, EXITS_OBSERVED, "exits");
// dumpMap(map);
hz.shutdown();
}
use of com.hazelcast.config.Config in project hazelcast by hazelcast.
the class MapLockTest method testLockEviction2.
@Test
public void testLockEviction2() throws Exception {
final TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
final Config config = getConfig();
final HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
final HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
warmUpPartitions(instance2, instance1);
final String name = randomString();
final IMap<Integer, Integer> map = instance1.getMap(name);
Random rand = new Random();
for (int i = 0; i < 5; i++) {
map.lock(i, rand.nextInt(5) + 1, TimeUnit.SECONDS);
}
final CountDownLatch latch = new CountDownLatch(5);
Thread t = new Thread(new Runnable() {
public void run() {
for (int i = 0; i < 5; i++) {
map.lock(i);
latch.countDown();
}
}
});
t.start();
assertTrue(latch.await(10, TimeUnit.SECONDS));
}
use of com.hazelcast.config.Config in project hazelcast by hazelcast.
the class MapLockTest method testLockEvictionWithMigration.
@Category(NightlyTest.class)
@Test
public void testLockEvictionWithMigration() throws Exception {
final TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
final Config config = getConfig();
final HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
final String name = randomString();
final IMap<Integer, Object> map = instance1.getMap(name);
for (int i = 0; i < 1000; i++) {
map.lock(i, 20, TimeUnit.SECONDS);
}
final HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
final HazelcastInstance instance3 = nodeFactory.newHazelcastInstance(config);
for (int i = 0; i < 1000; i++) {
assertTrue(map.isLocked(i));
}
final CountDownLatch latch = new CountDownLatch(1000);
Thread t = new Thread(new Runnable() {
public void run() {
for (int i = 0; i < 1000; i++) {
map.lock(i);
latch.countDown();
}
}
});
t.start();
assertOpenEventually(latch);
}
Aggregations