Skip to content

Commit

Permalink
More test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Linas Naginionis authored and Linas Naginionis committed Dec 3, 2019
1 parent bc962f3 commit aaabc6e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ private <T> T deserialize(byte[] buf, Serializer<T> serializer) throws IOExcepti
DataInputOutput bs = new DataInputOutput(buf);
Object ret = deserialize(bs, serializer);
if (bs.available() != 0) {
throw new RuntimeException("bytes left: " + bs.available());
throw new IOException("bytes left: " + bs.available());
}

return (T) ret;
Expand Down Expand Up @@ -991,9 +991,7 @@ private <T> T deserialize(DataInput is, Serializer<T> serializer) throws IOExcep
case ARRAY_OBJECT:
ret = deserializeArrayObject(is, serializer);
break;
case -1:
throw new EOFException();

default: throw new EOFException();
}
return (T) ret;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.nio.*;

import static org.junit.jupiter.api.Assertions.*;

@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
class TestStorageSerialization {

private StorageSerialization<Integer,Integer> serialization;
Expand Down Expand Up @@ -593,6 +593,38 @@ void testMultiDimensionalLongArray() throws IOException {
assertArrayEquals(d, res);
}

@Test
void should_throw_when_deserializing_and_serializer_is_not_registered() throws IOException {
var config = PalDBConfigBuilder.<String,Point>create()
.withValueSerializer(new TestStoreReader.PointSerializer())
.build();
var serialization = new StorageSerialization<>(config);
var bytes = serialization.serializeValue(new Point(5, 4));
var deserialization = new StorageSerialization<>(new Configuration<String,Point>());
assertThrows(MissingSerializer.class, () -> deserialization.deserializeValue(bytes));
}

@Test
void should_throw_when_deserializing_and_serializer_is_not_registered_compressed() throws IOException {
var config = PalDBConfigBuilder.<String,Point>create()
.withEnableCompression(true)
.withValueSerializer(new TestStoreReader.PointSerializer())
.build();
var serialization = new StorageSerialization<>(config);
var bytes = serialization.serializeValue(new Point(5, 4));
var deserialization = new StorageSerialization<>(PalDBConfigBuilder.<String,Point>create()
.withEnableCompression(true)
.build());
assertThrows(MissingSerializer.class, () -> deserialization.deserializeValue(bytes));
}

@Test
void should_serialize_removed_instance() throws IOException {
var serialization = new StorageSerialization<>(new Configuration<>());
var bytes = serialization.serializeValue(StorageSerialization.RemovedValue.INSTANCE);
assertSame(StorageSerialization.RemovedValue.INSTANCE, serialization.deserializeValue(bytes));
}

// UTILITY

private static int[] generateIntArray(int size) {
Expand Down

0 comments on commit aaabc6e

Please sign in to comment.