use of io.pravega.segmentstore.server.ReadResultMock in project pravega by pravega.
the class AsyncTableEntryReaderTests method testReadKey.
// region Reading Keys
/**
* Tests the ability to read a key.
*/
@Test
public void testReadKey() throws Exception {
val testItems = generateTestItems();
for (val e : testItems) {
val keyReader = AsyncTableEntryReader.readKey(1L, SERIALIZER, new TimeoutTimer(TIMEOUT));
Assert.assertEquals("Unexpected initial suggested read length.", AsyncTableEntryReader.INITIAL_READ_LENGTH, keyReader.getMaxReadAtOnce());
@Cleanup val rr = new ReadResultMock(e.serialization, e.serialization.length, 1);
AsyncReadResultProcessor.process(rr, keyReader, executorService());
AssertExtensions.assertEventuallyEquals(true, () -> {
int readerMaxReadAtOnce = keyReader.getMaxReadAtOnce();
return Math.min(rr.getMaxResultLength(), readerMaxReadAtOnce != 0 ? readerMaxReadAtOnce : Integer.MAX_VALUE) == rr.getMaxReadAtOnce();
}, 30 * 1000);
// Get the result and compare it with the original key.
val result = keyReader.getResult().get(BASE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
val expectedVersion = e.isRemoval ? TableKey.NOT_EXISTS : (e.explicitVersion == TableKey.NO_VERSION) ? 1L : e.explicitVersion;
Assert.assertEquals("Unexpected version.", expectedVersion, result.getVersion());
Assert.assertEquals("Unexpected key read back.", new ByteArraySegment(e.key), result.getKey());
Assert.assertEquals("Unexpected final suggested read length.", 0, keyReader.getMaxReadAtOnce());
}
}
use of io.pravega.segmentstore.server.ReadResultMock in project pravega by pravega.
the class AsyncTableEntryReaderTests method testReadKeyResultTooShort.
/**
* Tests the ability to handle a case where the key could not be read before the read result was done.
*/
@Test
public void testReadKeyResultTooShort() {
val testItems = generateTestItems();
for (val e : testItems) {
// Start a new reader & processor for this key-serialization pair.
val keyReader = AsyncTableEntryReader.readKey(1L, SERIALIZER, new TimeoutTimer(TIMEOUT));
@Cleanup val rr = new ReadResultMock(e.serialization, e.key.length - 1, 1);
AsyncReadResultProcessor.process(rr, keyReader, executorService());
AssertExtensions.assertThrows("Unexpected behavior for shorter read result.", () -> keyReader.getResult().get(BASE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS), ex -> ex instanceof SerializationException);
}
}
Aggregations