mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
HCOLL-219 support the importing and exporting of entries to a human readable file format like JSON
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Rob Austin.
|
||||
*/
|
||||
public class ChronicleMapImportExportTest {
|
||||
|
||||
|
||||
public static final String TMP = System.getProperty("java.io.tmpdir");
|
||||
|
||||
@Test
|
||||
public void test() throws IOException, InterruptedException {
|
||||
|
||||
File file = new File(TMP + "/chronicle-map-" + System.nanoTime() + ".json");
|
||||
file.deleteOnExit();
|
||||
|
||||
try (ChronicleMap<String, String> expected = ChronicleMapBuilder.of(String.class, String
|
||||
.class)
|
||||
.create()) {
|
||||
|
||||
expected.put("hello", "world");
|
||||
expected.put("aKey", "aValue");
|
||||
|
||||
System.out.println(expected);
|
||||
expected.getAll(file);
|
||||
|
||||
try (ChronicleMap<String, String> actual = ChronicleMapBuilder.of(String.class, String
|
||||
.class)
|
||||
.create()) {
|
||||
|
||||
actual.putAll(file);
|
||||
|
||||
Assert.assertEquals(expected, actual);
|
||||
}
|
||||
} finally {
|
||||
file.delete();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -270,6 +270,16 @@ public class ReplicationCheckingMap<K, V> implements ChronicleMap<K, V> {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getAll(File toFile) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putAll(File fromFile) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public V acquireUsing(@NotNull K key, V usingValue) {
|
||||
return map1.acquireUsing(key, usingValue);
|
||||
|
||||
@@ -192,6 +192,16 @@ public class StatelessChronicleMapTest extends JSR166TestCase {
|
||||
return d.removeLater(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getAll(File toFile) throws IOException {
|
||||
d.getAll(toFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putAll(File fromFile) throws IOException {
|
||||
d.putAll(fromFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public V putIfAbsent(K key, V value) {
|
||||
return d.putIfAbsent(key, value);
|
||||
|
||||
Reference in New Issue
Block a user