mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
HCOLL-172 Verified thath IntIntMultiMap now supports up to 2^32 entries; ShortShortMultiMap up to 2^16; ChronicleMap.Segment are now long-sized; attempt to support non-power-of-2 number of segments by HashSplitting (not tested yet); improved logic and dependencies between actualSegments(), actualEntriesPerSegments() and minSegments() methods in ChronicleMapBuilder; minor fixes
This commit is contained in:
@@ -45,7 +45,6 @@ public class BigData {
|
||||
|
||||
// static AtomicInteger Highwatermark = new AtomicInteger(0);
|
||||
static {
|
||||
builder.largeSegments(true);
|
||||
builder.actualSegments(8 * 1024);
|
||||
builder.entries(MAXSIZE);
|
||||
String dir = System.getProperty("dir", "/ocz/tmp");
|
||||
|
||||
@@ -91,7 +91,7 @@ public class CHMMetaDataTest {
|
||||
|
||||
@Override
|
||||
public void onRemove(ChronicleMap<String, String> map, Bytes entry, int metaDataBytes,
|
||||
String key, String value, int pos, SharedSegment segment) {
|
||||
String key, String value, long pos, SharedSegment segment) {
|
||||
assertEquals(8, metaDataBytes);
|
||||
System.out.println("Removed " + key + "/" + value + " with ts of " + entry.readLong(0));
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ public class EntryCountMapTest {
|
||||
map.acquireUsing(key, longValue);
|
||||
longValue.setValue(1);
|
||||
}
|
||||
int[] a = ((VanillaChronicleMap) map).segmentSizes();
|
||||
long[] a = ((VanillaChronicleMap) map).segmentSizes();
|
||||
System.out.println("segs: " + segments + " min: " + minSize + " was " + map.size() + " "
|
||||
+ Arrays.toString(a)
|
||||
+ " sum: " + sum(a));
|
||||
@@ -155,7 +155,7 @@ public class EntryCountMapTest {
|
||||
scoreCount++;
|
||||
boolean condition = minSize <= map.size() && map.size() <= maxSize;
|
||||
if (!condition) {
|
||||
int[] a = ((VanillaChronicleMap) map).segmentSizes();
|
||||
long[] a = ((VanillaChronicleMap) map).segmentSizes();
|
||||
System.out.println("segs: " + segments + " min: " + minSize + " was " + map.size() + " "
|
||||
+ Arrays.toString(a)
|
||||
+ " sum: " + sum(a));
|
||||
@@ -166,9 +166,9 @@ public class EntryCountMapTest {
|
||||
}
|
||||
}
|
||||
|
||||
private long sum(int[] ints) {
|
||||
private long sum(long[] longs) {
|
||||
long sum = 0;
|
||||
for (int i : ints) {
|
||||
for (long i : longs) {
|
||||
sum += i;
|
||||
}
|
||||
return sum;
|
||||
|
||||
@@ -21,10 +21,13 @@ package net.openhft.chronicle.map;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import net.openhft.lang.collection.SingleThreadedDirectBitSet;
|
||||
import net.openhft.lang.io.DirectStore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -36,11 +39,11 @@ import static org.junit.Assert.assertTrue;
|
||||
@RunWith(value = Parameterized.class)
|
||||
public class IntIntMultiMapTest {
|
||||
|
||||
IntIntMultiMap map;
|
||||
Multimap<Integer, Integer> referenceMap = HashMultimap.create();
|
||||
private Class<? extends IntIntMultiMap> c;
|
||||
MultiMap map;
|
||||
Multimap<Long, Long> referenceMap = HashMultimap.create();
|
||||
private Class<? extends MultiMap> c;
|
||||
|
||||
public IntIntMultiMapTest(Class<? extends IntIntMultiMap> c)
|
||||
public IntIntMultiMapTest(Class<? extends MultiMap> c)
|
||||
throws Exception {
|
||||
this.c = c;
|
||||
}
|
||||
@@ -53,20 +56,20 @@ public class IntIntMultiMapTest {
|
||||
});
|
||||
}
|
||||
|
||||
private void initMap(int capacity) {
|
||||
private void initMap(long capacity) {
|
||||
try {
|
||||
map = c.getConstructor(int.class).newInstance(capacity);
|
||||
map = c.getConstructor(long.class).newInstance(capacity);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void multiMapEquals() {
|
||||
class Action implements IntIntMultiMap.EntryConsumer {
|
||||
class Action implements MultiMap.EntryConsumer {
|
||||
int mapSize = 0;
|
||||
|
||||
@Override
|
||||
public void accept(int key, int value) {
|
||||
public void accept(long key, long value) {
|
||||
mapSize++;
|
||||
assertTrue(referenceMap.containsEntry(key, value));
|
||||
}
|
||||
@@ -76,24 +79,24 @@ public class IntIntMultiMapTest {
|
||||
assertEquals(referenceMap.size(), action.mapSize);
|
||||
}
|
||||
|
||||
private void valuesEqualsByKey(int k) {
|
||||
List<Integer> values = new ArrayList<Integer>();
|
||||
private void valuesEqualsByKey(long k) {
|
||||
List<Long> values = new ArrayList<Long>();
|
||||
map.startSearch(k);
|
||||
int v;
|
||||
while ((v = map.nextPos()) >= 0)
|
||||
long v;
|
||||
while ((v = map.nextPos()) >= 0L)
|
||||
values.add(v);
|
||||
Set<Integer> valueSet = new HashSet<Integer>(values);
|
||||
Set<Long> valueSet = new HashSet<Long>(values);
|
||||
assertEquals(values.size(), valueSet.size());
|
||||
assertEquals(new HashSet<Integer>(referenceMap.get(k)), valueSet);
|
||||
assertEquals(new HashSet<Long>(referenceMap.get(k)), valueSet);
|
||||
}
|
||||
|
||||
private void put(int k, int v) {
|
||||
private void put(long k, long v) {
|
||||
map.put(k, v);
|
||||
referenceMap.put(k, v);
|
||||
}
|
||||
|
||||
private void remove(int k, int v, boolean present) {
|
||||
assertEquals(present, map.remove(k, v));
|
||||
private void remove(long k, long v) {
|
||||
map.remove(k, v);
|
||||
referenceMap.remove(k, v);
|
||||
}
|
||||
|
||||
@@ -114,23 +117,22 @@ public class IntIntMultiMapTest {
|
||||
put(1, 15);
|
||||
multiMapEquals();
|
||||
|
||||
remove(1, 11, true);
|
||||
remove(1, 11);
|
||||
multiMapEquals();
|
||||
remove(1, 11, false);
|
||||
|
||||
valuesEqualsByKey(3);
|
||||
valuesEqualsByKey(1);
|
||||
|
||||
remove(1, 12, true);
|
||||
remove(1, 12);
|
||||
multiMapEquals();
|
||||
|
||||
remove(1, 15, true);
|
||||
remove(1, 15);
|
||||
multiMapEquals();
|
||||
|
||||
remove(1, 13, true);
|
||||
remove(1, 13);
|
||||
multiMapEquals();
|
||||
|
||||
remove(1, 14, true);
|
||||
remove(1, 14);
|
||||
multiMapEquals();
|
||||
}
|
||||
|
||||
@@ -146,4 +148,33 @@ public class IntIntMultiMapTest {
|
||||
map.startSearch(15);
|
||||
assertTrue(map.nextPos() < 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaxCapacity() throws NoSuchFieldException, IllegalAccessException {
|
||||
Field maxCapacityField = c.getDeclaredField("MAX_CAPACITY");
|
||||
long maxCapacity = maxCapacityField.getLong(null);
|
||||
Field entrySizeField = c.getDeclaredField("ENTRY_SIZE");
|
||||
entrySizeField.setAccessible(true);
|
||||
long entrySize = entrySizeField.getLong(null);
|
||||
if (Runtime.getRuntime().maxMemory() < maxCapacity * entrySize * 3L / 2L) {
|
||||
System.out.println("Skipped " + c + " maxCapacity test because there is not enough " +
|
||||
"memory in system");
|
||||
return;
|
||||
}
|
||||
initMap(maxCapacity);
|
||||
Random r = new Random();
|
||||
int bound = maxCapacity > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) maxCapacity;
|
||||
for (long i = 0L; i < maxCapacity; i++) {
|
||||
map.put(r.nextInt(bound), i);
|
||||
}
|
||||
final SingleThreadedDirectBitSet bs =
|
||||
new SingleThreadedDirectBitSet(new DirectStore(maxCapacity / 8).bytes());
|
||||
map.forEach(new MultiMap.EntryConsumer() {
|
||||
@Override
|
||||
public void accept(long key, long value) {
|
||||
bs.set(value);
|
||||
}
|
||||
});
|
||||
assertTrue(bs.allSet(0L, maxCapacity));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user