mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Enhanced thread safety tests with the latest lang release
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.chronicle.common.serialization.impl.ByteableMarshaller;
|
||||
import net.openhft.lang.io.Bytes;
|
||||
import net.openhft.lang.io.NativeBytes;
|
||||
import net.openhft.lang.io.serialization.BytesMarshaller;
|
||||
@@ -51,7 +52,7 @@ enum ByteableIntValueMarshaller implements BytesMarshaller<IntValue> {
|
||||
if (intValue == null)
|
||||
intValue = (IntValue) NativeBytes.UNSAFE.allocateInstance(DIRECT);
|
||||
Byteable biv = (Byteable) intValue;
|
||||
biv.bytes(bytes, bytes.position());
|
||||
ByteableMarshaller.setBytesAndOffset(biv, bytes);
|
||||
bytes.skip(biv.maxSize());
|
||||
return intValue;
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.chronicle.common.serialization.impl.ByteableMarshaller;
|
||||
import net.openhft.lang.io.Bytes;
|
||||
import net.openhft.lang.io.NativeBytes;
|
||||
import net.openhft.lang.io.serialization.BytesMarshaller;
|
||||
@@ -51,7 +52,7 @@ enum ByteableLongValueMarshaller implements BytesMarshaller<LongValue> {
|
||||
if (longValue == null)
|
||||
longValue = (LongValue) NativeBytes.UNSAFE.allocateInstance(DIRECT);
|
||||
Byteable biv = (Byteable) longValue;
|
||||
biv.bytes(bytes, bytes.position());
|
||||
ByteableMarshaller.setBytesAndOffset(biv, bytes);
|
||||
bytes.skip(biv.maxSize());
|
||||
return longValue;
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -470,8 +470,8 @@ public class ChronicleMapTest {
|
||||
|
||||
@Test
|
||||
public void testGetWithoutAcquireFirst() throws Exception {
|
||||
ChronicleMap<CharSequence, LongValue> map = getSharedMap(10 * 1000, 128, 24);
|
||||
assertNull(map.getUsing("key", new LongValue$$Native()));
|
||||
ChronicleMap<CharSequence, LongValue> map = getSharedMap(10 , 1, 24);
|
||||
assertNull(map.getUsing("key", DataValueClasses.newDirectReference(LongValue.class)));
|
||||
|
||||
map.close();
|
||||
}
|
||||
@@ -491,10 +491,10 @@ public class ChronicleMapTest {
|
||||
@Test
|
||||
public void testAcquireAndGet() throws IOException, ClassNotFoundException,
|
||||
IllegalAccessException, InstantiationException {
|
||||
int entries = 100 * 1000;
|
||||
testAcquireAndGet(getSharedMap(entries, 128, 24, NO_ALIGNMENT), entries);
|
||||
testAcquireAndGet(getSharedMap(entries, 128, 24, OF_4_BYTES), entries);
|
||||
testAcquireAndGet(getSharedMap(entries, 128, 24, OF_8_BYTES), entries);
|
||||
int entries = 3/*00 * 1000*/;
|
||||
testAcquireAndGet(getSharedMap(entries, 1, 24, OF_4_BYTES), entries);
|
||||
testAcquireAndGet(getSharedMap(entries, 1, 24, NO_ALIGNMENT), entries);
|
||||
testAcquireAndGet(getSharedMap(entries, 1, 24, OF_8_BYTES), entries);
|
||||
}
|
||||
|
||||
public void testAcquireAndGet(ChronicleMap<CharSequence, LongValue> map, int entries)
|
||||
|
||||
@@ -23,10 +23,13 @@ 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 org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
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.*;
|
||||
|
||||
@@ -51,8 +54,8 @@ public class IntIntMultiMapTest {
|
||||
@Parameterized.Parameters
|
||||
public static Collection<Object[]> data() {
|
||||
return Arrays.asList(new Object[][]{
|
||||
{VanillaShortShortMultiMap.class},
|
||||
{VanillaIntIntMultiMap.class},
|
||||
{VanillaShortShortMultiMap.class}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -150,13 +153,14 @@ public class IntIntMultiMapTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Very long running test")
|
||||
public void testMaxCapacity() throws NoSuchFieldException, IllegalAccessException {
|
||||
Field maxCapacityField = c.getDeclaredField("MAX_CAPACITY");
|
||||
long maxCapacity = maxCapacityField.getLong(null);
|
||||
Field entrySizeField = c.getDeclaredField("ENTRY_SIZE");
|
||||
entrySizeField.setAccessible(true);
|
||||
long entrySize = entrySizeField.getLong(null);
|
||||
if (Runtime.getRuntime().maxMemory() < maxCapacity * entrySize * 3L / 2L) {
|
||||
if (maxMemory() * 1024L < maxCapacity * entrySize * 3L / 2L) {
|
||||
System.out.println("Skipped " + c + " maxCapacity test because there is not enough " +
|
||||
"memory in system");
|
||||
return;
|
||||
@@ -177,4 +181,16 @@ public class IntIntMultiMapTest {
|
||||
});
|
||||
assertTrue(bs.allSet(0L, maxCapacity));
|
||||
}
|
||||
|
||||
private long maxMemory() {
|
||||
File meminfo = new File("/proc/meminfo");
|
||||
try {
|
||||
try (Scanner sc = new Scanner(meminfo)) {
|
||||
sc.next();
|
||||
return sc.nextLong();
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,9 @@
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.lang.io.ByteBufferBytes;
|
||||
import net.openhft.lang.model.Byteable;
|
||||
import net.openhft.lang.model.DataValueClasses;
|
||||
import net.openhft.lang.values.IntValue;
|
||||
import net.openhft.lang.values.IntValue$$Native;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -45,16 +46,15 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class TCPSocketReplicationIntValueTest {
|
||||
|
||||
|
||||
private ChronicleMapBuilder<IntValue, CharSequence> map1Builder;
|
||||
private ChronicleMap<IntValue, CharSequence> map1;
|
||||
private ChronicleMap<IntValue, CharSequence> map2;
|
||||
private IntValue$$Native value;
|
||||
private IntValue value;
|
||||
|
||||
@Before
|
||||
public void setup() throws IOException {
|
||||
value = new IntValue$$Native();
|
||||
value.bytes(new ByteBufferBytes(ByteBuffer.allocateDirect(4)), 0);
|
||||
value = DataValueClasses.newDirectReference(IntValue.class);
|
||||
((Byteable) value).bytes(new ByteBufferBytes(ByteBuffer.allocateDirect(4)), 0);
|
||||
map1Builder = newTcpSocketShmBuilder(IntValue.class, CharSequence.class,
|
||||
(byte) 1, 8076, new InetSocketAddress("localhost", 8077));
|
||||
map1Builder.keyMarshaller(ByteableIntValueMarshaller.INSTANCE).file(getPersistenceFile());
|
||||
@@ -88,7 +88,7 @@ public class TCPSocketReplicationIntValueTest {
|
||||
assertTrue(!map1.isEmpty());
|
||||
}
|
||||
|
||||
private IntValue$$Native set(int x) {
|
||||
private IntValue set(int x) {
|
||||
|
||||
value.setValue(x);
|
||||
return value;
|
||||
|
||||
@@ -112,7 +112,7 @@ public class TCPSocketReplicationTest3VoidValueTest {
|
||||
map2.put(5, null);
|
||||
|
||||
// allow time for the recompilation to resolve
|
||||
assertTrue(waitTillEqual(5000));
|
||||
assertTrue("test timed out", waitTillEqual(5000));
|
||||
|
||||
assertEquals(map3, map3);
|
||||
assertTrue(!map1.isEmpty());
|
||||
|
||||
Reference in New Issue
Block a user