From 90c4aebe5d372c86a11627b51fa1cefcd7ea9ea6 Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Fri, 22 May 2015 15:23:21 +0100 Subject: [PATCH] added test case testReplicationUsingAProxyMapThatsUpdatedViaSharedMemory --- .../chronicle/map/TestReplication.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/test/java/net/openhft/chronicle/map/TestReplication.java b/src/test/java/net/openhft/chronicle/map/TestReplication.java index 1a573b3f9..1d9c835dc 100644 --- a/src/test/java/net/openhft/chronicle/map/TestReplication.java +++ b/src/test/java/net/openhft/chronicle/map/TestReplication.java @@ -7,6 +7,7 @@ import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; +import java.io.File; import java.net.InetSocketAddress; /** @@ -52,6 +53,62 @@ public class TestReplication { } + /** + * tests that replication works when the chronicle map that is getting the update is sharing + * memory with the maps that is doing the update + */ + @Test + public void testReplicationUsingAProxyMapThatsUpdatedViaSharedMemory() throws Exception { + + ChronicleMap server1 = null; + ChronicleMap server2 = null; + + // server 1 - for this test server1 and server 2 are on the same localhost but diffent + // ports, to make it easier to run in a unit test + { + final File tempFile = File.createTempFile("test", "chron"); + + + server1 = ChronicleMapBuilder.of(String.class, String.class) + .replication( + (byte) 1).createPersistedTo + (tempFile); + + TcpTransportAndNetworkConfig serverConfig = TcpTransportAndNetworkConfig.of(8088); + + // user for replication only + ChronicleMapBuilder.of(String.class, String.class) + .replication((byte) 1, serverConfig).createPersistedTo(tempFile); + + } + + // server 2- for this test server1 and server 2 are on the same localhost but diffent + // ports, to make it easier to run in a unit test + { + TcpTransportAndNetworkConfig server2Config = TcpTransportAndNetworkConfig.of(8090, new + InetSocketAddress("localhost", 8088)); + + server2 = ChronicleMapBuilder.of(String.class, String + .class).replication((byte) 2, server2Config).create(); + + } + + final String expected = "value"; + server1.put("key", expected); + + String actual; + + + // we have a while loop here as we have to wait a few seconds for the data to replicate + do { + actual = server2.get("key"); + } + while (actual == null); + + Assert.assertEquals(expected, actual); + + } +