mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Small tests cleanup and fixed a bug in ReplicatingCluster.asReplica.lastModificationTime()
This commit is contained in:
@@ -138,8 +138,8 @@ public final class ReplicatingCluster implements Closeable {
|
||||
@Override
|
||||
public long lastModificationTime(byte remoteIdentifier) {
|
||||
long t = System.currentTimeMillis();
|
||||
for (int i = (int) chronicleChannelBitSet.nextSetBit(0); i > 0;
|
||||
i = (int) chronicleChannelBitSet.nextSetBit(i + 1)) {
|
||||
for (int i = (int) chronicleChannelBitSet.previousSetBit(chronicleChannels.length);
|
||||
i > 0; i = (int) chronicleChannelBitSet.previousSetBit(i - 1)) {
|
||||
t = min(t, chronicleChannels[i].lastModificationTime(remoteIdentifier));
|
||||
}
|
||||
return t;
|
||||
|
||||
@@ -83,8 +83,9 @@ public class PostClusterMapCreationTest {
|
||||
|
||||
|
||||
{
|
||||
final TcpReplicationConfig tcpReplicationConfig =
|
||||
TcpReplicationConfig.of(8087).heartBeatInterval(1, SECONDS);
|
||||
final TcpReplicationConfig tcpReplicationConfig = TcpReplicationConfig
|
||||
.of(8087, new InetSocketAddress("localhost", 8086))
|
||||
.heartBeatInterval(1, SECONDS);
|
||||
|
||||
clusterB = new ReplicatingClusterBuilder((byte) 2, 1024)
|
||||
.tcpReplication(tcpReplicationConfig).create();
|
||||
|
||||
@@ -1,160 +0,0 @@
|
||||
/*
|
||||
* Copyright 2014 Higher Frequency Trading http://www.higherfrequencytrading.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Test ReplicatedChronicleMap where the Replicated is over a TCP Socket, but with 4 nodes
|
||||
*
|
||||
* @author Rob Austin.
|
||||
*/
|
||||
public class PreClusterMapCreationTest {
|
||||
|
||||
private ChronicleMap<Integer, CharSequence> map1a;
|
||||
private ChronicleMap<Integer, CharSequence> map2a;
|
||||
|
||||
private ChronicleMap<Integer, CharSequence> map1b;
|
||||
private ChronicleMap<Integer, CharSequence> map2b;
|
||||
|
||||
private ReplicatingCluster clusterB;
|
||||
private ReplicatingCluster clusterA;
|
||||
|
||||
|
||||
public static File getPersistenceFile() {
|
||||
String TMP = System.getProperty("java.io.tmpdir");
|
||||
File file = new File(TMP + "/test" + System.nanoTime());
|
||||
file.deleteOnExit();
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
@Before
|
||||
|
||||
public void setup() throws IOException {
|
||||
|
||||
{
|
||||
final TcpReplicationConfig tcpReplicationConfig = TcpReplicationConfig
|
||||
.of(8086, new InetSocketAddress("localhost", 8087))
|
||||
.heartBeatInterval(1, SECONDS);
|
||||
|
||||
clusterA = new ReplicatingClusterBuilder((byte) 1, 1024)
|
||||
.tcpReplication(tcpReplicationConfig).create();
|
||||
|
||||
|
||||
// this is how you add maps after the custer is created
|
||||
map1a = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
|
||||
.entries(1000)
|
||||
.addReplicator(clusterA.channelReplicator((short) 1))
|
||||
.create(getPersistenceFile());
|
||||
|
||||
map2a = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
|
||||
.entries(1000)
|
||||
.addReplicator(clusterA.channelReplicator((short) 2))
|
||||
.create(getPersistenceFile());
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
|
||||
final TcpReplicationConfig tcpReplicationConfig =
|
||||
TcpReplicationConfig.of(8087).heartBeatInterval(1, SECONDS);
|
||||
|
||||
clusterB = new ReplicatingClusterBuilder((byte) 2, 1024)
|
||||
.tcpReplication(tcpReplicationConfig).create();
|
||||
|
||||
|
||||
// this is how you add maps after the custer is created
|
||||
map1b = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
|
||||
.entries(1000)
|
||||
.addReplicator(clusterB.channelReplicator((short) 1))
|
||||
.create(getPersistenceFile());
|
||||
|
||||
map2b = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
|
||||
.entries(1000)
|
||||
.addReplicator(clusterB.channelReplicator((short) 2))
|
||||
.create(getPersistenceFile());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws InterruptedException {
|
||||
|
||||
for (final Closeable closeable : new Closeable[]{clusterA, clusterB}) {
|
||||
try {
|
||||
closeable.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void test() throws IOException, InterruptedException {
|
||||
|
||||
|
||||
map2a.put(1, "EXAMPLE-2");
|
||||
map1a.put(1, "EXAMPLE-1");
|
||||
|
||||
// allow time for the recompilation to resolve
|
||||
waitTillEqual(2500);
|
||||
|
||||
Assert.assertEquals("map1a=map1b", map1a, map1b);
|
||||
Assert.assertEquals("map2a=map2b", map2a, map2b);
|
||||
|
||||
assertTrue("map1a.empty", !map1a.isEmpty());
|
||||
assertTrue("map2a.empty", !map2a.isEmpty());
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* waits until map1 and map2 show the same value
|
||||
*
|
||||
* @param timeOutMs timeout in milliseconds
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
|
||||
private void waitTillEqual(final int timeOutMs) throws InterruptedException {
|
||||
for (int t = 0; t < timeOutMs; t++) {
|
||||
if (map1a.equals(map1b) &&
|
||||
map2a.equals(map2b))
|
||||
break;
|
||||
Thread.sleep(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -44,9 +44,6 @@ public class SingleMapClusterTest {
|
||||
private ReplicatingCluster clusterB;
|
||||
private ReplicatingCluster clusterA;
|
||||
|
||||
private ReplicatingClusterBuilder replicatingClusterBuilder;
|
||||
private ReplicatingClusterBuilder replicatingClusterBuilder1;
|
||||
|
||||
|
||||
public static File getPersistenceFile() {
|
||||
String TMP = System.getProperty("java.io.tmpdir");
|
||||
@@ -60,9 +57,9 @@ public class SingleMapClusterTest {
|
||||
public void setup() throws IOException {
|
||||
|
||||
{
|
||||
final TcpReplicationConfig tcpReplicationConfig =
|
||||
TcpReplicationConfig.of(8086, new InetSocketAddress("localhost", 8087))
|
||||
.heartBeatInterval(1, SECONDS);
|
||||
final TcpReplicationConfig tcpReplicationConfig = TcpReplicationConfig
|
||||
.of(8086, new InetSocketAddress("localhost", 8087))
|
||||
.heartBeatInterval(1, SECONDS);
|
||||
|
||||
clusterA = new ReplicatingClusterBuilder((byte) 1, 1024)
|
||||
.tcpReplication(tcpReplicationConfig).create();
|
||||
@@ -75,12 +72,12 @@ public class SingleMapClusterTest {
|
||||
|
||||
|
||||
{
|
||||
|
||||
final TcpReplicationConfig replicationConfig =
|
||||
TcpReplicationConfig.of(8087).heartBeatInterval(1, SECONDS);
|
||||
final TcpReplicationConfig tcpReplicationConfig = TcpReplicationConfig
|
||||
.of(8087, new InetSocketAddress("localhost", 8086))
|
||||
.heartBeatInterval(1, SECONDS);
|
||||
|
||||
clusterB = new ReplicatingClusterBuilder((byte) 2, 1024)
|
||||
.tcpReplication(replicationConfig).create();
|
||||
.tcpReplication(tcpReplicationConfig).create();
|
||||
// this is how you add maps after the custer is created
|
||||
map1b = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
|
||||
.addReplicator(clusterB.channelReplicator((short) 1))
|
||||
@@ -105,9 +102,6 @@ public class SingleMapClusterTest {
|
||||
@Test
|
||||
public void test() throws IOException, InterruptedException {
|
||||
|
||||
// todo remove this sleep
|
||||
|
||||
|
||||
map1a.put(1, "EXAMPLE-1");
|
||||
|
||||
// allow time for the recompilation to resolve
|
||||
|
||||
Reference in New Issue
Block a user