updated the wait till equal on the TcpSocketReplicationTest

This commit is contained in:
Rob Austin
2014-12-26 18:40:06 +00:00
parent 5087aebf91
commit b6ec1598e8
@@ -25,6 +25,8 @@ import org.junit.Test;
import java.io.Closeable;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.Set;
@@ -176,10 +178,27 @@ public class TCPSocketReplicationTest {
* @throws InterruptedException
*/
private void waitTillEqual(final int timeOutMs) throws InterruptedException {
int t = 0;
for (; t < timeOutMs; t++) {
if (map1.equals(map2))
break;
Map map1UnChanged = new HashMap();
Map map2UnChanged = new HashMap();
int numberOfTimesTheSame = 0;
for (int t = 0; t < timeOutMs + 100; t++) {
if (map1.equals(map2)) {
if (map1.equals(map1UnChanged) && map2.equals(map2UnChanged)) {
numberOfTimesTheSame++;
} else {
numberOfTimesTheSame = 0;
map1UnChanged = new HashMap(map1);
map2UnChanged = new HashMap(map2);
}
Thread.sleep(1);
if (numberOfTimesTheSame == 100) {
System.out.println("same");
break;
}
}
Thread.sleep(1);
}
}