mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -2,6 +2,7 @@ package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.lang.io.serialization.impl.*;
|
||||
import net.openhft.lang.values.*;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -18,8 +19,8 @@ import static org.junit.Assert.*;
|
||||
|
||||
public class CHMUseCasesTest {
|
||||
/**
|
||||
* String is not as efficient as CharSequence as a key or value but easier to use The key can
|
||||
* only be on heap and variable length serialised.
|
||||
* String is not as efficient as CharSequence as a key or value but easier to use The key can only be on heap and
|
||||
* variable length serialised.
|
||||
*/
|
||||
@Test
|
||||
public void testStringStringMap() throws ExecutionException, InterruptedException {
|
||||
@@ -32,19 +33,18 @@ public class CHMUseCasesTest {
|
||||
try (ChronicleMap<String, String> map = chmb.create()) {
|
||||
*/
|
||||
try (ChronicleMap<String, String> map = ChronicleMapBuilder
|
||||
.of(String.class, String.class)
|
||||
.checkSerializedValues() // for testing purposes only
|
||||
.of(String.class, String.class) // for testing purposes only
|
||||
.create()) {
|
||||
map.put("Hello", "World");
|
||||
assertEquals("World", map.get("Hello"));
|
||||
|
||||
assertEquals("New World", map.mapForKey("Hello", new Function<String, String>() {
|
||||
assertEquals("New World", map.getMapped("Hello", new Function<String, String>() {
|
||||
@Override
|
||||
public String apply(String s) {
|
||||
return "New " + s;
|
||||
}
|
||||
}));
|
||||
assertEquals(null, map.mapForKey("No key", new Function<String, String>() {
|
||||
assertEquals(null, map.getMapped("No key", new Function<String, String>() {
|
||||
@Override
|
||||
public String apply(String s) {
|
||||
return "New " + s;
|
||||
@@ -67,32 +67,29 @@ public class CHMUseCasesTest {
|
||||
try (ChronicleMap<String, String> map = chmb.create()) {
|
||||
*/
|
||||
try (ChronicleMap<String, String> map = ChronicleMapBuilder
|
||||
.of(String.class, String.class)
|
||||
.checkSerializedValues() // for testing purposes only
|
||||
.of(String.class, String.class) // for testing purposes only
|
||||
.create()) {
|
||||
map.put("Hello", "World");
|
||||
|
||||
|
||||
map.putWith("Hello", new Mutator<String>() {
|
||||
map.putMapped("Hello", new UnaryOperator<String>() {
|
||||
@Override
|
||||
public String update(String s) {
|
||||
return "New " + s;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* CharSequence is more efficient when object creation is avoided. The key can only be on heap
|
||||
* and variable length serialised.
|
||||
* CharSequence is more efficient when object creation is avoided. The key can only be on heap and variable length
|
||||
* serialised.
|
||||
*/
|
||||
@Test
|
||||
public void testCharSequenceCharSequenceMap() throws ExecutionException, InterruptedException {
|
||||
try (ChronicleMap<CharSequence, CharSequence> map = ChronicleMapBuilder
|
||||
.of(CharSequence.class, CharSequence.class)
|
||||
.checkSerializedValues() // for testing purposes only
|
||||
.of(CharSequence.class, CharSequence.class) // for testing purposes only
|
||||
.defaultValue("")
|
||||
.create()) {
|
||||
map.put("Hello", "World");
|
||||
StringBuilder key = new StringBuilder();
|
||||
@@ -109,14 +106,14 @@ public class CHMUseCasesTest {
|
||||
assertNull(map.getUsing(key, value));
|
||||
|
||||
|
||||
assertEquals("New World", map.mapForKey("Hello", new
|
||||
assertEquals("New World", map.getMapped("Hello", new
|
||||
Function<CharSequence, CharSequence>() {
|
||||
@Override
|
||||
public CharSequence apply(CharSequence s) {
|
||||
return "New " + s;
|
||||
}
|
||||
}));
|
||||
assertEquals(null, map.mapForKey("No key", new
|
||||
assertEquals(null, map.getMapped("No key", new
|
||||
Function<CharSequence, CharSequence>() {
|
||||
@Override
|
||||
public CharSequence apply(CharSequence s) {
|
||||
@@ -124,8 +121,8 @@ public class CHMUseCasesTest {
|
||||
}
|
||||
}));
|
||||
|
||||
assertEquals("New World !!", map.putWith("Hello", new
|
||||
Mutator<CharSequence>() {
|
||||
assertEquals("New World !!", map.putMapped("Hello", new
|
||||
UnaryOperator<CharSequence>() {
|
||||
@Override
|
||||
public CharSequence update(CharSequence s) {
|
||||
((StringBuilder) s).append(" !!");
|
||||
@@ -135,8 +132,8 @@ public class CHMUseCasesTest {
|
||||
|
||||
assertEquals("New World !!", map.get("Hello").toString());
|
||||
|
||||
assertEquals(null, map.putWith("no-key", new
|
||||
Mutator<CharSequence>() {
|
||||
assertEquals("New !!", map.putMapped("no-key", new
|
||||
UnaryOperator<CharSequence>() {
|
||||
@Override
|
||||
public CharSequence update(CharSequence s) {
|
||||
((StringBuilder) s).append("!!");
|
||||
@@ -153,13 +150,12 @@ public class CHMUseCasesTest {
|
||||
@Test
|
||||
public void testStringValueStringValueMap() {
|
||||
try (ChronicleMap<StringValue, StringValue> map = ChronicleMapBuilder
|
||||
.of(StringValue.class, StringValue.class)
|
||||
.checkSerializedValues() // for testing purposes only
|
||||
.of(StringValue.class, StringValue.class) // for testing purposes only
|
||||
.create()) {
|
||||
StringValue key1 = ChronicleMapBuilder.newInstance(StringValue.class, true);
|
||||
StringValue key2 = ChronicleMapBuilder.newInstance(StringValue.class, true);
|
||||
StringValue value1 = ChronicleMapBuilder.newInstance(StringValue.class, false);
|
||||
StringValue value2 = ChronicleMapBuilder.newInstance(StringValue.class, false);
|
||||
StringValue key1 = map.newKeyInstance();
|
||||
StringValue key2 = map.newKeyInstance();
|
||||
StringValue value1 = map.newValueInstance();
|
||||
StringValue value2 = map.newValueInstance();
|
||||
|
||||
key1.setValue(new StringBuilder("1"));
|
||||
value1.setValue("11");
|
||||
@@ -246,7 +242,7 @@ public class CHMUseCasesTest {
|
||||
try (ChronicleMap<Integer, Integer> map = ChronicleMapBuilder
|
||||
.of(Integer.class, Integer.class)
|
||||
.entrySize(8)
|
||||
.disableOversizedEntries(true) // disabled for testing purposes only.
|
||||
.disableOversizedEntries() // disabled for testing purposes only.
|
||||
.create()) {
|
||||
Integer key1;
|
||||
Integer key2;
|
||||
@@ -268,13 +264,13 @@ public class CHMUseCasesTest {
|
||||
assertEquals(null, map.get(3));
|
||||
assertEquals(null, map.get(4));
|
||||
|
||||
assertEquals((Integer) 110, map.mapForKey(1, new Function<Integer, Integer>() {
|
||||
assertEquals((Integer) 110, map.getMapped(1, new Function<Integer, Integer>() {
|
||||
@Override
|
||||
public Integer apply(Integer s) {
|
||||
return 10 * s;
|
||||
}
|
||||
}));
|
||||
assertEquals(null, map.mapForKey(-1, new Function<Integer, Integer>() {
|
||||
assertEquals(null, map.getMapped(-1, new Function<Integer, Integer>() {
|
||||
@Override
|
||||
public Integer apply(Integer s) {
|
||||
return 10 * s;
|
||||
@@ -282,7 +278,7 @@ public class CHMUseCasesTest {
|
||||
}));
|
||||
|
||||
try {
|
||||
map.putWith(1, new Mutator<Integer>() {
|
||||
map.putMapped(1, new UnaryOperator<Integer>() {
|
||||
@Override
|
||||
public Integer update(Integer s) {
|
||||
return s + 1;
|
||||
@@ -300,7 +296,7 @@ public class CHMUseCasesTest {
|
||||
try (ChronicleMap<Long, Long> map = ChronicleMapBuilder
|
||||
.of(Long.class, Long.class)
|
||||
.entrySize(16)
|
||||
.disableOversizedEntries(true) // disabled for testing purposes only.
|
||||
.disableOversizedEntries() // disabled for testing purposes only.
|
||||
.create()) {
|
||||
map.put(1L, 11L);
|
||||
assertEquals((Long) 11L, map.get(1L));
|
||||
@@ -311,13 +307,13 @@ public class CHMUseCasesTest {
|
||||
assertEquals(null, map.get(3L));
|
||||
assertEquals(null, map.get(4L));
|
||||
|
||||
assertEquals((Long) 110L, map.mapForKey(1L, new Function<Long, Long>() {
|
||||
assertEquals((Long) 110L, map.getMapped(1L, new Function<Long, Long>() {
|
||||
@Override
|
||||
public Long apply(Long s) {
|
||||
return 10 * s;
|
||||
}
|
||||
}));
|
||||
assertEquals(null, map.mapForKey(-1L, new Function<Long, Long>() {
|
||||
assertEquals(null, map.getMapped(-1L, new Function<Long, Long>() {
|
||||
@Override
|
||||
public Long apply(Long s) {
|
||||
return 10 * s;
|
||||
@@ -325,7 +321,7 @@ public class CHMUseCasesTest {
|
||||
}));
|
||||
|
||||
try {
|
||||
map.putWith(1L, new Mutator<Long>() {
|
||||
map.putMapped(1L, new UnaryOperator<Long>() {
|
||||
@Override
|
||||
public Long update(Long s) {
|
||||
return s + 1;
|
||||
@@ -342,7 +338,7 @@ public class CHMUseCasesTest {
|
||||
public void testDoubleDoubleMap() throws ExecutionException, InterruptedException {
|
||||
try (ChronicleMap<Double, Double> map = ChronicleMapBuilder
|
||||
.of(Double.class, Double.class)
|
||||
.disableOversizedEntries(true) // disabled for testing purposes only.
|
||||
.disableOversizedEntries() // disabled for testing purposes only.
|
||||
.entrySize(16)
|
||||
.create()) {
|
||||
map.put(1.0, 11.0);
|
||||
@@ -354,13 +350,13 @@ public class CHMUseCasesTest {
|
||||
assertEquals(null, map.get(3.0));
|
||||
assertEquals(null, map.get(4.0));
|
||||
|
||||
assertEquals((Double) 110.0, map.mapForKey(1.0, new Function<Double, Double>() {
|
||||
assertEquals((Double) 110.0, map.getMapped(1.0, new Function<Double, Double>() {
|
||||
@Override
|
||||
public Double apply(Double s) {
|
||||
return 10 * s;
|
||||
}
|
||||
}));
|
||||
assertEquals(null, map.mapForKey(-1.0, new Function<Double, Double>() {
|
||||
assertEquals(null, map.getMapped(-1.0, new Function<Double, Double>() {
|
||||
@Override
|
||||
public Double apply(Double s) {
|
||||
return 10 * s;
|
||||
@@ -368,7 +364,7 @@ public class CHMUseCasesTest {
|
||||
}));
|
||||
|
||||
try {
|
||||
map.putWith(1.0, new Mutator<Double>() {
|
||||
map.putMapped(1.0, new UnaryOperator<Double>() {
|
||||
@Override
|
||||
public Double update(Double s) {
|
||||
return s + 1;
|
||||
@@ -386,7 +382,7 @@ public class CHMUseCasesTest {
|
||||
public void testByteArrayByteArrayMap() throws ExecutionException, InterruptedException {
|
||||
try (ChronicleMap<byte[], byte[]> map = ChronicleMapBuilder
|
||||
.of(byte[].class, byte[].class)
|
||||
.disableOversizedEntries(true) // disabled for testing purposes only.
|
||||
.disableOversizedEntries() // disabled for testing purposes only.
|
||||
.entrySize(12)
|
||||
.create()) {
|
||||
byte[] key1 = {1, 1, 1, 1};
|
||||
@@ -401,20 +397,20 @@ public class CHMUseCasesTest {
|
||||
map.put(key1, value1);
|
||||
|
||||
|
||||
assertTrue(Arrays.equals(new byte[]{11, 11}, map.mapForKey(key1, new Function<byte[], byte[]>() {
|
||||
assertTrue(Arrays.equals(new byte[]{11, 11}, map.getMapped(key1, new Function<byte[], byte[]>() {
|
||||
@Override
|
||||
public byte[] apply(byte[] s) {
|
||||
return Arrays.copyOf(s, 2);
|
||||
}
|
||||
})));
|
||||
assertEquals(null, map.mapForKey(key2, new Function<byte[], byte[]>() {
|
||||
assertEquals(null, map.getMapped(key2, new Function<byte[], byte[]>() {
|
||||
@Override
|
||||
public byte[] apply(byte[] s) {
|
||||
return Arrays.copyOf(s, 2);
|
||||
}
|
||||
}));
|
||||
|
||||
assertTrue(Arrays.equals(new byte[]{12, 10}, map.putWith(key1, new Mutator<byte[]>() {
|
||||
assertTrue(Arrays.equals(new byte[]{12, 10}, map.putMapped(key1, new UnaryOperator<byte[]>() {
|
||||
@Override
|
||||
public byte[] update(byte[] s) {
|
||||
s[0]++;
|
||||
@@ -434,10 +430,11 @@ public class CHMUseCasesTest {
|
||||
public void testByteBufferByteBufferMap() throws ExecutionException, InterruptedException {
|
||||
try (ChronicleMap<ByteBuffer, ByteBuffer> map = ChronicleMapBuilder
|
||||
.of(ByteBuffer.class, ByteBuffer.class)
|
||||
.valueMarshaller(ByteBufferMarshaller.INSTANCE)
|
||||
.keyMarshaller(ByteBufferMarshaller.INSTANCE)
|
||||
.disableOversizedEntries(true) // disabled for testing purposes only.
|
||||
.entrySize(20)
|
||||
.valueMarshaller(ByteBufferMarshaller.INSTANCE)
|
||||
.disableOversizedEntries() // disabled for testing purposes only.
|
||||
// TODO does this have to be 14 bytes?
|
||||
.entrySize(14)
|
||||
.create()) {
|
||||
ByteBuffer key1 = ByteBuffer.wrap(new byte[]{1, 1, 1, 1});
|
||||
ByteBuffer key2 = ByteBuffer.wrap(new byte[]{2, 2, 2, 2});
|
||||
@@ -458,10 +455,10 @@ public class CHMUseCasesTest {
|
||||
};
|
||||
|
||||
map.put(key1, value1);
|
||||
assertBBEquals(ByteBuffer.wrap(new byte[]{11, 11}), map.mapForKey(key1, function));
|
||||
assertEquals(null, map.mapForKey(key2, function));
|
||||
assertBBEquals(ByteBuffer.wrap(new byte[]{11, 11}), map.getMapped(key1, function));
|
||||
assertEquals(null, map.getMapped(key2, function));
|
||||
|
||||
assertBBEquals(ByteBuffer.wrap(new byte[]{12, 10}), map.putWith(key1, new Mutator<ByteBuffer>() {
|
||||
assertBBEquals(ByteBuffer.wrap(new byte[]{12, 10}), map.putMapped(key1, new UnaryOperator<ByteBuffer>() {
|
||||
@Override
|
||||
public ByteBuffer update(ByteBuffer s) {
|
||||
s.put(0, (byte) (s.get(0) + 1));
|
||||
@@ -510,7 +507,6 @@ public class CHMUseCasesTest {
|
||||
|
||||
|
||||
try (WriteContext wc = map.acquireUsingLocked(key1, valueB)) {
|
||||
|
||||
assertBBEquals(value1, valueB);
|
||||
appendMode(valueB);
|
||||
valueB.putShort((short) 12345);
|
||||
@@ -522,7 +518,7 @@ public class CHMUseCasesTest {
|
||||
|
||||
ByteBuffer bb1 = ByteBuffer.allocate(8);
|
||||
bb1.put(value1);
|
||||
bb1.putShort((short)12345);
|
||||
bb1.putShort((short) 12345);
|
||||
bb1.flip();
|
||||
assertBBEquals(bb1, valueA);
|
||||
}
|
||||
@@ -543,7 +539,7 @@ public class CHMUseCasesTest {
|
||||
.of(ByteBuffer.class, ByteBuffer.class)
|
||||
.valueMarshaller(ByteBufferMarshaller.INSTANCE) // we should not have to to this !
|
||||
.keyMarshaller(ByteBufferMarshaller.INSTANCE) // we should not have to to this !
|
||||
.disableOversizedEntries(true) // disabled for testing purposes only.
|
||||
.disableOversizedEntries() // disabled for testing purposes only.
|
||||
.entrySize(12)
|
||||
.create()) {
|
||||
ByteBuffer key1 = ByteBuffer.wrap(new byte[]{1, 1, 1, 1});
|
||||
@@ -568,10 +564,10 @@ public class CHMUseCasesTest {
|
||||
return slice;
|
||||
}
|
||||
};
|
||||
assertBBEquals(ByteBuffer.wrap(new byte[]{11, 11}), map.mapForKey(key1, function));
|
||||
assertEquals(null, map.mapForKey(key2, function));
|
||||
assertBBEquals(ByteBuffer.wrap(new byte[]{11, 11}), map.getMapped(key1, function));
|
||||
assertEquals(null, map.getMapped(key2, function));
|
||||
|
||||
assertBBEquals(ByteBuffer.wrap(new byte[]{12, 10}), map.putWith(key1, new Mutator<ByteBuffer>() {
|
||||
assertBBEquals(ByteBuffer.wrap(new byte[]{12, 10}), map.putMapped(key1, new UnaryOperator<ByteBuffer>() {
|
||||
@Override
|
||||
public ByteBuffer update(ByteBuffer s) {
|
||||
s.put(0, (byte) (s.get(0) + 1));
|
||||
@@ -595,13 +591,18 @@ public class CHMUseCasesTest {
|
||||
public void testIntValueIntValueMap() {
|
||||
try (ChronicleMap<IntValue, IntValue> map = ChronicleMapBuilder
|
||||
.of(IntValue.class, IntValue.class)
|
||||
.disableOversizedEntries(true) // disabled for testing purposes only.
|
||||
.disableOversizedEntries() // disabled for testing purposes only.
|
||||
.entrySize(8)
|
||||
.create()) {
|
||||
IntValue key1 = ChronicleMapBuilder.newInstance(IntValue.class, false);
|
||||
IntValue key2 = ChronicleMapBuilder.newInstance(IntValue.class, false);
|
||||
IntValue value1 = ChronicleMapBuilder.newInstance(IntValue.class, false);
|
||||
IntValue value2 = ChronicleMapBuilder.newInstance(IntValue.class, false);
|
||||
IntValue key1 = map.newKeyInstance();
|
||||
IntValue key2 = map.newKeyInstance();
|
||||
IntValue value1 = map.newValueInstance();
|
||||
IntValue value2 = map.newValueInstance();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
key1.setValue(1);
|
||||
value1.setValue(11);
|
||||
@@ -670,6 +671,26 @@ public class CHMUseCasesTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Generated code creates a field too large ie. it ignores the @Range")
|
||||
public void testUnsignedIntValueUnsignedIntValueMapEntrySize() {
|
||||
// TODO once this is working, merge the next test.
|
||||
try (ChronicleMap<UnsignedIntValue, UnsignedIntValue> map = ChronicleMapBuilder
|
||||
.of(UnsignedIntValue.class, UnsignedIntValue.class)
|
||||
.disableOversizedEntries() // disabled for testing purposes only.
|
||||
.entrySize(8)
|
||||
.create()) {
|
||||
UnsignedIntValue key1 = map.newKeyInstance();
|
||||
UnsignedIntValue value1 = map.newValueInstance();
|
||||
|
||||
key1.setValue(1);
|
||||
value1.setValue(11);
|
||||
map.put(key1, value1);
|
||||
assertEquals(value1, map.get(key1));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For unsigned int -> unsigned int entries, the key can be on heap or off heap.
|
||||
*/
|
||||
@@ -677,13 +698,14 @@ public class CHMUseCasesTest {
|
||||
public void testUnsignedIntValueUnsignedIntValueMap() {
|
||||
try (ChronicleMap<UnsignedIntValue, UnsignedIntValue> map = ChronicleMapBuilder
|
||||
.of(UnsignedIntValue.class, UnsignedIntValue.class)
|
||||
.disableOversizedEntries(true) // disabled for testing purposes only.
|
||||
.entrySize(8)
|
||||
.create()) {
|
||||
UnsignedIntValue key1 = ChronicleMapBuilder.newInstance(UnsignedIntValue.class, true);
|
||||
UnsignedIntValue key2 = ChronicleMapBuilder.newInstance(UnsignedIntValue.class, true);
|
||||
UnsignedIntValue value1 = ChronicleMapBuilder.newInstance(UnsignedIntValue.class, false);
|
||||
UnsignedIntValue value2 = ChronicleMapBuilder.newInstance(UnsignedIntValue.class, false);
|
||||
|
||||
|
||||
|
||||
UnsignedIntValue key1 = map.newKeyInstance();
|
||||
UnsignedIntValue key2 = map.newKeyInstance();
|
||||
UnsignedIntValue value1 = map.newValueInstance();
|
||||
UnsignedIntValue value2 = map.newValueInstance();
|
||||
|
||||
key1.setValue(1);
|
||||
value1.setValue(11);
|
||||
@@ -759,13 +781,13 @@ public class CHMUseCasesTest {
|
||||
public void testIntValueShortValueMap() {
|
||||
try (ChronicleMap<IntValue, ShortValue> map = ChronicleMapBuilder
|
||||
.of(IntValue.class, ShortValue.class)
|
||||
.disableOversizedEntries(true) // disabled for testing purposes only.
|
||||
.disableOversizedEntries() // disabled for testing purposes only.
|
||||
.entrySize(6)
|
||||
.create()) {
|
||||
IntValue key1 = ChronicleMapBuilder.newInstance(IntValue.class, false);
|
||||
IntValue key2 = ChronicleMapBuilder.newInstance(IntValue.class, false);
|
||||
ShortValue value1 = ChronicleMapBuilder.newInstance(ShortValue.class, false);
|
||||
ShortValue value2 = ChronicleMapBuilder.newInstance(ShortValue.class, false);
|
||||
IntValue key1 = map.newKeyInstance();
|
||||
IntValue key2 = map.newKeyInstance();
|
||||
ShortValue value1 = map.newValueInstance();
|
||||
ShortValue value2 = map.newValueInstance();
|
||||
|
||||
key1.setValue(1);
|
||||
value1.setValue((short) 11);
|
||||
@@ -842,12 +864,13 @@ public class CHMUseCasesTest {
|
||||
try (ChronicleMap<IntValue, UnsignedShortValue> map = ChronicleMapBuilder
|
||||
.of(IntValue.class, UnsignedShortValue.class)
|
||||
.entrySize(6)
|
||||
.disableOversizedEntries(true) // disabled for testing purposes only.
|
||||
.disableOversizedEntries() // disabled for testing purposes only.
|
||||
.create()) {
|
||||
IntValue key1 = ChronicleMapBuilder.newInstance(IntValue.class, false);
|
||||
IntValue key2 = ChronicleMapBuilder.newInstance(IntValue.class, false);
|
||||
UnsignedShortValue value1 = ChronicleMapBuilder.newInstance(UnsignedShortValue.class, false);
|
||||
UnsignedShortValue value2 = ChronicleMapBuilder.newInstance(UnsignedShortValue.class, false);
|
||||
|
||||
IntValue key1 = map.newKeyInstance();
|
||||
IntValue key2 = map.newKeyInstance();
|
||||
UnsignedShortValue value1 = map.newValueInstance();
|
||||
UnsignedShortValue value2 = map.newValueInstance();
|
||||
|
||||
key1.setValue(1);
|
||||
value1.setValue(11);
|
||||
@@ -923,13 +946,14 @@ public class CHMUseCasesTest {
|
||||
public void testIntValueCharValueMap() {
|
||||
try (ChronicleMap<IntValue, CharValue> map = ChronicleMapBuilder
|
||||
.of(IntValue.class, CharValue.class)
|
||||
.disableOversizedEntries(true) // disabled for testing purposes only.
|
||||
.disableOversizedEntries() // disabled for testing purposes only.
|
||||
.entrySize(6)
|
||||
.create()) {
|
||||
IntValue key1 = ChronicleMapBuilder.newInstance(IntValue.class, false);
|
||||
IntValue key2 = ChronicleMapBuilder.newInstance(IntValue.class, false);
|
||||
CharValue value1 = ChronicleMapBuilder.newInstance(CharValue.class, false);
|
||||
CharValue value2 = ChronicleMapBuilder.newInstance(CharValue.class, false);
|
||||
|
||||
IntValue key1 = map.newKeyInstance();
|
||||
IntValue key2 = map.newKeyInstance();
|
||||
CharValue value1 = map.newValueInstance();
|
||||
CharValue value2 = map.newValueInstance();
|
||||
|
||||
key1.setValue(1);
|
||||
value1.setValue((char) 11);
|
||||
@@ -1006,12 +1030,16 @@ public class CHMUseCasesTest {
|
||||
try (ChronicleMap<IntValue, UnsignedByteValue> map = ChronicleMapBuilder
|
||||
.of(IntValue.class, UnsignedByteValue.class)
|
||||
.entrySize(5)
|
||||
.disableOversizedEntries(true) // disabled for testing purposes only.
|
||||
.disableOversizedEntries() // disabled for testing purposes only.
|
||||
.create()) {
|
||||
IntValue key1 = ChronicleMapBuilder.newInstance(IntValue.class, false);
|
||||
IntValue key2 = ChronicleMapBuilder.newInstance(IntValue.class, false);
|
||||
UnsignedByteValue value1 = ChronicleMapBuilder.newInstance(UnsignedByteValue.class, false);
|
||||
UnsignedByteValue value2 = ChronicleMapBuilder.newInstance(UnsignedByteValue.class, false);
|
||||
|
||||
|
||||
IntValue key1 = map.newKeyInstance();
|
||||
IntValue key2 = map.newKeyInstance();
|
||||
UnsignedByteValue value1 = map.newValueInstance();
|
||||
UnsignedByteValue value2 = map.newValueInstance();
|
||||
|
||||
|
||||
|
||||
key1.setValue(1);
|
||||
value1.setValue(11);
|
||||
@@ -1087,13 +1115,17 @@ public class CHMUseCasesTest {
|
||||
public void testIntValueBooleanValueMap() {
|
||||
try (ChronicleMap<IntValue, BooleanValue> map = ChronicleMapBuilder
|
||||
.of(IntValue.class, BooleanValue.class)
|
||||
.disableOversizedEntries(true) // disabled for testing purposes only.
|
||||
.disableOversizedEntries() // disabled for testing purposes only.
|
||||
.entrySize(5)
|
||||
.create()) {
|
||||
IntValue key1 = ChronicleMapBuilder.newInstance(IntValue.class, false);
|
||||
IntValue key2 = ChronicleMapBuilder.newInstance(IntValue.class, false);
|
||||
BooleanValue value1 = ChronicleMapBuilder.newInstance(BooleanValue.class, false);
|
||||
BooleanValue value2 = ChronicleMapBuilder.newInstance(BooleanValue.class, false);
|
||||
|
||||
|
||||
|
||||
IntValue key1 = map.newKeyInstance();
|
||||
IntValue key2 = map.newKeyInstance();
|
||||
BooleanValue value1 = map.newValueInstance();
|
||||
BooleanValue value2 = map.newValueInstance();
|
||||
|
||||
|
||||
key1.setValue(1);
|
||||
value1.setValue(true);
|
||||
@@ -1170,12 +1202,14 @@ public class CHMUseCasesTest {
|
||||
try (ChronicleMap<FloatValue, FloatValue> map = ChronicleMapBuilder
|
||||
.of(FloatValue.class, FloatValue.class)
|
||||
.entrySize(8)
|
||||
.disableOversizedEntries(true) // disabled for testing purposes only.
|
||||
.disableOversizedEntries() // disabled for testing purposes only.
|
||||
.create()) {
|
||||
FloatValue key1 = ChronicleMapBuilder.newInstance(FloatValue.class, false);
|
||||
FloatValue key2 = ChronicleMapBuilder.newInstance(FloatValue.class, false);
|
||||
FloatValue value1 = ChronicleMapBuilder.newInstance(FloatValue.class, false);
|
||||
FloatValue value2 = ChronicleMapBuilder.newInstance(FloatValue.class, false);
|
||||
|
||||
FloatValue key1 = map.newKeyInstance();
|
||||
FloatValue key2 = map.newKeyInstance();
|
||||
FloatValue value1 = map.newValueInstance();
|
||||
FloatValue value2 = map.newValueInstance();
|
||||
|
||||
|
||||
key1.setValue(1);
|
||||
value1.setValue(11);
|
||||
@@ -1254,10 +1288,10 @@ public class CHMUseCasesTest {
|
||||
.entrySize(16)
|
||||
.create()) {
|
||||
|
||||
DoubleValue key1 = ChronicleMapBuilder.newInstance(DoubleValue.class, false);
|
||||
DoubleValue key2 = ChronicleMapBuilder.newInstance(DoubleValue.class, false);
|
||||
DoubleValue value1 = ChronicleMapBuilder.newInstance(DoubleValue.class, false);
|
||||
DoubleValue value2 = ChronicleMapBuilder.newInstance(DoubleValue.class, false);
|
||||
DoubleValue key1 = map.newKeyInstance();
|
||||
DoubleValue key2 = map.newKeyInstance();
|
||||
DoubleValue value1 = map.newValueInstance();
|
||||
DoubleValue value2 = map.newValueInstance();
|
||||
|
||||
|
||||
key1.setValue(1);
|
||||
@@ -1337,12 +1371,14 @@ public class CHMUseCasesTest {
|
||||
try (ChronicleMap<LongValue, LongValue> map = ChronicleMapBuilder
|
||||
.of(LongValue.class, LongValue.class)
|
||||
.entrySize(16)
|
||||
.disableOversizedEntries(true) // disabled for testing purposes only.
|
||||
.disableOversizedEntries() // disabled for testing purposes only.
|
||||
.create()) {
|
||||
LongValue key1 = ChronicleMapBuilder.newInstance(LongValue.class, false);
|
||||
LongValue key2 = ChronicleMapBuilder.newInstance(LongValue.class, false);
|
||||
LongValue value1 = ChronicleMapBuilder.newInstance(LongValue.class, false);
|
||||
LongValue value2 = ChronicleMapBuilder.newInstance(LongValue.class, false);
|
||||
|
||||
LongValue key1 = map.newKeyInstance();
|
||||
LongValue key2 = map.newKeyInstance();
|
||||
LongValue value1 = map.newValueInstance();
|
||||
LongValue value2 = map.newValueInstance();
|
||||
|
||||
|
||||
|
||||
key1.setValue(1);
|
||||
|
||||
@@ -27,7 +27,7 @@ package net.openhft.chronicle.map;
|
||||
/*import junit.framework.Test;
|
||||
import junit.framework.TestSuite;*/
|
||||
|
||||
import net.openhft.chronicle.map.jrs166.JSR166TestCase;
|
||||
import net.openhft.chronicle.map.jsr166.JSR166TestCase;
|
||||
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
|
||||
@@ -26,36 +26,39 @@ import org.junit.Test;
|
||||
|
||||
import java.beans.XMLEncoder;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Created by peter on 06/12/14.
|
||||
*/
|
||||
public class LargeEntriesTest {
|
||||
|
||||
static final int ENTRIES = 640;
|
||||
static final int ENTRY_SIZE = 1024;
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testLargeStrings() throws ExecutionException, InterruptedException {
|
||||
public void testLargeStrings() throws ExecutionException, InterruptedException, IOException {
|
||||
final int ENTRIES = 250;
|
||||
final int ENTRY_SIZE = 100 * 1024;
|
||||
|
||||
File file = File.createTempFile("largeEntries", ".deleteme");
|
||||
file.deleteOnExit();
|
||||
final ChronicleMap<String, String> map = ChronicleMapBuilder
|
||||
.of(String.class, String.class)
|
||||
.valueMarshaller(SnappyStringMarshaller.INSTANCE)
|
||||
.actualSegments(1) // to force an error.
|
||||
.entries(ENTRIES * 2)
|
||||
.entrySize(ENTRY_SIZE / 4)
|
||||
.entries(ENTRIES)
|
||||
.entrySize(ENTRY_SIZE / 6)
|
||||
.putReturnsNull(true)
|
||||
.create();
|
||||
.createPersistedTo(file);
|
||||
{
|
||||
int threads = 2; //Runtime.getRuntime().availableProcessors();
|
||||
warmUpCompression(ENTRY_SIZE);
|
||||
int threads = 4; //Runtime.getRuntime().availableProcessors();
|
||||
ExecutorService es = Executors.newFixedThreadPool(threads);
|
||||
final int block = ENTRIES / threads;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
@@ -63,11 +66,10 @@ public class LargeEntriesTest {
|
||||
List<Future<?>> futureList = new ArrayList<>();
|
||||
for (int t = 0; t < threads; t++) {
|
||||
final int finalT = t;
|
||||
final int finalI = i;
|
||||
futureList.add(es.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
exerciseLargeStrings(map, finalI, finalT * block, finalT * block + block, ENTRY_SIZE);
|
||||
exerciseLargeStrings(map, finalT * block, finalT * block + block, ENTRY_SIZE);
|
||||
}
|
||||
}));
|
||||
}
|
||||
@@ -84,7 +86,70 @@ public class LargeEntriesTest {
|
||||
}
|
||||
}
|
||||
|
||||
void exerciseLargeStrings(ChronicleMap<String, String> map, int run, int start, int finish, int entrySize) {
|
||||
private void warmUpCompression(int entrySize) {
|
||||
String value = generateValue(entrySize);
|
||||
DirectBytes bytes = DirectStore.allocate(entrySize / 6).bytes();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
// warmup to compression.
|
||||
bytes.clear();
|
||||
SnappyStringMarshaller.INSTANCE.write(bytes, value);
|
||||
bytes.flip();
|
||||
SnappyStringMarshaller.INSTANCE.read(bytes);
|
||||
}
|
||||
bytes.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testLargeStringsPerf() throws ExecutionException, InterruptedException, IOException {
|
||||
doLargeEntryPerf(10000, 100 * 1024);
|
||||
doLargeEntryPerf(100000, 10 * 1024);
|
||||
doLargeEntryPerf(10000, 100 * 1024);
|
||||
doLargeEntryPerf(3000, 1024 * 1024);
|
||||
}
|
||||
|
||||
private void doLargeEntryPerf(int ENTRIES, final int ENTRY_SIZE) throws IOException, InterruptedException, ExecutionException {
|
||||
System.out.printf("Testing %,d entries of %,d KB%n", ENTRIES, ENTRY_SIZE);
|
||||
File file = File.createTempFile("largeEntries", ".deleteme");
|
||||
file.deleteOnExit();
|
||||
final ChronicleMap<String, String> map = ChronicleMapBuilder
|
||||
.of(String.class, String.class)
|
||||
.valueMarshaller(SnappyStringMarshaller.INSTANCE)
|
||||
.entries(ENTRIES * 2)
|
||||
.entrySize(ENTRY_SIZE / 6)
|
||||
.putReturnsNull(true)
|
||||
.createPersistedTo(file);
|
||||
{
|
||||
warmUpCompression(ENTRY_SIZE);
|
||||
int threads = Runtime.getRuntime().availableProcessors();
|
||||
ExecutorService es = Executors.newFixedThreadPool(threads);
|
||||
final int block = ENTRIES / threads;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
long start = System.currentTimeMillis();
|
||||
List<Future<?>> futureList = new ArrayList<>();
|
||||
for (int t = 0; t < threads; t++) {
|
||||
final int finalT = t;
|
||||
futureList.add(es.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
exerciseLargeStrings(map, finalT * block, finalT * block + block, ENTRY_SIZE);
|
||||
}
|
||||
}));
|
||||
}
|
||||
for (Future<?> future : futureList) {
|
||||
future.get();
|
||||
}
|
||||
long time = System.currentTimeMillis() - start;
|
||||
long operations = 3;
|
||||
System.out.printf("Put/Get rate was %.1f MB/s%n", operations * ENTRIES * ENTRY_SIZE / 1e6 / (time / 1e3));
|
||||
}
|
||||
es.shutdown();
|
||||
if (es.isTerminated())
|
||||
map.close();
|
||||
}
|
||||
}
|
||||
|
||||
void exerciseLargeStrings(ChronicleMap<String, String> map, int start, int finish, int entrySize) {
|
||||
/*
|
||||
final Thread thisThread = Thread.currentThread();
|
||||
Thread monitor = new Thread(new Runnable() {
|
||||
@@ -107,28 +172,15 @@ public class LargeEntriesTest {
|
||||
});
|
||||
monitor.start();
|
||||
*/
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
XMLEncoder xml = new XMLEncoder(baos);
|
||||
Map<String, String> map2 = new HashMap<>();
|
||||
Random rand = new Random(1);
|
||||
for (int i = 0; i < entrySize / 80; i++)
|
||||
map2.put("key-" + i, "value-" + rand.nextInt(1000));
|
||||
xml.writeObject(map2);
|
||||
xml.close();
|
||||
String value = baos.toString().substring(0, entrySize);
|
||||
// warmup to compression.
|
||||
if (run == 0) {
|
||||
DirectBytes bytes = DirectStore.allocate(entrySize).bytes();
|
||||
SnappyStringMarshaller.INSTANCE.write(bytes, value);
|
||||
bytes.flip();
|
||||
SnappyStringMarshaller.INSTANCE.read(bytes);
|
||||
bytes.release();
|
||||
}
|
||||
String value = generateValue(entrySize);
|
||||
|
||||
for (int i = start; i < finish; i++) {
|
||||
String key = "key-" + i;
|
||||
String object;
|
||||
|
||||
map.put(key, value);
|
||||
String object = map.get(key);
|
||||
object = map.get(key);
|
||||
assertTrue(key, map.containsKey(key));
|
||||
|
||||
assertNotNull(key, object);
|
||||
assertEquals(key, entrySize, object.length());
|
||||
@@ -138,10 +190,23 @@ public class LargeEntriesTest {
|
||||
for (int i = start; i < finish; i++) {
|
||||
// System.out.println(i);
|
||||
String key = "key-" + i;
|
||||
|
||||
String object = map.get(key);
|
||||
|
||||
assertNotNull(key, object);
|
||||
assertEquals(key, entrySize, object.length());
|
||||
}
|
||||
}
|
||||
|
||||
private String generateValue(int entrySize) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
XMLEncoder xml = new XMLEncoder(baos);
|
||||
Map<String, String> map2 = new HashMap<>();
|
||||
Random rand = new Random(1);
|
||||
for (int i = 0; i < entrySize / 80; i++)
|
||||
map2.put("key-" + i, "value-" + rand.nextInt(1000));
|
||||
xml.writeObject(map2);
|
||||
xml.close();
|
||||
return baos.toString().substring(0, entrySize);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.chronicle.map.jrs166.JSR166TestCase;
|
||||
import net.openhft.chronicle.map.jsr166.JSR166TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -218,13 +218,13 @@ public class ReplicationCheckingMap<K, V> implements ChronicleMap<K, V> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R mapForKey(K key, @NotNull Function<? super V, R> function) {
|
||||
return map1.mapForKey(key, function);
|
||||
public <R> R getMapped(K key, @NotNull Function<? super V, R> function) {
|
||||
return map1.getMapped(key, function);
|
||||
}
|
||||
|
||||
@Override
|
||||
public V putWith(K key, @NotNull Mutator<V> mutator) {
|
||||
return map1.putWith(key, mutator);
|
||||
public V putMapped(K key, @NotNull UnaryOperator<V> unaryOperator) {
|
||||
return map1.putMapped(key, unaryOperator);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -237,6 +237,16 @@ public class ReplicationCheckingMap<K, V> implements ChronicleMap<K, V> {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public V newValueInstance() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public K newKeyInstance() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public V acquireUsing(@NotNull K key, V usingValue) {
|
||||
return map1.acquireUsing(key, usingValue);
|
||||
|
||||
@@ -41,7 +41,7 @@ import static org.junit.Assert.assertTrue;
|
||||
public class StatelessClientTest {
|
||||
|
||||
public static final int SIZE = 2500;
|
||||
static int s_port = 9050;
|
||||
static int s_port = 9070;
|
||||
|
||||
enum ToString implements Function<Object, String> {
|
||||
INSTANCE;
|
||||
@@ -114,7 +114,7 @@ public class StatelessClientTest {
|
||||
.class, StringBuilder.class)
|
||||
.putReturnsNull(true)
|
||||
.statelessClient(new InetSocketAddress("localhost", port)).create()) {
|
||||
String actual = statelessMap.mapForKey(10, ToString.INSTANCE);
|
||||
String actual = statelessMap.getMapped(10, ToString.INSTANCE);
|
||||
|
||||
assertEquals("Hello World", actual);
|
||||
}
|
||||
@@ -134,7 +134,7 @@ public class StatelessClientTest {
|
||||
try (ChronicleMap<Integer, StringBuilder> statelessMap = ChronicleMapBuilder.of(Integer
|
||||
.class, StringBuilder.class)
|
||||
.statelessClient(new InetSocketAddress("localhost", port)).create()) {
|
||||
String actual = statelessMap.mapForKey(11, ToString.INSTANCE);
|
||||
String actual = statelessMap.getMapped(11, ToString.INSTANCE);
|
||||
|
||||
assertEquals(null, actual);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.chronicle.hash.replication.TimeProvider;
|
||||
import net.openhft.chronicle.map.jrs166.JSR166TestCase;
|
||||
import net.openhft.chronicle.map.jsr166.JSR166TestCase;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map.jrs166;
|
||||
package net.openhft.chronicle.map.jsr166;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import org.junit.After;
|
||||
+2
-2
@@ -16,11 +16,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map.jrs166.map;
|
||||
package net.openhft.chronicle.map.jsr166.map;
|
||||
|
||||
import net.openhft.chronicle.map.ChronicleMap;
|
||||
import net.openhft.chronicle.map.ChronicleMapBuilder;
|
||||
import net.openhft.chronicle.map.jrs166.JSR166TestCase;
|
||||
import net.openhft.chronicle.map.jsr166.JSR166TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map.jrs166.map;
|
||||
package net.openhft.chronicle.map.jsr166.map;
|
||||
|
||||
/*
|
||||
* Written by Doug Lea with assistance from members of JCP JSR-166
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map.jrs166.map;
|
||||
package net.openhft.chronicle.map.jsr166.map;
|
||||
|
||||
import net.openhft.chronicle.map.ChronicleMap;
|
||||
import net.openhft.chronicle.map.ChronicleMapBuilder;
|
||||
+16
-6
@@ -16,11 +16,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map.jrs166.map;
|
||||
package net.openhft.chronicle.map.jsr166.map;
|
||||
|
||||
import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
|
||||
import net.openhft.chronicle.map.*;
|
||||
import net.openhft.chronicle.map.jrs166.JSR166TestCase;
|
||||
import net.openhft.chronicle.map.jsr166.JSR166TestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -170,13 +170,13 @@ public class StatelessChronicleMapTest extends JSR166TestCase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R mapForKey(K key, @NotNull Function<? super V, R> function) {
|
||||
return d.mapForKey(key, function);
|
||||
public <R> R getMapped(K key, @NotNull Function<? super V, R> function) {
|
||||
return d.getMapped(key, function);
|
||||
}
|
||||
|
||||
@Override
|
||||
public V putWith(K key, @NotNull Mutator<V> mutator) {
|
||||
return d.putWith(key, mutator);
|
||||
public V putMapped(K key, @NotNull UnaryOperator<V> unaryOperator) {
|
||||
return d.putMapped(key, unaryOperator);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -189,6 +189,16 @@ public class StatelessChronicleMapTest extends JSR166TestCase {
|
||||
d.putAll(fromFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public V newValueInstance() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public K newKeyInstance() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public V putIfAbsent(K key, V value) {
|
||||
return d.putIfAbsent(key, value);
|
||||
Reference in New Issue
Block a user