From a7a50b05cca86898321245fff4720e15b15f5dcd Mon Sep 17 00:00:00 2001 From: leventov Date: Sun, 19 Jul 2015 18:07:02 +0300 Subject: [PATCH] Updated StatelessClientDuplicateKeyTest #33 --- .../map/StatelessClientDuplicateKeyTest.java | 51 ++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/src/test/java/net/openhft/chronicle/map/StatelessClientDuplicateKeyTest.java b/src/test/java/net/openhft/chronicle/map/StatelessClientDuplicateKeyTest.java index 20d74e0f3..cc52acff9 100644 --- a/src/test/java/net/openhft/chronicle/map/StatelessClientDuplicateKeyTest.java +++ b/src/test/java/net/openhft/chronicle/map/StatelessClientDuplicateKeyTest.java @@ -32,7 +32,8 @@ import static net.openhft.chronicle.map.ChronicleMapStatelessClientBuilder.*; public class StatelessClientDuplicateKeyTest { @Test - public void statelessClientDuplicateKeyTest() throws IOException, InterruptedException, ExecutionException { + public void statelessClientDuplicateIntegerKeyTest() + throws IOException, InterruptedException, ExecutionException { ChronicleMap map = ChronicleMapBuilder.of(Integer.class, Integer.class) .replication((byte) 1, TcpTransportAndNetworkConfig.of(8080)) @@ -62,4 +63,52 @@ public class StatelessClientDuplicateKeyTest { Assert.assertEquals((Integer) 1, future.get()); } } + + @Test + public void statelessClientDuplicateBytesKeyTest() + throws IOException, InterruptedException, ExecutionException, TimeoutException { + ChronicleMap map = + ChronicleMapBuilder.of(byte[].class, byte[].class) + .averageKeySize(10).averageValueSize(10) + .entries(100) + .actualSegments(4) + .replication((byte) 1, TcpTransportAndNetworkConfig.of(8080)) + .create(); + + byte[] _42 = {42}; + map.put(_42, new byte[] {1, 2, 3}); + map.put(new byte[]{1, 2, 3}, _42); + byte[] longKey = "fooBarFooBarFooBarFooBar".getBytes(); + map.put(longKey, "bar".getBytes()); + + final ChronicleMap client = + createClientOf(new InetSocketAddress("localhost", 8080)); + + ExecutorService runner = new ThreadPoolExecutor(16, 256, 300L, TimeUnit.SECONDS, + new LinkedBlockingDeque()); + + class Run implements Callable { + final byte[] key; + + Run(byte[] key) { + this.key = key; + } + + @Override + public byte[] call() { + return client.get(key); + } + } + + List items = new ArrayList<>(1000); + for (int i = 0; i < 1000; i++) { + byte[] bs = i % 3 == 0 ? _42 : (i % 3 == 1 ? new byte[] {(byte) i} : longKey); + items.add(new Run(bs)); + } + + List> futures = runner.invokeAll(items); + for (Future future : futures) { + future.get(1, TimeUnit.MILLISECONDS); + } + } }