use of io.pravega.segmentstore.server.SegmentMock in project pravega by pravega.
the class TableBucketReaderTests method testFindEntry.
/**
* Tests the ability to locate Table Entries in a Table Bucket using {@link TableBucketReader#key}.
*/
@Test
public void testFindEntry() throws Exception {
val segment = new SegmentMock(executorService());
// Generate our test data and append it to the segment.
val data = generateData();
segment.append(new ByteArraySegment(data.serialization), null, TIMEOUT).join();
val reader = TableBucketReader.entry(segment, (s, offset, timeout) -> CompletableFuture.completedFuture(data.getBackpointer(offset)), executorService());
// Check a valid result.
val validEntry = data.entries.get(1);
val validResult = reader.find(validEntry.getKey().getKey(), data.getBucketOffset(), new TimeoutTimer(TIMEOUT)).get(TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
Assert.assertEquals("Unexpected version from valid key.", data.getEntryOffset(1), validResult.getKey().getVersion());
Assert.assertEquals("Unexpected 'valid' key returned.", validEntry.getKey().getKey(), validResult.getKey().getKey());
Assert.assertEquals("Unexpected 'valid' key returned.", validEntry.getValue(), validResult.getValue());
// Check a key that does not exist.
val invalidKey = data.unlinkedEntry.getKey();
val invalidResult = reader.find(invalidKey.getKey(), data.getBucketOffset(), new TimeoutTimer(TIMEOUT)).get(TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
Assert.assertNull("Not expecting any result for key that does not exist.", invalidResult);
}
use of io.pravega.segmentstore.server.SegmentMock in project pravega by pravega.
the class TableBucketReaderTests method testFindEntryNotExists.
/**
* Tests the ability to (not) locate Table Entries in a Table Bucket for deleted and inexistent keys.
*/
@Test
public void testFindEntryNotExists() throws Exception {
val segment = new SegmentMock(executorService());
// Generate our test data.
val es = new EntrySerializer();
val entries = generateEntries(es);
// Deleted key (that was previously indexed).
val deletedKey = entries.get(0).getKey();
val data = es.serializeRemoval(Collections.singleton(deletedKey));
segment.append(data, null, TIMEOUT).join();
val reader = TableBucketReader.entry(segment, // No backpointers.
(s, offset, timeout) -> CompletableFuture.completedFuture(-1L), executorService());
val deletedResult = reader.find(deletedKey.getKey(), 0L, new TimeoutTimer(TIMEOUT)).get(TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
Assert.assertNull("Expecting a TableEntry with null value for deleted key.", deletedResult.getValue());
// Inexistent key (that did not exist previously).
val inexistentKey = entries.get(1).getKey();
val inexistentResult = reader.find(inexistentKey.getKey(), 0L, new TimeoutTimer(TIMEOUT)).get(TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
Assert.assertNull("Not expecting any result for key that was never present.", inexistentResult);
}
use of io.pravega.segmentstore.server.SegmentMock in project pravega by pravega.
the class ContainerEventProcessorTests method testReadWithFailingSegment.
/**
* Test the behavior of the EventProcessor when internal Segment reads fail.
*
* @throws Exception
*/
@Test(timeout = 10000)
public void testReadWithFailingSegment() throws Exception {
DirectSegmentAccess faultySegment = spy(new SegmentMock(this.executorService()));
Function<String, CompletableFuture<DirectSegmentAccess>> faultySegmentSupplier = s -> CompletableFuture.completedFuture(faultySegment);
@Cleanup ContainerEventProcessor eventProcessorService = new ContainerEventProcessorImpl(0, faultySegmentSupplier, ITERATION_DELAY, CONTAINER_OPERATION_TIMEOUT, this.executorService());
int maxItemsProcessed = 10;
int maxOutstandingBytes = 4 * 1024 * 1024;
int truncationDataSize = 500;
ContainerEventProcessor.EventProcessorConfig config = new ContainerEventProcessor.EventProcessorConfig(maxItemsProcessed, maxOutstandingBytes, truncationDataSize);
ReusableLatch latch = new ReusableLatch();
Function<List<BufferView>, CompletableFuture<Void>> doNothing = l -> {
latch.release();
return CompletableFuture.completedFuture(null);
};
// Make the internal Segment of the processor to fail upon a read.
when(faultySegment.read(anyLong(), anyInt(), any(Duration.class))).thenThrow(IntentionalException.class).thenCallRealMethod();
@Cleanup ContainerEventProcessor.EventProcessor processor = eventProcessorService.forConsumer("testSegmentMax", doNothing, config).get(TIMEOUT_FUTURE.toSeconds(), TimeUnit.SECONDS);
// Write an event to make sure that the processor is running and await for it to be processed.
BufferView event = new ByteArraySegment("Test".getBytes());
processor.add(event, TIMEOUT_FUTURE).join();
latch.await();
}
use of io.pravega.segmentstore.server.SegmentMock in project pravega by pravega.
the class ContainerEventProcessorTests method executeEventOrderingTest.
private void executeEventOrderingTest(int numEvents, List<Integer> readEvents, Consumer<DirectSegmentAccess> segmentFailure) throws Exception {
DirectSegmentAccess faultySegment = spy(new SegmentMock(this.executorService()));
Function<String, CompletableFuture<DirectSegmentAccess>> faultySegmentSupplier = s -> CompletableFuture.completedFuture(faultySegment);
@Cleanup ContainerEventProcessor eventProcessorService = new ContainerEventProcessorImpl(0, faultySegmentSupplier, ITERATION_DELAY, CONTAINER_OPERATION_TIMEOUT, this.executorService());
int maxItemsProcessed = 100;
int maxOutstandingBytes = 4 * 1024 * 1024;
int truncationDataSize = 500;
Function<List<BufferView>, CompletableFuture<Void>> handler = l -> {
l.forEach(d -> readEvents.add(new ByteArraySegment(d.getCopy()).getInt(0)));
return CompletableFuture.completedFuture(null);
};
// Induce some desired failures.
segmentFailure.accept(faultySegment);
ContainerEventProcessor.EventProcessorConfig config = new ContainerEventProcessor.EventProcessorConfig(maxItemsProcessed, maxOutstandingBytes, truncationDataSize);
@Cleanup ContainerEventProcessor.EventProcessor processor = eventProcessorService.forConsumer("testSequence", handler, config).get(TIMEOUT_FUTURE.toSeconds(), TimeUnit.SECONDS);
// Write some data.
for (int i = 0; i < numEvents; i++) {
ByteArraySegment b = new ByteArraySegment(new byte[Integer.BYTES]);
b.setInt(0, i);
processor.add(b.slice(), TIMEOUT_FUTURE).join();
}
// Wait until the last event is read.
AssertExtensions.assertEventuallyEquals(true, () -> !readEvents.isEmpty() && readEvents.get(readEvents.size() - 1) == numEvents - 1, 10000);
}
Aggregations