HCOLL-167 now using the builder to create the Stateless client

This commit is contained in:
Rob Austin
2014-10-20 16:30:08 +01:00
parent c047e59d56
commit 1b40eb8147
12 changed files with 634 additions and 696 deletions
@@ -1,6 +1,5 @@
package net.openhft.chronicle.map;
import org.junit.Ignore;
import org.junit.Test;
import org.testng.Assert;
@@ -8,6 +7,7 @@ import java.io.IOException;
import java.net.InetSocketAddress;
import static java.util.concurrent.TimeUnit.SECONDS;
import static net.openhft.chronicle.StatelessBuilder.remoteAddress;
import static net.openhft.chronicle.map.Builder.getPersistenceFile;
import static net.openhft.chronicle.map.TcpReplicationConfig.of;
@@ -18,26 +18,38 @@ public class StatelessClientTest {
@Test
@Ignore
public void test() throws IOException, InterruptedException {
ChronicleMapBuilder<Integer, CharSequence> builder =
ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.entries(20000L)
.replicators((byte) 2, of(8076).heartBeatInterval(1L, SECONDS));
final ChronicleMap<Integer, CharSequence> serverMap;
final ChronicleMap<Integer, CharSequence> statelessMap;
// server
{
final ChronicleMap<Integer, CharSequence> map2a =
builder.create(getPersistenceFile());
map2a.put(10, "EXAMPLE-10"); // this will be the last time that map1 go an update from map2
serverMap = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.entries(20000L)
.replicators((byte) 2, of(8076).heartBeatInterval(1L, SECONDS))
.create(getPersistenceFile());
serverMap.put(10, "EXAMPLE-10");
}
KeyValueSerializer keyValueSerializer = new KeyValueSerializer(builder.keyBuilder, builder.valueBuilder);
InetSocketAddress remote = new InetSocketAddress("localhost", 8076);
StatelessMapClient<Integer, String> map = new StatelessMapClient<Integer, String>(keyValueSerializer, remote);
// stateless client
{
statelessMap = ChronicleMapBuilder.of(Integer
.class, CharSequence.class)
.stateless(remoteAddress(new InetSocketAddress("localhost", 8076))).create();
Assert.assertEquals("EXAMPLE-10", statelessMap.get(10));
Assert.assertEquals(1, statelessMap.size());
}
serverMap.close();
statelessMap.close();
Assert.assertEquals("EXAMPLE-10", map.get(10));
Assert.assertEquals(1, map.size());
}
}