Merge remote-tracking branch 'origin/master'

Conflicts:
	src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java
This commit is contained in:
Rob Austin
2014-12-11 19:36:50 +00:00
51 changed files with 1677 additions and 2650 deletions
@@ -5,7 +5,6 @@ import net.openhft.chronicle.map.ChronicleMap;
import net.openhft.chronicle.map.ChronicleMapBuilder;
import net.openhft.lang.model.DataValueClasses;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import java.net.InetSocketAddress;
@@ -39,7 +39,7 @@ public class CHMTest5 {
.entries(1000);
//// don't include this, just to check it is as expected.
assertEquals(8, ((AbstractChronicleMapBuilder) builder.delegate).minSegments());
assertEquals(8, builder.minSegments());
//// end of test
String chmPath = System.getProperty("java.io.tmpdir") + System.getProperty("file.separator") + "CHMTest5";
@@ -241,9 +241,9 @@ public class CHMUseCasesTest {
public void testIntegerIntegerMap() throws ExecutionException, InterruptedException {
try (ChronicleMap<Integer, Integer> map = ChronicleMapBuilder
.of(Integer.class, Integer.class)
.entrySize(8)
.disableOversizedEntries() // disabled for testing purposes only.
.create()) {
assertEquals(8, ((VanillaChronicleMap) map).entrySize);
assertEquals(1, ((VanillaChronicleMap) map).maxEntryOversizeFactor);
Integer key1;
Integer key2;
Integer value1;
@@ -295,9 +295,9 @@ public class CHMUseCasesTest {
public void testLongLongMap() throws ExecutionException, InterruptedException {
try (ChronicleMap<Long, Long> map = ChronicleMapBuilder
.of(Long.class, Long.class)
.entrySize(16)
.disableOversizedEntries() // disabled for testing purposes only.
.create()) {
assertEquals(16, ((VanillaChronicleMap) map).entrySize);
assertEquals(1, ((VanillaChronicleMap) map).maxEntryOversizeFactor);
map.put(1L, 11L);
assertEquals((Long) 11L, map.get(1L));
@@ -338,9 +338,9 @@ public class CHMUseCasesTest {
public void testDoubleDoubleMap() throws ExecutionException, InterruptedException {
try (ChronicleMap<Double, Double> map = ChronicleMapBuilder
.of(Double.class, Double.class)
.disableOversizedEntries() // disabled for testing purposes only.
.entrySize(16)
.create()) {
assertEquals(16, ((VanillaChronicleMap) map).entrySize);
assertEquals(1, ((VanillaChronicleMap) map).maxEntryOversizeFactor);
map.put(1.0, 11.0);
assertEquals((Double) 11.0, map.get(1.0));
@@ -382,8 +382,8 @@ public class CHMUseCasesTest {
public void testByteArrayByteArrayMap() throws ExecutionException, InterruptedException {
try (ChronicleMap<byte[], byte[]> map = ChronicleMapBuilder
.of(byte[].class, byte[].class)
.disableOversizedEntries() // disabled for testing purposes only.
.entrySize(12)
.keySize(4).valueSize(4)
.maxEntryOversizeFactor(1)
.create()) {
byte[] key1 = {1, 1, 1, 1};
byte[] key2 = {2, 2, 2, 2};
@@ -432,9 +432,9 @@ public class CHMUseCasesTest {
.of(ByteBuffer.class, ByteBuffer.class)
.keyMarshaller(ByteBufferMarshaller.INSTANCE)
.valueMarshaller(ByteBufferMarshaller.INSTANCE)
.disableOversizedEntries() // disabled for testing purposes only.
// TODO does this have to be 14 bytes?
.entrySize(14)
.keySize(8)
.valueSize(8)
.maxEntryOversizeFactor(1)
.create()) {
ByteBuffer key1 = ByteBuffer.wrap(new byte[]{1, 1, 1, 1});
ByteBuffer key2 = ByteBuffer.wrap(new byte[]{2, 2, 2, 2});
@@ -539,8 +539,8 @@ 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() // disabled for testing purposes only.
.entrySize(12)
.keySize(5).valueSize(5)
.maxEntryOversizeFactor(1)
.create()) {
ByteBuffer key1 = ByteBuffer.wrap(new byte[]{1, 1, 1, 1});
ByteBuffer key2 = ByteBuffer.wrap(new byte[]{2, 2, 2, 2});
@@ -591,9 +591,9 @@ public class CHMUseCasesTest {
public void testIntValueIntValueMap() {
try (ChronicleMap<IntValue, IntValue> map = ChronicleMapBuilder
.of(IntValue.class, IntValue.class)
.disableOversizedEntries() // disabled for testing purposes only.
.entrySize(8)
.create()) {
assertEquals(8, ((VanillaChronicleMap) map).entrySize);
assertEquals(1, ((VanillaChronicleMap) map).maxEntryOversizeFactor);
IntValue key1 = map.newKeyInstance();
IntValue key2 = map.newKeyInstance();
IntValue value1 = map.newValueInstance();
@@ -677,9 +677,9 @@ public class CHMUseCasesTest {
// 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()) {
assertEquals(8, ((VanillaChronicleMap) map).entrySize);
assertEquals(1, ((VanillaChronicleMap) map).maxEntryOversizeFactor);
UnsignedIntValue key1 = map.newKeyInstance();
UnsignedIntValue value1 = map.newValueInstance();
@@ -781,9 +781,9 @@ public class CHMUseCasesTest {
public void testIntValueShortValueMap() {
try (ChronicleMap<IntValue, ShortValue> map = ChronicleMapBuilder
.of(IntValue.class, ShortValue.class)
.disableOversizedEntries() // disabled for testing purposes only.
.entrySize(6)
.create()) {
assertEquals(6, ((VanillaChronicleMap) map).entrySize);
assertEquals(1, ((VanillaChronicleMap) map).maxEntryOversizeFactor);
IntValue key1 = map.newKeyInstance();
IntValue key2 = map.newKeyInstance();
ShortValue value1 = map.newValueInstance();
@@ -863,10 +863,10 @@ public class CHMUseCasesTest {
public void testIntValueUnsignedShortValueMap() {
try (ChronicleMap<IntValue, UnsignedShortValue> map = ChronicleMapBuilder
.of(IntValue.class, UnsignedShortValue.class)
.entrySize(6)
.disableOversizedEntries() // disabled for testing purposes only.
.create()) {
// TODO should be 6
assertEquals(8, ((VanillaChronicleMap) map).entrySize);
assertEquals(1, ((VanillaChronicleMap) map).maxEntryOversizeFactor);
IntValue key1 = map.newKeyInstance();
IntValue key2 = map.newKeyInstance();
UnsignedShortValue value1 = map.newValueInstance();
@@ -946,10 +946,9 @@ public class CHMUseCasesTest {
public void testIntValueCharValueMap() {
try (ChronicleMap<IntValue, CharValue> map = ChronicleMapBuilder
.of(IntValue.class, CharValue.class)
.disableOversizedEntries() // disabled for testing purposes only.
.entrySize(6)
.create()) {
assertEquals(6, ((VanillaChronicleMap) map).entrySize);
assertEquals(1, ((VanillaChronicleMap) map).maxEntryOversizeFactor);
IntValue key1 = map.newKeyInstance();
IntValue key2 = map.newKeyInstance();
CharValue value1 = map.newValueInstance();
@@ -1029,10 +1028,11 @@ public class CHMUseCasesTest {
public void testIntValueUnsignedByteMap() {
try (ChronicleMap<IntValue, UnsignedByteValue> map = ChronicleMapBuilder
.of(IntValue.class, UnsignedByteValue.class)
.entrySize(5)
.disableOversizedEntries() // disabled for testing purposes only.
.create()) {
// TODO should be 5, but shorter fields based on range doesn't seem to be implemented
// on data value generation level yet
assertEquals(8, ((VanillaChronicleMap) map).entrySize);
assertEquals(1, ((VanillaChronicleMap) map).maxEntryOversizeFactor);
IntValue key1 = map.newKeyInstance();
IntValue key2 = map.newKeyInstance();
@@ -1115,11 +1115,9 @@ public class CHMUseCasesTest {
public void testIntValueBooleanValueMap() {
try (ChronicleMap<IntValue, BooleanValue> map = ChronicleMapBuilder
.of(IntValue.class, BooleanValue.class)
.disableOversizedEntries() // disabled for testing purposes only.
.entrySize(5)
.create()) {
assertEquals(5, ((VanillaChronicleMap) map).entrySize);
assertEquals(1, ((VanillaChronicleMap) map).maxEntryOversizeFactor);
IntValue key1 = map.newKeyInstance();
IntValue key2 = map.newKeyInstance();
@@ -1201,9 +1199,9 @@ public class CHMUseCasesTest {
public void testFloatValueFloatValueMap() {
try (ChronicleMap<FloatValue, FloatValue> map = ChronicleMapBuilder
.of(FloatValue.class, FloatValue.class)
.entrySize(8)
.disableOversizedEntries() // disabled for testing purposes only.
.create()) {
assertEquals(8, ((VanillaChronicleMap) map).entrySize);
assertEquals(1, ((VanillaChronicleMap) map).maxEntryOversizeFactor);
FloatValue key1 = map.newKeyInstance();
FloatValue key2 = map.newKeyInstance();
@@ -1285,8 +1283,9 @@ public class CHMUseCasesTest {
public void testDoubleValueDoubleValueMap() {
try (ChronicleMap<DoubleValue, DoubleValue> map = ChronicleMapBuilder
.of(DoubleValue.class, DoubleValue.class)
.entrySize(16)
.create()) {
assertEquals(16, ((VanillaChronicleMap) map).entrySize);
assertEquals(1, ((VanillaChronicleMap) map).maxEntryOversizeFactor);
DoubleValue key1 = map.newKeyInstance();
DoubleValue key2 = map.newKeyInstance();
@@ -1370,9 +1369,9 @@ public class CHMUseCasesTest {
public void testLongValueLongValueMap() {
try (ChronicleMap<LongValue, LongValue> map = ChronicleMapBuilder
.of(LongValue.class, LongValue.class)
.entrySize(16)
.disableOversizedEntries() // disabled for testing purposes only.
.create()) {
assertEquals(16, ((VanillaChronicleMap) map).entrySize);
assertEquals(1, ((VanillaChronicleMap) map).maxEntryOversizeFactor);
LongValue key1 = map.newKeyInstance();
LongValue key2 = map.newKeyInstance();
@@ -20,7 +20,6 @@ import net.openhft.lang.model.Byteable;
import net.openhft.lang.model.DataValueClasses;
import net.openhft.lang.values.IntValue;
import net.openhft.lang.values.LongValue;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@@ -30,7 +29,7 @@ public class DataKeyValueTest {
@Test
public void dataKeyValueTest() {
ChronicleMap<IntValue, LongValue> map =
OnHeapUpdatableChronicleMapBuilder.of(IntValue.class, LongValue.class)
ChronicleMapBuilder.of(IntValue.class, LongValue.class)
.entries(1000).create();
IntValue heapKey = DataValueClasses.newInstance(IntValue.class);
IntValue directKey = DataValueClasses.newDirectInstance(IntValue.class);
@@ -37,7 +37,7 @@ public class DefaultValueTest {
ArrayList<Integer> defaultValue = new ArrayList<Integer>();
defaultValue.add(42);
try (ChronicleMap<String, List<Integer>> map = OnHeapUpdatableChronicleMapBuilder
try (ChronicleMap<String, List<Integer>> map = ChronicleMapBuilder
.of(String.class, (Class<List<Integer>>) ((Class) List.class))
.defaultValue(defaultValue).createPersistedTo(file)) {
ArrayList<Integer> using = new ArrayList<Integer>();
@@ -49,7 +49,7 @@ public class DefaultValueTest {
}
ArrayList<Integer> using = new ArrayList<Integer>();
try (ChronicleMap<String, List<Integer>> map = OnHeapUpdatableChronicleMapBuilder
try (ChronicleMap<String, List<Integer>> map = ChronicleMapBuilder
.of(String.class, (Class<List<Integer>>) ((Class) List.class))
.createPersistedTo(file)) {
assertEquals(defaultValue, map.acquireUsing("c", using));
@@ -0,0 +1,34 @@
/*
* Copyright 2014 Higher Frequency Trading http://www.higherfrequencytrading.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.openhft.chronicle.map;
import net.openhft.chronicle.map.fromdocs.BondVOInterface;
import net.openhft.lang.model.DataValueGenerator;
import org.junit.Assert;
import org.junit.Test;
import java.util.Arrays;
import static org.hamcrest.CoreMatchers.hasItem;
public class FirstPrimitiveFieldTest {
@Test
public void firstPrimitiveFieldTest() {
Assert.assertThat(Arrays.<Class>asList(long.class, double.class),
hasItem(DataValueGenerator.firstPrimitiveFieldType(BondVOInterface.class)));
}
}
@@ -36,7 +36,7 @@ public class IntValueMapTest {
@Test
public void test() throws IOException {
try (final ChronicleMap<IntValue, CharSequence> map = OnHeapUpdatableChronicleMapBuilder
try (final ChronicleMap<IntValue, CharSequence> map = ChronicleMapBuilder
.of(IntValue.class, CharSequence.class)
.entries(20000)
.keyMarshaller(ByteableIntValueMarshaller.INSTANCE).create()) {
@@ -32,7 +32,7 @@ public class Issue42Test {
if (!Jvm.isWindows())
return;
try (final ChronicleMap<CharSequence, CharSequence> map = OnHeapUpdatableChronicleMapBuilder
try (final ChronicleMap<CharSequence, CharSequence> map = ChronicleMapBuilder
.of(CharSequence.class, CharSequence.class)
.entrySize(18)
.entries(1500000)
@@ -16,6 +16,7 @@
package net.openhft.chronicle.map;
import net.openhft.chronicle.hash.ChronicleHashInstanceConfig;
import net.openhft.chronicle.hash.replication.ReplicationHub;
import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
import org.junit.Before;
@@ -45,16 +46,19 @@ public class MapByNameTest {
}
@Test
@Ignore("builder is not serializable")
public void testSerializingBuilder() throws TimeoutException, InterruptedException, IOException {
final ChronicleMapBuilder<CharSequence, CharSequence> builder = ChronicleMapBuilder.of(CharSequence.class, CharSequence.class)
final MapInstanceConfig<CharSequence, CharSequence> config =
(MapInstanceConfig<CharSequence, CharSequence>)
ChronicleMapBuilder.of(CharSequence.class, CharSequence.class)
.entries(2)
.minSegments(2)
.name("map1")
.replication((byte) 1, TcpTransportAndNetworkConfig.of(8244))
.removeReturnsNull(true);
.removeReturnsNull(true)
.instance().name("map1");
final ChronicleMap<CharSequence, CharSequence> map = findMapByName.create(builder);
final ChronicleMap<CharSequence, CharSequence> map = findMapByName.create(config);
map.put("hello", "world");
assertEquals(map.get("hello"), "world");
@@ -71,14 +75,16 @@ public class MapByNameTest {
NodeDiscovery nodeDiscovery = new NodeDiscovery();
ChronicleMapBuilder<CharSequence, CharSequence> builder = ChronicleMapBuilder.of(CharSequence
.class, CharSequence.class)
MapInstanceConfig<CharSequence, CharSequence> config =
(MapInstanceConfig<CharSequence, CharSequence>)
ChronicleMapBuilder.of(CharSequence.class, CharSequence.class)
.minSegments(2)
.name("myMap")
.removeReturnsNull(true);
.removeReturnsNull(true)
.instance()
.name("myMap");
ReplicationHubFindByName<CharSequence> mapByName = nodeDiscovery.mapByName();
// mapByName.add(builder);
// mapByName.add(config);
ChronicleMap<CharSequence, CharSequence> myMap2 = mapByName.from("myMap");
}
@@ -89,14 +95,16 @@ public class MapByNameTest {
final ReplicationHubFindByName<CharSequence> mapByName = nodeDiscovery.mapByName();
Thread.sleep(2000);
ChronicleMapBuilder<CharSequence, CharSequence> builder = ChronicleMapBuilder.of(CharSequence
.class, CharSequence.class)
MapInstanceConfig<CharSequence, CharSequence> config =
(MapInstanceConfig<CharSequence, CharSequence>)
ChronicleMapBuilder.of(CharSequence.class, CharSequence.class)
.minSegments(2)
.entries(2)
.name("myMap6")
.removeReturnsNull(true);
.removeReturnsNull(true)
.instance()
.name("myMap6");
ChronicleMap<String, String> map = mapByName.create(builder);
ChronicleMap<String, String> map = mapByName.create(config);
map.put("hello", "world");
// final ChronicleMap<CharSequence, CharSequence> map = mapByName.from("myMap5");
@@ -44,17 +44,19 @@ public class NoTcpReplicationSoakTest {
map1 = (ReplicatedChronicleMap) ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.name("map1")
.replication((byte) 1)
.timeProvider(timeProvider)
.instance()
.name("map1")
.create();
}
{
map2 = (ReplicatedChronicleMap) ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.name("map2")
.replication((byte) 2)
.timeProvider(timeProvider)
.instance()
.name("map2")
.create();
}
@@ -70,9 +70,8 @@ public class SerializerTest {
final ByteBufferBytes out = new ByteBufferBytes(ByteBuffer.allocateDirect(1024));
ByteBufferBytes in = out.slice();
ChronicleMapBuilder cBuilder = ChronicleMapBuilder.of(Integer.class, valueClass);
OnHeapUpdatableChronicleMapBuilder builder = (OnHeapUpdatableChronicleMapBuilder) cBuilder.delegate;
ChronicleMapBuilder builder =
ChronicleMapBuilder.of(Integer.class, valueClass);
builder.preMapConstruction(false);
@@ -95,9 +94,7 @@ public class SerializerTest {
final ByteBufferBytes out = new ByteBufferBytes(ByteBuffer.allocateDirect(1024));
ByteBufferBytes in = out.slice();
ChronicleMapBuilder cBuilder = ChronicleMapBuilder.of(clazz, Integer.class);
OnHeapUpdatableChronicleMapBuilder builder = (OnHeapUpdatableChronicleMapBuilder) cBuilder.delegate;
ChronicleMapBuilder builder = ChronicleMapBuilder.of(clazz, Integer.class);
builder.preMapConstruction(false);
{
@@ -38,25 +38,29 @@ public class TcpReplicationSoakTest {
{
final TcpTransportAndNetworkConfig tcpConfig1 = TcpTransportAndNetworkConfig.of(s_port,
endpoint).autoReconnectedUponDroppedConnection(true).name(" map1")
.heartBeatInterval(1, TimeUnit.SECONDS);
.heartBeatInterval(1, TimeUnit.SECONDS)
.packetSize(1024 * 64);
map1 = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.entries(Builder.SIZE + Builder.SIZE)
.actualSegments(1)
.name("map1")
.replication((byte) 1, tcpConfig1)
.instance()
.name("map1")
.create();
}
{
final TcpTransportAndNetworkConfig tcpConfig2 = TcpTransportAndNetworkConfig.of
(s_port + 1).autoReconnectedUponDroppedConnection(true).name("map2")
.heartBeatInterval(1, TimeUnit.SECONDS);
.heartBeatInterval(1, TimeUnit.SECONDS)
.packetSize(1024 * 64);
map2 = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.entries(Builder.SIZE + Builder.SIZE)
.name("map2")
.replication((byte) 2, tcpConfig2)
.instance()
.name("map2")
.create();
}
@@ -56,7 +56,7 @@ public class OpenJDKAndHashMapExamplesTest {
file.deleteOnExit();
ChronicleMap<String, BondVOInterface> chm = ChronicleMapBuilder
.of(String.class, BondVOInterface.class)
.of(String.class, DataValueClasses.directClassFor(BondVOInterface.class))
.keySize(10)
.createPersistedTo(file);