public Collection<V> remove(Object key) { TxnMultiMapRemoveAllRequest request = new TxnMultiMapRemoveAllRequest(getName(), toData(key)); PortableCollection portableCollection = invoke(request); final Collection<Data> collection = portableCollection.getCollection(); Collection<V> coll; if (collection instanceof List) { coll = new ArrayList<V>(collection.size()); } else { coll = new HashSet<V>(collection.size()); } for (Data data : collection) { coll.add((V) toObject(data)); } return coll; }
@Test public void testDrain() throws IOException { IQueue q = getQueue(); q.offer("item1"); q.offer("item2"); q.offer("item3"); q.offer("item4"); q.offer("item5"); final SimpleClient client = getClient(); client.send(new DrainRequest(queueName, 1)); PortableCollection result = (PortableCollection) client.receive(); Collection<Data> coll = result.getCollection(); assertEquals(1, coll.size()); assertEquals("item1", ss.toObject(coll.iterator().next())); assertEquals(4, q.size()); }
@Test public void testIterator() throws IOException { IQueue q = getQueue(); q.offer("item1"); q.offer("item2"); q.offer("item3"); q.offer("item4"); q.offer("item5"); final SimpleClient client = getClient(); client.send(new IteratorRequest(queueName)); PortableCollection result = (PortableCollection) client.receive(); Collection<Data> coll = result.getCollection(); int i = 1; for (Data data : coll) { assertEquals("item" + i, ss.toObject(data)); i++; } }