mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
added test case testReplicationUsingAProxyMapThatsUpdatedViaSharedMemory
This commit is contained in:
@@ -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<String, String> server1 = null;
|
||||
ChronicleMap<String, String> 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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user