Search in sources :

Example 56 with Config

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

Example 57 with Config

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);
}
Also used : MapIndexConfig(com.hazelcast.config.MapIndexConfig) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig)

Example 58 with 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();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapListener(com.hazelcast.map.listener.MapListener) Config(com.hazelcast.config.Config) SqlPredicate(com.hazelcast.query.SqlPredicate)

Example 59 with Config

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

Example 60 with Config

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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) CountDownLatch(java.util.concurrent.CountDownLatch) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Category(org.junit.experimental.categories.Category) NightlyTest(com.hazelcast.test.annotation.NightlyTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

Config (com.hazelcast.config.Config)1190 Test (org.junit.Test)838 HazelcastInstance (com.hazelcast.core.HazelcastInstance)815 QuickTest (com.hazelcast.test.annotation.QuickTest)718 ParallelTest (com.hazelcast.test.annotation.ParallelTest)648 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)361 MapConfig (com.hazelcast.config.MapConfig)341 MapStoreConfig (com.hazelcast.config.MapStoreConfig)211 CountDownLatch (java.util.concurrent.CountDownLatch)145 NightlyTest (com.hazelcast.test.annotation.NightlyTest)142 NearCacheConfig (com.hazelcast.config.NearCacheConfig)125 Before (org.junit.Before)115 AssertTask (com.hazelcast.test.AssertTask)113 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)93 MapIndexConfig (com.hazelcast.config.MapIndexConfig)91 ClientConfig (com.hazelcast.client.config.ClientConfig)83 IMap (com.hazelcast.core.IMap)81 GroupConfig (com.hazelcast.config.GroupConfig)69 ListenerConfig (com.hazelcast.config.ListenerConfig)60 JoinConfig (com.hazelcast.config.JoinConfig)59