Search in sources :

Example 46 with Employee

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

the class QueryAdvancedTest method testTwoMembers.

@Test
public void testTwoMembers() {
    Config config = getConfig();
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
    nodeFactory.newHazelcastInstance(config);
    IMap<String, Employee> map = instance.getMap("employees");
    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 47 with Employee

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

the class QueryAdvancedTest method testTwoMembersWithIndexesAndShutdown3.

@Test
public void testTwoMembersWithIndexesAndShutdown3() {
    Config config = getConfig();
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
    IMap<String, Employee> map = instance1.getMap("employees");
    map.addIndex(IndexType.HASH, "name");
    map.addIndex(IndexType.SORTED, "age");
    map.addIndex(IndexType.HASH, "active");
    QueryBasicTest.doFunctionalQueryTest(map);
    assertEquals(101, map.size());
    HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
    assertEquals(101, map.size());
    instance1.getLifecycleService().shutdown();
    map = instance2.getMap("employees");
    assertEquals(101, map.size());
    Set<Map.Entry<String, Employee>> entries = map.entrySet(Predicates.sql("active and age=23"));
    assertEquals(2, entries.size());
    for (Map.Entry<String, Employee> entry : entries) {
        Employee employee = entry.getValue();
        assertEquals(employee.getAge(), 23);
        assertTrue(employee.isActive());
    }
}
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) HashMap(java.util.HashMap) Map(java.util.Map) IMap(com.hazelcast.map.IMap) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 48 with Employee

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

the class QueryAdvancedTest method testQueryWithTTL.

@Test
public void testQueryWithTTL() {
    Config config = getConfig();
    // disable background expiration task to keep test safe from jitter
    config.setProperty(PROP_CLEANUP_ENABLED, "false");
    String mapName = "default";
    config.getMapConfig(mapName).setTimeToLiveSeconds(3);
    HazelcastInstance instance = createHazelcastInstance(config);
    IMap<String, Employee> map = instance.getMap(mapName);
    map.addIndex(IndexType.HASH, "name");
    map.addIndex(IndexType.SORTED, "age");
    map.addIndex(IndexType.HASH, "active");
    int passiveEmployees = 5;
    int activeEmployees = 5;
    int allEmployees = passiveEmployees + activeEmployees;
    final CountDownLatch latch = new CountDownLatch(allEmployees);
    map.addEntryListener((EntryExpiredListener) event -> latch.countDown(), false);
    for (int i = 0; i < activeEmployees; i++) {
        Employee employee = new Employee("activeEmployee" + i, 60, true, i);
        map.put("activeEmployee" + i, employee);
    }
    for (int i = 0; i < passiveEmployees; i++) {
        Employee employee = new Employee("passiveEmployee" + i, 60, false, i);
        map.put("passiveEmployee" + i, employee);
    }
    // check the query result before eviction
    final Collection values = map.values(Predicates.sql("active"));
    assertTrueEventually(() -> assertEquals(String.format("Expected %s results but got %s." + " Number of evicted entries: %s.", activeEmployees, values.size(), allEmployees - latch.getCount()), activeEmployees, values.size()));
    // delete expire keys by explicitly calling `map#get`
    assertTrueEventually(() -> {
        for (int i = 0; i < activeEmployees; i++) {
            assertNull(map.get("activeEmployee" + i));
        }
        for (int i = 0; i < passiveEmployees; i++) {
            assertNull(map.get("passiveEmployee" + i));
        }
    });
    // wait until eviction is completed
    assertOpenEventually(latch);
    // check the query result after eviction
    assertEquals(0, map.values(Predicates.sql("active")).size());
}
Also used : ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) PortableEmployee(com.hazelcast.query.SampleTestObjects.PortableEmployee) QuickTest(com.hazelcast.test.annotation.QuickTest) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) HashSet(java.util.HashSet) ValueType(com.hazelcast.query.SampleTestObjects.ValueType) IndexType(com.hazelcast.config.IndexType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) DataSerializable(com.hazelcast.nio.serialization.DataSerializable) MapStoreAdapter(com.hazelcast.map.MapStoreAdapter) Employee(com.hazelcast.query.SampleTestObjects.Employee) ObjectDataInput(com.hazelcast.nio.ObjectDataInput) Predicate(com.hazelcast.query.Predicate) ExpectedException(org.junit.rules.ExpectedException) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastException(com.hazelcast.core.HazelcastException) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HazelcastTestSupport(com.hazelcast.test.HazelcastTestSupport) Collection(java.util.Collection) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Category(org.junit.experimental.categories.Category) EntryExpiredListener(com.hazelcast.map.listener.EntryExpiredListener) IndexConfig(com.hazelcast.config.IndexConfig) CountDownLatch(java.util.concurrent.CountDownLatch) Rule(org.junit.Rule) Assert.assertNull(org.junit.Assert.assertNull) RootCauseMatcher(com.hazelcast.internal.util.RootCauseMatcher) Predicates(com.hazelcast.query.Predicates) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) MapStoreConfig(com.hazelcast.config.MapStoreConfig) ObjectDataOutput(com.hazelcast.nio.ObjectDataOutput) PROP_CLEANUP_ENABLED(com.hazelcast.map.impl.eviction.MapClearExpiredRecordsTask.PROP_CLEANUP_ENABLED) Assert.assertEquals(org.junit.Assert.assertEquals) IMap(com.hazelcast.map.IMap) 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) Collection(java.util.Collection) CountDownLatch(java.util.concurrent.CountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 49 with Employee

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

the class MapTransactionTest method testValues_withPagingPredicate.

@Test(expected = IllegalArgumentException.class)
public void testValues_withPagingPredicate() throws TransactionException {
    final int nodeCount = 1;
    final String mapName = randomMapName("testValuesWithPagingPredicate");
    final Config config = getConfig();
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(nodeCount);
    final HazelcastInstance node = factory.newHazelcastInstance(config);
    final IMap<Integer, Employee> map = node.getMap(mapName);
    final Employee emp = new Employee("name", 77, true, 10D);
    map.put(1, emp);
    node.executeTransaction(options, (context) -> {
        final TransactionalMap<Integer, Employee> txMap = context.getMap(mapName);
        Predicate<Integer, Employee> predicate = Predicates.pagingPredicate(5);
        txMap.values(predicate);
        return true;
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleTestObjects.Employee) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 50 with Employee

use of com.hazelcast.query.SampleTestObjects.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(Predicates.sql("age > 70 "));
            assertEquals(0, coll.size());
            return true;
        }
    });
    node.shutdown();
}
Also used : TransactionalMap(com.hazelcast.transaction.TransactionalMap) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleTestObjects.Employee) TransactionException(com.hazelcast.transaction.TransactionException) Collection(java.util.Collection) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) 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