mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
HCOLL-228 Add support for .json.gz files.
This commit is contained in:
@@ -52,6 +52,8 @@ import java.nio.ByteOrder;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import static java.lang.Class.forName;
|
||||
import static java.lang.Long.numberOfTrailingZeros;
|
||||
@@ -612,7 +614,10 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
// ideally we will use java serialization if we can
|
||||
lazyXStreamConverter().registerConverter(xstream);
|
||||
|
||||
try (FileOutputStream out = new FileOutputStream(toFile)) {
|
||||
OutputStream outputStream = new FileOutputStream(toFile);
|
||||
if (toFile.getName().toLowerCase().endsWith(".gz"))
|
||||
outputStream = new GZIPOutputStream(outputStream);
|
||||
try (OutputStream out = outputStream) {
|
||||
xstream.toXML(entrySet(), out);
|
||||
}
|
||||
}
|
||||
@@ -626,7 +631,10 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
// ideally we will use java serialization if we can
|
||||
lazyXStreamConverter().registerConverter(xstream);
|
||||
|
||||
try (FileInputStream out = new FileInputStream(fromFile)) {
|
||||
InputStream inputStream = new FileInputStream(fromFile);
|
||||
if (fromFile.getName().toLowerCase().endsWith(".gz"))
|
||||
inputStream = new GZIPInputStream(inputStream);
|
||||
try (InputStream out = inputStream) {
|
||||
xstream.fromXML(out);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,16 +32,16 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Created by peter on 06/12/14.
|
||||
*/
|
||||
public class LargeEntriesTest {
|
||||
|
||||
static final int ENTRIES = 640;
|
||||
static final int ENTRIES = 6400;
|
||||
static final int ENTRY_SIZE = 1024;
|
||||
private static final boolean TESTING = Boolean.getBoolean("testing");
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@@ -55,7 +55,7 @@ public class LargeEntriesTest {
|
||||
.putReturnsNull(true)
|
||||
.create();
|
||||
{
|
||||
int threads = 2; //Runtime.getRuntime().availableProcessors();
|
||||
int threads = 4; //Runtime.getRuntime().availableProcessors();
|
||||
ExecutorService es = Executors.newFixedThreadPool(threads);
|
||||
final int block = ENTRIES / threads;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
@@ -124,11 +124,20 @@ public class LargeEntriesTest {
|
||||
SnappyStringMarshaller.INSTANCE.read(bytes);
|
||||
bytes.release();
|
||||
}
|
||||
Object lock = TESTING ? Thread.currentThread() : map;
|
||||
|
||||
List<String> keys = new ArrayList<>();
|
||||
for (int i = start; i < finish; i++) {
|
||||
String key = "key-" + i;
|
||||
map.put(key, value);
|
||||
String object = map.get(key);
|
||||
String object;
|
||||
synchronized (lock) {
|
||||
map.put(key, value);
|
||||
keys.add(key);
|
||||
for (String s : keys)
|
||||
assertTrue(s, map.containsKey(s));
|
||||
object = map.get(key);
|
||||
assertTrue(key, map.containsKey(key));
|
||||
}
|
||||
|
||||
assertNotNull(key, object);
|
||||
assertEquals(key, entrySize, object.length());
|
||||
@@ -138,10 +147,12 @@ public class LargeEntriesTest {
|
||||
for (int i = start; i < finish; i++) {
|
||||
// System.out.println(i);
|
||||
String key = "key-" + i;
|
||||
String object = map.get(key);
|
||||
synchronized (lock) {
|
||||
String object = map.get(key);
|
||||
|
||||
assertNotNull(key, object);
|
||||
assertEquals(key, entrySize, object.length());
|
||||
assertNotNull(key, object);
|
||||
assertEquals(key, entrySize, object.length());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user