mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
First step in separation of core ChronicleHash functionality from Map and Set; Start Java 8 adoption; Bug fixes
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.chronicle.hash.impl.util.BuildVersion;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import com.google.common.primitives.Chars;
|
||||
import net.openhft.chronicle.hash.function.Function;
|
||||
import net.openhft.chronicle.hash.function.SerializableFunction;
|
||||
import net.openhft.chronicle.hash.replication.SingleChronicleHashReplication;
|
||||
import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
|
||||
import net.openhft.chronicle.map.fromdocs.BondVOInterface;
|
||||
@@ -318,7 +318,7 @@ public class CHMUseCasesTest {
|
||||
}
|
||||
}
|
||||
|
||||
static class PrefixStringFunction implements Function<String, String> {
|
||||
static class PrefixStringFunction implements SerializableFunction<String, String> {
|
||||
private final String prefix;
|
||||
|
||||
public PrefixStringFunction(@NotNull String prefix) {
|
||||
@@ -605,14 +605,14 @@ public class CHMUseCasesTest {
|
||||
|
||||
|
||||
assertEquals("New World", map.getMapped("Hello", new
|
||||
Function<CharSequence, CharSequence>() {
|
||||
SerializableFunction<CharSequence, CharSequence>() {
|
||||
@Override
|
||||
public CharSequence apply(CharSequence s) {
|
||||
return "New " + s;
|
||||
}
|
||||
}));
|
||||
assertEquals(null, map.getMapped("No key", new
|
||||
Function<CharSequence, CharSequence>() {
|
||||
SerializableFunction<CharSequence, CharSequence>() {
|
||||
@Override
|
||||
public CharSequence apply(CharSequence s) {
|
||||
return "New " + s;
|
||||
@@ -968,7 +968,7 @@ public class CHMUseCasesTest {
|
||||
|
||||
mapChecks();
|
||||
|
||||
assertEquals((Integer) 110, map.getMapped(1, new Function<Integer, Integer>() {
|
||||
assertEquals((Integer) 110, map.getMapped(1, new SerializableFunction<Integer, Integer>() {
|
||||
@Override
|
||||
public Integer apply(Integer s) {
|
||||
return 10 * s;
|
||||
@@ -977,7 +977,7 @@ public class CHMUseCasesTest {
|
||||
|
||||
mapChecks();
|
||||
|
||||
assertEquals(null, map.getMapped(-1, new Function<Integer, Integer>() {
|
||||
assertEquals(null, map.getMapped(-1, new SerializableFunction<Integer, Integer>() {
|
||||
@Override
|
||||
public Integer apply(Integer s) {
|
||||
return 10 * s;
|
||||
@@ -1025,13 +1025,13 @@ public class CHMUseCasesTest {
|
||||
|
||||
mapChecks();
|
||||
|
||||
assertEquals((Long) 110L, map.getMapped(1L, new Function<Long, Long>() {
|
||||
assertEquals((Long) 110L, map.getMapped(1L, new SerializableFunction<Long, Long>() {
|
||||
@Override
|
||||
public Long apply(Long s) {
|
||||
return 10 * s;
|
||||
}
|
||||
}));
|
||||
assertEquals(null, map.getMapped(-1L, new Function<Long, Long>() {
|
||||
assertEquals(null, map.getMapped(-1L, new SerializableFunction<Long, Long>() {
|
||||
@Override
|
||||
public Long apply(Long s) {
|
||||
return 10 * s;
|
||||
@@ -1077,13 +1077,13 @@ public class CHMUseCasesTest {
|
||||
assertEquals(null, map.get(3.0));
|
||||
assertEquals(null, map.get(4.0));
|
||||
|
||||
assertEquals((Double) 110.0, map.getMapped(1.0, new Function<Double, Double>() {
|
||||
assertEquals((Double) 110.0, map.getMapped(1.0, new SerializableFunction<Double, Double>() {
|
||||
@Override
|
||||
public Double apply(Double s) {
|
||||
return 10 * s;
|
||||
}
|
||||
}));
|
||||
assertEquals(null, map.getMapped(-1.0, new Function<Double, Double>() {
|
||||
assertEquals(null, map.getMapped(-1.0, new SerializableFunction<Double, Double>() {
|
||||
@Override
|
||||
public Double apply(Double s) {
|
||||
return 10 * s;
|
||||
@@ -1131,13 +1131,13 @@ public class CHMUseCasesTest {
|
||||
|
||||
|
||||
assertTrue(Arrays.equals(new byte[]{11, 11},
|
||||
map.getMapped(key1, new Function<byte[], byte[]>() {
|
||||
map.getMapped(key1, new SerializableFunction<byte[], byte[]>() {
|
||||
@Override
|
||||
public byte[] apply(byte[] s) {
|
||||
return Arrays.copyOf(s, 2);
|
||||
}
|
||||
})));
|
||||
assertEquals(null, map.getMapped(key2, new Function<byte[], byte[]>() {
|
||||
assertEquals(null, map.getMapped(key2, new SerializableFunction<byte[], byte[]>() {
|
||||
@Override
|
||||
public byte[] apply(byte[] s) {
|
||||
return Arrays.copyOf(s, 2);
|
||||
@@ -1218,8 +1218,8 @@ public class CHMUseCasesTest {
|
||||
assertBBEquals(value2, map.get(key1));
|
||||
assertNull(map.get(key2));
|
||||
|
||||
final Function<ByteBuffer, ByteBuffer> function =
|
||||
new Function<ByteBuffer, ByteBuffer>() {
|
||||
final SerializableFunction<ByteBuffer, ByteBuffer> function =
|
||||
new SerializableFunction<ByteBuffer, ByteBuffer>() {
|
||||
@Override
|
||||
public ByteBuffer apply(ByteBuffer s) {
|
||||
ByteBuffer slice = s.slice();
|
||||
@@ -1339,8 +1339,8 @@ public class CHMUseCasesTest {
|
||||
assertNull(map.get(key2));
|
||||
map.put(key1, value1);
|
||||
mapChecks();
|
||||
final Function<ByteBuffer, ByteBuffer> function =
|
||||
new Function<ByteBuffer, ByteBuffer>() {
|
||||
final SerializableFunction<ByteBuffer, ByteBuffer> function =
|
||||
new SerializableFunction<ByteBuffer, ByteBuffer>() {
|
||||
@Override
|
||||
public ByteBuffer apply(ByteBuffer s) {
|
||||
ByteBuffer slice = s.slice();
|
||||
@@ -2684,7 +2684,7 @@ class Data implements IData, BytesMarshallable {
|
||||
}
|
||||
}
|
||||
|
||||
enum ToString implements Function<Object, String> {
|
||||
enum ToString implements SerializableFunction<Object, String> {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,16 +20,12 @@ 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 net.openhft.lang.io.NativeBytes;
|
||||
import net.openhft.chronicle.hash.impl.hashlookup.EntryConsumer;
|
||||
import net.openhft.chronicle.hash.impl.hashlookup.HashLookup;
|
||||
import org.junit.*;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
|
||||
import static net.openhft.lang.io.NativeBytes.UNSAFE;
|
||||
@@ -75,7 +71,7 @@ public class HashLookupTest {
|
||||
}
|
||||
|
||||
private void multiMapEquals() {
|
||||
class Action implements HashLookup.EntryConsumer {
|
||||
class Action implements EntryConsumer {
|
||||
int mapSize = 0;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.chronicle.hash.function.Function;
|
||||
import net.openhft.chronicle.hash.function.SerializableFunction;
|
||||
import net.openhft.lang.MemoryUnit;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -34,7 +34,7 @@ public class MarkTest {
|
||||
|
||||
@Test(timeout = 25000)
|
||||
public void inMemoryTest() {
|
||||
test(new Function<ChronicleMapBuilder<Integer, Integer>, ChronicleMap<Integer, Integer>>() {
|
||||
test(new SerializableFunction<ChronicleMapBuilder<Integer, Integer>, ChronicleMap<Integer, Integer>>() {
|
||||
@Override
|
||||
public ChronicleMap<Integer, Integer> apply(
|
||||
ChronicleMapBuilder<Integer, Integer> builder) {
|
||||
@@ -50,8 +50,8 @@ public class MarkTest {
|
||||
if (db.exists())
|
||||
db.delete();
|
||||
try {
|
||||
test(new Function<ChronicleMapBuilder<Integer, Integer>,
|
||||
ChronicleMap<Integer, Integer>>() {
|
||||
test(new SerializableFunction<ChronicleMapBuilder<Integer, Integer>,
|
||||
ChronicleMap<Integer, Integer>>() {
|
||||
@Override
|
||||
public ChronicleMap<Integer, Integer> apply(
|
||||
ChronicleMapBuilder<Integer, Integer> builder) {
|
||||
@@ -70,8 +70,8 @@ public class MarkTest {
|
||||
}
|
||||
}
|
||||
|
||||
private static void test(Function<ChronicleMapBuilder<Integer, Integer>,
|
||||
ChronicleMap<Integer, Integer>> createMap) {
|
||||
private static void test(SerializableFunction<ChronicleMapBuilder<Integer, Integer>,
|
||||
ChronicleMap<Integer, Integer>> createMap) {
|
||||
long ms = System.currentTimeMillis();
|
||||
try (ChronicleMap<Integer, Integer> map = createMap.apply(ChronicleMapBuilder
|
||||
.of(Integer.class, Integer.class)
|
||||
|
||||
@@ -18,9 +18,7 @@
|
||||
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.chronicle.hash.function.Consumer;
|
||||
import net.openhft.chronicle.hash.function.Function;
|
||||
import net.openhft.chronicle.hash.function.Predicate;
|
||||
import net.openhft.chronicle.hash.function.SerializableFunction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Assert;
|
||||
|
||||
@@ -29,6 +27,8 @@ import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* @author Rob Austin.
|
||||
@@ -221,7 +221,7 @@ public class ReplicationCheckingMap<K, V> implements ChronicleMap<K, V> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R getMapped(K key, @NotNull Function<? super V, R> function) {
|
||||
public <R> R getMapped(K key, @NotNull SerializableFunction<? super V, R> function) {
|
||||
return map1.getMapped(key, function);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.chronicle.hash.serialization.internal.ReaderWithSize;
|
||||
import net.openhft.lang.io.ByteBufferBytes;
|
||||
import net.openhft.lang.io.Bytes;
|
||||
import net.openhft.lang.io.serialization.BytesMarshallable;
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import net.openhft.chronicle.hash.function.Function;
|
||||
import net.openhft.chronicle.hash.function.SerializableFunction;
|
||||
import net.openhft.chronicle.hash.replication.SingleChronicleHashReplication;
|
||||
import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
|
||||
import net.openhft.lang.io.ByteBufferBytes;
|
||||
@@ -51,7 +51,7 @@ public class StatelessClientTest {
|
||||
public static final int SIZE = 2500;
|
||||
static int s_port = 9070;
|
||||
|
||||
enum ToString implements Function<Object, String> {
|
||||
enum ToString implements SerializableFunction<Object, String> {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -150,7 +150,7 @@ public class TCPSocketReplicationTest {
|
||||
map1.remove(1);
|
||||
|
||||
map2.put(1, "EXAMPLE-1");
|
||||
map2.remove(1);
|
||||
map2.remove(1);
|
||||
|
||||
// allow time for the recompilation to resolve
|
||||
waitTillEqual(5000);
|
||||
|
||||
@@ -18,9 +18,7 @@
|
||||
|
||||
package net.openhft.chronicle.map.jsr166.map;
|
||||
|
||||
import net.openhft.chronicle.hash.function.Consumer;
|
||||
import net.openhft.chronicle.hash.function.Function;
|
||||
import net.openhft.chronicle.hash.function.Predicate;
|
||||
import net.openhft.chronicle.hash.function.SerializableFunction;
|
||||
import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
|
||||
import net.openhft.chronicle.map.*;
|
||||
import net.openhft.chronicle.map.MapKeyContext;
|
||||
@@ -37,6 +35,8 @@ import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static net.openhft.chronicle.map.StatelessClientTest.localClient;
|
||||
import static org.junit.Assert.*;
|
||||
@@ -174,7 +174,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R getMapped(K key, @NotNull Function<? super V, R> function) {
|
||||
public <R> R getMapped(K key, @NotNull SerializableFunction<? super V, R> function) {
|
||||
return d.getMapped(key, function);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user