Skip to content

Commit

Permalink
More test coverage.
Browse files Browse the repository at this point in the history
Updated readme
  • Loading branch information
Linas Naginionis authored and Linas Naginionis committed Nov 25, 2019
1 parent e9fab4f commit c081257
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 7 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ PalDB is an embeddable persistent key-value store with very fast read performanc

PalDB's JAR is only 65K and has a single dependency (snappy, which isn't mandatory). It's also very easy to use with just a few configuration parameters.

**This is separate evolution of original PalDB.**

Improvements from PalDB 1.0.2
-------------------
- StoreReader is now fully thread-safe without any performance decrease.
- StoreReader and StoreWriter can be used with generics (StoreReader<K<V> and StoreWriter<K,V>)
- Typesafe ``PalDBConfigBuilder`` for easier configuration
- There are no limits on how many keys you can store
- Duplicates could be optionally allowed
- Bloom filters could be enabled for even better read performance in some cases

Performance
-----------

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>net.soundvibe</groupId>
<artifactId>paldb</artifactId>
<version>2.0.1</version>
<version>2.0.2</version>
<packaging>jar</packaging>
<name>paldb</name>
<description>Embeddable persistent write-once key-value store</description>
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/linkedin/paldb/api/Serializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@
* configuration.registerSerializer(new PointSerializer());
* </pre>
*
* @param <K> class type
* @param <T> class type
*/
public interface Serializer<K> extends Serializable {
public interface Serializer<T> extends Serializable {

/**
* Writes the instance <code>input</code> to the data output.
* @param dataOutput data output
* @param input instance
* @throws IOException if an io error occurs
*/
void write(DataOutput dataOutput, K input) throws IOException;
void write(DataOutput dataOutput, T input) throws IOException;

/**
* Reads the data input and creates the instance.
Expand All @@ -48,7 +48,7 @@ public interface Serializer<K> extends Serializable {
* @return new instance of type <code>K</code>.
* @throws IOException if an io error occurs
*/
K read(DataInput dataInput) throws IOException;
T read(DataInput dataInput) throws IOException;

Class<K> serializedClass();
Class<T> serializedClass();
}
1 change: 0 additions & 1 deletion src/main/java/com/linkedin/paldb/impl/StorageWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,6 @@ private File buildIndex(int keyLength, BloomFilter bloomFilter) throws IOExcepti
} finally {
Arrays.fill(indexBuffers, null);
indexBuffers = null;
System.gc();
if (tempIndexFile.delete()) {
log.info("Temporary index file {} has been deleted", tempIndexFile.getName());
}
Expand Down
33 changes: 33 additions & 0 deletions src/test/java/com/linkedin/paldb/impl/TestStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,39 @@ void should_allow_duplicates() {
}
}

@Test
void should_not_allow_put_null_keys() {
try (StoreWriter<String,byte[]> writer = PalDB.createWriter(storeFile)) {
assertThrows(NullPointerException.class, () -> writer.put((String)null, EMPTY_VALUE));
assertThrows(NullPointerException.class, () -> writer.putAll((String[])null, new byte[][]{}));
}
}

@Test
void should_not_allow_getting_null_keys() {
try (StoreWriter<String,byte[]> writer = PalDB.createWriter(storeFile)) {
writer.put("any value", EMPTY_VALUE);
}

try (StoreReader<String,byte[]> reader = PalDB.createReader(storeFile)) {
assertThrows(NullPointerException.class, () -> reader.get(null));
}
}

@Test
void should_not_find_when_bloom_filter_enabled() {
var config = PalDBConfigBuilder.create()
.withEnableBloomFilter(true).build();
try (StoreWriter<String,byte[]> writer = PalDB.createWriter(storeFile, config)) {
writer.put("abc", EMPTY_VALUE);
}

try (StoreReader<String,byte[]> reader = PalDB.createReader(storeFile, config)) {
assertNull(reader.get("foo"));
assertArrayEquals(EMPTY_VALUE, reader.get("abc"));
}
}

private static final byte[] EMPTY_VALUE = new byte[0];

@Test
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/com/linkedin/paldb/utils/BloomFilterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ void should_be_equal() {
assertEquals(sut1, sut2);
}

@Test
void should_return_same_bits() {
var bits = new long[Math.max(1, (int) Math.ceil((double) 6235225 / Long.SIZE))];
var sut = new BloomFilter(4, 6235225, bits);

assertArrayEquals(bits, sut.bits());
}

@Test
void correctness() {
System.out.println("Testing correctness.\n"+
Expand Down

0 comments on commit c081257

Please sign in to comment.