mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
HCOLL-219 improved the test coverage and implementation of import and export
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import net.openhft.lang.values.LongValue;
|
||||
import net.openhft.lang.values.LongValue$$Native;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Rob Austin.
|
||||
@@ -26,8 +31,6 @@ public class ChronicleMapImportExportTest {
|
||||
|
||||
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
|
||||
@@ -46,5 +49,165 @@ public class ChronicleMapImportExportTest {
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWithMapValue() throws IOException, InterruptedException {
|
||||
|
||||
File file = new File(TMP + "/chronicle-map-" + System.nanoTime() + ".json");
|
||||
file.deleteOnExit();
|
||||
|
||||
System.out.println(file.getAbsoluteFile());
|
||||
try (ChronicleMap<String, Map> expected = ChronicleMapBuilder.of(String.class, Map
|
||||
.class)
|
||||
.create()) {
|
||||
|
||||
HashMap<String, String> data = new HashMap<>();
|
||||
data.put("myKey", "myValue");
|
||||
expected.put("hello", data);
|
||||
expected.getAll(file);
|
||||
|
||||
try (ChronicleMap<String, Map> actual = ChronicleMapBuilder.of(String.class, Map
|
||||
.class)
|
||||
.create()) {
|
||||
|
||||
actual.putAll(file);
|
||||
|
||||
Assert.assertEquals(expected, actual);
|
||||
}
|
||||
} finally {
|
||||
file.delete();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWithMapOfMapValue() throws IOException, InterruptedException {
|
||||
|
||||
File file = new File(TMP + "/chronicle-map-" + System.nanoTime() + ".json");
|
||||
file.deleteOnExit();
|
||||
|
||||
System.out.println(file.getAbsoluteFile());
|
||||
try (ChronicleMap expected = ChronicleMapBuilder.of
|
||||
(String.class, Map.class).create()) {
|
||||
|
||||
HashMap<String, Map> data = new HashMap<>();
|
||||
HashMap<String, String> data2 = new HashMap<>();
|
||||
data2.put("nested", "map");
|
||||
data.put("myKey", data2);
|
||||
expected.put("hello", data);
|
||||
|
||||
expected.getAll(file);
|
||||
|
||||
try (ChronicleMap<String, Map> actual = ChronicleMapBuilder.of(String.class, Map
|
||||
.class)
|
||||
.create()) {
|
||||
|
||||
actual.putAll(file);
|
||||
|
||||
Assert.assertEquals(expected, actual);
|
||||
}
|
||||
} finally {
|
||||
file.delete();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWithIntegerAndDouble() throws IOException, InterruptedException {
|
||||
|
||||
File file = new File(TMP + "/chronicle-map-" + System.nanoTime() + ".json");
|
||||
file.deleteOnExit();
|
||||
|
||||
try (ChronicleMap<Integer, Double> expected = ChronicleMapBuilder.of(Integer.class, Double
|
||||
.class)
|
||||
.create()) {
|
||||
|
||||
|
||||
expected.put(1, 1.0);
|
||||
|
||||
|
||||
expected.getAll(file);
|
||||
|
||||
try (ChronicleMap<Integer, Double> actual = ChronicleMapBuilder.of(Integer.class, Double
|
||||
.class)
|
||||
.create()) {
|
||||
|
||||
actual.putAll(file);
|
||||
|
||||
Assert.assertEquals(expected, actual);
|
||||
}
|
||||
} finally {
|
||||
file.delete();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWithCharSeq() throws IOException, InterruptedException {
|
||||
|
||||
File file = new File(TMP + "/chronicle-map-" + System.nanoTime() + ".json");
|
||||
file.deleteOnExit();
|
||||
|
||||
System.out.println(file.getAbsolutePath());
|
||||
try (ChronicleMap<CharSequence, CharSequence> expected = ChronicleMapBuilder.of(CharSequence.class, CharSequence
|
||||
.class)
|
||||
.create()) {
|
||||
|
||||
|
||||
expected.put("hello", "world");
|
||||
|
||||
|
||||
expected.getAll(file);
|
||||
|
||||
try (ChronicleMap<CharSequence, CharSequence> actual = ChronicleMapBuilder.of(CharSequence.class, CharSequence
|
||||
.class)
|
||||
.create()) {
|
||||
|
||||
actual.putAll(file);
|
||||
|
||||
Assert.assertEquals(expected, actual);
|
||||
}
|
||||
} finally {
|
||||
file.delete();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Ignore("this tyep of off heap reference is not currently supported")
|
||||
@Test
|
||||
public void testWithLongValue() throws IOException, InterruptedException {
|
||||
|
||||
File file = new File(TMP + "/chronicle-map-" + System.nanoTime() + ".json");
|
||||
file.deleteOnExit();
|
||||
|
||||
System.out.println(file.getAbsolutePath());
|
||||
try (ChronicleMap<CharSequence, LongValue> expected = ChronicleMapBuilder.of(CharSequence.class, LongValue
|
||||
.class)
|
||||
.create()) {
|
||||
|
||||
|
||||
expected.put("hello", new LongValue$$Native());
|
||||
|
||||
expected.getAll(file);
|
||||
|
||||
try (ChronicleMap<CharSequence, LongValue> actual = ChronicleMapBuilder.of(CharSequence.class, LongValue
|
||||
.class)
|
||||
.create()) {
|
||||
|
||||
actual.putAll(file);
|
||||
|
||||
Assert.assertEquals(expected, actual);
|
||||
}
|
||||
} finally {
|
||||
file.delete();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -67,9 +67,8 @@ public class MapByNameTest {
|
||||
// }
|
||||
|
||||
|
||||
// currently work in progress
|
||||
@Test
|
||||
@Ignore
|
||||
@Ignore("currently work in progress")
|
||||
public void testConnectByName() throws IOException, InterruptedException, TimeoutException {
|
||||
|
||||
NodeDiscovery nodeDiscovery = new NodeDiscovery();
|
||||
|
||||
Reference in New Issue
Block a user