Search in sources :

Example 91 with HazelcastInstance

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");
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) MapStoreConfig(com.hazelcast.config.MapStoreConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 92 with HazelcastInstance

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));
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) MapStoreConfig(com.hazelcast.config.MapStoreConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 93 with HazelcastInstance

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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 94 with HazelcastInstance

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();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) GlobalSerializerConfig(com.hazelcast.config.GlobalSerializerConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 95 with HazelcastInstance

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));
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) GlobalSerializerConfig(com.hazelcast.config.GlobalSerializerConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

HazelcastInstance (com.hazelcast.core.HazelcastInstance)2084 Test (org.junit.Test)1684 QuickTest (com.hazelcast.test.annotation.QuickTest)1466 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1389 Config (com.hazelcast.config.Config)815 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)665 AssertTask (com.hazelcast.test.AssertTask)263 MapConfig (com.hazelcast.config.MapConfig)254 CountDownLatch (java.util.concurrent.CountDownLatch)251 NightlyTest (com.hazelcast.test.annotation.NightlyTest)230 MapStoreConfig (com.hazelcast.config.MapStoreConfig)169 IMap (com.hazelcast.core.IMap)149 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)144 ClientConfig (com.hazelcast.client.config.ClientConfig)137 Before (org.junit.Before)111 NearCacheConfig (com.hazelcast.config.NearCacheConfig)106 Member (com.hazelcast.core.Member)99 Map (java.util.Map)96 SlowTest (com.hazelcast.test.annotation.SlowTest)94 SqlPredicate (com.hazelcast.query.SqlPredicate)83