Search in sources :

Example 26 with Segment

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();
}
Also used : StreamCut(io.pravega.client.stream.StreamCut) HashMap(java.util.HashMap) Stream(io.pravega.client.stream.Stream) Segment(io.pravega.client.segment.impl.Segment) Test(org.junit.Test)

Example 27 with Segment

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();
}
Also used : StreamCut(io.pravega.client.stream.StreamCut) HashMap(java.util.HashMap) Stream(io.pravega.client.stream.Stream) Segment(io.pravega.client.segment.impl.Segment) Test(org.junit.Test)

Example 28 with Segment

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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) Semaphore(java.util.concurrent.Semaphore) Segment(io.pravega.client.segment.impl.Segment) RetriesExhaustedException(io.pravega.common.util.RetriesExhaustedException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 29 with Segment

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();
}
Also used : StreamCut(io.pravega.client.stream.StreamCut) HashMap(java.util.HashMap) Stream(io.pravega.client.stream.Stream) Segment(io.pravega.client.segment.impl.Segment) Test(org.junit.Test)

Example 30 with Segment

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();
}
Also used : SegmentInputStream(io.pravega.client.segment.impl.SegmentInputStream) AtomicLong(java.util.concurrent.atomic.AtomicLong) SegmentOutputStream(io.pravega.client.segment.impl.SegmentOutputStream) MockSegmentStreamFactory(io.pravega.client.stream.mock.MockSegmentStreamFactory) Segment(io.pravega.client.segment.impl.Segment) Test(org.junit.Test)

Aggregations

Segment (io.pravega.client.segment.impl.Segment)97 Test (org.junit.Test)63 Cleanup (lombok.Cleanup)35 HashMap (java.util.HashMap)27 MockSegmentStreamFactory (io.pravega.client.stream.mock.MockSegmentStreamFactory)22 SegmentOutputStream (io.pravega.client.segment.impl.SegmentOutputStream)19 AtomicLong (java.util.concurrent.atomic.AtomicLong)19 PravegaNodeUri (io.pravega.shared.protocol.netty.PravegaNodeUri)17 SegmentOutputStreamFactory (io.pravega.client.segment.impl.SegmentOutputStreamFactory)16 EventWriterConfig (io.pravega.client.stream.EventWriterConfig)16 MockController (io.pravega.client.stream.mock.MockController)15 ClientFactory (io.pravega.client.ClientFactory)13 Stream (io.pravega.client.stream.Stream)13 MockConnectionFactoryImpl (io.pravega.client.stream.mock.MockConnectionFactoryImpl)13 SynchronizerConfig (io.pravega.client.state.SynchronizerConfig)12 InlineExecutor (io.pravega.test.common.InlineExecutor)12 TreeMap (java.util.TreeMap)10 lombok.val (lombok.val)10 StreamCut (io.pravega.client.stream.StreamCut)8 ByteBuffer (java.nio.ByteBuffer)8