Moved to CityHash (proven to be faster); Made Hashing and BytesInterop API more cohrent; removed Void marshalling because values should never be null

This commit is contained in:
leventov
2015-01-26 13:21:27 +07:00
parent 935c2422dd
commit 68697831b8
51 changed files with 1623 additions and 550 deletions
@@ -19,6 +19,7 @@
package net.openhft.chronicle.map;
import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
import net.openhft.chronicle.hash.serialization.internal.DummyValue;
import java.io.File;
import java.io.IOException;
@@ -58,11 +59,11 @@ public class Builder {
return file;
}
public static <T extends ChronicleMap<Integer, Void>> T newMapVoid(
public static <T extends ChronicleMap<Integer, DummyValue>> T newMapDummyValue(
final byte identifier,
final int serverPort,
final InetSocketAddress... endpoints) throws IOException {
return (T) newTcpSocketShmBuilder(Integer.class, Void.class,
return (T) newTcpSocketShmBuilder(Integer.class, DummyValue.class,
identifier, serverPort, endpoints).create();
}
@@ -1,38 +0,0 @@
/*
* 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 com.google.common.hash.HashFunction;
import com.google.common.hash.Hashing;
import net.openhft.chronicle.hash.hashing.Hasher;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class HasherTest {
@Test
public void test() {
HashFunction hashFunction = Hashing.murmur3_128();
for (int i=0;i<10;i++)
{
String key = "010758403"+String.format("%06d",i)+"S-INJFIX_SLE";
long hashCode = Hasher.hash(key.getBytes());
long guavaHashCode = hashFunction.hashBytes(key.getBytes()).asLong();
assertEquals(guavaHashCode, hashCode);
}
}
}
@@ -18,6 +18,7 @@
package net.openhft.chronicle.map;
import net.openhft.chronicle.hash.serialization.internal.DummyValue;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -27,7 +28,8 @@ import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.Set;
import static net.openhft.chronicle.map.Builder.newMapVoid;
import static net.openhft.chronicle.hash.serialization.internal.DummyValue.DUMMY_VALUE;
import static net.openhft.chronicle.map.Builder.newMapDummyValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -39,16 +41,16 @@ import static org.junit.Assert.assertTrue;
public class TCPSocketReplication3VoidValueTest {
private ChronicleMap<Integer, Void> map1;
private ChronicleMap<Integer, Void> map2;
private ChronicleMap<Integer, Void> map3;
private ChronicleMap<Integer, DummyValue> map1;
private ChronicleMap<Integer, DummyValue> map2;
private ChronicleMap<Integer, DummyValue> map3;
@Before
public void setup() throws IOException {
map1 = newMapVoid((byte) 1, 8036, new InetSocketAddress("localhost", 8037),
map1 = newMapDummyValue((byte) 1, 8036, new InetSocketAddress("localhost", 8037),
new InetSocketAddress("localhost", 8039));
map2 = newMapVoid((byte) 2, 8037, new InetSocketAddress("localhost", 8039));
map3 = newMapVoid((byte) 3, 8039);
map2 = newMapDummyValue((byte) 2, 8037, new InetSocketAddress("localhost", 8039));
map3 = newMapDummyValue((byte) 3, 8039);
}
@After
@@ -78,7 +80,7 @@ public class TCPSocketReplication3VoidValueTest {
@Test
public void test3() throws IOException, InterruptedException {
assertEquals(null, map3.put(5, null));
assertEquals(null, map3.put(5, DUMMY_VALUE));
// allow time for the recompilation to resolve
assertTrue(waitTillEqual(15000));
@@ -90,16 +92,16 @@ public class TCPSocketReplication3VoidValueTest {
@Test
public void test() throws IOException, InterruptedException {
assertEquals(null, map1.put(1, null));
assertEquals(null, map1.put(2, null));
assertEquals(null, map1.put(1, DUMMY_VALUE));
assertEquals(null, map1.put(2, DUMMY_VALUE));
assertEquals(null, map2.put(5, null));
assertEquals(null, map2.put(6, null));
assertEquals(null, map2.put(5, DUMMY_VALUE));
assertEquals(null, map2.put(6, DUMMY_VALUE));
map1.remove(2);
map2.remove(3);
map1.remove(3);
map2.put(5, null);
map2.put(5, DUMMY_VALUE);
// allow time for the recompilation to resolve
assertTrue(waitTillEqual(5000));
@@ -111,15 +113,15 @@ public class TCPSocketReplication3VoidValueTest {
@Test
public void testClear() throws IOException, InterruptedException {
assertEquals(null, map1.put(1, null));
assertEquals(null, map1.put(2, null));
assertEquals(null, map1.put(1, DUMMY_VALUE));
assertEquals(null, map1.put(2, DUMMY_VALUE));
assertEquals(null, map2.put(5, null));
assertEquals(null, map2.put(6, null));
assertEquals(null, map2.put(5, DUMMY_VALUE));
assertEquals(null, map2.put(6, DUMMY_VALUE));
map1.clear();
map2.put(5, null);
map2.put(5, DUMMY_VALUE);
// allow time for the recompilation to resolve
assertTrue("test timed out", waitTillEqual(15000));
@@ -18,19 +18,22 @@ package net.openhft.chronicle.map.fromdocs;
import net.openhft.chronicle.hash.serialization.BytesReader;
import net.openhft.lang.io.Bytes;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
enum LongPairArrayReader implements BytesReader<LongPair[]> {
INSTANCE;
@NotNull
@Override
public LongPair[] read(Bytes bytes, long size) {
public LongPair[] read(@NotNull Bytes bytes, long size) {
return read(bytes, size, null);
}
@NotNull
@Override
public LongPair[] read(Bytes bytes, long size, LongPair[] toReuse) {
public LongPair[] read(@NotNull Bytes bytes, long size, LongPair[] toReuse) {
if (size > Integer.MAX_VALUE * 16L)
throw new IllegalStateException("LongPair[] size couldn't be " + (size / 16L));
int resLen = (int) (size / 16L);
@@ -18,17 +18,18 @@ package net.openhft.chronicle.map.fromdocs;
import net.openhft.chronicle.hash.serialization.BytesWriter;
import net.openhft.lang.io.Bytes;
import org.jetbrains.annotations.NotNull;
enum LongPairArrayWriter implements BytesWriter<LongPair[]> {
INSTANCE;
@Override
public long size(LongPair[] longPairs) {
public long size(@NotNull LongPair[] longPairs) {
return longPairs.length * 16L;
}
@Override
public void write(Bytes bytes, LongPair[] longPairs) {
public void write(@NotNull Bytes bytes, @NotNull LongPair[] longPairs) {
for (LongPair pair : longPairs) {
bytes.writeLong(pair.first);
bytes.writeLong(pair.second);
@@ -704,6 +704,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase {
c.get(null);
shouldThrow();
} catch (NullPointerException success) {
} catch (IllegalArgumentException success) {
}
}
@@ -716,6 +717,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase {
c.containsKey(null);
shouldThrow();
} catch (NullPointerException success) {
} catch (IllegalArgumentException success) {
}
}