Search in sources :

Example 11 with EntryListener

use of com.hazelcast.core.EntryListener in project hazelcast by hazelcast.

the class MapPreconditionsTest method testAddEntryListenerWithEntryListenerAndKey_NullKey.

@Test(expected = NullPointerException.class)
public void testAddEntryListenerWithEntryListenerAndKey_NullKey() throws Exception {
    EntryListener entryListener = new TestEntryListener();
    map.addEntryListener(entryListener, null, false);
}
Also used : EntryListener(com.hazelcast.core.EntryListener) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 12 with EntryListener

use of com.hazelcast.core.EntryListener in project hazelcast by hazelcast.

the class AllTest method loadMapOperations.

private List<Runnable> loadMapOperations() {
    ArrayList<Runnable> operations = new ArrayList<Runnable>();
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            map.evict(random.nextInt(SIZE));
        }
    }, 5);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            try {
                map.getAsync(random.nextInt(SIZE)).get();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            } catch (ExecutionException e) {
                throw new RuntimeException(e);
            }
        }
    }, 1);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            map.containsKey(random.nextInt(SIZE));
        }
    }, 2);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            map.containsValue(new Customer(random.nextInt(100), String.valueOf(random.nextInt(100000))));
        }
    }, 2);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            int key = random.nextInt(SIZE);
            map.lock(key);
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            } finally {
                map.unlock(key);
            }
        }
    }, 1);
    //        addOperation(operations, new Runnable() {
    //            public void run() {
    //                IMap map = hazelcast.getMap("myMap");
    //                int key = random.nextInt(SIZE);
    //                map.lockMap(10, TimeUnit.MILLISECONDS);
    //                try {
    //                    Thread.sleep(1);
    //                } catch (InterruptedException e) {
    //                } finally {
    //                    map.unlockMap();
    //                }
    //            }
    //        }, 1);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            int key = random.nextInt(SIZE);
            boolean locked = map.tryLock(key);
            if (locked) {
                try {
                    Thread.sleep(1);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                } finally {
                    map.unlock(key);
                }
            }
        }
    }, 1);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            int key = random.nextInt(SIZE);
            boolean locked = false;
            try {
                locked = map.tryLock(key, 10, TimeUnit.MILLISECONDS);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            if (locked) {
                try {
                    Thread.sleep(1);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                } finally {
                    map.unlock(key);
                }
            }
        }
    }, 1);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            Iterator it = map.entrySet().iterator();
            for (int i = 0; i < 10 && it.hasNext(); i++) {
                it.next();
            }
        }
    }, 1);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            map.getEntryView(random.nextInt(SIZE));
        }
    }, 2);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            map.isEmpty();
        }
    }, 3);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            map.put(random.nextInt(SIZE), new Customer(random.nextInt(100), String.valueOf(random.nextInt(10000))));
        }
    }, 50);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            map.tryPut(random.nextInt(SIZE), new Customer(random.nextInt(100), String.valueOf(random.nextInt(10000))), 10, TimeUnit.MILLISECONDS);
        }
    }, 5);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            try {
                map.putAsync(random.nextInt(SIZE), new Customer(random.nextInt(100), String.valueOf(random.nextInt(10000)))).get();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            } catch (ExecutionException e) {
                throw new RuntimeException(e);
            }
        }
    }, 5);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            map.put(random.nextInt(SIZE), new Customer(random.nextInt(100), String.valueOf(random.nextInt(10000))), 10, TimeUnit.MILLISECONDS);
        }
    }, 5);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            map.putIfAbsent(random.nextInt(SIZE), new Customer(random.nextInt(100), String.valueOf(random.nextInt(10000))), 10, TimeUnit.MILLISECONDS);
        }
    }, 5);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            map.putIfAbsent(random.nextInt(SIZE), new Customer(random.nextInt(100), String.valueOf(random.nextInt(10000))));
        }
    }, 5);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            Map localMap = new HashMap();
            for (int i = 0; i < 10; i++) {
                localMap.put(random.nextInt(SIZE), new Customer(random.nextInt(100), String.valueOf(random.nextInt(10000))));
            }
            map.putAll(localMap);
        }
    }, 1);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            map.get(random.nextInt(SIZE));
        }
    }, 100);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            map.remove(random.nextInt(SIZE));
        }
    }, 10);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            map.tryRemove(random.nextInt(SIZE), 10, TimeUnit.MILLISECONDS);
        }
    }, 10);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            map.removeAsync(random.nextInt(SIZE));
        }
    }, 10);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            map.remove(random.nextInt(SIZE), new Customer(random.nextInt(100), String.valueOf(random.nextInt(10000))));
        }
    }, 10);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            map.replace(random.nextInt(SIZE), new Customer(random.nextInt(100), String.valueOf(random.nextInt(10000))));
        }
    }, 4);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            map.replace(random.nextInt(SIZE), new Customer(random.nextInt(100), String.valueOf(random.nextInt(10000))), new Customer(random.nextInt(100), String.valueOf(random.nextInt(10000))));
        }
    }, 5);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            map.size();
        }
    }, 4);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            Iterator it = map.entrySet(new SqlPredicate("year=" + random.nextInt(100))).iterator();
            while (it.hasNext()) {
                it.next();
            }
        }
    }, 1);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            Iterator it = map.entrySet(new SqlPredicate("name=" + random.nextInt(10000))).iterator();
            while (it.hasNext()) {
                it.next();
            }
        }
    }, 10);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            Iterator it = map.keySet(new SqlPredicate("name=" + random.nextInt(10000))).iterator();
            while (it.hasNext()) {
                it.next();
            }
        }
    }, 10);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            Iterator it = map.localKeySet().iterator();
            while (it.hasNext()) {
                it.next();
            }
        }
    }, 10);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            Iterator it = map.localKeySet(new SqlPredicate("name=" + random.nextInt(10000))).iterator();
            while (it.hasNext()) {
                it.next();
            }
        }
    }, 10);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            final CountDownLatch latch = new CountDownLatch(1);
            EntryListener listener = new EntryAdapter() {

                @Override
                public void onEntryEvent(EntryEvent event) {
                    latch.countDown();
                }
            };
            String id = map.addEntryListener(listener, true);
            try {
                latch.await();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            map.removeEntryListener(id);
        }
    }, 1);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            map.addIndex("year", true);
        }
    }, 1);
    addOperation(operations, new Runnable() {

        public void run() {
            IMap map = hazelcast.getMap("myMap");
            final CountDownLatch latch = new CountDownLatch(1);
            EntryListener listener = new EntryAdapter() {

                @Override
                public void onEntryEvent(EntryEvent event) {
                    latch.countDown();
                }
            };
            String id = map.addLocalEntryListener(listener);
            try {
                latch.await();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            map.removeEntryListener(id);
        }
    }, 1);
    return operations;
}
Also used : HashMap(java.util.HashMap) EntryAdapter(com.hazelcast.core.EntryAdapter) ArrayList(java.util.ArrayList) SqlPredicate(com.hazelcast.query.SqlPredicate) CountDownLatch(java.util.concurrent.CountDownLatch) EntryListener(com.hazelcast.core.EntryListener) IMap(com.hazelcast.core.IMap) EntryEvent(com.hazelcast.core.EntryEvent) Iterator(java.util.Iterator) ExecutionException(java.util.concurrent.ExecutionException) HashMap(java.util.HashMap) Map(java.util.Map) IMap(com.hazelcast.core.IMap)

Example 13 with EntryListener

use of com.hazelcast.core.EntryListener in project hazelcast by hazelcast.

the class MapPreconditionsTest method testAddEntryListenerWithEntryListenerAndKey_NullListener.

@Test(expected = NullPointerException.class)
public void testAddEntryListenerWithEntryListenerAndKey_NullListener() {
    EntryListener entryListener = null;
    Integer i = 3;
    map.addEntryListener(entryListener, i, false);
}
Also used : EntryListener(com.hazelcast.core.EntryListener) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 14 with EntryListener

use of com.hazelcast.core.EntryListener in project hazelcast by hazelcast.

the class MapPreconditionsTest method testAddEntryListenerWithEntryListenerAndPredicate_NullListener.

@Test(expected = NullPointerException.class)
public void testAddEntryListenerWithEntryListenerAndPredicate_NullListener() {
    EntryListener entryListener = null;
    Predicate predicate = new TruePredicate();
    map.addEntryListener(entryListener, predicate, false);
}
Also used : TruePredicate(com.hazelcast.query.TruePredicate) EntryListener(com.hazelcast.core.EntryListener) TruePredicate(com.hazelcast.query.TruePredicate) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 15 with EntryListener

use of com.hazelcast.core.EntryListener in project hazelcast by hazelcast.

the class MapPreconditionsTest method testAddEntryListenerWithEntryListenerAndKey_NullKey.

@Test(expected = NullPointerException.class)
public void testAddEntryListenerWithEntryListenerAndKey_NullKey() {
    EntryListener entryListener = new TestEntryListener();
    map.addEntryListener(entryListener, null, false);
}
Also used : EntryListener(com.hazelcast.core.EntryListener) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

EntryListener (com.hazelcast.core.EntryListener)30 ParallelTest (com.hazelcast.test.annotation.ParallelTest)26 QuickTest (com.hazelcast.test.annotation.QuickTest)26 Test (org.junit.Test)26 Predicate (com.hazelcast.query.Predicate)16 TruePredicate (com.hazelcast.query.TruePredicate)16 EntryEvent (com.hazelcast.core.EntryEvent)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 EntryAdapter (com.hazelcast.core.EntryAdapter)2 SqlPredicate (com.hazelcast.query.SqlPredicate)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)1 ReplicatedMapConfig (com.hazelcast.config.ReplicatedMapConfig)1 EntryEventType (com.hazelcast.core.EntryEventType)1 HazelcastException (com.hazelcast.core.HazelcastException)1 HazelcastInstanceAware (com.hazelcast.core.HazelcastInstanceAware)1 IMap (com.hazelcast.core.IMap)1 MapEvent (com.hazelcast.core.MapEvent)1