From 696e6e6bacad65a1e8786abae53b07d9e389e957 Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Wed, 4 Feb 2015 23:46:15 +0000 Subject: [PATCH] changed to us File.createTempFile --- src/test/java/eg/RandyTest.java | 53 +++++++++++++++++++ .../net/openhft/chronicle/map/Builder.java | 4 +- .../chronicle/map/CHMUseCasesTest.java | 21 ++++++-- .../map/PostChannelCreationTest.java | 12 +++-- .../chronicle/map/SingleMapChannelTest.java | 8 +-- 5 files changed, 81 insertions(+), 17 deletions(-) create mode 100644 src/test/java/eg/RandyTest.java diff --git a/src/test/java/eg/RandyTest.java b/src/test/java/eg/RandyTest.java new file mode 100644 index 000000000..30dd5fa2b --- /dev/null +++ b/src/test/java/eg/RandyTest.java @@ -0,0 +1,53 @@ +package eg; + +import net.openhft.chronicle.map.ChronicleMap; +import net.openhft.chronicle.map.ChronicleMapBuilder; +import net.openhft.chronicle.map.ChronicleMapStatelessClientBuilder; +import org.junit.Test; + +import java.net.InetSocketAddress; + +/** + * @author Rob Austin. + */ +public class RandyTest { + + @Test + public void testName() throws Exception { + + + ChronicleMapStatelessClientBuilder builder = + ChronicleMapBuilder.of(CharSequence.class, InstrumentVOInterface.class, new + InetSocketAddress("localhost", 8090)); + //ChronicleMapBuilder builder = ChronicleMapBuilder.of(SmallCharSequence.class, InstrumentVOInterface.class) + builder + .putReturnsNull(true) + .removeReturnsNull(true); + //TODO: not used for stateless client + //.entries(numberOfEntries) + + // + // TODO use the stateless client for now + //.replication((byte) 2, tcpTransportAndNetworkConfig) + + // + // TODO It looks like the stateLess client skips any event listener processing + //.eventListener(new MapEventListener() { + // @Override + // public void onPut(SmallCharSequence key, InstrumentVOInterface newValue, InstrumentVOInterface replacedValue) { + // // + // //TODO make this a trace operation once fully baked + // if (log.isDebugEnabled()) { + // log.debug("onPut Instrument Key: " + key); + // } + // } + //} + //); + + // + // TODO We are using the replicated client + ChronicleMap charSequenceInstrumentVOInterfaceChronicleMap = builder.create(); + + + } +} diff --git a/src/test/java/net/openhft/chronicle/map/Builder.java b/src/test/java/net/openhft/chronicle/map/Builder.java index 68ac0c64a..c078edf90 100644 --- a/src/test/java/net/openhft/chronicle/map/Builder.java +++ b/src/test/java/net/openhft/chronicle/map/Builder.java @@ -38,8 +38,8 @@ public class Builder { static String WIN_OS = "WINDOWS"; public static File getPersistenceFile() throws IOException { - String TMP = System.getProperty("java.io.tmpdir"); - File file = new File(TMP + "/chm-test" + System.nanoTime() + (count++)); + + final File file = File.createTempFile("chm-test-", "map"); //Not Guaranteed to work on Windows, since OS file-lock takes precedence if (System.getProperty("os.name").indexOf(WIN_OS) > 0) { diff --git a/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java b/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java index c6e104b6b..5a3a2afe7 100644 --- a/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java +++ b/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java @@ -36,8 +36,6 @@ import static org.junit.Assert.*; @RunWith(value = Parameterized.class) public class CHMUseCasesTest { - private static final String TMP = System.getProperty("java.io.tmpdir"); - enum TypeOfMap {STATELESS, SIMPLE, SIMPLE_PERSISTED, REPLICATED} @@ -180,8 +178,13 @@ public class CHMUseCasesTest { private void checkJsonSerilization() { + File file = null; + try { + file = File.createTempFile("chronicle-map-", ".json"); + } catch (IOException e) { + e.printStackTrace(); + } - File file = new File(TMP + "/chronicle-map-" + System.currentTimeMillis() + (i++) + System.nanoTime() + ".json"); file.deleteOnExit(); try { @@ -228,8 +231,16 @@ public class CHMUseCasesTest { return map1; case SIMPLE_PERSISTED: - final File file = new File(TMP + "/chronicle-map-" + (i++) + System.nanoTime() + System.currentTimeMillis() + ".map"); - file.deleteOnExit(); + + File file0 = null; + try { + file0 = File.createTempFile("chronicle-map-", ".map"); + } catch (IOException e) { + e.printStackTrace(); + } + + file0.deleteOnExit(); + final File file = file0; map1 = builder.createPersistedTo(file); closeables.add(map1); closeables.add(new Closeable() { diff --git a/src/test/java/net/openhft/chronicle/map/PostChannelCreationTest.java b/src/test/java/net/openhft/chronicle/map/PostChannelCreationTest.java index 5eb183e70..b44063383 100644 --- a/src/test/java/net/openhft/chronicle/map/PostChannelCreationTest.java +++ b/src/test/java/net/openhft/chronicle/map/PostChannelCreationTest.java @@ -50,8 +50,13 @@ public class PostChannelCreationTest { private ReplicationHub hubB; public static File getPersistenceFile() { - String TMP = System.getProperty("java.io.tmpdir"); - File file = new File(TMP + "/test" + System.nanoTime()); + File file = null; + try { + file = File.createTempFile("chm-test", "map"); + } catch (IOException e) { + e.printStackTrace(); + } + file.deleteOnExit(); return file; } @@ -110,7 +115,8 @@ public class PostChannelCreationTest { } /** - * sets up a 2 clusters ( notionally one for each host ), and replicates 2 Chronicle Maps between them + * sets up a 2 clusters ( notionally one for each host ), and replicates 2 Chronicle Maps + * between them * * @throws IOException * @throws InterruptedException diff --git a/src/test/java/net/openhft/chronicle/map/SingleMapChannelTest.java b/src/test/java/net/openhft/chronicle/map/SingleMapChannelTest.java index 0fac03146..34ae7b1db 100644 --- a/src/test/java/net/openhft/chronicle/map/SingleMapChannelTest.java +++ b/src/test/java/net/openhft/chronicle/map/SingleMapChannelTest.java @@ -26,7 +26,6 @@ import org.junit.Before; import org.junit.Test; import java.io.Closeable; -import java.io.File; import java.io.IOException; import java.net.InetSocketAddress; @@ -47,12 +46,7 @@ public class SingleMapChannelTest { private ReplicationHub hubA; private ReplicationHub hubB; - public static File getPersistenceFile() { - String TMP = System.getProperty("java.io.tmpdir"); - File file = new File(TMP + "/test" + System.nanoTime()); - file.deleteOnExit(); - return file; - } + @Before public void setup() throws IOException {