Search in sources :

Example 21 with Config

use of com.hazelcast.config.Config in project hazelcast by hazelcast.

the class MultiMapListenerTest method testListeners.

@Test
public void testListeners() throws Exception {
    int count = 4;
    String name = randomMapName();
    Config config = new Config();
    config.getMultiMapConfig(name).setValueCollectionType(MultiMapConfig.ValueCollectionType.LIST);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(count);
    HazelcastInstance[] instances = factory.newInstances(config);
    final Set<String> keys = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
    EntryListener<String, String> listener = new EntryAdapter<String, String>() {

        public void entryAdded(EntryEvent<String, String> event) {
            keys.add(event.getKey());
        }

        public void entryRemoved(EntryEvent<String, String> event) {
            keys.remove(event.getKey());
        }

        @Override
        public void mapCleared(MapEvent event) {
            keys.clear();
        }
    };
    final MultiMap<String, String> multiMap = instances[0].getMultiMap(name);
    final String id = multiMap.addLocalEntryListener(listener);
    multiMap.put("key1", "val1");
    multiMap.put("key2", "val2");
    multiMap.put("key3", "val3");
    multiMap.put("key4", "val4");
    multiMap.put("key5", "val5");
    multiMap.put("key6", "val6");
    multiMap.put("key7", "val7");
    multiMap.put("key8", "val8");
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertContainsAll(multiMap.localKeySet(), keys);
        }
    });
    if (keys.size() != 0) {
        multiMap.remove(keys.iterator().next());
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertContainsAll(multiMap.localKeySet(), keys);
        }
    });
    multiMap.removeEntryListener(id);
    getMultiMap(instances, name).clear();
    keys.clear();
    final String id2 = multiMap.addEntryListener(listener, true);
    getMultiMap(instances, name).put("key3", "val3");
    getMultiMap(instances, name).put("key3", "val33");
    getMultiMap(instances, name).put("key4", "val4");
    getMultiMap(instances, name).remove("key3", "val33");
    assertSizeEventually(1, keys);
    getMultiMap(instances, name).clear();
    assertSizeEventually(0, keys);
    multiMap.removeEntryListener(id2);
    multiMap.addEntryListener(listener, "key7", true);
    getMultiMap(instances, name).put("key2", "val2");
    getMultiMap(instances, name).put("key3", "val3");
    getMultiMap(instances, name).put("key7", "val7");
    assertSizeEventually(1, keys);
}
Also used : MultiMapConfig(com.hazelcast.config.MultiMapConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) Config(com.hazelcast.config.Config) EntryAdapter(com.hazelcast.core.EntryAdapter) MapEvent(com.hazelcast.core.MapEvent) HazelcastInstance(com.hazelcast.core.HazelcastInstance) EntryEvent(com.hazelcast.core.EntryEvent) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 22 with Config

use of com.hazelcast.config.Config in project hazelcast by hazelcast.

the class MultiMapTransactionStressTest method createConfigWithDummyTxService.

private Config createConfigWithDummyTxService() {
    Config config = new Config();
    ServicesConfig servicesConfig = config.getServicesConfig();
    servicesConfig.addServiceConfig(new ServiceConfig().setName(DUMMY_TX_SERVICE).setEnabled(true).setImplementation(new MapTransactionStressTest.DummyTransactionalService(DUMMY_TX_SERVICE)));
    return config;
}
Also used : ServiceConfig(com.hazelcast.config.ServiceConfig) Config(com.hazelcast.config.Config) ServiceConfig(com.hazelcast.config.ServiceConfig) ServicesConfig(com.hazelcast.config.ServicesConfig) ServicesConfig(com.hazelcast.config.ServicesConfig)

Example 23 with Config

use of com.hazelcast.config.Config in project hazelcast by hazelcast.

the class MultiMapReturnedCollectionTest method createMultiMapWithCollectionType.

private MultiMap<Integer, Integer> createMultiMapWithCollectionType(MultiMapConfig.ValueCollectionType collectionType, int nodeCount) {
    String multiMapName = randomMapName();
    Config config = new Config();
    config.getMultiMapConfig(multiMapName).setValueCollectionType(collectionType);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(nodeCount);
    final HazelcastInstance[] instances = factory.newInstances(config);
    return instances[0].getMultiMap(multiMapName);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) MultiMapConfig(com.hazelcast.config.MultiMapConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory)

Example 24 with Config

use of com.hazelcast.config.Config in project hazelcast by hazelcast.

the class LocalOperationStatsImplTest method testNodeConstructor.

@Test
public void testNodeConstructor() {
    Config config = new Config();
    config.setProperty(GroupProperty.MC_MAX_VISIBLE_SLOW_OPERATION_COUNT.getName(), "139");
    HazelcastInstance hazelcastInstance = createHazelcastInstance(config);
    Node node = getNode(hazelcastInstance);
    LocalOperationStatsImpl localOperationStats = new LocalOperationStatsImpl(node);
    assertEquals(139, localOperationStats.getMaxVisibleSlowOperationCount());
    assertEquals(0, localOperationStats.getSlowOperations().size());
    assertTrue(localOperationStats.getCreationTime() > 0);
    assertNotNull(localOperationStats.toString());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) Node(com.hazelcast.instance.Node) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 25 with Config

use of com.hazelcast.config.Config in project hazelcast by hazelcast.

the class HazelcastOSGiServiceTest method groupNameIsSetToSpecifiedGroupNameWhenGroupingIsNotDisabled.

@Test
public void groupNameIsSetToSpecifiedGroupNameWhenGroupingIsNotDisabled() {
    final String GROUP_NAME = "my-osgi-group";
    HazelcastInternalOSGiService service = getService();
    Config config = new Config();
    config.getGroupConfig().setName(GROUP_NAME);
    HazelcastOSGiInstance osgiInstance = service.newHazelcastInstance(config);
    assertEquals(GROUP_NAME, osgiInstance.getConfig().getGroupConfig().getName());
    HazelcastInstance instance = osgiInstance.getDelegatedInstance();
    assertEquals(GROUP_NAME, instance.getConfig().getGroupConfig().getName());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) GroupConfig(com.hazelcast.config.GroupConfig) HazelcastInternalOSGiService(com.hazelcast.osgi.impl.HazelcastInternalOSGiService) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Aggregations

Config (com.hazelcast.config.Config)2458 Test (org.junit.Test)1570 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1465 QuickTest (com.hazelcast.test.annotation.QuickTest)1286 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1003 MapConfig (com.hazelcast.config.MapConfig)599 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)497 MapStoreConfig (com.hazelcast.config.MapStoreConfig)300 NearCacheConfig (com.hazelcast.config.NearCacheConfig)270 Before (org.junit.Before)242 ClientConfig (com.hazelcast.client.config.ClientConfig)228 SlowTest (com.hazelcast.test.annotation.SlowTest)204 NightlyTest (com.hazelcast.test.annotation.NightlyTest)186 CountDownLatch (java.util.concurrent.CountDownLatch)182 IndexConfig (com.hazelcast.config.IndexConfig)162 JoinConfig (com.hazelcast.config.JoinConfig)142 ParallelTest (com.hazelcast.test.annotation.ParallelTest)141 AssertTask (com.hazelcast.test.AssertTask)131 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)126 CacheSimpleConfig (com.hazelcast.config.CacheSimpleConfig)125