mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Merge remote-tracking branch 'origin/master'
Conflicts: pom.xml
This commit is contained in:
@@ -19,6 +19,8 @@
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
|
||||
import net.openhft.chronicle.hash.serialization.internal.DummyValue;
|
||||
import net.openhft.chronicle.hash.serialization.internal.DummyValueMarshaller;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -58,12 +60,14 @@ 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,
|
||||
identifier, serverPort, endpoints).create();
|
||||
return (T) newTcpSocketShmBuilder(Integer.class, DummyValue.class,
|
||||
identifier, serverPort, endpoints)
|
||||
.valueMarshallers(DummyValueMarshaller.INSTANCE, DummyValueMarshaller.INSTANCE)
|
||||
.valueSizeMarshaller(DummyValueMarshaller.INSTANCE).create();
|
||||
}
|
||||
|
||||
public static <K, V> ChronicleMapBuilder<K, V> newTcpSocketShmBuilder(
|
||||
|
||||
@@ -416,7 +416,8 @@ public class CHMUseCasesTest {
|
||||
Arrays.fill(expected, 'X');
|
||||
|
||||
ChronicleMapBuilder<CharSequence, char[]> builder = ChronicleMapBuilder
|
||||
.of(CharSequence.class, char[].class).entries(1).constantValueSizeBySample(expected);
|
||||
.of(CharSequence.class, char[].class).entries(1)
|
||||
.constantValueSizeBySample(expected);
|
||||
|
||||
try (ChronicleMap<CharSequence, char[]> map = newInstance(builder)) {
|
||||
map.put("Key", expected);
|
||||
@@ -658,28 +659,6 @@ public class CHMUseCasesTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUsingWithCharSequenceNoValue() throws IOException {
|
||||
ChronicleMapBuilder<CharSequence, CharSequence> builder = ChronicleMapBuilder
|
||||
.of(CharSequence.class, CharSequence.class);
|
||||
|
||||
if (typeOfMap == TypeOfMap.STATELESS)
|
||||
return; // context supported by the STATELESS client
|
||||
|
||||
try (ChronicleMap<CharSequence, CharSequence> map = newInstance(builder)) {
|
||||
|
||||
try (MapKeyContext<CharSequence, CharSequence> c = map.context("1")) {
|
||||
CharSequence value = c.get();
|
||||
assertTrue(value instanceof StringBuilder);
|
||||
((StringBuilder) value).append("Hello World");
|
||||
}
|
||||
|
||||
assertEquals(null, map.get("1"));
|
||||
mapChecks();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetUsingWithIntValueNoValue() throws IOException {
|
||||
|
||||
@@ -701,32 +680,6 @@ public class CHMUseCasesTest {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testAcquireUsingWithIntValueNoValue() throws IOException {
|
||||
|
||||
if (typeOfMap == TypeOfMap.STATELESS)
|
||||
throw new IllegalStateException(); // acquireContext supported by the STATELESS
|
||||
|
||||
|
||||
ChronicleMapBuilder<CharSequence, IntValue> builder = ChronicleMapBuilder
|
||||
.of(CharSequence.class, IntValue.class);
|
||||
|
||||
try (ChronicleMap<CharSequence, IntValue> map = newInstance(builder)) {
|
||||
|
||||
try (MapKeyContext<CharSequence, IntValue> c = map.context("1")) {
|
||||
c.updateLock().lock();
|
||||
IntValue value = c.get();
|
||||
assertTrue(value instanceof IntValue);
|
||||
value.setValue(1);
|
||||
}
|
||||
|
||||
assertEquals(null, map.get("1"));
|
||||
mapChecks();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testAcquireUsingImmutableUsing() throws IOException {
|
||||
|
||||
|
||||
@@ -592,9 +592,12 @@ public class ChronicleMapTest {
|
||||
CharSequence userCS = getUserCharSequence(i);
|
||||
|
||||
if (j > 1) {
|
||||
assertNotNull(userCS.toString(), map.getUsing(userCS, value));
|
||||
LongValue v = map.getUsing(userCS, value);
|
||||
assertNotNull(userCS.toString(), v);
|
||||
assertTrue(userCS.toString(), v == value);
|
||||
} else {
|
||||
map.acquireUsing(userCS, value);
|
||||
LongValue v = map.acquireUsing(userCS, value);
|
||||
assertTrue(userCS.toString(), v == value);
|
||||
}
|
||||
if (i >= 1)
|
||||
assertTrue(userCS.toString(), map.containsKey(getUserCharSequence(1)));
|
||||
|
||||
@@ -45,7 +45,10 @@ public class MarkTest {
|
||||
|
||||
@Test(timeout = 25000)
|
||||
public void persistedTest() {
|
||||
final File db = Paths.get(System.getProperty("java.io.tmpdir"), "mark").toFile();
|
||||
int rnd = new Random().nextInt();
|
||||
final File db = Paths.get(System.getProperty("java.io.tmpdir"), "mark" + rnd).toFile();
|
||||
if (db.exists())
|
||||
db.delete();
|
||||
try {
|
||||
test(new Function<ChronicleMapBuilder<Integer, Integer>,
|
||||
ChronicleMap<Integer, Integer>>() {
|
||||
|
||||
@@ -37,11 +37,15 @@ import static org.junit.Assert.*;
|
||||
public class ReplicatedChronicleMapTest extends JSR166TestCase {
|
||||
ChronicleMap<Integer, CharSequence> newShmIntString() throws IOException {
|
||||
return ChronicleMapBuilder.of(Integer.class, CharSequence.class)
|
||||
.replication((byte) 1)
|
||||
.entries(1000)
|
||||
.create();
|
||||
}
|
||||
|
||||
ChronicleMap<CharSequence, CharSequence> newShmStringString() throws IOException {
|
||||
return ChronicleMapBuilder.of(CharSequence.class, CharSequence.class)
|
||||
.replication((byte) 1)
|
||||
.entries(1000)
|
||||
.create();
|
||||
}
|
||||
|
||||
|
||||
@@ -300,7 +300,7 @@ public class StatelessClientTest {
|
||||
|
||||
serverMap.put("hello", "world");
|
||||
|
||||
statelessMap.replace("hello", "world", "hello");
|
||||
assertTrue(statelessMap.replace("hello", "world", "hello"));
|
||||
|
||||
assertEquals("hello", statelessMap.get("hello"));
|
||||
assertEquals(1, statelessMap.size());
|
||||
|
||||
@@ -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));
|
||||
|
||||
+1
-1
@@ -107,7 +107,7 @@ public class TCPSocketReplication3wayPutReturnsNullTest {
|
||||
|
||||
assertEquals(null, map1.put(1, "EXAMPLE-1"));
|
||||
assertEquals(null, map1.put(2, "EXAMPLE-2"));
|
||||
assertEquals("EXAMPLE-2", map1.put(2, "EXAMPLE-1"));
|
||||
assertEquals(null, map1.put(2, "EXAMPLE-1"));
|
||||
|
||||
assertEquals(null, map2.put(5, "EXAMPLE-2"));
|
||||
assertEquals(null, map2.put(6, "EXAMPLE-2"));
|
||||
|
||||
@@ -114,7 +114,7 @@ public class TimeBasedReplicationTest extends JSR166TestCase {
|
||||
|
||||
// should NOT throw LateUpdateException because the value is present and it is just
|
||||
// returned.
|
||||
assertEquals(map.putIfAbsent("key-1", "value-2"), null);
|
||||
assertEquals("value-1", map.putIfAbsent("key-1", "value-2"));
|
||||
|
||||
// we'll now flip the time back to the current in order to do the read the result
|
||||
current(timeProvider);
|
||||
|
||||
@@ -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) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user