mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
adding net.openhft.chronicle.map.NoTcpReplicationSoakTest
This commit is contained in:
@@ -11,9 +11,7 @@ import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Rob Austin.
|
||||
@@ -35,25 +33,26 @@ public class TcpReplicationSoakTest {
|
||||
|
||||
{
|
||||
final TcpTransportAndNetworkConfig tcpConfig1 = TcpTransportAndNetworkConfig.of(s_port,
|
||||
endpoint)
|
||||
.heartBeatInterval(1L, TimeUnit.SECONDS)
|
||||
.autoReconnectedUponDroppedConnection(true);
|
||||
endpoint).autoReconnectedUponDroppedConnection(true).name(" map1");
|
||||
|
||||
|
||||
map1 = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
|
||||
.entries(Builder.SIZE)
|
||||
.entries(Builder.SIZE + Builder.SIZE)
|
||||
.actualSegments(1)
|
||||
.name("map1")
|
||||
.replication((byte) 1, tcpConfig1)
|
||||
.create();
|
||||
}
|
||||
{
|
||||
final TcpTransportAndNetworkConfig tcpConfig2 = TcpTransportAndNetworkConfig.of(s_port + 1)
|
||||
.heartBeatInterval(1L, TimeUnit.SECONDS)
|
||||
.autoReconnectedUponDroppedConnection(true);
|
||||
final TcpTransportAndNetworkConfig tcpConfig2 = TcpTransportAndNetworkConfig.of
|
||||
(s_port + 1).autoReconnectedUponDroppedConnection(true).name("map2");
|
||||
|
||||
map2 = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
|
||||
.entries(Builder.SIZE)
|
||||
.entries(Builder.SIZE + Builder.SIZE)
|
||||
.name("map2")
|
||||
.replication((byte) 2, tcpConfig2)
|
||||
.create();
|
||||
|
||||
}
|
||||
s_port += 2;
|
||||
}
|
||||
@@ -86,8 +85,8 @@ public class TcpReplicationSoakTest {
|
||||
}
|
||||
|
||||
|
||||
// TODO test this with larger sizes.
|
||||
@Test(timeout = 20000)
|
||||
@Test
|
||||
@Ignore
|
||||
public void testSoakTestWithRandomData() throws IOException, InterruptedException {
|
||||
|
||||
System.out.print("SoakTesting ");
|
||||
@@ -99,32 +98,47 @@ public class TcpReplicationSoakTest {
|
||||
final int select = rnd.nextInt(2);
|
||||
final ChronicleMap<Integer, CharSequence> map = select > 0 ? map1 : map2;
|
||||
|
||||
if (rnd.nextBoolean()) {
|
||||
map.put(rnd.nextInt(Builder.SIZE), "test" + j);
|
||||
} else {
|
||||
map.remove(rnd.nextInt(Builder.SIZE));
|
||||
}
|
||||
if (rnd.nextBoolean()) {
|
||||
map.put(rnd.nextInt(Builder.SIZE), "test" + j);
|
||||
} else {
|
||||
map.remove(rnd.nextInt(Builder.SIZE));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Thread.sleep(1000);
|
||||
System.out.println("\nwaiting till equal");
|
||||
|
||||
waitTillEqual(10000);
|
||||
waitTillEqual(10000);
|
||||
|
||||
Assert.assertEquals(map1, map2);
|
||||
Assert.assertEquals(new TreeMap(map1), new TreeMap(map2));
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void waitTillEqual(final int timeOutMs) throws InterruptedException {
|
||||
|
||||
Map map1UnChanged = new HashMap();
|
||||
Map map2UnChanged = new HashMap();
|
||||
|
||||
int numberOfTimesTheSame = 0;
|
||||
for (int t = 0; t < timeOutMs + 100; t++) {
|
||||
if (map1.equals(map2)) {
|
||||
numberOfTimesTheSame++;
|
||||
Thread.sleep(1);
|
||||
if (numberOfTimesTheSame == 100)
|
||||
if (map1.equals(map1UnChanged) && map2.equals(map2UnChanged)) {
|
||||
numberOfTimesTheSame++;
|
||||
} else {
|
||||
numberOfTimesTheSame = 0;
|
||||
map1UnChanged = new HashMap(map1);
|
||||
map2UnChanged = new HashMap(map2);
|
||||
}
|
||||
Thread.sleep(500);
|
||||
if (numberOfTimesTheSame == 100) {
|
||||
System.out.println("same");
|
||||
break;
|
||||
} else numberOfTimesTheSame = 0;
|
||||
}
|
||||
|
||||
}
|
||||
Thread.sleep(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user