diff --git a/pom.xml b/pom.xml index e4da63f21..fd42e01ab 100755 --- a/pom.xml +++ b/pom.xml @@ -47,21 +47,13 @@ 3.4.2 import + net.openhft lang - 6.4.5-SNAPSHOT - - - net.openhft - affinity - 2.1.0 - - - net.openhft - compiler - 2.2.0 + 6.4.5 + net.openhft collections @@ -81,9 +73,10 @@ + net.openhft - collections + lang @@ -97,6 +90,11 @@ testng + + net.openhft + collections + + net.openhft collections diff --git a/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java b/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java index fb8b5b262..cbd7d1af1 100644 --- a/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java +++ b/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java @@ -21,7 +21,6 @@ package net.openhft.chronicle.map; import net.openhft.collections.*; import net.openhft.lang.io.serialization.BytesMarshallerFactory; import net.openhft.lang.io.serialization.ObjectSerializer; -import net.openhft.lang.model.constraints.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,7 +48,6 @@ public class ChronicleMapBuilder extends SharedHashMapBuilder implem @Override public ChronicleMapBuilder clone() { - return (ChronicleMapBuilder) super.clone(); } @@ -211,12 +209,6 @@ public class ChronicleMapBuilder extends SharedHashMapBuilder implem return this; } - - public ChronicleMapBuilder timeProvider(TimeProvider timeProvider) { - super.timeProvider(timeProvider); - return this; - } - public ChronicleMapBuilder identifier(byte identifier) { super.identifier(identifier); return this; @@ -245,10 +237,4 @@ public class ChronicleMapBuilder extends SharedHashMapBuilder implem return this; } - public ChronicleMapBuilder externalReplicatorBuilder(@NotNull ExternalReplicatorBuilder externalReplicatorBuilder) { - super.externalReplicatorBuilder(externalReplicatorBuilder); - return this; - } - - } diff --git a/src/test/java/net/openhft/collections/ClusterReplicationTest.java b/src/test/java/net/openhft/collections/ClusterReplicationTest.java new file mode 100644 index 000000000..516e9df09 --- /dev/null +++ b/src/test/java/net/openhft/collections/ClusterReplicationTest.java @@ -0,0 +1,163 @@ +/* + * 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.collections; + + +import org.junit.*; + +import java.io.Closeable; +import java.io.IOException; +import java.net.InetSocketAddress; + +import static java.util.concurrent.TimeUnit.SECONDS; +import static net.openhft.collections.Builder.getPersistenceFile; +import static org.junit.Assert.assertTrue; + +/** + * Test VanillaSharedReplicatedHashMap where the Replicated is over a TCP Socket, but with 4 nodes + * + * @author Rob Austin. + */ +public class ClusterReplicationTest { + + private SharedHashMap map1a; + private SharedHashMap map2a; + + private SharedHashMap map1b; + private SharedHashMap map2b; + + private ClusterReplicator clusterB; + private ClusterReplicator clusterA; + + private ClusterReplicatorBuilder clusterReplicatorBuilder; + private ClusterReplicatorBuilder clusterReplicatorBuilder1; + + + @Before + + public void setup() throws IOException { + + { + final TcpReplicatorBuilder tcpReplicatorBuilder = + new TcpReplicatorBuilder(8086, new InetSocketAddress("localhost", 8087)).heartBeatInterval(1, SECONDS); + + clusterReplicatorBuilder = new ClusterReplicatorBuilder((byte) 1, 1024); + clusterReplicatorBuilder.tcpReplicatorBuilder(tcpReplicatorBuilder); + + + // this is how you add maps after the custer is created + map1a = clusterReplicatorBuilder.create((short) 1, + SharedHashMapBuilder.of(Integer.class, CharSequence.class) + .entries(1000) + .file(getPersistenceFile())); + + clusterA = clusterReplicatorBuilder.create(); + + } + + + { + + final TcpReplicatorBuilder tcpReplicatorBuilder = + new TcpReplicatorBuilder(8087).heartBeatInterval(1, SECONDS); + + clusterReplicatorBuilder1 = new ClusterReplicatorBuilder((byte) + 2, 1024); + clusterReplicatorBuilder1.tcpReplicatorBuilder(tcpReplicatorBuilder); + + + // this is how you add maps after the custer is created + map1b = clusterReplicatorBuilder1.create((short) 1, + SharedHashMapBuilder.of(Integer.class, CharSequence.class) + .entries(1000) + .file(getPersistenceFile())); + + clusterB = clusterReplicatorBuilder1.create(); + + } + + } + + @After + public void tearDown() throws InterruptedException { + + for (final Closeable closeable : new Closeable[]{clusterA, clusterB}) { + try { + closeable.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + + @Test + @Ignore + public void test() throws IOException, InterruptedException { + + // todo remove this sleep + Thread.sleep(100); + + map2b = clusterReplicatorBuilder1.create((short) 2, + SharedHashMapBuilder.of(Integer.class, CharSequence.class) + .entries(1000) + .file(getPersistenceFile())); + + + map2a = clusterReplicatorBuilder.create((short) 2, + SharedHashMapBuilder.of(Integer.class, CharSequence.class) + .entries(1000) + .file(getPersistenceFile())); + + 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); + } + + } + +} + + +