use of io.pravega.client.segment.impl.Segment in project pravega by pravega.
the class ControllerImplTest method testGetSegmentsWithOverlappingStreamCuts.
@Test(expected = IllegalArgumentException.class)
public void testGetSegmentsWithOverlappingStreamCuts() throws Exception {
String scope = "scope1";
String stream = "stream1";
Stream s = new StreamImpl(scope, stream);
Map<Segment, Long> startSegments = new HashMap<>();
startSegments.put(new Segment(scope, stream, 3), 4L);
startSegments.put(new Segment(scope, stream, 2), 4L);
startSegments.put(new Segment(scope, stream, 1), 6L);
StreamCut cut = new StreamCutImpl(s, startSegments);
Map<Segment, Long> endSegments = new HashMap<>();
endSegments.put(new Segment(scope, stream, 0), 10L);
endSegments.put(new Segment(scope, stream, 7), 10L);
StreamCut endSC = new StreamCutImpl(s, endSegments);
controllerClient.getSegments(cut, endSC).get().getSegments();
}
use of io.pravega.client.segment.impl.Segment in project pravega by pravega.
the class ControllerImplTest method testGetSegmentsWithPartialOverlapStreamCuts.
@Test(expected = IllegalArgumentException.class)
public void testGetSegmentsWithPartialOverlapStreamCuts() throws Exception {
String scope = "scope1";
String stream = "stream1";
Stream s = new StreamImpl(scope, stream);
Map<Segment, Long> startSegments = new HashMap<>();
startSegments.put(new Segment(scope, stream, 0), 4L);
startSegments.put(new Segment(scope, stream, 7), 6L);
StreamCut cut = new StreamCutImpl(s, startSegments);
Map<Segment, Long> endSegments = new HashMap<>();
endSegments.put(new Segment(scope, stream, 5), 10L);
endSegments.put(new Segment(scope, stream, 4), 10L);
endSegments.put(new Segment(scope, stream, 6), 10L);
StreamCut endSC = new StreamCutImpl(s, endSegments);
controllerClient.getSegments(cut, endSC).get().getSegments();
}
use of io.pravega.client.segment.impl.Segment in project pravega by pravega.
the class ControllerImplTest method testParallelGetCurrentSegments.
@Test
public void testParallelGetCurrentSegments() throws Exception {
final ExecutorService executorService = ExecutorServiceHelpers.newScheduledThreadPool(10, "testParallelGetCurrentSegments");
Semaphore createCount = new Semaphore(-19);
AtomicBoolean success = new AtomicBoolean(true);
for (int i = 0; i < 10; i++) {
executorService.submit(() -> {
for (int j = 0; j < 2; j++) {
try {
CompletableFuture<StreamSegments> streamSegments;
streamSegments = controllerClient.getCurrentSegments("scope1", "streamparallel");
assertTrue(streamSegments.get().getSegments().size() == 2);
assertEquals(new Segment("scope1", "streamparallel", 0), streamSegments.get().getSegmentForKey(0.2));
assertEquals(new Segment("scope1", "streamparallel", 1), streamSegments.get().getSegmentForKey(0.6));
createCount.release();
} catch (Exception e) {
log.error("Exception when getting segments: {}", e);
// Don't wait for other threads to complete.
success.set(false);
createCount.release(20);
}
}
});
}
createCount.acquire();
executorService.shutdownNow();
assertTrue(success.get());
}
use of io.pravega.client.segment.impl.Segment in project pravega by pravega.
the class ControllerImplTest method testGetSegmentsWithPartialOverlapStreamCut.
@Test(expected = IllegalArgumentException.class)
public void testGetSegmentsWithPartialOverlapStreamCut() throws Exception {
String scope = "scope1";
String stream = "stream8";
Stream s = new StreamImpl(scope, stream);
Map<Segment, Long> startSegments = new HashMap<>();
startSegments.put(new Segment(scope, stream, 0), 4L);
startSegments.put(new Segment(scope, stream, 5), 6L);
startSegments.put(new Segment(scope, stream, 6), 6L);
startSegments.put(new Segment(scope, stream, 2), 6L);
StreamCut cut = new StreamCutImpl(s, startSegments);
Map<Segment, Long> endSegments = new HashMap<>();
endSegments.put(new Segment(scope, stream, 8), 10L);
endSegments.put(new Segment(scope, stream, 7), 10L);
endSegments.put(new Segment(scope, stream, 1), 10L);
endSegments.put(new Segment(scope, stream, 3), 10L);
endSegments.put(new Segment(scope, stream, 4), 10L);
StreamCut endSC = new StreamCutImpl(s, endSegments);
controllerClient.getSegments(cut, endSC).get().getSegments();
}
use of io.pravega.client.segment.impl.Segment in project pravega by pravega.
the class EventStreamReaderTest method testReleaseSegment.
@Test(timeout = 10000)
public void testReleaseSegment() throws SegmentSealedException, ReinitializationRequiredException {
AtomicLong clock = new AtomicLong();
MockSegmentStreamFactory segmentStreamFactory = new MockSegmentStreamFactory();
Orderer orderer = new Orderer();
ReaderGroupStateManager groupState = Mockito.mock(ReaderGroupStateManager.class);
EventStreamReaderImpl<byte[]> reader = new EventStreamReaderImpl<>(segmentStreamFactory, segmentStreamFactory, new ByteArraySerializer(), groupState, orderer, clock::get, ReaderConfig.builder().build());
Segment segment1 = Segment.fromScopedName("Foo/Bar/0");
Segment segment2 = Segment.fromScopedName("Foo/Bar/1");
Mockito.when(groupState.acquireNewSegmentsIfNeeded(0L)).thenReturn(ImmutableMap.of(segment1, 0L, segment2, 0L)).thenReturn(Collections.emptyMap());
SegmentOutputStream stream1 = segmentStreamFactory.createOutputStreamForSegment(segment1, segmentSealedCallback, writerConfig, "");
SegmentOutputStream stream2 = segmentStreamFactory.createOutputStreamForSegment(segment2, segmentSealedCallback, writerConfig, "");
writeInt(stream1, 1);
writeInt(stream2, 2);
reader.readNextEvent(0);
List<SegmentInputStream> readers = reader.getReaders();
assertEquals(2, readers.size());
Assert.assertEquals(segment1, readers.get(0).getSegmentId());
Assert.assertEquals(segment2, readers.get(1).getSegmentId());
Mockito.when(groupState.getCheckpoint()).thenReturn("checkpoint");
assertTrue(reader.readNextEvent(0).isCheckpoint());
Mockito.when(groupState.getCheckpoint()).thenReturn(null);
Mockito.when(groupState.findSegmentToReleaseIfRequired()).thenReturn(segment2);
Mockito.when(groupState.releaseSegment(Mockito.eq(segment2), Mockito.anyLong(), Mockito.anyLong())).thenReturn(true);
assertFalse(reader.readNextEvent(0).isCheckpoint());
Mockito.verify(groupState).releaseSegment(Mockito.eq(segment2), Mockito.anyLong(), Mockito.anyLong());
readers = reader.getReaders();
assertEquals(1, readers.size());
Assert.assertEquals(segment1, readers.get(0).getSegmentId());
reader.close();
}
Aggregations