mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
added in a fix for net.openhft.chronicle.map.ReplicateProxyMapUpdatedViaSharedMemoryTest.testReplicateProxyMapUpdatedViaSharedMemory
This commit is contained in:
@@ -67,50 +67,6 @@ public class TestReplication {
|
||||
|
||||
private ReplicationHub hubOnServer1;
|
||||
|
||||
@Test
|
||||
public void testAllDataGetsReplicated2() throws InterruptedException, IOException, ExecutionException {
|
||||
|
||||
try
|
||||
// server 1 with identifier = 1
|
||||
{
|
||||
ChronicleMapBuilder<Short, Short> builder =
|
||||
ChronicleMapBuilder.of(Short.class, Short.class)
|
||||
.entries(1000);
|
||||
|
||||
byte identifier = (byte) 1;
|
||||
|
||||
TcpTransportAndNetworkConfig tcpConfig = TcpTransportAndNetworkConfig
|
||||
.of(8086);
|
||||
|
||||
hubOnServer1 = ReplicationHub.builder()
|
||||
.tcpTransportAndNetwork(tcpConfig)
|
||||
.maxNumberOfChannels(SIZE)
|
||||
.createWithId(identifier);
|
||||
|
||||
for (short channel1 = 3; channel1 < SIZE; channel1++) {
|
||||
ChronicleMap<Short, Short> map = builder.instance()
|
||||
.replicatedViaChannel(hubOnServer1.createChannel(channel1)).create();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
map.put((short) i, (short) i);
|
||||
}
|
||||
|
||||
maps.put(channel1, map);
|
||||
|
||||
System.out.println("" + channel1);
|
||||
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
for (; ; ) {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import org.junit.Assert;
|
||||
import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
/**
|
||||
* Created by khoxsey on 5/22/15.
|
||||
*/
|
||||
public class ReplicateProxyMapUpdatedViaSharedMemoryTest {
|
||||
|
||||
/**
|
||||
* test 2 maps on one server ( one that replicates vai TCP/IP and one that just shares memory )
|
||||
* can connect to a remote map
|
||||
* connect to a remote map
|
||||
* @throws IOException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
@Test
|
||||
public void testReplicateProxyMapUpdatedViaSharedMemory() throws IOException, InterruptedException {
|
||||
|
||||
ChronicleMap<String, String> server1 = null;
|
||||
ChronicleMap<String, String> server2 = null;
|
||||
ChronicleMap<String, String> replicationMap = null;
|
||||
|
||||
{
|
||||
final File tempFile = File.createTempFile("temp", "chron");
|
||||
|
||||
server1 = ChronicleMapBuilder.of(String.class, String.class)
|
||||
.replication((byte) 1).createPersistedTo(tempFile);
|
||||
|
||||
TcpTransportAndNetworkConfig serverConfig = TcpTransportAndNetworkConfig.of(7077);
|
||||
replicationMap = ChronicleMapBuilder.of(String.class, String.class)
|
||||
.replication((byte) 1, serverConfig).createPersistedTo(tempFile);
|
||||
}
|
||||
|
||||
{
|
||||
TcpTransportAndNetworkConfig server2Config =
|
||||
TcpTransportAndNetworkConfig.of(6161, new InetSocketAddress("localhost", 7077));
|
||||
|
||||
server2 = ChronicleMapBuilder.of(String.class, String.class)
|
||||
.replication((byte) 2, server2Config).create();
|
||||
}
|
||||
|
||||
final String expected = "value";
|
||||
Thread.sleep(1000);
|
||||
server1.put("key", expected);
|
||||
|
||||
String actual;
|
||||
do {
|
||||
actual = server2.get("key");
|
||||
} while (actual == null);
|
||||
|
||||
Assert.assertEquals(expected, actual);
|
||||
|
||||
server1.close();
|
||||
server2.close();
|
||||
replicationMap.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user