HCOLL-81 StatelessClient : Add a visitor pattern to Chronicle Map

This commit is contained in:
Rob Austin
2014-11-13 18:55:15 +00:00
parent 316951efba
commit bfc2dcac25
4 changed files with 210 additions and 77 deletions
@@ -23,11 +23,13 @@ import org.junit.Assert;
import org.junit.Test;
import java.io.IOException;
import java.io.Serializable;
import java.net.InetSocketAddress;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
/**
@@ -39,6 +41,37 @@ public class StatelessClientTest {
public static final int SIZE = 100000;
static class StringBuilderToStringFunction implements Function<StringBuilder, String>, Serializable {
@Override
public String apply(StringBuilder stringBuilder) {
return stringBuilder.toString();
}
}
@Test
public void testMapForKey() throws IOException, InterruptedException {
try (ChronicleMap<Integer, StringBuilder> serverMap = ChronicleMapBuilder.of(Integer.class,
StringBuilder.class)
.replication((byte) 2, TcpTransportAndNetworkConfig.of(8056)).create()) {
serverMap.put(10, new StringBuilder("Hello World"));
try (ChronicleMap<Integer, StringBuilder> statelessMap = ChronicleMapBuilder.of(Integer
.class, StringBuilder.class)
.statelessClient(new InetSocketAddress("localhost", 8056)).create()) {
String actual = (String) ((StatelessChronicleMap) statelessMap).mapForKey(10, new StringBuilderToStringFunction());
Assert.assertEquals("Hello World", actual);
}
}
}
@Test(timeout = 5000)
public void testBufferOverFlowPutAllAndEntrySet() throws IOException, InterruptedException {
@@ -167,7 +200,6 @@ public class StatelessClientTest {
.statelessClient(new InetSocketAddress("localhost", 8056)).create()) {
serverMap.put(10, "EXAMPLE-10");
Assert.assertEquals("EXAMPLE-10", statelessMap.get(10));
@@ -301,7 +333,6 @@ public class StatelessClientTest {
final ChronicleMap<Integer, CharSequence> statelessMap2;
// server
{
serverMap1 = ChronicleMapBuilder.of(Integer.class, CharSequence.class)