diff --git a/src/main/java/net/openhft/chronicle/map/BuildVersion.java b/src/main/java/net/openhft/chronicle/map/BuildVersion.java index cf75beb8b..59ec7b9f9 100644 --- a/src/main/java/net/openhft/chronicle/map/BuildVersion.java +++ b/src/main/java/net/openhft/chronicle/map/BuildVersion.java @@ -34,14 +34,15 @@ class BuildVersion { /** * @return version of ChronicleMap being used, or NULL if its not known */ - public static String version() { + public static String readVersion() { + // the best way to get the version is to read it from the manifest final String version = getVersionFromManifest(); if (version != null) return version; - // as a fall back for development we will read the version from the pom file + // as a fall back for development, we will read the version from the pom file return getVersionFromPom(); } diff --git a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java index b64a2b89a..9600769f6 100755 --- a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java @@ -80,6 +80,7 @@ class VanillaChronicleMap, static final int MAX_ENTRY_OVERSIZE_FACTOR = 64; private static final long serialVersionUID = 2L; final Class kClass; + final String mapVersion; final SizeMarshaller keySizeMarshaller; final BytesReader originalKeyReader; final KI originalKeyInterop; @@ -128,6 +129,7 @@ class VanillaChronicleMap, kClass = keyBuilder.eClass; keySizeMarshaller = keyBuilder.sizeMarshaller(); originalKeyReader = keyBuilder.reader(); + mapVersion = BuildVersion.readVersion(); originalKeyInterop = (KI) keyBuilder.interop(); @@ -181,6 +183,13 @@ class VanillaChronicleMap, initTransients(); } + /** + * @return the version of Chronicle Map this instance was built with + */ + String version() { + return mapVersion; + } + final long segmentHash(long hash) { return hashSplitting.segmentHash(hash); } @@ -3018,4 +3027,5 @@ class VanillaChronicleMap, map, null, map.valueIdentity(), segmentHash, map, true); } } + } diff --git a/src/test/java/net/openhft/chronicle/map/BuildVersionTest.java b/src/test/java/net/openhft/chronicle/map/BuildVersionTest.java index 2f6ef24c5..3c20c9f17 100644 --- a/src/test/java/net/openhft/chronicle/map/BuildVersionTest.java +++ b/src/test/java/net/openhft/chronicle/map/BuildVersionTest.java @@ -32,7 +32,28 @@ public class BuildVersionTest { @Test public void test() throws IOException, InterruptedException { // checks that we always get a version - Assert.assertNotNull(BuildVersion.version()); + Assert.assertNotNull(BuildVersion.readVersion()); + } + + + /** + * check that the map records the version + * + * @throws IOException + * @throws InterruptedException + */ + @Test + public void testVersion() throws IOException, InterruptedException { + + try (ChronicleMap expected = ChronicleMapBuilder.of(Integer.class, Double + .class) + .create()) { + expected.put(1, 1.0); + + String version = ((VanillaChronicleMap) expected).version(); + Assert.assertNotNull(BuildVersion.readVersion(), version); + + } } }