Search in sources :

Example 1 with MultiMapConfig

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

the class TestFullApplicationContext method testMultimapConfig.

@Test
public void testMultimapConfig() {
    MultiMapConfig testMultiMapConfig = config.getMultiMapConfig("testMultimap");
    assertEquals(MultiMapConfig.ValueCollectionType.LIST, testMultiMapConfig.getValueCollectionType());
    assertEquals(2, testMultiMapConfig.getEntryListenerConfigs().size());
    assertFalse(testMultiMapConfig.isBinary());
    assertFalse(testMultiMapConfig.isStatisticsEnabled());
    for (EntryListenerConfig listener : testMultiMapConfig.getEntryListenerConfigs()) {
        if (listener.getClassName() != null) {
            assertNull(listener.getImplementation());
            assertTrue(listener.isIncludeValue());
            assertFalse(listener.isLocal());
        } else {
            assertNotNull(listener.getImplementation());
            assertEquals(entryListener, listener.getImplementation());
            assertTrue(listener.isLocal());
            assertTrue(listener.isIncludeValue());
        }
    }
}
Also used : MultiMapConfig(com.hazelcast.config.MultiMapConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) Test(org.junit.Test) QuickTest(com.hazelcast.test.annotation.QuickTest)

Example 2 with MultiMapConfig

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

the class MultiMapTestsFrom2X method testContains.

@Test
public void testContains() throws Exception {
    final HazelcastInstance instance = createHazelcastInstance();
    instance.getConfig().addMultiMapConfig(new MultiMapConfig().setName("testContains").setBinary(false));
    MultiMap<String, ComplexValue> multiMap = instance.getMultiMap("testContains");
    // MultiMap
    assertTrue(multiMap.put("1", new ComplexValue("text", 1)));
    assertFalse(multiMap.put("1", new ComplexValue("text", 1)));
    assertFalse(multiMap.put("1", new ComplexValue("text", 2)));
    assertTrue(multiMap.containsValue(new ComplexValue("text", 1)));
    assertTrue(multiMap.containsValue(new ComplexValue("text", 2)));
    assertTrue(multiMap.remove("1", new ComplexValue("text", 3)));
    assertFalse(multiMap.remove("1", new ComplexValue("text", 1)));
    assertTrue(multiMap.put("1", new ComplexValue("text", 1)));
    assertTrue(multiMap.containsEntry("1", new ComplexValue("text", 1)));
    assertTrue(multiMap.containsEntry("1", new ComplexValue("text", 2)));
    assertTrue(multiMap.remove("1", new ComplexValue("text", 1)));
    // MultiMap List
    instance.getConfig().addMultiMapConfig(new MultiMapConfig().setName("testContains.list").setValueCollectionType("LIST").setBinary(false));
    MultiMap<String, ComplexValue> mmList = instance.getMultiMap("testContains.list");
    assertTrue(mmList.put("1", new ComplexValue("text", 1)));
    assertTrue(mmList.put("1", new ComplexValue("text", 1)));
    assertTrue(mmList.put("1", new ComplexValue("text", 2)));
    assertEquals(3, mmList.size());
    assertTrue(mmList.remove("1", new ComplexValue("text", 4)));
    assertEquals(2, mmList.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MultiMapConfig(com.hazelcast.config.MultiMapConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with MultiMapConfig

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

the class MultiMapTest method testIssue1882.

/**
     * ConcurrentModificationExceptions
     */
@Test
public void testIssue1882() {
    String mmName = "mm";
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    final Config config = new Config();
    final MultiMapConfig multiMapConfig = config.getMultiMapConfig(mmName);
    multiMapConfig.setValueCollectionType(MultiMapConfig.ValueCollectionType.LIST);
    final HazelcastInstance instance1 = factory.newHazelcastInstance(config);
    final HazelcastInstance instance2 = factory.newHazelcastInstance(config);
    final String key = generateKeyOwnedBy(instance1);
    final MultiMap<Object, Object> mm1 = instance1.getMultiMap("mm");
    mm1.put(key, 1);
    mm1.put(key, 2);
    final AtomicBoolean running = new AtomicBoolean(true);
    new Thread() {

        @Override
        public void run() {
            int count = 3;
            while (running.get()) {
                mm1.put(key, count++);
            }
        }
    }.start();
    for (int i = 0; i < 10; i++) {
        mm1.get(key);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MultiMapConfig(com.hazelcast.config.MultiMapConfig) Config(com.hazelcast.config.Config) MultiMapConfig(com.hazelcast.config.MultiMapConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with MultiMapConfig

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

the class MultiMapService method init.

@Override
public void init(final NodeEngine nodeEngine, Properties properties) {
    int partitionCount = nodeEngine.getPartitionService().getPartitionCount();
    for (int partition = 0; partition < partitionCount; partition++) {
        partitionContainers[partition] = new MultiMapPartitionContainer(this, partition);
    }
    final LockService lockService = nodeEngine.getSharedService(LockService.SERVICE_NAME);
    if (lockService != null) {
        lockService.registerLockStoreConstructor(SERVICE_NAME, new ConstructorFunction<ObjectNamespace, LockStoreInfo>() {

            @Override
            public LockStoreInfo createNew(final ObjectNamespace key) {
                String name = key.getObjectName();
                final MultiMapConfig multiMapConfig = nodeEngine.getConfig().findMultiMapConfig(name);
                return new LockStoreInfo() {

                    @Override
                    public int getBackupCount() {
                        return multiMapConfig.getSyncBackupCount();
                    }

                    @Override
                    public int getAsyncBackupCount() {
                        return multiMapConfig.getAsyncBackupCount();
                    }
                };
            }
        });
    }
}
Also used : LockStoreInfo(com.hazelcast.concurrent.lock.LockStoreInfo) LockService(com.hazelcast.concurrent.lock.LockService) MultiMapConfig(com.hazelcast.config.MultiMapConfig) ObjectNamespace(com.hazelcast.spi.ObjectNamespace) MigrationEndpoint(com.hazelcast.spi.partition.MigrationEndpoint)

Example 5 with MultiMapConfig

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

the class MultiMapOperation method getValueCollectionType.

public final MultiMapConfig.ValueCollectionType getValueCollectionType(MultiMapContainer container) {
    checkNotNull(container, "Argument container should not be null");
    MultiMapConfig config = container.getConfig();
    return config.getValueCollectionType();
}
Also used : MultiMapConfig(com.hazelcast.config.MultiMapConfig)

Aggregations

MultiMapConfig (com.hazelcast.config.MultiMapConfig)5 QuickTest (com.hazelcast.test.annotation.QuickTest)3 Test (org.junit.Test)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 LockService (com.hazelcast.concurrent.lock.LockService)1 LockStoreInfo (com.hazelcast.concurrent.lock.LockStoreInfo)1 Config (com.hazelcast.config.Config)1 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)1 ObjectNamespace (com.hazelcast.spi.ObjectNamespace)1 MigrationEndpoint (com.hazelcast.spi.partition.MigrationEndpoint)1 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1