Search in sources :

Example 46 with Employee

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

the class MapStoreWriteThroughTest method testOneMemberWriteThroughWithLRU.

@Test(timeout = 120000)
public void testOneMemberWriteThroughWithLRU() throws Exception {
    final int size = 10000;
    TestMapStore testMapStore = new TestMapStore(size * 2, 1, 1);
    testMapStore.setLoadAllKeys(false);
    Config config = newConfig(testMapStore, 0);
    config.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
    MaxSizeConfig maxSizeConfig = new MaxSizeConfig();
    maxSizeConfig.setSize(size);
    MapConfig mapConfig = config.getMapConfig("default");
    mapConfig.setEvictionPolicy(EvictionPolicy.LRU);
    mapConfig.setMaxSizeConfig(maxSizeConfig);
    mapConfig.setMinEvictionCheckMillis(0);
    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 : MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) EntryAdapter(com.hazelcast.core.EntryAdapter) CountDownLatch(java.util.concurrent.CountDownLatch) MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleObjects.Employee) TestMapStore(com.hazelcast.map.impl.mapstore.MapStoreTest.TestMapStore) EntryEvent(com.hazelcast.core.EntryEvent) MapConfig(com.hazelcast.config.MapConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 47 with Employee

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

the class SqlPredicateTest method testSql_withString.

@Test
public void testSql_withString() {
    Employee value = createValue();
    Employee nullNameValue = new Employee(null, 34, true, 10D);
    assertSqlNotMatching("name = 'null'", nullNameValue);
    assertSqlMatching("name = null", nullNameValue);
    assertSqlMatching("name = NULL", nullNameValue);
    assertSqlMatching("name != null", value);
    assertSqlMatching("name != NULL", value);
    assertSqlMatching("name <> null", value);
    assertSqlMatching("name <> NULL", value);
    assertSqlMatching(" (name LIKE 'abc-%') AND (age <= " + 40 + ")", value);
    assertSqlMatching(" (name REGEX 'abc-.*') AND (age <= " + 40 + ")", value);
    assertSqlMatching("name='abc-123-xvz'", value);
    assertSqlMatching("name='abc 123-xvz'", createValue("abc 123-xvz"));
    assertSqlMatching("name='abc 123-xvz+(123)'", createValue("abc 123-xvz+(123)"));
    assertSqlNotMatching("name='abc 123-xvz+(123)'", createValue("abc123-xvz+(123)"));
    assertSqlMatching("name LIKE 'abc-%'", createValue("abc-123"));
    assertSqlMatching("name REGEX '^\\w{3}-\\d{3}-\\w{3}$'", value);
    assertSqlNotMatching("name REGEX '^[^\\w]{3}-\\d{3}-\\w{3}$'", value);
    assertSqlMatching(" (name ILIKE 'ABC-%') AND (age <= " + 40 + ")", value);
}
Also used : Employee(com.hazelcast.query.SampleObjects.Employee) QuickTest(com.hazelcast.test.annotation.QuickTest) DateHelperTest(com.hazelcast.query.impl.DateHelperTest) Test(org.junit.Test)

Example 48 with Employee

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

the class MapStoreTest method testIssue1115EnablingMapstoreMutatingValue.

@Test(timeout = 120000)
public void testIssue1115EnablingMapstoreMutatingValue() throws InterruptedException {
    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.SampleObjects.Employee) Random(java.util.Random) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) GroupConfig(com.hazelcast.config.GroupConfig) MapStore(com.hazelcast.core.MapStore) PostProcessingMapStore(com.hazelcast.core.PostProcessingMapStore) MapStoreConfig(com.hazelcast.config.MapStoreConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 49 with Employee

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

the class MapTransactionTest method testValuesWithPredicate_removingExistentEntry.

@Test
public void testValuesWithPredicate_removingExistentEntry() throws TransactionException {
    final int nodeCount = 1;
    final String mapName = randomMapName("_testValuesWithPredicate_removingExistentEntry_");
    final Config config = getConfig();
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(nodeCount);
    final HazelcastInstance node = factory.newHazelcastInstance(config);
    final IMap map = node.getMap(mapName);
    final Employee emp = new Employee("name", 77, true, 10D);
    map.put(1, emp);
    node.executeTransaction(options, new TransactionalTask<Boolean>() {

        public Boolean execute(TransactionalTaskContext context) throws TransactionException {
            final TransactionalMap<Object, Object> txMap = context.getMap(mapName);
            txMap.remove(1);
            Collection<Object> coll = txMap.values(new SqlPredicate("age > 70 "));
            assertEquals(0, coll.size());
            return true;
        }
    });
    node.shutdown();
}
Also used : TransactionalMap(com.hazelcast.core.TransactionalMap) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) SqlPredicate(com.hazelcast.query.SqlPredicate) IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleObjects.Employee) TransactionException(com.hazelcast.transaction.TransactionException) Collection(java.util.Collection) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

Employee (com.hazelcast.query.SampleObjects.Employee)49 Test (org.junit.Test)41 QuickTest (com.hazelcast.test.annotation.QuickTest)38 HazelcastInstance (com.hazelcast.core.HazelcastInstance)36 ParallelTest (com.hazelcast.test.annotation.ParallelTest)35 Config (com.hazelcast.config.Config)28 SqlPredicate (com.hazelcast.query.SqlPredicate)23 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)21 MapIndexConfig (com.hazelcast.config.MapIndexConfig)18 MapStoreConfig (com.hazelcast.config.MapStoreConfig)17 PortableEmployee (com.hazelcast.query.SampleObjects.PortableEmployee)14 IMap (com.hazelcast.core.IMap)11 MapConfig (com.hazelcast.config.MapConfig)10 Collection (java.util.Collection)8 Map (java.util.Map)8 EntryObject (com.hazelcast.query.EntryObject)6 Predicate (com.hazelcast.query.Predicate)6 PredicateBuilder (com.hazelcast.query.PredicateBuilder)6 HashMap (java.util.HashMap)6 TransactionalMap (com.hazelcast.core.TransactionalMap)5