@Test // (timeout = 10000) public void testIteration() { HTreeMap m = new HTreeMap<Integer, Integer>(recman, true) { @Override protected int hash(Object key) { return (Integer) key; } }; final int max = 140; final int inc = 111111; for (Integer i = 0; i < max; i++) { m.put(i, i + inc); } Iterator<Integer> keys = m.keySet().iterator(); for (Integer i = 0; i < max; i++) { assertTrue(keys.hasNext()); assertEquals(i, keys.next()); } assertTrue(!keys.hasNext()); Iterator<Integer> vals = m.values().iterator(); for (Integer i = inc; i < max + inc; i++) { assertTrue(vals.hasNext()); assertEquals(i, vals.next()); } assertTrue(!vals.hasNext()); // great it worked, test stuff spread across segments m.clear(); assertTrue(m.isEmpty()); for (int i = 0; i < max; i++) { m.put((1 << 30) + i, i + inc); m.put((2 << 30) + i, i + inc); m.put((3 << 30) + i, i + inc); } assertEquals(max * 3, m.size()); int countSegments = 0; for (long segmentRecid : m.segmentRecids) { if (recman.recordGet(segmentRecid, HTreeMap.DIR_SERIALIZER) != null) countSegments++; } assertEquals(3, countSegments); keys = m.keySet().iterator(); for (int i = 1; i <= 3; i++) { for (int j = 0; j < max; j++) { assertTrue(keys.hasNext()); assertEquals(Integer.valueOf((i << 30) + j), keys.next()); } } assertTrue(!keys.hasNext()); }
@Test public void clear() { HTreeMap m = new HTreeMap(recman, true); for (Integer i = 0; i < 100; i++) { m.put(i, i); } m.clear(); assertTrue(m.isEmpty()); assertEquals(0, m.size()); }
/** delete record/collection with given name */ public synchronized void delete(String name) { Object r = get(name); if (r instanceof Atomic.Boolean) { engine.delete(((Atomic.Boolean) r).recid, Serializer.BOOLEAN); } else if (r instanceof Atomic.Integer) { engine.delete(((Atomic.Integer) r).recid, Serializer.INTEGER); } else if (r instanceof Atomic.Long) { engine.delete(((Atomic.Long) r).recid, Serializer.LONG); } else if (r instanceof Atomic.String) { engine.delete(((Atomic.String) r).recid, Serializer.STRING_NOSIZE); } else if (r instanceof Atomic.Var) { engine.delete(((Atomic.Var) r).recid, ((Atomic.Var) r).serializer); } else if (r instanceof Queue) { // drain queue Queue q = (Queue) r; while (q.poll() != null) { // do nothing } } else if (r instanceof HTreeMap || r instanceof HTreeMap.KeySet) { HTreeMap m = (r instanceof HTreeMap) ? (HTreeMap) r : ((HTreeMap.KeySet) r).parent(); m.clear(); // delete segments for (long segmentRecid : m.segmentRecids) { engine.delete(segmentRecid, HTreeMap.DIR_SERIALIZER); } } else if (r instanceof BTreeMap || r instanceof BTreeMap.KeySet) { BTreeMap m = (r instanceof BTreeMap) ? (BTreeMap) r : (BTreeMap) ((BTreeMap.KeySet) r).m; // TODO on BTreeMap recursively delete all nodes m.clear(); if (m.counter != null) engine.delete(m.counter.recid, Serializer.LONG); } for (String n : catalog.keySet()) { if (!n.startsWith(name)) continue; catalog.remove(n); } namesInstanciated.remove(name); namesLookup.remove(r); }