diff --git a/src/test/java/net/openhft/chronicle/map/StatelessClientDuplicateKeyTest.java b/src/test/java/net/openhft/chronicle/map/StatelessClientDuplicateKeyTest.java new file mode 100644 index 000000000..20d74e0f3 --- /dev/null +++ b/src/test/java/net/openhft/chronicle/map/StatelessClientDuplicateKeyTest.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2015 higherfrequencytrading.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package net.openhft.chronicle.map; + +import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig; +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.concurrent.*; + +import static net.openhft.chronicle.map.ChronicleMapStatelessClientBuilder.*; + +public class StatelessClientDuplicateKeyTest { + + @Test + public void statelessClientDuplicateKeyTest() throws IOException, InterruptedException, ExecutionException { + ChronicleMap map = + ChronicleMapBuilder.of(Integer.class, Integer.class) + .replication((byte) 1, TcpTransportAndNetworkConfig.of(8080)) + .create(); + + map.put(42, 1); + + final ChronicleMap client = + createClientOf(new InetSocketAddress("localhost", 8080)); + + ExecutorService runner = new ThreadPoolExecutor(16, 256, 300L, TimeUnit.SECONDS, + new LinkedBlockingDeque()); + + class Run implements Callable { + + @Override + public Integer call() { + return client.get(42); + } + } + Collection items = new ArrayList<>(1000); + for (int i = 0; i < 1000; i++) { + items.add(new Run()); + } + List> futures = runner.invokeAll(items); + for (Future future : futures) { + Assert.assertEquals((Integer) 1, future.get()); + } + } +}