mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Add direct support for sparse files under Linux (with some size tuning) #313
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.chronicle.core.OS;
|
||||
import net.openhft.chronicle.core.io.IOTools;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
public class HugeSparseMapTest {
|
||||
|
||||
private static ChronicleMap<CharSequence, CharSequence> createMap(boolean sparseFile) throws IOException {
|
||||
File file = IOTools.createTempFile("huge-map");
|
||||
try {
|
||||
file.deleteOnExit();
|
||||
ChronicleMapBuilder<CharSequence, CharSequence> builder = ChronicleMapBuilder
|
||||
.of(CharSequence.class, CharSequence.class)
|
||||
.averageKeySize(64)
|
||||
// .entries(10_000_000_000L).averageValueSize(640) // 16 TB
|
||||
.entries(3_000_000_000L).averageValueSize(200) // 2 TB
|
||||
.sparseFile(sparseFile); // ~16 TB.
|
||||
ChronicleMap<CharSequence, CharSequence> map = builder.createPersistedTo(file);
|
||||
return map;
|
||||
} catch (Throwable t) {
|
||||
file.delete();
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hugeSparseMap() throws IOException {
|
||||
assumeTrue(OS.isLinux());
|
||||
try (ChronicleMap<CharSequence, CharSequence> map = createMap(true)) {
|
||||
map.put("hi", "there");
|
||||
assertEquals("there", map.get("hi").toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IOException.class)
|
||||
public void hugeAllocatedMap() throws IOException {
|
||||
assumeTrue(OS.isLinux());
|
||||
try (ChronicleMap<CharSequence, CharSequence> map = createMap(false)) {
|
||||
map.put("hi", "there");
|
||||
assertEquals("there", map.get("hi").toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user