mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
HCOLL-213 - started to integrate MapByName and improved the stateless clients handling of large values
This commit is contained in:
@@ -17,6 +17,8 @@
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import net.openhft.chronicle.hash.replication.ReplicationHub;
|
||||
import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -32,13 +34,18 @@ public class MapByNameTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws IOException {
|
||||
findMapByName = new FindMapByName((byte) 2);
|
||||
final ReplicationHub replicationHub = ReplicationHub.builder()
|
||||
.maxEntrySize(10 * 1024)
|
||||
.tcpTransportAndNetwork(TcpTransportAndNetworkConfig.of(8243))
|
||||
.createWithId((byte)1);
|
||||
|
||||
findMapByName = new FindMapByName(replicationHub);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerializingBuilder() throws IOException, InterruptedException {
|
||||
public void testSerializingBuilder() {
|
||||
{
|
||||
ChronicleMapBuilder<CharSequence, CharSequence> builder = ChronicleMapBuilder.of(CharSequence.class, CharSequence.class)
|
||||
final ChronicleMapBuilder<CharSequence, CharSequence> builder = ChronicleMapBuilder.of(CharSequence.class, CharSequence.class)
|
||||
.minSegments(2)
|
||||
.name("map1")
|
||||
.removeReturnsNull(true);
|
||||
@@ -46,11 +53,16 @@ public class MapByNameTest {
|
||||
findMapByName.add(builder);
|
||||
}
|
||||
|
||||
ChronicleMap<CharSequence, CharSequence> map = findMapByName.get("map1").create();
|
||||
final ChronicleMap<CharSequence, CharSequence> map = findMapByName.get("map1").create();
|
||||
map.put("hello", "world");
|
||||
|
||||
Assert.assertEquals(map.get("hello"), "world");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSerializingBuilderUnknownMap() {
|
||||
findMapByName.get("hello");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -24,10 +24,7 @@ import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
@@ -235,6 +232,62 @@ public class StatelessClientTest {
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testStringKeyMap() throws IOException, InterruptedException {
|
||||
|
||||
try (ChronicleMap<String, Map> serverMap = ChronicleMapBuilder.of(String.class, Map
|
||||
.class)
|
||||
.replication((byte) 2, TcpTransportAndNetworkConfig.of(8056)).create()) {
|
||||
|
||||
try (ChronicleMap<String, Map> statelessMap = ChronicleMapBuilder.of(String.class, Map
|
||||
.class)
|
||||
.statelessClient(new InetSocketAddress("localhost", 8056)).create()) {
|
||||
|
||||
|
||||
serverMap.put("hello", Collections.singletonMap("hello", "world"));
|
||||
|
||||
Assert.assertEquals(Collections.singletonMap("hello", "world"), statelessMap.get("hello"));
|
||||
Assert.assertEquals(1, statelessMap.size());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testStringKeyMapPutIntoStatelesMap() throws IOException, InterruptedException {
|
||||
|
||||
final Map<String, String> data = new HashMap<String, String>();
|
||||
|
||||
for (int i = 0; i < 60; i++) {
|
||||
data.put("" + i, new String(new char[10]));
|
||||
}
|
||||
|
||||
try (ChronicleMap<String, Map> serverMap = ChronicleMapBuilder.of(String.class, Map
|
||||
.class)
|
||||
.entrySize(1024)
|
||||
.replication((byte) 2, TcpTransportAndNetworkConfig.of(8056)).create()) {
|
||||
|
||||
try (ChronicleMap<String, Map> statelessMap = ChronicleMapBuilder.of(String.class, Map
|
||||
.class)
|
||||
.statelessClient(new InetSocketAddress("localhost", 8056)).create()) {
|
||||
|
||||
statelessMap.put("hello", data);
|
||||
|
||||
Assert.assertEquals(data, serverMap.get("hello"));
|
||||
Assert.assertEquals(1, statelessMap.size());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBufferOverFlowPutAll() throws IOException, InterruptedException {
|
||||
try (ChronicleMap<Integer, CharSequence> serverMap = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
|
||||
|
||||
Reference in New Issue
Block a user