mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
HCOLL-218 ReplicatedChronicleMapTest appears to use too much resources - I've looked at other tests as well and have attempted to ensure that close is called on every test, also prompting the GC to run after each test.
This commit is contained in:
@@ -31,31 +31,32 @@ public class CHMTestIterator1 {
|
||||
AtomicLong alKey = new AtomicLong();
|
||||
int runs = 3000000;
|
||||
ChronicleMapBuilder<String, Long> builder = ChronicleMapBuilder.of(String.class, Long.class)
|
||||
|
||||
.entries(runs);
|
||||
|
||||
ChronicleMap<String, Long> chm = builder.create();
|
||||
try (ChronicleMap<String, Long> chm = builder.create()) {
|
||||
/*chm.put("k1", alValue.incrementAndGet());
|
||||
chm.put("k2", alValue.incrementAndGet());
|
||||
chm.put("k3", alValue.incrementAndGet());
|
||||
chm.put("k4", alValue.incrementAndGet());
|
||||
chm.put("k5", alValue.incrementAndGet());*/
|
||||
//chm.keySet();
|
||||
//chm.keySet();
|
||||
|
||||
|
||||
for (int i = 0; i < runs; i++) {
|
||||
chm.put("k" + alKey.incrementAndGet(), alValue.incrementAndGet());
|
||||
}
|
||||
for (int i = 0; i < runs; i++) {
|
||||
chm.put("k" + alKey.incrementAndGet(), alValue.incrementAndGet());
|
||||
}
|
||||
|
||||
long start = System.nanoTime();
|
||||
for (Map.Entry<String, Long> entry : chm.entrySet()) {
|
||||
entry.getKey();
|
||||
entry.getValue();
|
||||
long start = System.nanoTime();
|
||||
for (Map.Entry<String, Long> entry : chm.entrySet()) {
|
||||
entry.getKey();
|
||||
entry.getValue();
|
||||
|
||||
}
|
||||
long time = System.nanoTime() - start;
|
||||
System.out.println("Average iteration time was " + time / runs / 1e3 + "us, for " + runs / 1e6 + "m entries");
|
||||
|
||||
}
|
||||
long time = System.nanoTime() - start;
|
||||
System.out.println("Average iteration time was " + time / runs / 1e3 + "us, for " + runs / 1e6 + "m entries");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -88,6 +88,7 @@ public class ChannelReplicationTest {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.gc();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -52,17 +52,18 @@ public class ConstantSizeBySampleTest {
|
||||
|
||||
@Test
|
||||
public void testUnexpectedlyLongConstantByteArrayValues() throws IOException {
|
||||
ChronicleMap<Long, byte[]> map = ChronicleMapBuilder.of(Long.class, byte[].class)
|
||||
try (ChronicleMap<Long, byte[]> map = ChronicleMapBuilder.of(Long.class, byte[].class)
|
||||
.constantValueSizeBySample(new byte[512 * 1024])
|
||||
.entries(100)
|
||||
.actualSegments(1)
|
||||
.create();
|
||||
.create()) {
|
||||
|
||||
byte[] value = new byte[512 * 1024];
|
||||
byte[] value = new byte[512 * 1024];
|
||||
|
||||
value[42] = 1;
|
||||
map.put(1L, value);
|
||||
Assert.assertTrue(Arrays.equals(map.get(1L), value));
|
||||
value[42] = 1;
|
||||
map.put(1L, value);
|
||||
Assert.assertTrue(Arrays.equals(map.get(1L), value));
|
||||
}
|
||||
}
|
||||
|
||||
static class ExternalizableData implements Externalizable {
|
||||
@@ -88,17 +89,18 @@ public class ConstantSizeBySampleTest {
|
||||
|
||||
@Test
|
||||
public void testUnexpectedlyLongConstantExternalizableValues() throws IOException {
|
||||
ChronicleMap<Long, ExternalizableData> map =
|
||||
try ( ChronicleMap<Long, ExternalizableData> map =
|
||||
ChronicleMapBuilder.of(Long.class, ExternalizableData.class)
|
||||
.constantValueSizeBySample(new ExternalizableData())
|
||||
.entries(100)
|
||||
.actualSegments(1)
|
||||
.create();
|
||||
.create()) {
|
||||
|
||||
ExternalizableData value = new ExternalizableData();
|
||||
value.data[42] = 1;
|
||||
map.put(1L, value);
|
||||
Assert.assertEquals(map.get(1L), value);
|
||||
ExternalizableData value = new ExternalizableData();
|
||||
value.data[42] = 1;
|
||||
map.put(1L, value);
|
||||
Assert.assertEquals(map.get(1L), value);
|
||||
}
|
||||
}
|
||||
|
||||
static class SerializableData implements Serializable {
|
||||
@@ -115,16 +117,17 @@ public class ConstantSizeBySampleTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void testUnexpectedlyLongConstantSerializableValues() throws IOException {
|
||||
ChronicleMap<Long, SerializableData> map =
|
||||
try ( ChronicleMap<Long, SerializableData> map =
|
||||
ChronicleMapBuilder.of(Long.class, SerializableData.class)
|
||||
.constantValueSizeBySample(new SerializableData())
|
||||
.entries(100)
|
||||
.actualSegments(1)
|
||||
.create();
|
||||
.create()) {
|
||||
|
||||
SerializableData value = new SerializableData();
|
||||
value.data[42] = 1;
|
||||
map.put(1L, value);
|
||||
Assert.assertEquals(map.get(1L), value);
|
||||
SerializableData value = new SerializableData();
|
||||
value.data[42] = 1;
|
||||
map.put(1L, value);
|
||||
Assert.assertEquals(map.get(1L), value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,85 +17,88 @@ public class DemoChronicleMapTest {
|
||||
File file = File.createTempFile("DummyOrders", ".test");
|
||||
file.deleteOnExit();
|
||||
int maxEntries = 1000;
|
||||
ChronicleMap<IntValue, DemoOrderVOInterface> map = ChronicleMapBuilder
|
||||
try (ChronicleMap<IntValue, DemoOrderVOInterface> map = ChronicleMapBuilder
|
||||
.of(IntValue.class, DemoOrderVOInterface.class)
|
||||
.putReturnsNull(true)
|
||||
.removeReturnsNull(true)
|
||||
.entries(maxEntries)
|
||||
.createPersistedTo(file);
|
||||
.createPersistedTo(file)) {
|
||||
|
||||
|
||||
IntValue key = DataValueClasses.newDirectInstance(IntValue.class);
|
||||
IntValue key = DataValueClasses.newDirectInstance(IntValue.class);
|
||||
|
||||
DemoOrderVOInterface value = DataValueClasses.newDirectReference(DemoOrderVOInterface.class);
|
||||
DemoOrderVOInterface value2 = DataValueClasses.newDirectReference(DemoOrderVOInterface.class);
|
||||
DemoOrderVOInterface value = DataValueClasses.newDirectReference(DemoOrderVOInterface.class);
|
||||
DemoOrderVOInterface value2 = DataValueClasses.newDirectReference(DemoOrderVOInterface.class);
|
||||
|
||||
// Initially populate the map
|
||||
for (int i = 0; i < maxEntries; i++) {
|
||||
key.setValue(i);
|
||||
// Initially populate the map
|
||||
for (int i = 0; i < maxEntries; i++) {
|
||||
key.setValue(i);
|
||||
|
||||
map.acquireUsing(key, value);
|
||||
map.acquireUsing(key, value);
|
||||
|
||||
value.setSymbol("IBM-" + i);
|
||||
value.addAtomicOrderQty(1000);
|
||||
value.setSymbol("IBM-" + i);
|
||||
value.addAtomicOrderQty(1000);
|
||||
|
||||
map.getUsing(key, value2);
|
||||
assertEquals("IBM-" + i, value.getSymbol());
|
||||
assertEquals(1000, value.getOrderQty(), 0.0);
|
||||
}
|
||||
map.getUsing(key, value2);
|
||||
assertEquals("IBM-" + i, value.getSymbol());
|
||||
assertEquals(1000, value.getOrderQty(), 0.0);
|
||||
}
|
||||
|
||||
for (Map.Entry<IntValue, DemoOrderVOInterface> entry : map.entrySet()) {
|
||||
for (Map.Entry<IntValue, DemoOrderVOInterface> entry : map.entrySet()) {
|
||||
|
||||
IntValue k = entry.getKey();
|
||||
DemoOrderVOInterface v = entry.getValue();
|
||||
IntValue k = entry.getKey();
|
||||
DemoOrderVOInterface v = entry.getValue();
|
||||
|
||||
System.out.println(String.format("Key %d %s", k.getValue(), v == null ? "<null>" : v.getSymbol()));
|
||||
assertNotNull(v);
|
||||
System.out.println(String.format("Key %d %s", k.getValue(), v == null ? "<null>" : v.getSymbol()));
|
||||
assertNotNull(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMapLocked() throws Exception {
|
||||
File file = File.createTempFile("DummyOrders", ".test");
|
||||
file.deleteOnExit();
|
||||
int maxEntries = 1000;
|
||||
ChronicleMap<IntValue, DemoOrderVOInterface> map = ChronicleMapBuilder
|
||||
try (ChronicleMap<IntValue, DemoOrderVOInterface> map = ChronicleMapBuilder
|
||||
.of(IntValue.class, DemoOrderVOInterface.class)
|
||||
.putReturnsNull(true)
|
||||
.removeReturnsNull(true)
|
||||
.entries(maxEntries)
|
||||
.createPersistedTo(file);
|
||||
.createPersistedTo(file)) {
|
||||
|
||||
|
||||
IntValue key = DataValueClasses.newDirectInstance(IntValue.class);
|
||||
IntValue key = DataValueClasses.newDirectInstance(IntValue.class);
|
||||
|
||||
DemoOrderVOInterface value = DataValueClasses.newDirectReference(DemoOrderVOInterface.class);
|
||||
DemoOrderVOInterface value2 = DataValueClasses.newDirectReference(DemoOrderVOInterface.class);
|
||||
DemoOrderVOInterface value = DataValueClasses.newDirectReference(DemoOrderVOInterface.class);
|
||||
DemoOrderVOInterface value2 = DataValueClasses.newDirectReference(DemoOrderVOInterface.class);
|
||||
|
||||
// Initially populate the map
|
||||
for (int i = 0; i < maxEntries; i++) {
|
||||
key.setValue(i);
|
||||
// Initially populate the map
|
||||
for (int i = 0; i < maxEntries; i++) {
|
||||
key.setValue(i);
|
||||
|
||||
try (WriteContext wc = map.acquireUsingLocked(key, value)) {
|
||||
value.setSymbol("IBM-" + i);
|
||||
value.addAtomicOrderQty(1000);
|
||||
try (WriteContext wc = map.acquireUsingLocked(key, value)) {
|
||||
value.setSymbol("IBM-" + i);
|
||||
value.addAtomicOrderQty(1000);
|
||||
}
|
||||
|
||||
try (ReadContext rc = map.getUsingLocked(key, value2)) {
|
||||
assertTrue(rc.present());
|
||||
assertEquals("IBM-" + i, value.getSymbol());
|
||||
assertEquals(1000, value.getOrderQty(), 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
try (ReadContext rc = map.getUsingLocked(key, value2)) {
|
||||
assertTrue(rc.present());
|
||||
assertEquals("IBM-" + i, value.getSymbol());
|
||||
assertEquals(1000, value.getOrderQty(), 0.0);
|
||||
for (Map.Entry<IntValue, DemoOrderVOInterface> entry : map.entrySet()) {
|
||||
|
||||
IntValue k = entry.getKey();
|
||||
DemoOrderVOInterface v = entry.getValue();
|
||||
|
||||
System.out.println(String.format("Key %d %s", k.getValue(), v == null ? "<null>" : v.getSymbol()));
|
||||
assertNotNull(v);
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<IntValue, DemoOrderVOInterface> entry : map.entrySet()) {
|
||||
|
||||
IntValue k = entry.getKey();
|
||||
DemoOrderVOInterface v = entry.getValue();
|
||||
|
||||
System.out.println(String.format("Key %d %s", k.getValue(), v == null ? "<null>" : v.getSymbol()));
|
||||
assertNotNull(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -87,6 +87,7 @@ public class EventListenerTestWithTCPSocketReplication {
|
||||
valueRef.set(null);
|
||||
replacedValueRef.set(null);
|
||||
keyRef.set(null);
|
||||
System.gc();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -37,22 +37,24 @@ public class IntValueMapTest {
|
||||
@Test
|
||||
public void test() throws IOException {
|
||||
|
||||
final ChronicleMap<IntValue, CharSequence> map = OnHeapUpdatableChronicleMapBuilder
|
||||
try (final ChronicleMap<IntValue, CharSequence> map = OnHeapUpdatableChronicleMapBuilder
|
||||
.of(IntValue.class, CharSequence.class)
|
||||
.entries(20000)
|
||||
.keyMarshaller(ByteableIntValueMarshaller.INSTANCE).create();
|
||||
.keyMarshaller(ByteableIntValueMarshaller.INSTANCE).create()) {
|
||||
|
||||
IntValue$$Native value = new IntValue$$Native();
|
||||
value.bytes(new ByteBufferBytes(ByteBuffer.allocateDirect(4)), 0);
|
||||
IntValue$$Native value = new IntValue$$Native();
|
||||
value.bytes(new ByteBufferBytes(ByteBuffer.allocateDirect(4)), 0);
|
||||
|
||||
value.setValue(1);
|
||||
final String expected = "test";
|
||||
map.put(value, expected);
|
||||
value.setValue(1);
|
||||
final String expected = "test";
|
||||
map.put(value, expected);
|
||||
|
||||
final CharSequence actual = map.get(value);
|
||||
assertEquals(expected, actual);
|
||||
final CharSequence actual = map.get(value);
|
||||
assertEquals(expected, actual);
|
||||
|
||||
// this will fail
|
||||
map.toString();
|
||||
// this will fail
|
||||
|
||||
map.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,22 +32,22 @@ public class Issue42Test {
|
||||
if (!Jvm.isWindows())
|
||||
return;
|
||||
|
||||
final ChronicleMap<CharSequence, CharSequence> map = OnHeapUpdatableChronicleMapBuilder
|
||||
try (final ChronicleMap<CharSequence, CharSequence> map = OnHeapUpdatableChronicleMapBuilder
|
||||
.of(CharSequence.class, CharSequence.class)
|
||||
.entrySize(18)
|
||||
.entries(1500000)
|
||||
.minSegments(128).create();
|
||||
.minSegments(128).create()) {
|
||||
|
||||
for (int i = 0; i < 1000000; ++i) {
|
||||
String s = String.valueOf(i);
|
||||
map.put(s, s);
|
||||
for (int i = 0; i < 1000000; ++i) {
|
||||
String s = String.valueOf(i);
|
||||
map.put(s, s);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 1000000; ++i) {
|
||||
String s = String.valueOf(i);
|
||||
Assert.assertEquals(s, map.get(s));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 1000000; ++i) {
|
||||
String s = String.valueOf(i);
|
||||
Assert.assertEquals(s, map.get(s));
|
||||
}
|
||||
|
||||
map.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,6 +111,7 @@ public class PostChannelCreationTest {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.gc();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -104,6 +104,7 @@ public class SingleMapChannelTest {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.gc();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ public class StatelessClientTest {
|
||||
|
||||
try (ChronicleMap<Integer, StringBuilder> serverMap = ChronicleMapBuilder.of(Integer.class,
|
||||
StringBuilder.class)
|
||||
.putReturnsNull(true)
|
||||
.defaultValue(new StringBuilder())
|
||||
.replication((byte) 2, TcpTransportAndNetworkConfig.of(8056)).create()) {
|
||||
|
||||
@@ -59,6 +60,7 @@ public class StatelessClientTest {
|
||||
|
||||
try (ChronicleMap<Integer, StringBuilder> statelessMap = ChronicleMapBuilder.of(Integer
|
||||
.class, StringBuilder.class)
|
||||
.putReturnsNull(true)
|
||||
.statelessClient(new InetSocketAddress("localhost", 8056)).create()) {
|
||||
|
||||
String actual = statelessMap.mapForKey(10, ToString.INSTANCE);
|
||||
|
||||
@@ -60,6 +60,7 @@ public class TCPSocketReplication3VoidValueTest {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.gc();
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
@@ -75,6 +75,7 @@ public class TCPSocketReplication3wayPutReturnsNullTest {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.gc();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -73,6 +73,7 @@ public class TCPSocketReplication4WayMapTest {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.gc();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -152,6 +152,7 @@ public class TCPSocketReplicationBootStrapTest {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.gc();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -77,6 +77,8 @@ public class TCPSocketReplicationIntValueTest {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
System.gc();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -74,6 +74,7 @@ public class TCPSocketReplicationNativeTest {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.gc();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -117,6 +117,7 @@ public class TCPSocketReplicationPostConnectionTest {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.gc();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -64,6 +64,7 @@ public class TCPSocketReplicationTest {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.gc();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -34,10 +34,11 @@ public class TestBooleanValues {
|
||||
*/
|
||||
@Test
|
||||
public void testTestBooleanValues() throws IOException, InterruptedException {
|
||||
ChronicleMap<Integer, Boolean> map =
|
||||
ChronicleMapBuilder.of(Integer.class, Boolean.class).create();
|
||||
map.put(7, true);
|
||||
Assert.assertEquals(true, map.get(7));
|
||||
try (ChronicleMap<Integer, Boolean> map =
|
||||
ChronicleMapBuilder.of(Integer.class, Boolean.class).create()) {
|
||||
map.put(7, true);
|
||||
Assert.assertEquals(true, map.get(7));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,154 +49,156 @@ public class TimeBasedReplicationTest extends JSR166TestCase {
|
||||
public void testIgnoreALatePut() throws IOException {
|
||||
|
||||
final TimeProvider timeProvider = Mockito.mock(TimeProvider.class);
|
||||
ChronicleMap map = ChronicleMapBuilder.of(CharSequence.class, CharSequence.class)
|
||||
try (ChronicleMap map = ChronicleMapBuilder.of(CharSequence.class, CharSequence.class)
|
||||
.entries(10)
|
||||
.timeProvider(timeProvider)
|
||||
.replication((byte)1)
|
||||
.create();
|
||||
.replication((byte) 1)
|
||||
.create()) {
|
||||
|
||||
current(timeProvider);
|
||||
current(timeProvider);
|
||||
|
||||
// we do a put at the current time
|
||||
map.put("key-1", "value-1");
|
||||
assertEquals(map.size(), 1);
|
||||
assertEquals(map.get("key-1"), "value-1");
|
||||
// we do a put at the current time
|
||||
map.put("key-1", "value-1");
|
||||
assertEquals(map.size(), 1);
|
||||
assertEquals(map.get("key-1"), "value-1");
|
||||
|
||||
// now test assume that we receive a late update to the map, the following update should be ignored
|
||||
late(timeProvider);
|
||||
// now test assume that we receive a late update to the map, the following update should be ignored
|
||||
late(timeProvider);
|
||||
|
||||
|
||||
map.put("key-1", "value-2");
|
||||
|
||||
// we'll now flip the time back to the current in order to do the read the result
|
||||
current(timeProvider);
|
||||
assertEquals(map.size(), 1);
|
||||
assertEquals(map.get("key-1"), "value-1");
|
||||
map.put("key-1", "value-2");
|
||||
|
||||
// we'll now flip the time back to the current in order to do the read the result
|
||||
current(timeProvider);
|
||||
assertEquals(map.size(), 1);
|
||||
assertEquals(map.get("key-1"), "value-1");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIgnoreALatePutIfAbsent() throws IOException {
|
||||
|
||||
final TimeProvider timeProvider = Mockito.mock(TimeProvider.class);
|
||||
ChronicleMap map = ChronicleMapBuilder.of(CharSequence.class, CharSequence.class)
|
||||
try (ChronicleMap map = ChronicleMapBuilder.of(CharSequence.class, CharSequence.class)
|
||||
.entries(10)
|
||||
.timeProvider(timeProvider)
|
||||
.replication((byte)1)
|
||||
.create();
|
||||
current(timeProvider);
|
||||
.replication((byte) 1)
|
||||
.create()) {
|
||||
current(timeProvider);
|
||||
|
||||
// we do a put at the current time
|
||||
map.put("key-1", "value-1");
|
||||
assertEquals(map.size(), 1);
|
||||
assertEquals(map.get("key-1"), "value-1");
|
||||
// we do a put at the current time
|
||||
map.put("key-1", "value-1");
|
||||
assertEquals(map.size(), 1);
|
||||
assertEquals(map.get("key-1"), "value-1");
|
||||
|
||||
// now test assume that we receive a late update to the map, the following update should be ignored
|
||||
late(timeProvider);
|
||||
// now test assume that we receive a late update to the map, the following update should be ignored
|
||||
late(timeProvider);
|
||||
|
||||
|
||||
final Object o = map.putIfAbsent("key-1", "value-2");
|
||||
assertEquals(o, null);
|
||||
|
||||
// we'll now flip the time back to the current in order to do the read the result
|
||||
current(timeProvider);
|
||||
assertEquals(1, map.size());
|
||||
assertEquals(map.get("key-1"), "value-1");
|
||||
final Object o = map.putIfAbsent("key-1", "value-2");
|
||||
assertEquals(o, null);
|
||||
|
||||
// we'll now flip the time back to the current in order to do the read the result
|
||||
current(timeProvider);
|
||||
assertEquals(1, map.size());
|
||||
assertEquals(map.get("key-1"), "value-1");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIgnoreALateReplace() throws IOException {
|
||||
|
||||
final TimeProvider timeProvider = Mockito.mock(TimeProvider.class);
|
||||
ChronicleMap map = ChronicleMapBuilder.of(CharSequence.class, CharSequence.class)
|
||||
try (ChronicleMap map = ChronicleMapBuilder.of(CharSequence.class, CharSequence.class)
|
||||
.entries(10)
|
||||
.timeProvider(timeProvider)
|
||||
.replication((byte)1)
|
||||
.create();
|
||||
.replication((byte) 1)
|
||||
.create()) {
|
||||
|
||||
current(timeProvider);
|
||||
current(timeProvider);
|
||||
|
||||
|
||||
// we do a put at the current time
|
||||
map.put("key-1", "value-1");
|
||||
assertEquals(1, map.size());
|
||||
assertEquals("value-1", map.get("key-1"));
|
||||
// we do a put at the current time
|
||||
map.put("key-1", "value-1");
|
||||
assertEquals(1, map.size());
|
||||
assertEquals("value-1", map.get("key-1"));
|
||||
|
||||
|
||||
// now test assume that we receive a late update to the map,
|
||||
// the following update should be ignored
|
||||
late(timeProvider);
|
||||
// now test assume that we receive a late update to the map,
|
||||
// the following update should be ignored
|
||||
late(timeProvider);
|
||||
|
||||
|
||||
final Object o = map.replace("key-1", "value-2");
|
||||
assertEquals(o, null);
|
||||
final Object o = map.replace("key-1", "value-2");
|
||||
assertEquals(o, null);
|
||||
|
||||
// we'll now flip the time back to the current in order to do the read the result
|
||||
current(timeProvider);
|
||||
assertEquals(map.size(), 1);
|
||||
assertEquals("value-1", map.get("key-1"));
|
||||
// we'll now flip the time back to the current in order to do the read the result
|
||||
current(timeProvider);
|
||||
assertEquals(map.size(), 1);
|
||||
assertEquals("value-1", map.get("key-1"));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIgnoreALateReplaceWithValue() throws IOException {
|
||||
|
||||
final TimeProvider timeProvider = Mockito.mock(TimeProvider.class);
|
||||
ChronicleMap map = ChronicleMapBuilder.of(CharSequence.class, CharSequence.class)
|
||||
try (ChronicleMap map = ChronicleMapBuilder.of(CharSequence.class, CharSequence.class)
|
||||
.entries(10)
|
||||
.timeProvider(timeProvider)
|
||||
.replication((byte) 1)
|
||||
.create();
|
||||
.create()) {
|
||||
|
||||
current(timeProvider);
|
||||
current(timeProvider);
|
||||
|
||||
// we do a put at the current time
|
||||
map.put("key-1", "value-1");
|
||||
assertEquals(1, map.size());
|
||||
assertEquals("value-1", map.get("key-1"));
|
||||
// we do a put at the current time
|
||||
map.put("key-1", "value-1");
|
||||
assertEquals(1, map.size());
|
||||
assertEquals("value-1", map.get("key-1"));
|
||||
|
||||
// now test assume that we receive a late update to the map, the following update should be ignored
|
||||
late(timeProvider);
|
||||
// now test assume that we receive a late update to the map, the following update should be ignored
|
||||
late(timeProvider);
|
||||
|
||||
|
||||
assertEquals(null, map.replace("key-1", "value-2"));
|
||||
assertEquals(null, map.replace("key-1", "value-2"));
|
||||
|
||||
|
||||
// we'll now flip the time back to the current in order to do the read the result
|
||||
current(timeProvider);
|
||||
assertEquals(1, map.size());
|
||||
assertEquals("value-1", map.get("key-1"));
|
||||
|
||||
// we'll now flip the time back to the current in order to do the read the result
|
||||
current(timeProvider);
|
||||
assertEquals(1, map.size());
|
||||
assertEquals("value-1", map.get("key-1"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIgnoreALateRemoveWithValue() throws IOException {
|
||||
|
||||
final TimeProvider timeProvider = Mockito.mock(TimeProvider.class);
|
||||
ChronicleMap map = ChronicleMapBuilder.of(CharSequence.class, CharSequence.class)
|
||||
try (ChronicleMap map = ChronicleMapBuilder.of(CharSequence.class, CharSequence.class)
|
||||
.entries(10)
|
||||
.timeProvider(timeProvider)
|
||||
.replication((byte) 1)
|
||||
.create();
|
||||
.create()) {
|
||||
|
||||
current(timeProvider);
|
||||
current(timeProvider);
|
||||
|
||||
// we do a put at the current time
|
||||
map.put("key-1", "value-1");
|
||||
assertEquals(1, map.size());
|
||||
assertEquals("value-1", map.get("key-1"));
|
||||
// we do a put at the current time
|
||||
map.put("key-1", "value-1");
|
||||
assertEquals(1, map.size());
|
||||
assertEquals("value-1", map.get("key-1"));
|
||||
|
||||
// now test assume that we receive a late update to the map, the following update should be ignored
|
||||
late(timeProvider);
|
||||
// now test assume that we receive a late update to the map, the following update should be ignored
|
||||
late(timeProvider);
|
||||
|
||||
|
||||
assertEquals(false, map.remove("key-1", "value-1"));
|
||||
assertEquals(false, map.remove("key-1", "value-1"));
|
||||
|
||||
// we'll now flip the time back to the current in order to do the read the result
|
||||
current(timeProvider);
|
||||
assertEquals(1, map.size());
|
||||
assertEquals("value-1", map.get("key-1"));
|
||||
// we'll now flip the time back to the current in order to do the read the result
|
||||
current(timeProvider);
|
||||
assertEquals(1, map.size());
|
||||
assertEquals("value-1", map.get("key-1"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -204,11 +206,11 @@ public class TimeBasedReplicationTest extends JSR166TestCase {
|
||||
public void testIgnoreALateRemove() throws IOException {
|
||||
|
||||
final TimeProvider timeProvider = Mockito.mock(TimeProvider.class);
|
||||
ChronicleMap map = ChronicleMapBuilder.of(CharSequence.class, CharSequence.class)
|
||||
try (ChronicleMap map = ChronicleMapBuilder.of(CharSequence.class, CharSequence.class)
|
||||
.entries(10)
|
||||
.timeProvider(timeProvider)
|
||||
.replication((byte) 1)
|
||||
.create();
|
||||
.create()) {
|
||||
|
||||
current(timeProvider);
|
||||
|
||||
@@ -226,37 +228,40 @@ public class TimeBasedReplicationTest extends JSR166TestCase {
|
||||
current(timeProvider);
|
||||
assertEquals(1, map.size());
|
||||
assertEquals("value-1", map.get("key-1"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testIgnoreWithRemoteRemove() throws IOException {
|
||||
|
||||
final TimeProvider timeProvider = Mockito.mock(TimeProvider.class);
|
||||
ReplicatedChronicleMap map = (ReplicatedChronicleMap) ChronicleMapBuilder.of(CharSequence.class, CharSequence.class)
|
||||
try (ReplicatedChronicleMap map = (ReplicatedChronicleMap) ChronicleMapBuilder.of
|
||||
(CharSequence.class, CharSequence.class)
|
||||
.entries(10)
|
||||
.timeProvider(timeProvider)
|
||||
.replication((byte) 1)
|
||||
.create();
|
||||
.create()) {
|
||||
|
||||
current(timeProvider);
|
||||
current(timeProvider);
|
||||
|
||||
// we do a put at the current time
|
||||
map.put("key-1", "value-1");
|
||||
assertEquals(1, map.size());
|
||||
assertEquals("value-1", map.get("key-1"));
|
||||
// we do a put at the current time
|
||||
map.put("key-1", "value-1");
|
||||
assertEquals(1, map.size());
|
||||
assertEquals("value-1", map.get("key-1"));
|
||||
|
||||
// now test assume that we receive a late update to the map, the following update should be ignored
|
||||
final long late = System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(5);
|
||||
assertEquals(null, map.remove("key-1", "value-2", IDENTIFIER, late));
|
||||
// now test assume that we receive a late update to the map, the following update should be ignored
|
||||
final long late = System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(5);
|
||||
assertEquals(null, map.remove("key-1", "value-2", IDENTIFIER, late));
|
||||
|
||||
// we'll now flip the time back to the current in order to do the read the result
|
||||
current(timeProvider);
|
||||
assertEquals(1, map.size());
|
||||
assertEquals("value-1", map.get("key-1"));
|
||||
assertTrue(map.containsValue("value-1"));
|
||||
assertFalse(map.containsValue("value-2"));
|
||||
// we'll now flip the time back to the current in order to do the read the result
|
||||
current(timeProvider);
|
||||
assertEquals(1, map.size());
|
||||
assertEquals("value-1", map.get("key-1"));
|
||||
assertTrue(map.containsValue("value-1"));
|
||||
assertFalse(map.containsValue("value-2"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -265,30 +270,33 @@ public class TimeBasedReplicationTest extends JSR166TestCase {
|
||||
|
||||
|
||||
final TimeProvider timeProvider = Mockito.mock(TimeProvider.class);
|
||||
ReplicatedChronicleMap map = (ReplicatedChronicleMap) ChronicleMapBuilder.of(CharSequence.class, CharSequence.class)
|
||||
try (ReplicatedChronicleMap map = (ReplicatedChronicleMap) ChronicleMapBuilder.of
|
||||
(CharSequence.class, CharSequence.class)
|
||||
.entries(10)
|
||||
.timeProvider(timeProvider)
|
||||
.replication((byte) 1)
|
||||
.create();
|
||||
.create()) {
|
||||
|
||||
current(timeProvider);
|
||||
current(timeProvider);
|
||||
|
||||
// we do a put at the current time
|
||||
map.put("key-1", "value-1");
|
||||
assertEquals(1, map.size());
|
||||
assertEquals("value-1", map.get("key-1"));
|
||||
// we do a put at the current time
|
||||
map.put("key-1", "value-1");
|
||||
assertEquals(1, map.size());
|
||||
assertEquals("value-1", map.get("key-1"));
|
||||
|
||||
// now test assume that we receive a late update to the map, the following update should be ignored
|
||||
// now test assume that we receive a late update to the map, the following update should be ignored
|
||||
final long late = System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(5);
|
||||
assertEquals(null, map.put("key-1", "value-2", IDENTIFIER, late));
|
||||
// now test assume that we receive a late update to the map, the following update should be ignored
|
||||
// now test assume that we receive a late update to the map, the following update should be ignored
|
||||
final long late = System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(5);
|
||||
assertEquals(null, map.put("key-1", "value-2", IDENTIFIER, late));
|
||||
|
||||
|
||||
// we'll now flip the time back to the current in order to do the read the result
|
||||
current(timeProvider);
|
||||
// we'll now flip the time back to the current in order to do the read the result
|
||||
current(timeProvider);
|
||||
|
||||
assertEquals("value-1", map.get("key-1"));
|
||||
assertEquals(1, map.size(), 0);
|
||||
assertEquals("value-1", map.get("key-1"));
|
||||
assertEquals(1, map.size(), 0);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -296,28 +304,30 @@ public class TimeBasedReplicationTest extends JSR166TestCase {
|
||||
public void testRemoveFollowedByLatePut() throws IOException {
|
||||
|
||||
final TimeProvider timeProvider = Mockito.mock(TimeProvider.class);
|
||||
ReplicatedChronicleMap map = (ReplicatedChronicleMap) ChronicleMapBuilder.of(CharSequence.class, CharSequence.class)
|
||||
try (ReplicatedChronicleMap map = (ReplicatedChronicleMap) ChronicleMapBuilder.of
|
||||
(CharSequence.class, CharSequence.class)
|
||||
.entries(10)
|
||||
.timeProvider(timeProvider)
|
||||
.replication((byte)1)
|
||||
.create();
|
||||
.replication((byte) 1)
|
||||
.create()) {
|
||||
|
||||
current(timeProvider);
|
||||
current(timeProvider);
|
||||
|
||||
// we do a put at the current time
|
||||
map.put("key-1", "value-1");
|
||||
map.remove("key-1", "value-1");
|
||||
assertEquals(0, map.size());
|
||||
assertEquals(null, map.get("key-1"));
|
||||
assertEquals(false, map.containsKey("key-1"));
|
||||
// we do a put at the current time
|
||||
map.put("key-1", "value-1");
|
||||
map.remove("key-1", "value-1");
|
||||
assertEquals(0, map.size());
|
||||
assertEquals(null, map.get("key-1"));
|
||||
assertEquals(false, map.containsKey("key-1"));
|
||||
|
||||
// test assume that we receive a late update to the map, the following update should be ignored
|
||||
final long late = System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(50);
|
||||
assertEquals(null, map.put("key-1", "value-2", IDENTIFIER, late));
|
||||
// test assume that we receive a late update to the map, the following update should be ignored
|
||||
final long late = System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(50);
|
||||
assertEquals(null, map.put("key-1", "value-2", IDENTIFIER, late));
|
||||
|
||||
assertEquals(null, map.get("key-1"));
|
||||
assertEquals(false, map.containsKey("key-1"));
|
||||
assertEquals(0, map.size(), 0);
|
||||
assertEquals(null, map.get("key-1"));
|
||||
assertEquals(false, map.containsKey("key-1"));
|
||||
assertEquals(0, map.size(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -325,21 +335,22 @@ public class TimeBasedReplicationTest extends JSR166TestCase {
|
||||
public void testPutRemovePut() throws IOException {
|
||||
|
||||
final TimeProvider timeProvider = Mockito.mock(TimeProvider.class);
|
||||
ChronicleMap map = ChronicleMapBuilder.of(CharSequence.class, CharSequence.class)
|
||||
try (ChronicleMap map = ChronicleMapBuilder.of(CharSequence.class, CharSequence.class)
|
||||
.entries(10)
|
||||
.timeProvider(timeProvider)
|
||||
.replication((byte)1)
|
||||
.create();
|
||||
current(timeProvider);
|
||||
.replication((byte) 1)
|
||||
.create()) {
|
||||
current(timeProvider);
|
||||
|
||||
// we do a put at the current time
|
||||
map.put("key-1", "value-1");
|
||||
map.remove("key-1");
|
||||
assertEquals(0, map.size());
|
||||
assertEquals(null, map.put("key-1", "new-value-2"));
|
||||
assertEquals(true, map.containsKey("key-1"));
|
||||
assertEquals("new-value-2", map.get("key-1"));
|
||||
assertEquals(1, map.size(), 0);
|
||||
// we do a put at the current time
|
||||
map.put("key-1", "value-1");
|
||||
map.remove("key-1");
|
||||
assertEquals(0, map.size());
|
||||
assertEquals(null, map.put("key-1", "new-value-2"));
|
||||
assertEquals(true, map.containsKey("key-1"));
|
||||
assertEquals("new-value-2", map.get("key-1"));
|
||||
assertEquals(1, map.size(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
private void current(TimeProvider timeProvider) {
|
||||
|
||||
@@ -70,6 +70,7 @@ public class TwoMapOnDifferentServersTest {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.gc();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -72,11 +72,12 @@ public class UDPSocketReplicationTest {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.gc();
|
||||
}
|
||||
|
||||
|
||||
/* @Test
|
||||
// @Ignore
|
||||
@Ignore
|
||||
public void testBufferOverflow() throws IOException, InterruptedException {
|
||||
|
||||
for (int i = 0; i < 1024; i++) {
|
||||
@@ -85,8 +86,7 @@ public class UDPSocketReplicationTest {
|
||||
System.out.println("" + map2);
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -29,17 +29,16 @@ public class DistributedSequenceMain {
|
||||
|
||||
public static void main(String... ignored) throws IOException {
|
||||
Class<LongValue> longValueClass = DataValueClasses.directClassFor(LongValue.class);
|
||||
ChronicleMap<String, LongValue> map =
|
||||
ChronicleMapBuilder.of(String.class, longValueClass)
|
||||
.entries(128)
|
||||
.actualSegments(1).create();
|
||||
LongValue value = DataValueClasses.newDirectReference(longValueClass);
|
||||
map.acquireUsing("sequence", value);
|
||||
try (ChronicleMap<String, LongValue> map =
|
||||
ChronicleMapBuilder.of(String.class, longValueClass)
|
||||
.entries(128)
|
||||
.actualSegments(1).create()) {
|
||||
LongValue value = DataValueClasses.newDirectReference(longValueClass);
|
||||
map.acquireUsing("sequence", value);
|
||||
|
||||
for (int i = 0; i < 1000000; i++) {
|
||||
long nextId = value.addAtomicValue(1);
|
||||
for (int i = 0; i < 1000000; i++) {
|
||||
long nextId = value.addAtomicValue(1);
|
||||
}
|
||||
}
|
||||
|
||||
map.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package net.openhft.chronicle.map.fromdocs;
|
||||
|
||||
import net.openhft.lang.threadlocal.StatefulCopyable;
|
||||
import net.openhft.chronicle.set.ChronicleSet;
|
||||
import net.openhft.chronicle.set.ChronicleSetBuilder;
|
||||
import net.openhft.lang.io.Bytes;
|
||||
@@ -26,12 +25,16 @@ import net.openhft.lang.io.CharBuffers;
|
||||
import net.openhft.lang.io.serialization.BytesMarshaller;
|
||||
import net.openhft.lang.model.constraints.NotNull;
|
||||
import net.openhft.lang.pool.CharSequenceInterner;
|
||||
import net.openhft.lang.threadlocal.StatefulCopyable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.*;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.Serializable;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.CharsetDecoder;
|
||||
import java.nio.charset.CharsetEncoder;
|
||||
@@ -186,18 +189,19 @@ public class StringEncodingExamplesTest {
|
||||
|
||||
private void testCustomKeyMarshaller(BytesMarshaller<CharSequence> marshaller)
|
||||
throws IOException {
|
||||
ChronicleSet<CharSequence> chineseWordSet = ChronicleSetBuilder.of(CharSequence.class)
|
||||
try (ChronicleSet<CharSequence> chineseWordSet = ChronicleSetBuilder.of(CharSequence.class)
|
||||
.keyMarshaller(marshaller)
|
||||
.actualSegments(1)
|
||||
.actualEntriesPerSegment(1000)
|
||||
.create();
|
||||
.create()) {
|
||||
|
||||
chineseWordSet.add("新闻");
|
||||
chineseWordSet.add("地图");
|
||||
chineseWordSet.add("贴吧");
|
||||
chineseWordSet.add("登录");
|
||||
chineseWordSet.add("设置");
|
||||
Assert.assertEquals(5, chineseWordSet.size());
|
||||
System.out.println(chineseWordSet);
|
||||
chineseWordSet.add("新闻");
|
||||
chineseWordSet.add("地图");
|
||||
chineseWordSet.add("贴吧");
|
||||
chineseWordSet.add("登录");
|
||||
chineseWordSet.add("设置");
|
||||
Assert.assertEquals(5, chineseWordSet.size());
|
||||
System.out.println(chineseWordSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,6 +284,7 @@ public class JSR166TestCase {
|
||||
throw new AssertionFailedError("interrupt status set in main thread");
|
||||
|
||||
checkForkJoinPoolThreadLeaks();
|
||||
System.gc();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -54,6 +54,9 @@ public class ChronicleMapTest extends JSR166TestCase {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static ChronicleMap<ArrayList, CharSequence> newShmListBoolean(int size) throws IOException {
|
||||
return ChronicleMapBuilder.of(ArrayList.class, CharSequence.class)
|
||||
.entries(size).create();
|
||||
@@ -64,7 +67,7 @@ public class ChronicleMapTest extends JSR166TestCase {
|
||||
return ChronicleMapBuilder.of(ArrayList.class, CharSequence.class).create();
|
||||
}
|
||||
|
||||
static ChronicleMap<CharSequence, CharSequence> newShmStringString(int size) throws IOException {
|
||||
static ChronicleMap<CharSequence, CharSequence> newStrStrMap(int size) throws IOException {
|
||||
return ChronicleMapBuilder.of(CharSequence.class, CharSequence.class)
|
||||
.entries(size).create();
|
||||
}
|
||||
@@ -94,415 +97,394 @@ public class ChronicleMapTest extends JSR166TestCase {
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* clear removes all pairs
|
||||
*/
|
||||
@Test
|
||||
@Test(timeout = 5000)
|
||||
public void testClear() throws IOException {
|
||||
ChronicleMap map = map5();
|
||||
map.clear();
|
||||
assertEquals(0, map.size());
|
||||
}
|
||||
try (ChronicleMap<Integer, String> map = map5()) {
|
||||
|
||||
/**
|
||||
* Maps with same contents are equal
|
||||
*/
|
||||
@Test
|
||||
public void testEquals() throws IOException {
|
||||
ChronicleMap map1 = map5();
|
||||
ChronicleMap map2 = map5();
|
||||
assertEquals(map1, map2);
|
||||
assertEquals(map2, map1);
|
||||
map1.clear();
|
||||
assertFalse(map1.equals(map2));
|
||||
assertFalse(map2.equals(map1));
|
||||
map.clear();
|
||||
assertEquals(0, map.size());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* contains returns true for contained value
|
||||
*/
|
||||
@Test
|
||||
@Test(timeout = 5000)
|
||||
public void testContains() throws IOException {
|
||||
ChronicleMap map = map5();
|
||||
assertTrue(map.containsValue("A"));
|
||||
assertFalse(map.containsValue("Z"));
|
||||
try (ChronicleMap map = map5()) {
|
||||
assertTrue(map.containsValue("A"));
|
||||
assertFalse(map.containsValue("Z"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* containsKey returns true for contained key
|
||||
*/
|
||||
@Test
|
||||
@Test(timeout = 5000)
|
||||
public void testContainsKey() throws IOException {
|
||||
ChronicleMap map = map5();
|
||||
assertTrue(map.containsKey(one));
|
||||
assertFalse(map.containsKey(zero));
|
||||
try (ChronicleMap map = map5()) {
|
||||
assertTrue(map.containsKey(one));
|
||||
assertFalse(map.containsKey(zero));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* containsValue returns true for held values
|
||||
*/
|
||||
@Test
|
||||
@Test(timeout = 5000)
|
||||
public void testContainsValue() throws IOException {
|
||||
ChronicleMap map = map5();
|
||||
assertTrue(map.containsValue("A"));
|
||||
assertFalse(map.containsValue("Z"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inserted elements that are subclasses of the same Comparable
|
||||
* class are found.
|
||||
*/
|
||||
/* @Test public void testComparableFamily() throws IOException {
|
||||
ChronicleMap<BI, Boolean> m =
|
||||
newShmBiBoolean();
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
assertTrue(m.put(new CI(i), true) == null);
|
||||
}
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
assertTrue(m.containsKey(new CI(i)));
|
||||
assertTrue(m.containsKey(new DI(i)));
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* TODO : fix test
|
||||
* Elements of classes with erased generic type parameters based
|
||||
* on Comparable can be inserted and found.
|
||||
*/
|
||||
/* @Test public void testGenericComparable() throws IOException {
|
||||
ChronicleMap<Object, Boolean> m =
|
||||
newShmBiBoolean();
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
BI bi = new BI(i);
|
||||
BS bs = new BS(String.valueOf(i));
|
||||
LexicographicList<BI> bis = new LexicographicList<BI>(bi);
|
||||
LexicographicList<BS> bss = new LexicographicList<BS>(bs);
|
||||
assertTrue(m.putIfAbsent(bis, true) == null);
|
||||
assertTrue(m.containsKey(bis));
|
||||
if (m.putIfAbsent(bss, true) == null)
|
||||
assertTrue(m.containsKey(bss));
|
||||
assertTrue(m.containsKey(bis));
|
||||
}
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
assertTrue(m.containsKey(new ArrayList(Collections.singleton(new BI(i)))));
|
||||
try (ChronicleMap map = map5()) {
|
||||
assertTrue(map.containsValue("A"));
|
||||
assertFalse(map.containsValue("Z"));
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Elements of non-comparable classes equal to those of classes
|
||||
* with erased generic type parameters based on Comparable can be
|
||||
* inserted and found.
|
||||
* get returns the correct element at the given key, or null if not present
|
||||
*/
|
||||
/* @Test public void testGenericComparable2() throws IOException {
|
||||
ChronicleMap<Object, Boolean> m =
|
||||
newShmListBoolean();
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
m.put(new ArrayList(Collections.singleton(new BI(i))), true);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
LexicographicList<BI> bis = new LexicographicList<BI>(new BI(i));
|
||||
assertTrue(m.containsKey(bis));
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* get returns the correct element at the given key,
|
||||
* or null if not present
|
||||
*/
|
||||
@Test
|
||||
@Test(timeout = 5000)
|
||||
public void testGet() throws IOException {
|
||||
ChronicleMap map = map5();
|
||||
assertEquals("A", (String) map.get(one));
|
||||
ChronicleMap empty = newShmIntString();
|
||||
assertNull(map.get(notPresent));
|
||||
try (ChronicleMap map = map5()) {
|
||||
assertEquals("A", (String) map.get(one));
|
||||
try (ChronicleMap empty = newStrStrMap(8078)) {
|
||||
assertNull(map.get(notPresent));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* isEmpty is true of empty map and false for non-empty
|
||||
*/
|
||||
@Test
|
||||
@Test(timeout = 5000)
|
||||
public void testIsEmpty() throws IOException {
|
||||
ChronicleMap empty = newShmIntString();
|
||||
ChronicleMap map = map5();
|
||||
assertTrue(empty.isEmpty());
|
||||
assertFalse(map.isEmpty());
|
||||
try (ChronicleMap empty = newShmIntString(8078)) {
|
||||
try (ChronicleMap map = map5()) {
|
||||
|
||||
if (!empty.isEmpty()) {
|
||||
System.out.print("not empty " + empty);
|
||||
}
|
||||
assertTrue(empty.isEmpty());
|
||||
assertFalse(map.isEmpty());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* keySet returns a Set containing all the keys
|
||||
*/
|
||||
@Test
|
||||
@Test(timeout = 5000)
|
||||
public void testKeySet() throws IOException {
|
||||
ChronicleMap map = map5();
|
||||
Set s = map.keySet();
|
||||
assertEquals(5, s.size());
|
||||
assertTrue(s.contains(one));
|
||||
assertTrue(s.contains(two));
|
||||
assertTrue(s.contains(three));
|
||||
assertTrue(s.contains(four));
|
||||
assertTrue(s.contains(five));
|
||||
try (ChronicleMap map = map5()) {
|
||||
Set s = map.keySet();
|
||||
assertEquals(5, s.size());
|
||||
assertTrue(s.contains(one));
|
||||
assertTrue(s.contains(two));
|
||||
assertTrue(s.contains(three));
|
||||
assertTrue(s.contains(four));
|
||||
assertTrue(s.contains(five));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* keySet.toArray returns contains all keys
|
||||
*/
|
||||
@Test
|
||||
@Test(timeout = 5000)
|
||||
public void testKeySetToArray() throws IOException {
|
||||
ChronicleMap map = map5();
|
||||
Set s = map.keySet();
|
||||
Object[] ar = s.toArray();
|
||||
assertTrue(s.containsAll(Arrays.asList(ar)));
|
||||
assertEquals(5, ar.length);
|
||||
ar[0] = m10;
|
||||
assertFalse(s.containsAll(Arrays.asList(ar)));
|
||||
try (ChronicleMap map = map5()) {
|
||||
Set s = map.keySet();
|
||||
Object[] ar = s.toArray();
|
||||
assertTrue(s.containsAll(Arrays.asList(ar)));
|
||||
assertEquals(5, ar.length);
|
||||
ar[0] = m10;
|
||||
assertFalse(s.containsAll(Arrays.asList(ar)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Values.toArray contains all values
|
||||
*/
|
||||
@Test
|
||||
@Test(timeout = 5000)
|
||||
public void testValuesToArray() throws IOException {
|
||||
ChronicleMap map = map5();
|
||||
Collection v = map.values();
|
||||
Object[] ar = v.toArray();
|
||||
ArrayList s = new ArrayList(Arrays.asList(ar));
|
||||
assertEquals(5, ar.length);
|
||||
assertTrue(s.contains("A"));
|
||||
assertTrue(s.contains("B"));
|
||||
assertTrue(s.contains("C"));
|
||||
assertTrue(s.contains("D"));
|
||||
assertTrue(s.contains("E"));
|
||||
}
|
||||
try (ChronicleMap map = map5()) {
|
||||
Collection v = map.values();
|
||||
Object[] ar = v.toArray();
|
||||
ArrayList s = new ArrayList(Arrays.asList(ar));
|
||||
assertEquals(5, ar.length);
|
||||
assertTrue(s.contains("A"));
|
||||
assertTrue(s.contains("B"));
|
||||
assertTrue(s.contains("C"));
|
||||
assertTrue(s.contains("D"));
|
||||
assertTrue(s.contains("E"));
|
||||
|
||||
/**
|
||||
* TODO : enumeration returns an enumeration containing the correct
|
||||
* elements
|
||||
*/
|
||||
/* @Test public void testEnumeration() throws IOException {
|
||||
ChronicleMap map = map5();
|
||||
Enumeration e = map.elements();
|
||||
int count = 0;
|
||||
while (e.hasMoreElements()) {
|
||||
count++;
|
||||
e.nextElement();
|
||||
}
|
||||
assertEquals(5, count);
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
* entrySet.toArray contains all entries
|
||||
*/
|
||||
@Test
|
||||
@Test(timeout = 5000)
|
||||
public void testEntrySetToArray() throws IOException {
|
||||
ChronicleMap map = map5();
|
||||
Set s = map.entrySet();
|
||||
Object[] ar = s.toArray();
|
||||
assertEquals(5, ar.length);
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
assertTrue(map.containsKey(((Map.Entry) (ar[i])).getKey()));
|
||||
assertTrue(map.containsValue(((Map.Entry) (ar[i])).getValue()));
|
||||
try (ChronicleMap map = map5()) {
|
||||
Set s = map.entrySet();
|
||||
Object[] ar = s.toArray();
|
||||
assertEquals(5, ar.length);
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
assertTrue(map.containsKey(((java.util.Map.Entry) (ar[i])).getKey()));
|
||||
assertTrue(map.containsValue(((java.util.Map.Entry) (ar[i])).getValue()));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* values collection contains all values
|
||||
*/
|
||||
@Test
|
||||
@Test(timeout = 5000)
|
||||
public void testValues() throws IOException {
|
||||
ChronicleMap map = map5();
|
||||
Collection s = map.values();
|
||||
assertEquals(5, s.size());
|
||||
assertTrue(s.contains("A"));
|
||||
assertTrue(s.contains("B"));
|
||||
assertTrue(s.contains("C"));
|
||||
assertTrue(s.contains("D"));
|
||||
assertTrue(s.contains("E"));
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO : keys returns an enumeration containing all the keys from the map
|
||||
*/
|
||||
/* @Test public void testKeys() throws IOException {
|
||||
ChronicleMap map = map5();
|
||||
Enumeration e = map.keys();
|
||||
int count = 0;
|
||||
while (e.hasMoreElements()) {
|
||||
count++;
|
||||
e.nextElement();
|
||||
try (ChronicleMap map = map5()) {
|
||||
Collection s = map.values();
|
||||
assertEquals(5, s.size());
|
||||
assertTrue(s.contains("A"));
|
||||
assertTrue(s.contains("B"));
|
||||
assertTrue(s.contains("C"));
|
||||
assertTrue(s.contains("D"));
|
||||
assertTrue(s.contains("E"));
|
||||
}
|
||||
assertEquals(5, count);
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
* entrySet contains all pairs
|
||||
*/
|
||||
@Test
|
||||
@Test(timeout = 5000)
|
||||
public void testEntrySet() throws IOException {
|
||||
ChronicleMap map = map5();
|
||||
Set s = map.entrySet();
|
||||
assertEquals(5, s.size());
|
||||
Iterator it = s.iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry e = (Map.Entry) it.next();
|
||||
assertTrue(
|
||||
(e.getKey().equals(one) && e.getValue().equals("A")) ||
|
||||
(e.getKey().equals(two) && e.getValue().equals("B")) ||
|
||||
(e.getKey().equals(three) && e.getValue().equals("C")) ||
|
||||
(e.getKey().equals(four) && e.getValue().equals("D")) ||
|
||||
(e.getKey().equals(five) && e.getValue().equals("E"))
|
||||
);
|
||||
try (ChronicleMap map = map5()) {
|
||||
Set s = map.entrySet();
|
||||
assertEquals(5, s.size());
|
||||
Iterator it = s.iterator();
|
||||
while (it.hasNext()) {
|
||||
java.util.Map.Entry e = (java.util.Map.Entry) it.next();
|
||||
assertTrue(
|
||||
(e.getKey().equals(one) && e.getValue().equals("A")) ||
|
||||
(e.getKey().equals(two) && e.getValue().equals("B")) ||
|
||||
(e.getKey().equals(three) && e.getValue().equals("C")) ||
|
||||
(e.getKey().equals(four) && e.getValue().equals("D")) ||
|
||||
(e.getKey().equals(five) && e.getValue().equals("E"))
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* putAll adds all key-value pairs from the given map
|
||||
*/
|
||||
@Test
|
||||
@Test(timeout = 5000)
|
||||
public void testPutAll() throws IOException {
|
||||
ChronicleMap empty = newShmIntString();
|
||||
ChronicleMap map = map5();
|
||||
empty.putAll(map);
|
||||
assertEquals(5, empty.size());
|
||||
assertTrue(empty.containsKey(one));
|
||||
assertTrue(empty.containsKey(two));
|
||||
assertTrue(empty.containsKey(three));
|
||||
assertTrue(empty.containsKey(four));
|
||||
assertTrue(empty.containsKey(five));
|
||||
|
||||
try (ChronicleMap empty = newShmIntString(8076)) {
|
||||
try (ChronicleMap map = map5()) {
|
||||
empty.putAll(map);
|
||||
assertEquals(5, empty.size());
|
||||
assertTrue(empty.containsKey(one));
|
||||
assertTrue(empty.containsKey(two));
|
||||
assertTrue(empty.containsKey(three));
|
||||
assertTrue(empty.containsKey(four));
|
||||
assertTrue(empty.containsKey(five));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* putIfAbsent works when the given key is not present
|
||||
*/
|
||||
@Test
|
||||
@Test(timeout = 5000)
|
||||
public void testPutIfAbsent() throws IOException {
|
||||
ChronicleMap map = map5();
|
||||
map.putIfAbsent(six, "Z");
|
||||
assertTrue(map.containsKey(six));
|
||||
try (ChronicleMap map = map5()) {
|
||||
map.putIfAbsent(six, "Z");
|
||||
assertTrue(map.containsKey(six));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* putIfAbsent does not add the pair if the key is already present
|
||||
*/
|
||||
@Test
|
||||
@Test(timeout = 5000)
|
||||
public void testPutIfAbsent2() throws IOException {
|
||||
ChronicleMap map = map5();
|
||||
assertEquals("A", map.putIfAbsent(one, "Z"));
|
||||
try (ChronicleMap map = map5()) {
|
||||
assertEquals("A", map.putIfAbsent(one, "Z"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* replace fails when the given key is not present
|
||||
*/
|
||||
@Test
|
||||
@Test(timeout = 5000)
|
||||
public void testReplace() throws IOException {
|
||||
ChronicleMap map = map5();
|
||||
assertNull(map.replace(six, "Z"));
|
||||
assertFalse(map.containsKey(six));
|
||||
try (ChronicleMap map = map5()) {
|
||||
assertNull(map.replace(six, "Z"));
|
||||
assertFalse(map.containsKey(six));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* replace succeeds if the key is already present
|
||||
*/
|
||||
@Test
|
||||
public void testReplace2() throws IOException {
|
||||
ChronicleMap map = map5();
|
||||
assertNotNull(map.replace(one, "Z"));
|
||||
assertEquals("Z", map.get(one));
|
||||
@Test(timeout = 5000)
|
||||
public void testReplace2() throws
|
||||
IOException {
|
||||
try (ChronicleMap map = map5()) {
|
||||
assertNotNull(map.replace(one, "Z"));
|
||||
assertEquals("Z", map.get(one));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* replace value fails when the given key not mapped to expected value
|
||||
*/
|
||||
@Test
|
||||
public void testReplaceValue() throws IOException {
|
||||
ChronicleMap map = map5();
|
||||
assertEquals("A", map.get(one));
|
||||
assertFalse(map.replace(one, "Z", "Z"));
|
||||
assertEquals("A", map.get(one));
|
||||
@Test(timeout = 5000)
|
||||
public void testReplaceValue() throws
|
||||
IOException {
|
||||
try (ChronicleMap map = map5()) {
|
||||
assertEquals("A", map.get(one));
|
||||
assertFalse(map.replace(one, "Z", "Z"));
|
||||
assertEquals("A", map.get(one));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* replace value succeeds when the given key mapped to expected value
|
||||
*/
|
||||
@Test
|
||||
public void testReplaceValue2() throws IOException {
|
||||
ChronicleMap map = map5();
|
||||
assertEquals("A", map.get(one));
|
||||
assertTrue(map.replace(one, "A", "Z"));
|
||||
assertEquals("Z", map.get(one));
|
||||
@Test(timeout = 5000)
|
||||
public void testReplaceValue2
|
||||
() throws IOException {
|
||||
try (ChronicleMap map = map5()) {
|
||||
assertEquals("A", map.get(one));
|
||||
assertTrue(map.replace(one, "A", "Z"));
|
||||
assertEquals("Z", map.get(one));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* remove removes the correct key-value pair from the map
|
||||
*/
|
||||
@Test
|
||||
public void testRemove() throws IOException {
|
||||
ChronicleMap map = map5();
|
||||
map.remove(five);
|
||||
assertEquals(4, map.size());
|
||||
assertFalse(map.containsKey(five));
|
||||
@Test(timeout = 5000)
|
||||
public void testRemove() throws
|
||||
IOException {
|
||||
try (ChronicleMap map = map5()) {
|
||||
map.remove(five);
|
||||
assertEquals(4, map.size());
|
||||
assertFalse(map.containsKey(five));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* remove(key,value) removes only if pair present
|
||||
*/
|
||||
@Test
|
||||
public void testRemove2() throws IOException {
|
||||
ChronicleMap map = map5();
|
||||
@Test(timeout = 5000)
|
||||
public void testRemove2
|
||||
() throws IOException {
|
||||
/* try( ChronicleMap map = map5(8076)) {
|
||||
map.remove(five, "E");
|
||||
assertEquals(4, map.size());
|
||||
assertEquals(4, map.size());
|
||||
assertFalse(map.containsKey(five));
|
||||
map.remove(four, "A");
|
||||
assertEquals(4, map.size());
|
||||
assertTrue(map.containsKey(four));
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* size returns the correct values
|
||||
*/
|
||||
@Test
|
||||
@Test(timeout = 5000)
|
||||
public void testSize() throws IOException {
|
||||
ChronicleMap map = map5();
|
||||
ChronicleMap empty = newShmIntString();
|
||||
assertEquals(0, empty.size());
|
||||
assertEquals(5, map.size());
|
||||
try (ChronicleMap map = map5()) {
|
||||
|
||||
try (ChronicleMap empty = newShmIntString(8078)) {
|
||||
assertEquals(0, empty.size());
|
||||
assertEquals(5, map.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* size returns the correct values
|
||||
*/
|
||||
@Test(timeout = 10000)
|
||||
public void testSize2() throws IOException {
|
||||
try (ChronicleMap map = map5()) {
|
||||
|
||||
try (ChronicleMap empty = newShmIntString(8078)) {
|
||||
assertEquals(0, empty.size());
|
||||
assertEquals(5, map.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* size returns the correct values
|
||||
*/
|
||||
@Test(timeout = 5000)
|
||||
public void testSize3() throws IOException {
|
||||
try (ChronicleMap map = map5()) {
|
||||
|
||||
try (ChronicleMap empty = newShmIntString(8078)) {
|
||||
assertEquals(0, empty.size());
|
||||
assertEquals(5, map.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* toString contains toString of elements
|
||||
*/
|
||||
@Test
|
||||
@Test(timeout = 5000)
|
||||
public void testToString() throws IOException {
|
||||
ChronicleMap map = map5();
|
||||
String s = map.toString();
|
||||
for (int i = 1; i <= 5; ++i) {
|
||||
assertTrue(s.contains(String.valueOf(i)));
|
||||
try (ChronicleMap map = map5()) {
|
||||
String s = map.toString();
|
||||
for (int i = 1; i <= 5; ++i) {
|
||||
assertTrue(s.contains(String.valueOf(i)));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get(null) throws NPE
|
||||
*/
|
||||
@Test
|
||||
@Test(timeout = 5000)
|
||||
public void testGet_NullPointerException() throws IOException {
|
||||
try {
|
||||
ChronicleMap c = newShmIntString(5);
|
||||
|
||||
try (ChronicleMap c = newShmIntString(8076)) {
|
||||
c.get(null);
|
||||
shouldThrow();
|
||||
} catch (NullPointerException success) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* containsKey(null) throws NPE
|
||||
*/
|
||||
@Test
|
||||
@Test(timeout = 5000)
|
||||
public void testContainsKey_NullPointerException() throws IOException {
|
||||
try {
|
||||
ChronicleMap c = newShmIntString(5);
|
||||
try (ChronicleMap c = newShmIntString(8076)) {
|
||||
c.containsKey(null);
|
||||
shouldThrow();
|
||||
} catch (NullPointerException success) {
|
||||
@@ -512,10 +494,9 @@ public class ChronicleMapTest extends JSR166TestCase {
|
||||
/**
|
||||
* put(null,x) throws NPE
|
||||
*/
|
||||
@Test
|
||||
@Test(timeout = 5000)
|
||||
public void testPut1_NullPointerException() throws IOException {
|
||||
try {
|
||||
ChronicleMap c = newShmIntString(5);
|
||||
try (ChronicleMap c = newShmIntString(8076)) {
|
||||
c.put(null, "whatever");
|
||||
shouldThrow();
|
||||
} catch (NullPointerException success) {
|
||||
@@ -525,10 +506,10 @@ public class ChronicleMapTest extends JSR166TestCase {
|
||||
/**
|
||||
* put(x, null) throws NPE
|
||||
*/
|
||||
@Test
|
||||
public void testPut2_NullPointerException() throws IOException {
|
||||
try {
|
||||
ChronicleMap c = newShmIntString(5);
|
||||
@Test(timeout = 5000)
|
||||
public void testPut2_NullPointerException
|
||||
() throws IOException {
|
||||
try (ChronicleMap c = newShmIntString(8076)) {
|
||||
c.put(notPresent, null);
|
||||
shouldThrow();
|
||||
} catch (NullPointerException success) {
|
||||
@@ -538,58 +519,24 @@ public class ChronicleMapTest extends JSR166TestCase {
|
||||
/**
|
||||
* putIfAbsent(null, x) throws NPE
|
||||
*/
|
||||
@Test
|
||||
public void testPutIfAbsent1_NullPointerException() throws IOException {
|
||||
try {
|
||||
ChronicleMap c = newShmIntString(5);
|
||||
@Test(timeout = 5000)
|
||||
public void testPutIfAbsent1_NullPointerException
|
||||
() throws IOException {
|
||||
try (ChronicleMap c = newShmIntString(8076)) {
|
||||
c.putIfAbsent(null, "whatever");
|
||||
shouldThrow();
|
||||
} catch (NullPointerException success) {
|
||||
}
|
||||
}
|
||||
|
||||
// Exception tests
|
||||
|
||||
/**
|
||||
* TODO : Cannot create with negative capacity
|
||||
*/
|
||||
/* @Test public void testConstructor1() {
|
||||
try {
|
||||
newShmIntString(-1, 0, 1);
|
||||
shouldThrow();
|
||||
} catch (IllegalArgumentException success) {
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* TODO : Cannot create with negative concurrency level
|
||||
*/
|
||||
/*@Test public void testConstructor2() {
|
||||
try {
|
||||
newShmIntString(1, 0, -1);
|
||||
shouldThrow();
|
||||
} catch (IllegalArgumentException success) {
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* TODO :Cannot create with only negative capacity
|
||||
*/
|
||||
/* @Test public void testConstructor3() {
|
||||
try {
|
||||
newShmIntString(-1);
|
||||
shouldThrow();
|
||||
} catch (IllegalArgumentException success) {
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* replace(null, x) throws NPE
|
||||
*/
|
||||
@Test
|
||||
public void testReplace_NullPointerException() throws IOException {
|
||||
try {
|
||||
ChronicleMap c = newShmIntString(5);
|
||||
@Test(timeout = 5000)
|
||||
public void testReplace_NullPointerException
|
||||
() throws IOException {
|
||||
try (ChronicleMap c = newShmIntString(8076)) {
|
||||
c.replace(null, "whatever");
|
||||
shouldThrow();
|
||||
} catch (NullPointerException success) {
|
||||
@@ -599,49 +546,23 @@ public class ChronicleMapTest extends JSR166TestCase {
|
||||
/**
|
||||
* replace(null, x, y) throws NPE
|
||||
*/
|
||||
@Test
|
||||
public void testReplaceValue_NullPointerException() throws IOException {
|
||||
try {
|
||||
ChronicleMap c = newShmIntString(5);
|
||||
@Test(timeout = 5000)
|
||||
public void testReplaceValue_NullPointerException
|
||||
() throws IOException {
|
||||
try (ChronicleMap c = newShmIntString(8076)) {
|
||||
c.replace(null, "A", "whatever");
|
||||
shouldThrow();
|
||||
} catch (NullPointerException success) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* containsValue(null) throws NPE
|
||||
*/
|
||||
/* @Test public void testContainsValue_NullPointerException() throws IOException {
|
||||
try {
|
||||
ChronicleMap c = newShmIntString(5);
|
||||
c.containsValue(null);
|
||||
shouldThrow();
|
||||
} catch (NullPointerException success) {
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* todo : contains(null) throws NPE
|
||||
*/
|
||||
/*
|
||||
@Test public void testContains_NullPointerException() throws IOException {
|
||||
try {
|
||||
ChronicleMap c = newShmIntString(5);
|
||||
c.contains(null);
|
||||
shouldThrow();
|
||||
} catch (NullPointerException success) {
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* putIfAbsent(x, null) throws NPE
|
||||
*/
|
||||
@Test
|
||||
@Test(timeout = 5000)
|
||||
public void testPutIfAbsent2_NullPointerException() throws IOException {
|
||||
try {
|
||||
ChronicleMap c = newShmIntString(5);
|
||||
try (ChronicleMap c = newShmIntString(8076)) {
|
||||
c.putIfAbsent(notPresent, null);
|
||||
shouldThrow();
|
||||
} catch (NullPointerException success) {
|
||||
@@ -651,10 +572,9 @@ public class ChronicleMapTest extends JSR166TestCase {
|
||||
/**
|
||||
* replace(x, null) throws NPE
|
||||
*/
|
||||
@Test
|
||||
@Test(timeout = 5000)
|
||||
public void testReplace2_NullPointerException() throws IOException {
|
||||
try {
|
||||
ChronicleMap c = newShmIntString(5);
|
||||
try (ChronicleMap c = newShmIntString(8076)) {
|
||||
c.replace(notPresent, null);
|
||||
shouldThrow();
|
||||
} catch (NullPointerException success) {
|
||||
@@ -664,10 +584,10 @@ public class ChronicleMapTest extends JSR166TestCase {
|
||||
/**
|
||||
* replace(x, null, y) throws NPE
|
||||
*/
|
||||
@Test
|
||||
public void testReplaceValue2_NullPointerException() throws IOException {
|
||||
try {
|
||||
ChronicleMap c = newShmIntString(5);
|
||||
@Test(timeout = 5000)
|
||||
public void testReplaceValue2_NullPointerException
|
||||
() throws IOException {
|
||||
try (ChronicleMap c = newShmIntString(8076)) {
|
||||
c.replace(notPresent, null, "A");
|
||||
shouldThrow();
|
||||
} catch (NullPointerException success) {
|
||||
@@ -677,10 +597,9 @@ public class ChronicleMapTest extends JSR166TestCase {
|
||||
/**
|
||||
* replace(x, y, null) throws NPE
|
||||
*/
|
||||
@Test
|
||||
@Test(timeout = 5000)
|
||||
public void testReplaceValue3_NullPointerException() throws IOException {
|
||||
try {
|
||||
ChronicleMap c = newShmIntString(5);
|
||||
try (ChronicleMap c = newShmIntString(8076)) {
|
||||
c.replace(notPresent, "A", null);
|
||||
shouldThrow();
|
||||
} catch (NullPointerException success) {
|
||||
@@ -690,10 +609,9 @@ public class ChronicleMapTest extends JSR166TestCase {
|
||||
/**
|
||||
* remove(null) throws NPE
|
||||
*/
|
||||
@Test
|
||||
@Test(timeout = 5000)
|
||||
public void testRemove1_NullPointerException() throws IOException {
|
||||
try {
|
||||
ChronicleMap c = newShmStringString(5);
|
||||
try (ChronicleMap c = newStrStrMap(8076)) {
|
||||
c.put("sadsdf", "asdads");
|
||||
c.remove(null);
|
||||
shouldThrow();
|
||||
@@ -704,10 +622,10 @@ public class ChronicleMapTest extends JSR166TestCase {
|
||||
/**
|
||||
* remove(null, x) throws NPE
|
||||
*/
|
||||
@Test
|
||||
public void testRemove2_NullPointerException() throws IOException {
|
||||
try {
|
||||
ChronicleMap c = newShmStringString(5);
|
||||
@Test(timeout = 5000)
|
||||
public void testRemove2_NullPointerException
|
||||
() throws IOException {
|
||||
try (ChronicleMap c = newStrStrMap(8086)) {
|
||||
c.put("sadsdf", "asdads");
|
||||
c.remove(null, "whatever");
|
||||
shouldThrow();
|
||||
@@ -718,13 +636,19 @@ public class ChronicleMapTest extends JSR166TestCase {
|
||||
/**
|
||||
* remove(x, null) returns false
|
||||
*/
|
||||
@Test
|
||||
@Test(timeout = 5000)
|
||||
public void testRemove3() throws IOException {
|
||||
ChronicleMap c = newShmStringString(5);
|
||||
c.put("sadsdf", "asdads");
|
||||
assertFalse(c.remove("sadsdf", null));
|
||||
|
||||
try (ChronicleMap c = newStrStrMap(8076)) {
|
||||
c.put("sadsdf", "asdads");
|
||||
assertFalse(c.remove("sadsdf", null));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// classes for testing Comparable fallbacks
|
||||
static class BI implements Comparable<BI> {
|
||||
private final int value;
|
||||
|
||||
@@ -21,22 +21,20 @@ package net.openhft.chronicle.set;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class ChronicleSetBuilderTest {
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
|
||||
Set<Integer> integers = ChronicleSetBuilder.of(Integer.class).create();
|
||||
try (ChronicleSet<Integer> integers = ChronicleSetBuilder.of(Integer.class).create()) {
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
integers.add(i);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
integers.add(i);
|
||||
}
|
||||
|
||||
Assert.assertTrue(integers.contains(5));
|
||||
Assert.assertEquals(10, integers.size());
|
||||
}
|
||||
|
||||
Assert.assertTrue(integers.contains(5));
|
||||
Assert.assertEquals(10, integers.size());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+9
-11
@@ -16,31 +16,29 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map;
|
||||
package net.openhft.chronicle.set;
|
||||
|
||||
import net.openhft.chronicle.set.ChronicleSet;
|
||||
import net.openhft.chronicle.set.ChronicleSetBuilder;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class Issue3Test {
|
||||
|
||||
@Test
|
||||
public void test() throws IOException {
|
||||
Set<Long> set = ChronicleSetBuilder.of(Long.class)
|
||||
try (ChronicleSet<Long> set = ChronicleSetBuilder.of(Long.class)
|
||||
.actualSegments(1)
|
||||
.actualEntriesPerSegment(1000)
|
||||
.create();
|
||||
.create()) {
|
||||
|
||||
Random r = new Random();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
for (int j = 0; j < 300; j++) {
|
||||
set.add(r.nextLong());
|
||||
Random r = new Random();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
for (int j = 0; j < 300; j++) {
|
||||
set.add(r.nextLong());
|
||||
}
|
||||
set.clear();
|
||||
}
|
||||
set.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,6 +77,7 @@ public class SetForTCPSocketReplication3wayTest {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.gc();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user