Search in sources :

Example 26 with Employee

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

the class QueryIndexingTest method assertGettersCalledNTimes.

private static void assertGettersCalledNTimes(Collection<Employee> matchingEmployees, int expectedCalls) {
    for (Employee employee : matchingEmployees) {
        verify(employee, times(expectedCalls)).getCity();
        verify(employee, times(expectedCalls)).getName();
    }
}
Also used : Employee(com.hazelcast.query.SampleTestObjects.Employee)

Example 27 with Employee

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

the class SqlPredicateTest method testSql_withEnum.

@Test
public void testSql_withEnum() {
    Employee value = createValue();
    value.setState(SampleTestObjects.State.STATE2);
    Employee nullNameValue = createValue(null);
    assertSqlMatching("state == TestUtil.State.STATE2", value);
    assertSqlMatching("state == " + SampleTestObjects.State.STATE2, value);
    assertSqlNotMatching("state == TestUtil.State.STATE1", value);
    assertSqlNotMatching("state == TestUtil.State.STATE1", nullNameValue);
    assertSqlMatching("state == NULL", nullNameValue);
}
Also used : Employee(com.hazelcast.query.SampleTestObjects.Employee) QuickTest(com.hazelcast.test.annotation.QuickTest) DateHelperTest(com.hazelcast.query.impl.DateHelperTest) Test(org.junit.Test)

Example 28 with Employee

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

the class PredicatesTest method testCriteriaAPI.

@Test
public void testCriteriaAPI() {
    Object value = new Employee(12, "abc-123-xvz", 34, true, 10D);
    EntryObject e = Predicates.newPredicateBuilder().getEntryObject();
    EntryObject e2 = e.get("age");
    Predicate predicate = e2.greaterEqual(29).and(e2.lessEqual(36));
    assertTrue(predicate.apply(createEntry("1", value)));
    e = Predicates.newPredicateBuilder().getEntryObject();
    assertTrue(e.get("id").equal(12).apply(createEntry("1", value)));
}
Also used : Employee(com.hazelcast.query.SampleTestObjects.Employee) EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 29 with Employee

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

the class EvictionTest method testMaxIdle_readThroughIndex.

private void testMaxIdle_readThroughIndex(IndexType type) {
    String mapName = randomMapName();
    Config config = getConfig();
    config.getMapConfig("default").setPerEntryStatsEnabled(true);
    // "disable" the cleaner task
    config.setProperty(PROP_TASK_PERIOD_SECONDS, Integer.toString(MAX_VALUE));
    HazelcastInstance node = createHazelcastInstance(config);
    IMap<Integer, Employee> map = node.getMap(mapName);
    map.addIndex(type, "city");
    int entryCount = 5;
    Map<Integer, Long> lastAccessTimes = new HashMap<>();
    for (int i = 0; i < entryCount; ++i) {
        String cityName = i % 2 == 0 ? "cityname" : null;
        Employee emp = new Employee(i, "name" + i, cityName, 0, true, i);
        map.put(i, emp, 0L, SECONDS, 60L, SECONDS);
        // we do get to set the last access time
        map.get(i);
        EntryView view = map.getEntryView(i);
        long lastAccessTime = view.getLastAccessTime();
        assertTrue(lastAccessTime > 0);
        lastAccessTimes.put(i, lastAccessTime);
    }
    sleepAtLeastSeconds(1);
    EntryObject entryObject = new PredicateBuilderImpl().getEntryObject();
    Predicate predicateCityNull = entryObject.get("city").isNull();
    Collection<Employee> valuesNullCity = map.values(predicateCityNull);
    Collection<Employee> valuesNotNullCity = map.values(Predicates.equal("city", "cityname"));
    assertEquals(entryCount, valuesNullCity.size() + valuesNotNullCity.size());
    // check that evaluating the predicate didn't update the last access time of the returned records
    for (int i = 0; i < entryCount; ++i) {
        EntryView view = map.getEntryView(i);
        assertNotNull(view);
        long lastAccessTime = view.getLastAccessTime();
        long prevLastAccessTime = lastAccessTimes.get(i);
        assertTrue("lastAccessTime=" + lastAccessTime + ", prevLastAccessTime=" + prevLastAccessTime, lastAccessTime == prevLastAccessTime);
    }
}
Also used : EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) HashMap(java.util.HashMap) MapConfig(com.hazelcast.config.MapConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) Config(com.hazelcast.config.Config) Predicate(com.hazelcast.query.Predicate) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleTestObjects.Employee) PredicateBuilderImpl(com.hazelcast.query.impl.PredicateBuilderImpl) EntryView(com.hazelcast.core.EntryView)

Example 30 with Employee

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

the class MapStoreTest method testIssue1115EnablingMapstoreMutatingValue.

@Test(timeout = 120000)
public void testIssue1115EnablingMapstoreMutatingValue() {
    Config config = getConfig();
    String mapName = "testIssue1115";
    MapStore mapStore = new ProcessingStore();
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setEnabled(true);
    mapStoreConfig.setImplementation(mapStore);
    config.getMapConfig(mapName).setMapStoreConfig(mapStoreConfig);
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
    nodeFactory.newHazelcastInstance(config);
    IMap<Integer, Employee> map = instance.getMap(mapName);
    Random random = new Random();
    // testing put with new object
    for (int i = 0; i < 10; i++) {
        Employee emp = new Employee();
        emp.setAge(random.nextInt(20) + 20);
        map.put(i, emp);
    }
    for (int i = 0; i < 10; i++) {
        Employee employee = map.get(i);
        assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
    }
    // testing put with existing object
    for (int i = 0; i < 10; i++) {
        Employee emp = map.get(i);
        emp.setAge(random.nextInt(20) + 20);
        map.put(i, emp);
    }
    for (int i = 0; i < 10; i++) {
        Employee employee = map.get(i);
        assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
    }
    // testing put with replace
    for (int i = 0; i < 10; i++) {
        Employee emp = map.get(i);
        emp.setAge(random.nextInt(20) + 20);
        map.replace(i, emp);
    }
    for (int i = 0; i < 10; i++) {
        Employee employee = map.get(i);
        assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
    }
    // testing put with putIfAbsent
    for (int i = 10; i < 20; i++) {
        Employee emp = new Employee();
        emp.setAge(random.nextInt(20) + 20);
        map.putIfAbsent(i, emp);
    }
    for (int i = 10; i < 20; i++) {
        Employee employee = map.get(i);
        assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleTestObjects.Employee) Random(java.util.Random) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) PostProcessingMapStore(com.hazelcast.map.PostProcessingMapStore) MapStore(com.hazelcast.map.MapStore) 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)

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