Search in sources :

Example 86 with Config

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

the class QueryAdvancedTest method testTwoNodesWithIndexes.

@Test
public void testTwoNodesWithIndexes() throws Exception {
    Config config = getConfig();
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
    HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
    IMap<String, Employee> map = instance1.getMap("employees");
    map.addIndex("name", false);
    map.addIndex("city", false);
    map.addIndex("age", true);
    map.addIndex("active", false);
    for (int i = 0; i < 5000; i++) {
        Employee employee = new Employee(i, "name" + i % 100, "city" + (i % 100), i % 60, ((i & 1) == 1), (double) i);
        map.put(String.valueOf(i), employee);
    }
    assertEquals(2, instance1.getCluster().getMembers().size());
    assertEquals(2, instance2.getCluster().getMembers().size());
    map = instance2.getMap("employees");
    map.addIndex("name", false);
    map.addIndex("city", false);
    map.addIndex("age", true);
    map.addIndex("active", false);
    Collection<Employee> entries = map.values(new SqlPredicate("name='name3' and city='city3' and age > 2"));
    assertEquals(50, entries.size());
    for (Employee employee : entries) {
        assertEquals("name3", employee.getName());
        assertEquals("city3", employee.getCity());
    }
    entries = map.values(new SqlPredicate("name LIKE '%name3' and city like '%city3' and age > 2"));
    assertEquals(50, entries.size());
    for (Employee employee : entries) {
        assertEquals("name3", employee.getName());
        assertEquals("city3", employee.getCity());
        assertTrue(employee.getAge() > 2);
    }
    entries = map.values(new SqlPredicate("name LIKE '%name3%' and city like '%city30%'"));
    assertEquals(50, entries.size());
    for (Employee employee : entries) {
        assertTrue(employee.getName().startsWith("name3"));
        assertTrue(employee.getCity().startsWith("city3"));
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleObjects.Employee) PortableEmployee(com.hazelcast.query.SampleObjects.PortableEmployee) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) SqlPredicate(com.hazelcast.query.SqlPredicate) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 87 with Config

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

the class QueryAdvancedTest method testMapWithIndexAfterShutDown.

@Test
public void testMapWithIndexAfterShutDown() {
    Config config = getConfig();
    String mapName = "default";
    config.getMapConfig(mapName).addMapIndexConfig(new MapIndexConfig("typeName", false));
    HazelcastInstance[] instances = createHazelcastInstanceFactory(3).newInstances(config);
    final IMap<Integer, ValueType> map = instances[0].getMap(mapName);
    final int sampleSize1 = 100;
    final int sampleSize2 = 30;
    int totalSize = sampleSize1 + sampleSize2;
    for (int i = 0; i < sampleSize1; i++) {
        map.put(i, new ValueType("type" + i));
    }
    for (int i = sampleSize1; i < totalSize; i++) {
        map.put(i, new ValueType("typex"));
    }
    Collection typexValues = map.values(new SqlPredicate("typeName = typex"));
    assertEquals(sampleSize2, typexValues.size());
    instances[1].shutdown();
    assertEquals(totalSize, map.size());
    assertTrueEventually(new AssertTask() {

        public void run() {
            final Collection values = map.values(new SqlPredicate("typeName = typex"));
            assertEquals(sampleSize2, values.size());
        }
    });
    instances[2].shutdown();
    assertEquals(totalSize, map.size());
    assertTrueEventually(new AssertTask() {

        public void run() {
            final Collection values = map.values(new SqlPredicate("typeName = typex"));
            assertEquals(sampleSize2, values.size());
        }
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MapIndexConfig(com.hazelcast.config.MapIndexConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ValueType(com.hazelcast.query.SampleObjects.ValueType) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Collection(java.util.Collection) SqlPredicate(com.hazelcast.query.SqlPredicate) AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 88 with Config

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

the class QueryBasicTest method testQueryUsingNestedPortableObject.

@Test
public void testQueryUsingNestedPortableObject() {
    Config config = getConfig();
    testQueryUsingNestedPortableObject(config, randomMapName());
}
Also used : MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 89 with Config

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

the class MemberMapRecordStateStressTest method all_records_are_readable_state_in_the_end.

@Test
public void all_records_are_readable_state_in_the_end() throws Exception {
    HazelcastInstance member1 = factory.newHazelcastInstance();
    HazelcastInstance member2 = factory.newHazelcastInstance();
    Config config = new Config();
    config.getMapConfig(mapName).setNearCacheConfig(newNearCacheConfig());
    HazelcastInstance nearCachedMember = factory.newHazelcastInstance(config);
    IMap memberMap = member1.getMap(mapName);
    // initial population of imap from member
    for (int i = 0; i < KEY_SPACE; i++) {
        memberMap.put(i, i);
    }
    List<Thread> threads = new ArrayList<Thread>();
    // member
    for (int i = 0; i < PUT_THREAD_COUNT; i++) {
        Put put = new Put(memberMap);
        threads.add(put);
    }
    // nearCachedMap
    IMap nearCachedMap = nearCachedMember.getMap(mapName);
    // member
    for (int i = 0; i < PUT_LOCAL_THREAD_COUNT; i++) {
        Put put = new Put(nearCachedMap);
        threads.add(put);
    }
    for (int i = 0; i < GET_ALL_THREAD_COUNT; i++) {
        GetAll getAll = new GetAll(nearCachedMap);
        threads.add(getAll);
    }
    for (int i = 0; i < GET_THREAD_COUNT; i++) {
        Get get = new Get(nearCachedMap);
        threads.add(get);
    }
    for (int i = 0; i < REMOVE_THREAD_COUNT; i++) {
        Remove remove = new Remove(nearCachedMap);
        threads.add(remove);
    }
    for (int i = 0; i < CLEAR_THREAD_COUNT; i++) {
        Clear clear = new Clear(nearCachedMap);
        threads.add(clear);
    }
    // start threads
    for (Thread thread : threads) {
        thread.start();
    }
    // stress for a while
    sleepSeconds(TEST_RUN_SECONDS);
    // stop threads
    stop.set(true);
    for (Thread thread : threads) {
        thread.join();
    }
    assertFinalRecordStateIsReadPermitted(member1, ((NearCachedMapProxyImpl) nearCachedMap).getNearCache());
}
Also used : IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) ArrayList(java.util.ArrayList) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 90 with Config

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

the class NearCacheBatchInvalidationTest method testBatchInvalidationRemovesEntries.

@Test
public void testBatchInvalidationRemovesEntries() throws Exception {
    String mapName = randomMapName();
    Config config = newConfig(mapName);
    config.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
    configureBatching(config, true, 12, 1);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    HazelcastInstance node1 = factory.newHazelcastInstance(config);
    HazelcastInstance node2 = factory.newHazelcastInstance(config);
    final IMap<Integer, Integer> map1 = node1.getMap(mapName);
    final IMap<Integer, Integer> map2 = node2.getMap(mapName);
    int size = 1000;
    // fill map-1
    for (int i = 0; i < size; i++) {
        map1.put(i, i);
    }
    // fill Near Cache on node-1
    for (int i = 0; i < size; i++) {
        map1.get(i);
    }
    // fill Near Cache on node-2
    for (int i = 0; i < size; i++) {
        map2.get(i);
    }
    // generate invalidation data
    for (int i = 0; i < size; i++) {
        map1.put(i, i);
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            NearCache nearCache1 = ((NearCachedMapProxyImpl) map1).getNearCache();
            NearCache nearCache2 = ((NearCachedMapProxyImpl) map2).getNearCache();
            assertEquals(0, nearCache1.size() + nearCache2.size());
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) AssertTask(com.hazelcast.test.AssertTask) NearCache(com.hazelcast.internal.nearcache.NearCache) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) 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