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:
@@ -20,6 +20,7 @@ package eg;
|
||||
|
||||
import net.openhft.affinity.AffinitySupport;
|
||||
import net.openhft.chronicle.map.ChronicleMapBuilder;
|
||||
import net.openhft.chronicle.map.ChronicleMapBuilder;
|
||||
import net.openhft.lang.io.Bytes;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
@@ -30,7 +30,7 @@ public class AcquireGetUsingMain {
|
||||
public static void main(String[] args) throws Exception {
|
||||
File file = new File(System.getProperty("java.io.tmpdir") + "/test1");
|
||||
ChronicleMap<String, Data> theSharedMap =
|
||||
OffHeapUpdatableChronicleMapBuilder.of(String.class, Data.class)
|
||||
ChronicleMapBuilder.of(String.class, Data.class)
|
||||
.createPersistedTo(file);
|
||||
Data data = DataValueClasses.newDirectReference(Data.class);
|
||||
String processType = "testkey";
|
||||
|
||||
@@ -75,9 +75,8 @@ public class Builder {
|
||||
TcpTransportAndNetworkConfig tcpConfig = TcpTransportAndNetworkConfig.of(serverPort, Arrays.asList(endpoints))
|
||||
.heartBeatInterval(1L, TimeUnit.SECONDS);
|
||||
return ChronicleMapBuilder.of(kClass, vClass)
|
||||
.replication(identifier, tcpConfig);
|
||||
.replication(identifier, tcpConfig);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class CHMLatencyTestMain {
|
||||
// File file = new File("testCHMLatency.deleteme");
|
||||
file.delete();
|
||||
ChronicleMap<LongValue, LongValue> countersMap =
|
||||
OffHeapUpdatableChronicleMapBuilder.of(LongValue.class, LongValue.class)
|
||||
ChronicleMapBuilder.of(LongValue.class, LongValue.class)
|
||||
.entries(KEYS)
|
||||
.entrySize(16)
|
||||
.createPersistedTo(file);
|
||||
|
||||
@@ -34,12 +34,12 @@ public class CHMTest5 {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
//First create (or access if already created) the shared map
|
||||
OffHeapUpdatableChronicleMapBuilder<String, CHMTest5Data> builder =
|
||||
OffHeapUpdatableChronicleMapBuilder.of(String.class, CHMTest5Data.class)
|
||||
ChronicleMapBuilder<String, CHMTest5Data> builder =
|
||||
ChronicleMapBuilder.of(String.class, CHMTest5Data.class)
|
||||
.entries(1000);
|
||||
|
||||
//// don't include this, just to check it is as expected.
|
||||
assertEquals(8, builder.minSegments());
|
||||
assertEquals(8, ((AbstractChronicleMapBuilder) builder.delegate).minSegments());
|
||||
//// end of test
|
||||
|
||||
String chmPath = System.getProperty("java.io.tmpdir") + System.getProperty("file.separator") + "CHMTest5";
|
||||
|
||||
@@ -110,7 +110,7 @@ public class ChronicleMapTest {
|
||||
private static ChronicleMap<CharSequence, LongValue> getSharedMap(
|
||||
long entries, int segments, int entrySize, Alignment alignment)
|
||||
throws IOException {
|
||||
return OffHeapUpdatableChronicleMapBuilder.of(CharSequence.class, LongValue.class)
|
||||
return ChronicleMapBuilder.of(CharSequence.class, LongValue.class)
|
||||
.entries(entries)
|
||||
.minSegments(segments)
|
||||
.entrySize(entrySize)
|
||||
@@ -582,7 +582,7 @@ public class ChronicleMapTest {
|
||||
// JAVA 8 produces more garbage than previous versions for internal work.
|
||||
// System.gc();
|
||||
final long entries = runs * 1000 * 1000L;
|
||||
OffHeapUpdatableChronicleMapBuilder<CharSequence, LongValue> builder = OffHeapUpdatableChronicleMapBuilder
|
||||
ChronicleMapBuilder<CharSequence, LongValue> builder = ChronicleMapBuilder
|
||||
.of(CharSequence.class, LongValue.class)
|
||||
.entries(entries)
|
||||
.actualSegments(8 * 1024)
|
||||
@@ -654,7 +654,7 @@ public class ChronicleMapTest {
|
||||
// JAVA 8 produces more garbage than previous versions for internal work.
|
||||
// System.gc();
|
||||
final long entries = runs * 1000 * 1000L;
|
||||
OffHeapUpdatableChronicleMapBuilder<CharSequence, LongValue> builder = OffHeapUpdatableChronicleMapBuilder
|
||||
ChronicleMapBuilder<CharSequence, LongValue> builder = ChronicleMapBuilder
|
||||
.of(CharSequence.class, LongValue.class)
|
||||
.entries(entries)
|
||||
.entryAndValueAlignment(OF_8_BYTES)
|
||||
@@ -728,7 +728,7 @@ public class ChronicleMapTest {
|
||||
// JAVA 8 produces more garbage than previous versions for internal work.
|
||||
// System.gc();
|
||||
final long entries = runs * 1000 * 1000L;
|
||||
OffHeapUpdatableChronicleMapBuilder<LongValue, LongValue> builder = OffHeapUpdatableChronicleMapBuilder
|
||||
ChronicleMapBuilder<LongValue, LongValue> builder = ChronicleMapBuilder
|
||||
.of(LongValue.class, LongValue.class)
|
||||
.entries(entries)
|
||||
.entryAndValueAlignment(OF_8_BYTES)
|
||||
@@ -1356,13 +1356,13 @@ public class ChronicleMapTest {
|
||||
|
||||
@Test
|
||||
public void equalsTest() throws IOException {
|
||||
final ChronicleMap<Integer, String> map1 = ChronicleMapBuilder
|
||||
final ChronicleMap<Integer, String> map1 = OnHeapUpdatableChronicleMapBuilder
|
||||
.of(Integer.class, String.class).create();
|
||||
|
||||
map1.put(1, "one");
|
||||
map1.put(2, "two");
|
||||
|
||||
final ChronicleMap<Integer, String> map2 = ChronicleMapBuilder
|
||||
final ChronicleMap<Integer, String> map2 = OnHeapUpdatableChronicleMapBuilder
|
||||
.of(Integer.class, String.class).create();
|
||||
|
||||
map2.put(1, "one");
|
||||
@@ -1406,7 +1406,7 @@ public class ChronicleMapTest {
|
||||
|
||||
@Test
|
||||
public void testOffheapAcquireUsingLocked() throws IOException {
|
||||
OffHeapUpdatableChronicleMapBuilder<CharSequence, LongValue> builder = OffHeapUpdatableChronicleMapBuilder
|
||||
ChronicleMapBuilder<CharSequence, LongValue> builder = ChronicleMapBuilder
|
||||
.of(CharSequence.class, LongValue.class)
|
||||
.entries(1000)
|
||||
.entrySize(16);
|
||||
@@ -1487,8 +1487,31 @@ public class ChronicleMapTest {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testOnheapAcquireUsingLockedStringBuilder() throws IOException {
|
||||
|
||||
try (final ChronicleMap<CharSequence, CharSequence> map = ChronicleMapBuilder
|
||||
.of(CharSequence.class, CharSequence.class)
|
||||
.entries(1000)
|
||||
.entrySize(40)
|
||||
.defaultValue("")
|
||||
.create()) {
|
||||
|
||||
StringBuilder value = new StringBuilder();
|
||||
|
||||
try (WriteContext<?, CharSequence> context = map.acquireUsingLocked("one", value)) {
|
||||
value.append("Hello World");
|
||||
}
|
||||
|
||||
assertEquals("Hello World", value.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testOnheapAcquireUsingLocked() throws IOException {
|
||||
ChronicleMapBuilder<CharSequence, LongValue> builder = ChronicleMapBuilder
|
||||
|
||||
@@ -42,7 +42,7 @@ public class ConcurrentMap8Test extends JSR166TestCase {
|
||||
/* private static ConcurrentMap<Long, Long> newLongMap() {
|
||||
//First create (or access if already created) the shared map
|
||||
|
||||
final ChronicleMapBuilder<Long, Long> builder = ChronicleMapBuilder.of(Long.class, Long.class);
|
||||
final ChronicleMapOnHeapUpdatableBuilder<Long, Long> builder = ChronicleMapBuilder.of(Long.class, Long.class);
|
||||
|
||||
|
||||
//// don't include this, just to check it is as expected.
|
||||
@@ -64,7 +64,7 @@ public class ConcurrentMap8Test extends JSR166TestCase {
|
||||
private static ConcurrentMap newIntegerStringMap() {
|
||||
|
||||
|
||||
final ChronicleMapBuilder<Integer, String> builder = ChronicleMapBuilder.of(Integer.class,
|
||||
final ChronicleMapOnHeapUpdatableBuilder<Integer, String> builder = ChronicleMapBuilder.of(Integer.class,
|
||||
String.class);
|
||||
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ public class DefaultValueTest {
|
||||
|
||||
ArrayList<Integer> defaultValue = new ArrayList<Integer>();
|
||||
defaultValue.add(42);
|
||||
try (ChronicleMap<String, List<Integer>> map = ChronicleMapBuilder
|
||||
try (ChronicleMap<String, List<Integer>> map = OnHeapUpdatableChronicleMapBuilder
|
||||
.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 = ChronicleMapBuilder
|
||||
try (ChronicleMap<String, List<Integer>> map = OnHeapUpdatableChronicleMapBuilder
|
||||
.of(String.class, (Class<List<Integer>>) ((Class) List.class))
|
||||
.createPersistedTo(file)) {
|
||||
assertEquals(defaultValue, map.acquireUsing("c", using));
|
||||
|
||||
@@ -17,7 +17,7 @@ public class DemoChronicleMapTest {
|
||||
File file = File.createTempFile("DummyOrders", ".test");
|
||||
file.deleteOnExit();
|
||||
int maxEntries = 1000;
|
||||
ChronicleMap<IntValue, DemoOrderVOInterface> map = OffHeapUpdatableChronicleMapBuilder
|
||||
ChronicleMap<IntValue, DemoOrderVOInterface> map = ChronicleMapBuilder
|
||||
.of(IntValue.class, DemoOrderVOInterface.class)
|
||||
.putReturnsNull(true)
|
||||
.removeReturnsNull(true)
|
||||
@@ -59,7 +59,7 @@ public class DemoChronicleMapTest {
|
||||
File file = File.createTempFile("DummyOrders", ".test");
|
||||
file.deleteOnExit();
|
||||
int maxEntries = 1000;
|
||||
ChronicleMap<IntValue, DemoOrderVOInterface> map = OffHeapUpdatableChronicleMapBuilder
|
||||
ChronicleMap<IntValue, DemoOrderVOInterface> map = ChronicleMapBuilder
|
||||
.of(IntValue.class, DemoOrderVOInterface.class)
|
||||
.putReturnsNull(true)
|
||||
.removeReturnsNull(true)
|
||||
|
||||
@@ -51,7 +51,8 @@ public class EntryCountMapTest {
|
||||
private static ChronicleMap<CharSequence, LongValue> getSharedMap(
|
||||
long entries, int segments, int entrySize, Alignment alignment)
|
||||
throws IOException {
|
||||
OffHeapUpdatableChronicleMapBuilder<CharSequence, LongValue> mapBuilder = OffHeapUpdatableChronicleMapBuilder.of(CharSequence.class, LongValue.class)
|
||||
ChronicleMapBuilder<CharSequence, LongValue> mapBuilder = ChronicleMapBuilder.of(CharSequence
|
||||
.class, LongValue.class)
|
||||
.entries(entries)
|
||||
.actualSegments(segments)
|
||||
.entrySize(entrySize)
|
||||
|
||||
@@ -37,7 +37,7 @@ public class IntValueMapTest {
|
||||
@Test
|
||||
public void test() throws IOException {
|
||||
|
||||
final ChronicleMap<IntValue, CharSequence> map = ChronicleMapBuilder
|
||||
final ChronicleMap<IntValue, CharSequence> map = OnHeapUpdatableChronicleMapBuilder
|
||||
.of(IntValue.class, CharSequence.class)
|
||||
.entries(20000)
|
||||
.keyMarshaller(ByteableIntValueMarshaller.INSTANCE).create();
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Issue42Test {
|
||||
if (!Jvm.isWindows())
|
||||
return;
|
||||
|
||||
final ChronicleMap<CharSequence, CharSequence> map = ChronicleMapBuilder
|
||||
final ChronicleMap<CharSequence, CharSequence> map = OnHeapUpdatableChronicleMapBuilder
|
||||
.of(CharSequence.class, CharSequence.class)
|
||||
.entrySize(18)
|
||||
.entries(1500000)
|
||||
|
||||
@@ -72,7 +72,13 @@ public class SerializerTest {
|
||||
final ByteBufferBytes out = new ByteBufferBytes(ByteBuffer.allocateDirect(1024));
|
||||
ByteBufferBytes in = out.slice();
|
||||
|
||||
ChronicleMapBuilder builder = ChronicleMapBuilder.of(Integer.class, valueClass);
|
||||
|
||||
ChronicleMapBuilder cBuilder = ChronicleMapBuilder.of(Integer
|
||||
.class, valueClass);
|
||||
|
||||
OnHeapUpdatableChronicleMapBuilder builder = (OnHeapUpdatableChronicleMapBuilder) cBuilder.delegate;
|
||||
|
||||
|
||||
builder.preMapConstruction(false);
|
||||
|
||||
Serializer v = new Serializer(builder.valueBuilder);
|
||||
@@ -95,7 +101,10 @@ public class SerializerTest {
|
||||
final ByteBufferBytes out = new ByteBufferBytes(ByteBuffer.allocateDirect(1024));
|
||||
ByteBufferBytes in = out.slice();
|
||||
|
||||
ChronicleMapBuilder builder = ChronicleMapBuilder.of(clazz, Integer.class);
|
||||
ChronicleMapBuilder cBuilder = ChronicleMapBuilder.of(clazz, Integer.class);
|
||||
|
||||
OnHeapUpdatableChronicleMapBuilder builder = (OnHeapUpdatableChronicleMapBuilder) cBuilder.delegate;
|
||||
|
||||
builder.preMapConstruction(false);
|
||||
{
|
||||
Serializer v = new Serializer(builder.keyBuilder);
|
||||
|
||||
@@ -19,17 +19,16 @@
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
|
||||
import net.openhft.chronicle.java8.Function;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
|
||||
/**
|
||||
@@ -41,7 +40,7 @@ public class StatelessClientTest {
|
||||
public static final int SIZE = 100000;
|
||||
|
||||
|
||||
static class StringBuilderToStringFunction implements Function<StringBuilder, String>, Serializable {
|
||||
static class StringBuilderToStringFunction implements Function<StringBuilder, String> {
|
||||
|
||||
@Override
|
||||
public String apply(StringBuilder stringBuilder) {
|
||||
@@ -51,11 +50,12 @@ public class StatelessClientTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testMapForKey() throws IOException, InterruptedException {
|
||||
public void testMapForKeyWithEntry() throws IOException, InterruptedException {
|
||||
|
||||
|
||||
try (ChronicleMap<Integer, StringBuilder> serverMap = ChronicleMapBuilder.of(Integer.class,
|
||||
StringBuilder.class)
|
||||
.defaultValue(new StringBuilder())
|
||||
.replication((byte) 2, TcpTransportAndNetworkConfig.of(8056)).create()) {
|
||||
|
||||
serverMap.put(10, new StringBuilder("Hello World"));
|
||||
@@ -64,7 +64,8 @@ public class StatelessClientTest {
|
||||
.class, StringBuilder.class)
|
||||
.statelessClient(new InetSocketAddress("localhost", 8056)).create()) {
|
||||
|
||||
String actual = (String) ((StatelessChronicleMap) statelessMap).mapForKey(10, new StringBuilderToStringFunction());
|
||||
String actual = (String) ((StatelessChronicleMap) statelessMap).mapForKey(10, new
|
||||
StringBuilderToStringFunction());
|
||||
|
||||
Assert.assertEquals("Hello World", actual);
|
||||
}
|
||||
@@ -72,6 +73,30 @@ public class StatelessClientTest {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testMapForKeyWhenNoEntry() throws IOException, InterruptedException {
|
||||
|
||||
|
||||
try (ChronicleMap<Integer, StringBuilder> serverMap = ChronicleMapBuilder.of(Integer.class,
|
||||
StringBuilder.class)
|
||||
.defaultValue(new StringBuilder())
|
||||
.replication((byte) 2, TcpTransportAndNetworkConfig.of(8056)).create()) {
|
||||
|
||||
serverMap.put(10, new StringBuilder("Hello World"));
|
||||
|
||||
try (ChronicleMap<Integer, StringBuilder> statelessMap = ChronicleMapBuilder.of(Integer
|
||||
.class, StringBuilder.class)
|
||||
.statelessClient(new InetSocketAddress("localhost", 8056)).create()) {
|
||||
|
||||
String actual = (String) ((StatelessChronicleMap) statelessMap).mapForKey(11, new
|
||||
StringBuilderToStringFunction());
|
||||
|
||||
Assert.assertEquals("", actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout = 5000)
|
||||
public void testBufferOverFlowPutAllAndEntrySet() throws IOException, InterruptedException {
|
||||
|
||||
|
||||
@@ -53,13 +53,13 @@ public class TCPSocketReplicationNativeTest {
|
||||
TcpTransportAndNetworkConfig tcpConfig1 = TcpTransportAndNetworkConfig.of(8076, endpoint)
|
||||
.heartBeatInterval(1L, TimeUnit.SECONDS);
|
||||
|
||||
map1 = OffHeapUpdatableChronicleMapBuilder.of(Integer.class, LongValue.class)
|
||||
map1 = ChronicleMapBuilder.of(Integer.class, LongValue.class)
|
||||
.replication((byte) 1, tcpConfig1).create();
|
||||
|
||||
TcpTransportAndNetworkConfig tcpConfig2 = TcpTransportAndNetworkConfig.of(8077)
|
||||
.heartBeatInterval(1L, TimeUnit.SECONDS);
|
||||
|
||||
map2 = OffHeapUpdatableChronicleMapBuilder.of(Integer.class, LongValue.class)
|
||||
map2 = ChronicleMapBuilder.of(Integer.class, LongValue.class)
|
||||
.replication((byte) 2, tcpConfig2).create();
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import net.openhft.chronicle.hash.replication.ReplicationHub;
|
||||
import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
|
||||
import net.openhft.chronicle.map.ChronicleMap;
|
||||
import net.openhft.chronicle.map.ChronicleMapBuilder;
|
||||
import net.openhft.chronicle.map.ChronicleMapBuilder;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ import net.openhft.chronicle.map.ChronicleMapBuilder;
|
||||
import net.openhft.lang.model.DataValueClasses;
|
||||
import net.openhft.lang.values.LongValue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class DistributedSequenceMain {
|
||||
|
||||
@@ -52,8 +52,7 @@ public class StringsMapMain {
|
||||
public static void startRemoteClient(String hostname) throws IOException {
|
||||
final ChronicleMap<CharSequence, CharSequence> map;
|
||||
if (stateless) {
|
||||
map = ChronicleMapBuilder
|
||||
.of(CharSequence.class, CharSequence.class)
|
||||
map = ChronicleMapBuilder.of(CharSequence.class, CharSequence.class)
|
||||
.putReturnsNull(true)
|
||||
.statelessClient(new InetSocketAddress(hostname, port)).create();
|
||||
} else {
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
package net.openhft.chronicle.map.fromdocs;
|
||||
|
||||
import net.openhft.chronicle.map.ChronicleMap;
|
||||
import net.openhft.chronicle.map.OffHeapUpdatableChronicleMapBuilder;
|
||||
import net.openhft.chronicle.map.ChronicleMapBuilder;
|
||||
import net.openhft.chronicle.map.ReadContext;
|
||||
import net.openhft.chronicle.map.WriteContext;
|
||||
import net.openhft.lang.model.DataValueClasses;
|
||||
@@ -56,7 +56,7 @@ public class OpenJDKAndHashMapExamplesTest {
|
||||
File file = new File(TMP + "/chm-myBondPortfolioCHM-" + System.nanoTime());
|
||||
file.deleteOnExit();
|
||||
|
||||
ChronicleMap<String, BondVOInterface> chm = OffHeapUpdatableChronicleMapBuilder
|
||||
ChronicleMap<String, BondVOInterface> chm = ChronicleMapBuilder
|
||||
.of(String.class, BondVOInterface.class)
|
||||
.keySize(10)
|
||||
.createPersistedTo(file);
|
||||
@@ -76,7 +76,7 @@ public class OpenJDKAndHashMapExamplesTest {
|
||||
mpx1030.setBidPx(107.6);
|
||||
}
|
||||
|
||||
ChronicleMap<String, BondVOInterface> chmB = OffHeapUpdatableChronicleMapBuilder
|
||||
ChronicleMap<String, BondVOInterface> chmB = ChronicleMapBuilder
|
||||
.of(String.class, BondVOInterface.class)
|
||||
.keySize(10)
|
||||
.createPersistedTo(file);
|
||||
|
||||
@@ -23,7 +23,6 @@ import net.openhft.chronicle.map.ChronicleMap;
|
||||
import net.openhft.chronicle.map.ChronicleMapBuilder;
|
||||
import net.openhft.chronicle.map.fromdocs.BondVOInterface;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user