@Test public void destroy() { HazelcastClient hClient = getHazelcastClient(); ISet<Integer> set = hClient.getSet("destroy"); for (int i = 0; i < 100; i++) { assertTrue(set.add(i)); } ISet<Integer> set2 = hClient.getSet("destroy"); assertTrue(set == set2); assertTrue(set.getId().equals(set2.getId())); set.destroy(); set2 = hClient.getSet("destroy"); assertFalse(set == set2); // for(int i=0;i<100;i++){ // assertNull(list2.get(i)); // } }
@Test public void size() { HazelcastClient hClient = getHazelcastClient(); ISet<Integer> set = hClient.getSet("size"); int count = 100; assertTrue(set.isEmpty()); for (int i = 0; i < count; i++) { assertTrue(set.add(i)); } assertEquals(count, set.size()); for (int i = 0; i < count / 2; i++) { assertFalse(set.add(i)); } assertFalse(set.isEmpty()); assertEquals(count, set.size()); }
@Test public void remove() { HazelcastClient hClient = getHazelcastClient(); ISet<Integer> set = hClient.getSet("remove"); int count = 100; assertTrue(set.isEmpty()); for (int i = 0; i < count; i++) { assertTrue(set.add(i)); } assertEquals(count, set.size()); for (int i = 0; i < count; i++) { assertTrue(set.remove((Object) i)); } assertTrue(set.isEmpty()); for (int i = count; i < 2 * count; i++) { assertFalse(set.remove((Object) i)); } }
@Test public void iterate() { HazelcastClient hClient = getHazelcastClient(); ISet<Integer> set = hClient.getSet("iterate"); set.add(1); set.add(2); set.add(2); set.add(3); assertEquals(3, set.size()); Map<Integer, Integer> counter = new HashMap<Integer, Integer>(); counter.put(1, 1); counter.put(2, 1); counter.put(3, 1); for (Iterator<Integer> iterator = set.iterator(); iterator.hasNext(); ) { Integer integer = iterator.next(); counter.put(integer, counter.get(integer) - 1); iterator.remove(); } assertEquals(Integer.valueOf(0), counter.get(1)); assertEquals(Integer.valueOf(0), counter.get(2)); assertEquals(Integer.valueOf(0), counter.get(3)); assertTrue(set.isEmpty()); }
@Override protected void execute(String... args) { withHazelcast(hazelcast -> { String name = "default"; ISet<Integer> set = hazelcast.getSet(name); if (args.length > 0) { if ("master".equals(args[0])) { IntStream.rangeClosed(1, 10).forEach(set::add); } } readConsoleWhile(hazelcast, name, () -> { set.forEach(e -> show("element = %d.", e)); return null; }, set::size); }); }
@Override @SuppressWarnings("unchecked") public <E> ISet<E> getISet(String name) { name = Objects.requireNonNull(name); final ISet<E> valu = getBeanSafely(name, ISet.class); if (null != valu) { return valu; } return hz().getSet(name); }
@Override public boolean equals(Object o) { if (o instanceof ISet && o != null) { return getName().equals(((ISet) o).getName()); } else { return false; } }
@Test public void addRemoveItemListener() throws InterruptedException { HazelcastClient hClient = getHazelcastClient(); final ISet<String> set = hClient.getSet("addRemoveItemListenerSet"); final CountDownLatch addLatch = new CountDownLatch(2); final CountDownLatch removeLatch = new CountDownLatch(2); ItemListener<String> listener = new CountDownItemListener<String>(addLatch, removeLatch); set.addItemListener(listener, true); set.add("hello"); set.add("hello"); set.remove("hello"); set.remove("hello"); for (int i = 0; i < 100; i++) { if (removeLatch.getCount() != 1 || addLatch.getCount() != 1) { Thread.sleep(50); } else { break; } } assertEquals(1, removeLatch.getCount()); assertEquals(1, addLatch.getCount()); set.removeItemListener(listener); set.add("hello"); set.add("hello"); set.remove("hello"); set.remove("hello"); Thread.sleep(50); assertEquals(1, addLatch.getCount()); assertEquals(1, removeLatch.getCount()); }
@Test public void add() { HazelcastClient hClient = getHazelcastClient(); ISet<Integer> set = hClient.getSet("add"); int count = 100; for (int i = 0; i < count; i++) { assertTrue(set.add(i)); } for (int i = 0; i < count; i++) { assertFalse(set.add(i)); } assertEquals(count, set.size()); }
@Test public void contains() { HazelcastClient hClient = getHazelcastClient(); ISet<Integer> set = hClient.getSet("contains"); int count = 100; for (int i = 0; i < count; i++) { set.add(i); } for (int i = 0; i < count; i++) { assertTrue(set.contains(i)); } for (int i = count; i < 2 * count; i++) { assertFalse(set.contains(i)); } }
@Test public void addAll() { HazelcastClient hClient = getHazelcastClient(); ISet<Integer> set = hClient.getSet("addAll"); List<Integer> arr = new ArrayList<Integer>(); int count = 100; for (int i = 0; i < count; i++) { arr.add(i); } assertTrue(set.addAll(arr)); }
@Test public void containsAll() { HazelcastClient hClient = getHazelcastClient(); ISet<Integer> set = hClient.getSet("containsAll"); List<Integer> arrList = new ArrayList<Integer>(); int count = 100; for (int i = 0; i < count; i++) { arrList.add(i); } assertTrue(set.addAll(arrList)); assertTrue(set.containsAll(arrList)); arrList.set((int) count / 2, count + 1); assertFalse(set.containsAll(arrList)); }
@Test public void clear() { HazelcastClient hClient = getHazelcastClient(); ISet<Integer> set = hClient.getSet("clear"); int count = 100; assertTrue(set.isEmpty()); for (int i = 0; i < count; i++) { assertTrue(set.add(i)); } assertEquals(count, set.size()); set.clear(); assertTrue(set.isEmpty()); }
@Test public void removeAll() { HazelcastClient hClient = getHazelcastClient(); ISet<Integer> set = hClient.getSet("removeAll"); List<Integer> arrList = new ArrayList<Integer>(); int count = 100; for (int i = 0; i < count; i++) { arrList.add(i); } assertTrue(set.addAll(arrList)); assertTrue(set.removeAll(arrList)); assertFalse(set.removeAll(arrList.subList(0, count / 10))); }
@Override public <E> ISet<E> getSet(String s) { return null; }
public <V> ISet<V> getSet(String name) { return substance.getSet(name); }
public HazelcastSetConsumer(HazelcastInstance hazelcastInstance, Endpoint endpoint, Processor processor, String cacheName) { super(hazelcastInstance, endpoint, processor, cacheName); ISet<Object> set = hazelcastInstance.getSet(cacheName); set.addItemListener(new CamelItemListener(this, cacheName), true); }
@Override public <T> ISet<T> getSet(String SetName) { ISet<T> set = client.getSet(SetName); return set; }
protected ISet getSet(String name) { return hazelcastClient.getSet(name); }
@Override public <S> void register(PublishedServiceInfo<S> serviceInfo) { //when a service register itself, all other processes will be notified (thanks to Hazelcast) ISet<Object> set = hazelcastInstance.getSet(PUBLISHED_SERVICES); set.add(serviceInfo); }
@Override public <S> void deRegister(PublishedServiceInfo<S> serviceInfo) { ISet<Object> set = hazelcastInstance.getSet(PUBLISHED_SERVICES); set.remove(serviceInfo); }
@Override public <E> ISet<E> getSet(final String name) { return getHazelcastInstance().getSet(name); }
public SetMBean(ISet<?> managedObject, ManagementService managementService) { super(managedObject, managementService); }
@Test(expected = NullPointerException.class) public void testAddNull() throws InterruptedException { HazelcastClient hClient = getHazelcastClient(); ISet<?> set = hClient.getSet("testAddNull"); set.add(null); }
@Test public void getSetName() { HazelcastClient hClient = getHazelcastClient(); ISet<String> set = hClient.getSet("getSetName"); assertEquals("getSetName", set.getName()); }