use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.
the class InterceptorTest method testMapInterceptor.
@Test
public void testMapInterceptor() throws InterruptedException {
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
Config config = getConfig();
HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
final IMap<Object, Object> map = instance1.getMap("testMapInterceptor");
SimpleInterceptor interceptor = new SimpleInterceptor();
String id = map.addInterceptor(interceptor);
map.put(1, "New York");
map.put(2, "Istanbul");
map.put(3, "Tokyo");
map.put(4, "London");
map.put(5, "Paris");
map.put(6, "Cairo");
map.put(7, "Hong Kong");
try {
map.remove(1);
} catch (Exception ignore) {
}
try {
map.remove(2);
} catch (Exception ignore) {
}
assertEquals(6, map.size());
assertEquals(null, map.get(1));
assertEquals(map.get(2), "ISTANBUL:");
assertEquals(map.get(3), "TOKYO:");
assertEquals(map.get(4), "LONDON:");
assertEquals(map.get(5), "PARIS:");
assertEquals(map.get(6), "CAIRO:");
assertEquals(map.get(7), "HONG KONG:");
map.removeInterceptor(id);
map.put(8, "Moscow");
assertEquals(map.get(8), "Moscow");
assertEquals(map.get(1), null);
assertEquals(map.get(2), "ISTANBUL");
assertEquals(map.get(3), "TOKYO");
assertEquals(map.get(4), "LONDON");
assertEquals(map.get(5), "PARIS");
assertEquals(map.get(6), "CAIRO");
assertEquals(map.get(7), "HONG KONG");
}
use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.
the class InterceptorTest method testMapInterceptorOnNewMember.
@Test
public void testMapInterceptorOnNewMember() throws InterruptedException {
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
Config config = getConfig();
HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
IMap<Integer, Object> map = instance1.getMap("map");
for (int i = 0; i < 100; i++) {
map.put(i, i);
}
map.addInterceptor(new NegativeInterceptor());
for (int i = 0; i < 100; i++) {
assertEquals(i * -1, map.get(i));
}
HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
for (int i = 0; i < 100; i++) {
assertEquals(i * -1, map.get(i));
}
}
use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.
the class IssuesTest method testMapClearDoesNotTriggerEqualsOrHashCodeOnKeyObject.
// Issue #1795
@Test
public void testMapClearDoesNotTriggerEqualsOrHashCodeOnKeyObject() {
int n = 1;
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(n);
final HazelcastInstance instance = factory.newHazelcastInstance(getConfig());
final IMap<CompositeKey, String> map = instance.getMap(randomString());
final CompositeKey key = new CompositeKey();
map.put(key, "value");
map.clear();
assertFalse("hashCode method should not have been called on key during clear", CompositeKey.hashCodeCalled);
assertFalse("equals method should not have been called on key during clear", CompositeKey.equalsCalled);
}
use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.
the class IssuesTest method testIssue174NearCacheContainsKeySingleNode.
@Test
public void testIssue174NearCacheContainsKeySingleNode() {
int n = 1;
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(n);
Config config = getConfig();
config.getGroupConfig().setName("testIssue174NearCacheContainsKeySingleNode");
NearCacheConfig nearCacheConfig = new NearCacheConfig();
config.getMapConfig("default").setNearCacheConfig(nearCacheConfig);
HazelcastInstance h = factory.newHazelcastInstance(config);
IMap<String, String> map = h.getMap("testIssue174NearCacheContainsKeySingleNode");
map.put("key", "value");
assertTrue(map.containsKey("key"));
h.shutdown();
}
use of com.hazelcast.core.HazelcastInstance 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));
}
}
Aggregations