Package com.hazelcast.core

Examples of com.hazelcast.core.IMap


    @Test(timeout = 1000 * 60)
    public void testTwoNodesWithIndexes() throws Exception {
        TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
        HazelcastInstance h1 = nodeFactory.newHazelcastInstance();
        HazelcastInstance h2 = nodeFactory.newHazelcastInstance();
        IMap imap = h1.getMap("employees");
        imap.addIndex("name", false);
        imap.addIndex("city", false);
        imap.addIndex("age", true);
        imap.addIndex("active", false);
        for (int i = 0; i < 5000; i++) {
            Employee employee = new Employee(i, "name" + i % 100, "city" + (i % 100), i % 60, ((i & 1) == 1), (double) i);
            imap.put(String.valueOf(i), employee);
        }
        assertEquals(2, h1.getCluster().getMembers().size());
        assertEquals(2, h2.getCluster().getMembers().size());
        imap = h2.getMap("employees");
        imap.addIndex("name", false);
        imap.addIndex("city", false);
        imap.addIndex("age", true);
        imap.addIndex("active", false);
        Collection<Employee> entries = imap.values(new SqlPredicate("name='name3' and city='city3' and age > 2"));
        assertEquals(50, entries.size());
        for (Employee e : entries) {
            assertEquals("name3", e.getName());
            assertEquals("city3", e.getCity());
        }
        entries = imap.values(new SqlPredicate("name LIKE '%name3' and city like '%city3' and age > 2"));
        assertEquals(50, entries.size());
        for (Employee e : entries) {
            assertEquals("name3", e.getName());
            assertEquals("city3", e.getCity());
            assertTrue(e.getAge() > 2);
        }
        entries = imap.values(new SqlPredicate("name LIKE '%name3%' and city like '%city30%'"));
        assertEquals(50, entries.size());
        for (Employee e : entries) {
            assertTrue(e.getName().startsWith("name3"));
            assertTrue(e.getCity().startsWith("city3"));
        }
View Full Code Here


        assertEquals(0, map.size());
    }

    @Test
    public void testRemoveIfSame() {
        final IMap map = createMap();
        fillMap(map);
        assertFalse(map.remove("key2", "value"));
        assertEquals(10, map.size());

        assertTrue(map.remove("key2", "value2"));
        assertEquals(9, map.size());
    }
View Full Code Here

        assertOpenEventually(flushMapStore.latch, 5);
    }

    @Test
    public void testGetAllPutAll() {
        final IMap map = createMap();
        Map mm = new HashMap();
        for (int i = 0; i < 100; i++) {
            mm.put(i, i);
        }
        map.putAll(mm);
        assertEquals(map.size(), 100);
        for (int i = 0; i < 100; i++) {
            assertEquals(map.get(i), i);
        }

        Set ss = new HashSet();
        ss.add(1);
        ss.add(3);
        Map m2 = map.getAll(ss);
        assertEquals(m2.size(), 2);
        assertEquals(m2.get(1), 1);
        assertEquals(m2.get(3), 3);
    }
View Full Code Here

        assertEquals(m2.get(3), 3);
    }

    @Test
    public void testAsyncGet() throws Exception {
        final IMap map = createMap();
        fillMap(map);
        Future f = map.getAsync("key1");
        Object o = f.get();
        assertEquals("value1", o);
    }
View Full Code Here

        assertEquals("value1", o);
    }

    @Test
    public void testAsyncPut() throws Exception {
        final IMap map = createMap();
        fillMap(map);
        Future f = map.putAsync("key3", "value");
        Object o = f.get();
        assertEquals("value3", o);
        assertEquals("value", map.get("key3"));
    }
View Full Code Here


    @Test(timeout = 1000 * 60)
    public void testOneMemberWithoutIndex() {
        HazelcastInstance h1 = createHazelcastInstance();
        IMap imap = h1.getMap("employees");
        doFunctionalQueryTest(imap);
    }
View Full Code Here

    }

    @Test(timeout = 1000 * 60)
    public void testOneMemberWithIndex() {
        HazelcastInstance instance = createHazelcastInstance();
        IMap imap = instance.getMap("employees");
        imap.addIndex("name", false);
        imap.addIndex("age", true);
        imap.addIndex("active", false);
        doFunctionalQueryTest(imap);
    }
View Full Code Here

        assertEquals("value", map.get("key3"));
    }

    @Test
    public void testAsyncPutWithTtl() throws Exception {
        final IMap map = createMap();
        final CountDownLatch latch = new CountDownLatch(1);
        map.addEntryListener(new EntryAdapter<String, String>() {
            public void entryEvicted(EntryEvent<String, String> event) {
                latch.countDown();
            }
        }, true);

        Future<String> f1 = map.putAsync("key", "value1", 3, TimeUnit.SECONDS);
        String f1Val = f1.get();
        assertNull(f1Val);
        assertEquals("value1", map.get("key"));

        assertTrue(latch.await(10, TimeUnit.SECONDS));
        assertNull(map.get("key"));
    }
View Full Code Here

        assertNull(map.get("key"));
    }

    @Test
    public void testAsyncRemove() throws Exception {
        final IMap map = createMap();
        fillMap(map);
        Future f = map.removeAsync("key4");
        Object o = f.get();
        assertEquals("value4", o);
        assertEquals(9, map.size());
    }
View Full Code Here

    }

    @Test(timeout = 1000 * 60)
    public void testOneMemberSQLWithoutIndex() {
        HazelcastInstance h1 = createHazelcastInstance();
        IMap imap = h1.getMap("employees");
        doFunctionalSQLQueryTest(imap);
        Set<Map.Entry> entries = imap.entrySet(new SqlPredicate("active and age>23"));
        assertEquals(27, entries.size());
    }
View Full Code Here

TOP

Related Classes of com.hazelcast.core.IMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.