Search in sources :

Example 6 with Employee

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

the class QueryAdvancedTest method testQueryAfterInitialLoad.

// issue 1404 "to be fixed by issue 1404"
@Test
public void testQueryAfterInitialLoad() {
    final int size = 100;
    String name = "default";
    Config config = getConfig();
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setEnabled(true);
    mapStoreConfig.setImplementation(new MapStoreAdapter<Integer, Employee>() {

        @Override
        public Map<Integer, Employee> loadAll(Collection<Integer> keys) {
            Map<Integer, Employee> map = new HashMap<Integer, Employee>();
            for (Integer key : keys) {
                Employee emp = new Employee();
                emp.setActive(true);
                map.put(key, emp);
            }
            return map;
        }

        @Override
        public Set<Integer> loadAllKeys() {
            Set<Integer> set = new HashSet<Integer>();
            for (int i = 0; i < size; i++) {
                set.add(i);
            }
            return set;
        }
    });
    config.getMapConfig(name).setMapStoreConfig(mapStoreConfig);
    HazelcastInstance instance = createHazelcastInstance(config);
    final IMap map = instance.getMap(name);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            Collection values = map.values(new SqlPredicate("active = true"));
            assertEquals(size, values.size());
        }
    });
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) SqlPredicate(com.hazelcast.query.SqlPredicate) MapStoreConfig(com.hazelcast.config.MapStoreConfig) IOException(java.io.IOException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IMap(com.hazelcast.core.IMap) Employee(com.hazelcast.query.SampleObjects.Employee) PortableEmployee(com.hazelcast.query.SampleObjects.PortableEmployee) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map) IMap(com.hazelcast.core.IMap) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 7 with Employee

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

the class WriteBehindWithEntryProcessorTest method testAllPartialUpdatesStored_whenInMemoryFormatIsObject.

@Test
public void testAllPartialUpdatesStored_whenInMemoryFormatIsObject() throws Exception {
    CountDownLatch pauseStoreOp = new CountDownLatch(1);
    JournalingMapStore<Integer, Employee> mapStore = new JournalingMapStore<Integer, Employee>(pauseStoreOp);
    IMap<Integer, Employee> map = TestMapUsingMapStoreBuilder.<Integer, Employee>create().withMapStore(mapStore).withNodeFactory(createHazelcastInstanceFactory(1)).withWriteDelaySeconds(1).withWriteCoalescing(false).withInMemoryFormat(InMemoryFormat.OBJECT).build();
    Double[] salaries = { 73D, 111D, -23D, 99D, 12D, 77D, 33D };
    for (Double salary : salaries) {
        updateSalary(map, 1, salary);
    }
    pauseStoreOp.countDown();
    assertStoreOperationsCompleted(salaries.length, mapStore);
    assertArrayEquals("Map store should contain all partial updates on the object", salaries, getStoredSalaries(mapStore));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Employee(com.hazelcast.query.SampleObjects.Employee) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) MapStoreTest(com.hazelcast.map.impl.mapstore.MapStoreTest) Test(org.junit.Test)

Example 8 with Employee

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

the class WriteBehindWithEntryProcessorTest method getStoredSalaries.

private Double[] getStoredSalaries(JournalingMapStore<Integer, Employee> mapStore) {
    List<Double> salaries = new ArrayList<Double>();
    Iterator<Employee> iterator = mapStore.iterator();
    while (iterator.hasNext()) {
        Employee storedEmployee = iterator.next();
        double salary = storedEmployee.getSalary();
        salaries.add(salary);
    }
    return salaries.toArray(new Double[mapStore.queue.size()]);
}
Also used : Employee(com.hazelcast.query.SampleObjects.Employee) ArrayList(java.util.ArrayList)

Example 9 with Employee

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

the class MapStoreWriteThroughTest method testOneMemberWriteThrough.

@Test(timeout = 120000)
public void testOneMemberWriteThrough() throws Exception {
    TestMapStore testMapStore = new TestMapStore(1, 1, 1);
    testMapStore.setLoadAllKeys(false);
    Config config = newConfig(testMapStore, 0);
    HazelcastInstance instance = createHazelcastInstance(config);
    Employee employee = new Employee("joe", 25, true, 100.00);
    Employee newEmployee = new Employee("ali", 26, true, 1000);
    testMapStore.insert("1", employee);
    testMapStore.insert("2", employee);
    testMapStore.insert("3", employee);
    testMapStore.insert("4", employee);
    testMapStore.insert("5", employee);
    testMapStore.insert("6", employee);
    testMapStore.insert("7", employee);
    IMap<String, Employee> map = instance.getMap("default");
    map.addIndex("name", false);
    assertEquals(0, map.size());
    assertEquals(employee, map.get("1"));
    assertEquals(employee, testMapStore.getStore().get("1"));
    assertEquals(1, map.size());
    assertEquals(employee, map.put("2", newEmployee));
    assertEquals(newEmployee, testMapStore.getStore().get("2"));
    assertEquals(2, map.size());
    map.remove("1");
    map.put("1", employee, 1, TimeUnit.SECONDS);
    map.put("1", employee);
    Thread.sleep(2000);
    assertEquals(employee, testMapStore.getStore().get("1"));
    assertEquals(employee, map.get("1"));
    map.evict("2");
    assertEquals(newEmployee, map.get("2"));
    assertEquals(employee, map.get("3"));
    assertEquals(employee, map.put("3", newEmployee));
    assertEquals(newEmployee, map.get("3"));
    assertEquals(employee, map.remove("4"));
    assertEquals(employee, map.get("5"));
    assertEquals(employee, map.remove("5"));
    assertEquals(employee, map.putIfAbsent("6", newEmployee));
    assertEquals(employee, map.get("6"));
    assertEquals(employee, testMapStore.getStore().get("6"));
    assertTrue(map.containsKey("7"));
    assertEquals(employee, map.get("7"));
    assertNull(map.get("8"));
    assertFalse(map.containsKey("8"));
    assertNull(map.putIfAbsent("8", employee));
    assertEquals(employee, map.get("8"));
    assertEquals(employee, testMapStore.getStore().get("8"));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleObjects.Employee) TestMapStore(com.hazelcast.map.impl.mapstore.MapStoreTest.TestMapStore) MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 10 with Employee

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

the class MapTransactionTest method testValues_WithPredicates_notContains_oldValues.

@Test
public void testValues_WithPredicates_notContains_oldValues() throws TransactionException {
    Config config = getConfig();
    final String mapName = "testValuesWithPredicate_notContains_oldValues";
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    final HazelcastInstance h1 = factory.newHazelcastInstance(config);
    final HazelcastInstance h2 = factory.newHazelcastInstance(config);
    final IMap<Integer, Employee> map = h1.getMap(mapName);
    final Employee employeeAtAge22 = new Employee("emin", 22, true, 10D);
    final Employee employeeAtAge23 = new Employee("emin", 23, true, 10D);
    map.put(1, employeeAtAge22);
    h1.executeTransaction(options, new TransactionalTask<Boolean>() {

        public Boolean execute(TransactionalTaskContext context) throws TransactionException {
            TransactionalMap<Object, Object> txMap = context.getMap(mapName);
            assertEquals(1, txMap.values(new SqlPredicate("age > 21")).size());
            txMap.put(1, employeeAtAge23);
            Collection coll = txMap.values(new SqlPredicate("age > 21"));
            assertEquals(1, coll.size());
            return true;
        }
    });
    h1.shutdown();
    h2.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) 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