HCOLL-343 HCOLL-227 Remove old entries from ReplicatedChronicleMap

This commit is contained in:
leventov
2015-08-23 00:01:44 +03:00
parent a3a45e1681
commit 904ecca036
40 changed files with 945 additions and 90 deletions
@@ -298,6 +298,11 @@ public class ReplicationCheckingMap<K, V> implements ChronicleMap<K, V> {
throw new UnsupportedOperationException();
}
@Override
public int segments() {
throw new UnsupportedOperationException();
}
@Override
public File file() {
throw new UnsupportedOperationException();
@@ -309,6 +314,11 @@ public class ReplicationCheckingMap<K, V> implements ChronicleMap<K, V> {
map2.close();
}
@Override
public boolean isOpen() {
throw new UnsupportedOperationException();
}
@Override
public boolean equals(Object o) {
return map1.equals(o);
@@ -92,6 +92,7 @@ public class TCPSocketReplication4WayMapTest {
map1.put(1, "EXAMPLE-1");
map2.put(2, "EXAMPLE-1");
map3.put(3, "EXAMPLE-1");
map4.put(3, "EXAMPLE-1");
map4.remove(3);
// allow time for the recompilation to resolve
@@ -16,11 +16,13 @@
package net.openhft.chronicle.map;
import com.google.common.collect.Maps;
import net.openhft.chronicle.hash.replication.SingleChronicleHashReplication;
import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
import net.openhft.lang.io.ByteBufferBytes;
import net.openhft.lang.model.Byteable;
import net.openhft.lang.model.DataValueClasses;
import net.openhft.lang.threadlocal.ThreadLocalCopies;
import net.openhft.lang.values.IntValue;
import org.junit.*;
@@ -28,10 +30,8 @@ import java.io.Closeable;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
/**
@@ -60,7 +60,9 @@ public class TcpReplicationSoakTest {
map1 = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.entries(Builder.SIZE + Builder.SIZE)
.removedEntryCleanupTimeout(1, TimeUnit.MILLISECONDS)
.actualSegments(1)
.averageValue("test" + 1000)
.replication(SingleChronicleHashReplication.builder()
.tcpTransportAndNetwork(tcpConfig1)
.name("map1")
@@ -77,6 +79,8 @@ public class TcpReplicationSoakTest {
map2 = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.entries(Builder.SIZE + Builder.SIZE)
.removedEntryCleanupTimeout(1, TimeUnit.MILLISECONDS)
.averageValue("test" + 1000)
.replication(SingleChronicleHashReplication.builder()
.tcpTransportAndNetwork(tcpConfig2)
.name("map2")
@@ -149,6 +153,34 @@ public class TcpReplicationSoakTest {
}
@Test
public void testFloodReplicatedMapWithDeletedEntries() throws InterruptedException {
try {
Random r = ThreadLocalRandom.current();
NavigableSet<Integer> put = new TreeSet<>();
for (int i = 0; i < Builder.SIZE * 10; i++) {
if (r.nextBoolean() || put.isEmpty()) {
int key = r.nextInt();
map1.put(key, "test");
put.add(key);
} else {
Integer key = put.pollFirst();
map1.remove(key);
}
// Thread.sleep(0, 1000);
}
System.out.println("\nwaiting till equal");
waitTillEqual(15000);
if (!map1.equals(map2))
Assert.assertEquals(Maps.difference(map1, map2).toString(), map1, map2);
} finally {
map1.close();
map2.close();
}
}
private void waitTillEqual(final int timeOutMs) throws InterruptedException {
@@ -63,6 +63,16 @@ public class TcpTimeBasedReplicationSoakTest {
else
return t;
}
@Override
public long scale(long time, TimeUnit unit) {
return TimeUnit.MILLISECONDS.convert(time, unit);
}
@Override
public long unscale(long time, TimeUnit toUnit) {
return toUnit.convert(time, TimeUnit.MILLISECONDS);
}
};
{
@@ -82,6 +82,11 @@ public class StatelessChronicleMapTest extends JSR166TestCase {
}
}
@Override
public boolean isOpen() {
return d.isOpen();
}
@Override
public long longSize() {
return d.longSize();
@@ -130,6 +135,11 @@ public class StatelessChronicleMapTest extends JSR166TestCase {
return d.segmentContext(segmentIndex);
}
@Override
public int segments() {
return d.segments();
}
@Override
public V get(Object key) {
return d.get(key);