From 5cca6cb3a4d695103fa9f53f6e4fd05e8733b539 Mon Sep 17 00:00:00 2001 From: leventov Date: Wed, 2 Dec 2015 21:37:08 +0300 Subject: [PATCH] Add a test from issue #61 --- .../map/DatasetTrackerIssue61Test.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/test/java/net/openhft/chronicle/map/DatasetTrackerIssue61Test.java diff --git a/src/test/java/net/openhft/chronicle/map/DatasetTrackerIssue61Test.java b/src/test/java/net/openhft/chronicle/map/DatasetTrackerIssue61Test.java new file mode 100644 index 000000000..ec78bdbf9 --- /dev/null +++ b/src/test/java/net/openhft/chronicle/map/DatasetTrackerIssue61Test.java @@ -0,0 +1,72 @@ +/* + * 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.set.Builder; +import org.junit.Assert; +import org.junit.Test; + +import java.io.*; + +public class DatasetTrackerIssue61Test { + + @Test + public void issue61Test() throws IOException { + + // replace Externalizable with DatasetTrackerIssue61Test to make this work + ChronicleMapBuilder builder = ChronicleMapBuilder + .of(String.class, Externalizable.class) + .averageKeySize(200) + .averageValueSize(200) + .entries(100); + + File dbFile = Builder.getPersistenceFile(); + + try (ChronicleMap datasetMap = builder.createPersistedTo(dbFile)) { + System.out.printf("%s%n", datasetMap); + + String key = "esg_dataroot/obs4MIPs/observations/atmos/husNobs/mon/grid/NASA-JPL/AIRS/v20110608/husNobs_AIRS_L3_RetStd-v5_200209-201105.nc"; + datasetMap.put(key, new Value("value")); + + Value saved = (Value) datasetMap.get(key); + Assert.assertEquals("value", saved.value); + } + } + + static class Value implements Externalizable { + + String value; + + public Value(String value) { + this.value = value; + } + + /** According to Externalizable spec, there should be a public no-arg constructor */ + public Value() { + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + out.writeUTF(value); + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + value = in.readUTF(); + } + } +}