use of io.pravega.segmentstore.server.DirectSegmentAccess in project pravega by pravega.
the class StreamSegmentContainerTests method testPinnedSegmentReload.
/**
* Tests that call to getOrCreateInternalSegment is idempotent and always provides pinned segments.
*/
@Test(timeout = 30000)
public void testPinnedSegmentReload() {
@Cleanup TestContext context = createContext();
val container = (StreamSegmentContainer) context.container;
container.startAsync().awaitRunning();
Function<String, CompletableFuture<DirectSegmentAccess>> segmentSupplier = ContainerEventProcessorImpl.getOrCreateInternalSegment(container, container.metadataStore, TIMEOUT_EVENT_PROCESSOR_ITERATION);
long segmentId = segmentSupplier.apply("dummySegment").join().getSegmentId();
for (int i = 0; i < 10; i++) {
DirectSegmentAccess segment = segmentSupplier.apply("dummySegment").join();
assertTrue(segment.getInfo().isPinned());
assertEquals(segmentId, segment.getSegmentId());
}
}
use of io.pravega.segmentstore.server.DirectSegmentAccess in project pravega by pravega.
the class StreamSegmentContainerTests method checkAttributeIterators.
private void checkAttributeIterators(DirectSegmentAccess segment, List<AttributeId> sortedAttributes, Map<AttributeId, Long> allExpectedValues) throws Exception {
int skip = sortedAttributes.size() / 10;
for (int i = 0; i < sortedAttributes.size() / 2; i += skip) {
AttributeId fromId = sortedAttributes.get(i);
AttributeId toId = sortedAttributes.get(sortedAttributes.size() - i - 1);
val expectedValues = allExpectedValues.entrySet().stream().filter(e -> fromId.compareTo(e.getKey()) <= 0 && toId.compareTo(e.getKey()) >= 0).sorted(Comparator.comparing(Map.Entry::getKey)).collect(Collectors.toList());
val actualValues = new ArrayList<Map.Entry<AttributeId, Long>>();
val ids = new HashSet<AttributeId>();
val iterator = segment.attributeIterator(fromId, toId, TIMEOUT).get(TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
iterator.forEachRemaining(batch -> batch.forEach(attribute -> {
Assert.assertTrue("Duplicate key found.", ids.add(attribute.getKey()));
actualValues.add(attribute);
}), executorService()).get(TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
AssertExtensions.assertListEquals("Unexpected iterator result.", expectedValues, actualValues, (e1, e2) -> e1.getKey().equals(e2.getKey()) && e1.getValue().equals(e2.getValue()));
}
}
use of io.pravega.segmentstore.server.DirectSegmentAccess in project pravega by pravega.
the class ContainerEventProcessorTests method testInitializationException.
/**
* Check that if the creation of the EventProcessor fails, the future is completed exceptionally.
*
* @throws Exception
*/
@Test(timeout = 10000)
public void testInitializationException() throws Exception {
AtomicBoolean induceFailure = new AtomicBoolean(true);
Function<String, CompletableFuture<DirectSegmentAccess>> failingSegmentSupplier = s -> induceFailure.getAndSet(!induceFailure.get()) ? CompletableFuture.failedFuture(new IntentionalException()) : CompletableFuture.completedFuture(new SegmentMock(this.executorService()));
@Cleanup ContainerEventProcessorImpl eventProcessorService = new ContainerEventProcessorImpl(0, failingSegmentSupplier, 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);
// Verify that if the creation of the EventProcessor takes too long, the future completes exceptionally.
AssertExtensions.assertFutureThrows("Expected future exceptionally complete with IntentionalException", eventProcessorService.forConsumer("testExceptionForConsumer", l -> null, config), ex -> ex instanceof IntentionalException);
// If the call has failed, the future for that EventProcessor should have been removed from the map.
Assert.assertNull(eventProcessorService.getEventProcessorMap().get("testExceptionForConsumer"));
// The next call is expected to succeed, so the future should be in the map when this call completes.
Assert.assertNotNull(eventProcessorService.forConsumer("testExceptionForConsumer", l -> null, config).join());
Assert.assertNotNull(eventProcessorService.getEventProcessorMap().get("testExceptionForConsumer"));
AssertExtensions.assertFutureThrows("Expected future exceptionally complete with IntentionalException", eventProcessorService.forDurableQueue("testExceptionForDurableQueue"), ex -> ex instanceof IntentionalException);
Assert.assertNull(eventProcessorService.getEventProcessorMap().get("testExceptionForDurableQueue"));
Assert.assertNotNull(eventProcessorService.forDurableQueue("testExceptionForDurableQueue").join());
Assert.assertNotNull(eventProcessorService.getEventProcessorMap().get("testExceptionForDurableQueue"));
}
use of io.pravega.segmentstore.server.DirectSegmentAccess in project pravega by pravega.
the class ContainerEventProcessorTests method testAppendWithFailingSegment.
/**
* Check the behavior of the EventProcessor when there are failures when adding events to the internal Segment.
*
* @throws Exception
*/
@Test(timeout = 10000)
public void testAppendWithFailingSegment() throws Exception {
DirectSegmentAccess faultySegment = mock(SegmentMock.class);
when(faultySegment.append(any(), any(), any())).thenThrow(NullPointerException.class);
SegmentMetadata mockMetadata = mock(SegmentMetadata.class);
when(mockMetadata.getLength()).thenReturn(0L);
when(faultySegment.getInfo()).thenReturn(mockMetadata);
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);
Function<List<BufferView>, CompletableFuture<Void>> doNothing = l -> null;
@Cleanup ContainerEventProcessor.EventProcessor processor = eventProcessorService.forConsumer("testSegmentMax", doNothing, config).get(TIMEOUT_FUTURE.toSeconds(), TimeUnit.SECONDS);
// Verify that the client gets the exception if there is some issue on add().
BufferView event = new ByteArraySegment("Test".getBytes());
AssertExtensions.assertThrows(NullPointerException.class, () -> processor.add(event, TIMEOUT_FUTURE).join());
}
use of io.pravega.segmentstore.server.DirectSegmentAccess in project pravega by pravega.
the class ContainerKeyIndexTests method testRegularSegmentThrottling.
/**
* Tests that regular Segments get the right amount of credits.
*/
@Test
public void testRegularSegmentThrottling() {
@Cleanup val context = new TestContext();
@Cleanup ContainerKeyIndex.SegmentTracker segmentTracker = context.index.new SegmentTracker();
DirectSegmentAccess mockSegment = Mockito.mock(DirectSegmentAccess.class);
SegmentMetadata mockSegmentMetadata = Mockito.mock(SegmentMetadata.class);
// Regular segment.
SegmentType segmentType = SegmentType.builder().build();
Mockito.when(mockSegmentMetadata.getType()).thenReturn(segmentType);
Mockito.when(mockSegment.getInfo()).thenReturn(mockSegmentMetadata);
Mockito.when(mockSegment.getSegmentId()).thenReturn(1L);
int updateSize = TableExtensionConfig.MAX_UNINDEXED_LENGTH.getDefaultValue() - 1;
segmentTracker.throttleIfNeeded(mockSegment, () -> CompletableFuture.completedFuture(null), updateSize).join();
Assert.assertEquals(segmentTracker.getUnindexedSizeBytes(1L), TableExtensionConfig.MAX_UNINDEXED_LENGTH.getDefaultValue() - 1);
}
Aggregations