Search in sources :

Example 31 with Employee

use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.

the class MapStoreWriteThroughTest method testTwoMemberWriteThrough.

@Test(timeout = 120000)
public void testTwoMemberWriteThrough() throws Exception {
    TestMapStore testMapStore = new TestMapStore(1, 1, 1);
    testMapStore.setLoadAllKeys(false);
    Config config = newConfig(testMapStore, 0);
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
    HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
    nodeFactory.newHazelcastInstance(config);
    Employee employee = new Employee("joe", 25, true, 100.00);
    Employee employee2 = new Employee("jay", 35, false, 100.00);
    testMapStore.insert("1", employee);
    IMap<String, Employee> map = instance.getMap("default");
    map.addIndex(IndexType.HASH, "name");
    assertEquals(0, map.size());
    assertEquals(employee, map.get("1"));
    assertEquals(employee, testMapStore.getStore().get("1"));
    assertEquals(1, map.size());
    map.put("2", employee2);
    assertEquals(employee2, testMapStore.getStore().get("2"));
    assertEquals(2, testMapStore.getStore().size());
    assertEquals(2, map.size());
    map.remove("2");
    assertEquals(1, testMapStore.getStore().size());
    assertEquals(1, map.size());
    testMapStore.assertAwait(10);
    assertEquals(5, testMapStore.callCount.get());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleTestObjects.Employee) TestMapStore(com.hazelcast.map.impl.mapstore.MapStoreTest.TestMapStore) MapConfig(com.hazelcast.config.MapConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) Config(com.hazelcast.config.Config) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 32 with Employee

use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.

the class MapStoreWriteThroughTest method testOneMemberWriteThroughWithLRU.

@Test(timeout = 120000)
public void testOneMemberWriteThroughWithLRU() {
    final int size = 10000;
    TestMapStore testMapStore = new TestMapStore(size * 2, 1, 1);
    testMapStore.setLoadAllKeys(false);
    Config config = newConfig(testMapStore, 0);
    config.setProperty(ClusterProperty.PARTITION_COUNT.getName(), "1");
    MapConfig mapConfig = config.getMapConfig("default");
    EvictionConfig evictionConfig = mapConfig.getEvictionConfig();
    evictionConfig.setEvictionPolicy(EvictionPolicy.LRU);
    evictionConfig.setSize(size);
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
    HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
    IMap<Integer, Employee> map = instance.getMap("default");
    final CountDownLatch countDownLatch = new CountDownLatch(size);
    map.addEntryListener(new EntryAdapter() {

        @Override
        public void entryEvicted(EntryEvent event) {
            countDownLatch.countDown();
        }
    }, false);
    for (int i = 0; i < size * 2; i++) {
        // trigger eviction
        if (i == (size * 2) - 1 || i == size) {
            sleepMillis(1001);
        }
        map.put(i, new Employee("joe", i, true, 100.00));
    }
    assertEquals(testMapStore.getStore().size(), size * 2);
    assertOpenEventually(countDownLatch);
    final String msgFailure = String.format("map size: %d put count: %d", map.size(), size);
    assertTrue(msgFailure, map.size() > size / 2);
    assertTrue(msgFailure, map.size() <= size);
    assertEquals(testMapStore.getStore().size(), size * 2);
}
Also used : MapConfig(com.hazelcast.config.MapConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) Config(com.hazelcast.config.Config) EvictionConfig(com.hazelcast.config.EvictionConfig) EntryAdapter(com.hazelcast.core.EntryAdapter) CountDownLatch(java.util.concurrent.CountDownLatch) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleTestObjects.Employee) TestMapStore(com.hazelcast.map.impl.mapstore.MapStoreTest.TestMapStore) EntryEvent(com.hazelcast.core.EntryEvent) MapConfig(com.hazelcast.config.MapConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 33 with Employee

use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.

the class QueryAdvancedTest method testOneMemberWithIndex.

@Test
public void testOneMemberWithIndex() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<String, Employee> map = instance.getMap("employees");
    map.addIndex(IndexType.HASH, "name");
    map.addIndex(IndexType.SORTED, "age");
    map.addIndex(IndexType.HASH, "active");
    QueryBasicTest.doFunctionalQueryTest(map);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) PortableEmployee(com.hazelcast.query.SampleTestObjects.PortableEmployee) Employee(com.hazelcast.query.SampleTestObjects.Employee) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 34 with Employee

use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.

the class QueryAdvancedTest method testSecondMemberAfterAddingIndexes.

@Test
public void testSecondMemberAfterAddingIndexes() {
    Config config = getConfig();
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
    IMap<String, Employee> map = instance.getMap("employees");
    map.addIndex(IndexType.HASH, "name");
    map.addIndex(IndexType.SORTED, "age");
    map.addIndex(IndexType.HASH, "active");
    nodeFactory.newHazelcastInstance(config);
    QueryBasicTest.doFunctionalQueryTest(map);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) PortableEmployee(com.hazelcast.query.SampleTestObjects.PortableEmployee) Employee(com.hazelcast.query.SampleTestObjects.Employee) Config(com.hazelcast.config.Config) IndexConfig(com.hazelcast.config.IndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 35 with Employee

use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.

the class QueryBasicTest method doFunctionalQueryTest.

public static void doFunctionalQueryTest(IMap<String, Employee> map) {
    map.put("1", new Employee("joe", 33, false, 14.56));
    map.put("2", new Employee("ali", 23, true, 15.00));
    for (int i = 3; i < 103; i++) {
        map.put(String.valueOf(i), new Employee("name" + i, i % 60, ((i & 1) == 1), i));
    }
    Set<Map.Entry<String, Employee>> entries = map.entrySet();
    assertEquals(102, entries.size());
    int entryCount = 0;
    for (Map.Entry entry : entries) {
        Employee employee = (Employee) entry.getValue();
        assertNotNull(employee);
        entryCount++;
    }
    assertEquals(102, entryCount);
    EntryObject entryObject = Predicates.newPredicateBuilder().getEntryObject();
    Predicate predicate = entryObject.is("active").and(entryObject.get("age").equal(23));
    entries = map.entrySet(predicate);
    for (Map.Entry entry : entries) {
        Employee employee = (Employee) entry.getValue();
        assertEquals(employee.getAge(), 23);
        assertTrue(employee.isActive());
    }
    map.remove("2");
    entries = map.entrySet(predicate);
    assertEquals(2, entries.size());
    for (Map.Entry entry : entries) {
        Employee employee = (Employee) entry.getValue();
        assertEquals(employee.getAge(), 23);
        assertTrue(employee.isActive());
    }
    entries = map.entrySet(Predicates.sql(" (age >= " + 30 + ") AND (age <= " + 40 + ")"));
    assertEquals(23, entries.size());
    for (Map.Entry entry : entries) {
        Employee employee = (Employee) entry.getValue();
        assertTrue(employee.getAge() >= 30);
        assertTrue(employee.getAge() <= 40);
    }
}
Also used : Employee(com.hazelcast.query.SampleTestObjects.Employee) EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) Map(java.util.Map) IMap(com.hazelcast.map.IMap) Predicate(com.hazelcast.query.Predicate)

Aggregations

Employee (com.hazelcast.query.SampleTestObjects.Employee)52 Test (org.junit.Test)42 QuickTest (com.hazelcast.test.annotation.QuickTest)39 HazelcastInstance (com.hazelcast.core.HazelcastInstance)38 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)37 Config (com.hazelcast.config.Config)25 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)23 MapStoreConfig (com.hazelcast.config.MapStoreConfig)17 PortableEmployee (com.hazelcast.query.SampleTestObjects.PortableEmployee)14 IndexConfig (com.hazelcast.config.IndexConfig)13 IMap (com.hazelcast.map.IMap)11 MapConfig (com.hazelcast.config.MapConfig)8 Collection (java.util.Collection)8 Map (java.util.Map)8 Predicate (com.hazelcast.query.Predicate)7 EntryObject (com.hazelcast.query.PredicateBuilder.EntryObject)7 HashMap (java.util.HashMap)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 NightlyTest (com.hazelcast.test.annotation.NightlyTest)5 EvictionConfig (com.hazelcast.config.EvictionConfig)4