Search in sources :

Example 96 with Segment

use of io.pravega.client.segment.impl.Segment in project pravega by pravega.

the class StreamSegmentsTest method getCounts.

private LinkedHashMap<Segment, Integer> getCounts(StreamSegments streamSegments) {
    LinkedHashMap<Segment, Integer> counts = new LinkedHashMap<>();
    for (Segment s : streamSegments.getSegments()) {
        counts.put(s, 0);
    }
    for (double key : new double[] { 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9 }) {
        Segment segment = streamSegments.getSegmentForKey(key);
        counts.put(segment, counts.get(segment) + 1);
    }
    return counts;
}
Also used : Segment(io.pravega.client.segment.impl.Segment) LinkedHashMap(java.util.LinkedHashMap)

Example 97 with Segment

use of io.pravega.client.segment.impl.Segment in project pravega by pravega.

the class StreamSegmentsTest method testSameRoutingKey.

@Test
public void testSameRoutingKey() {
    StreamSegments streamSegments = initStreamSegments(4);
    int[] counts = new int[4];
    Arrays.fill(counts, 0);
    for (int i = 0; i < 20; i++) {
        Segment segment = streamSegments.getSegmentForKey("Foo");
        assertNotNull(segment);
        counts[NameUtils.getSegmentNumber(segment.getSegmentId())]++;
    }
    assertArrayEquals(new int[] { 20, 0, 0, 0 }, counts);
}
Also used : Segment(io.pravega.client.segment.impl.Segment) Test(org.junit.Test)

Example 98 with Segment

use of io.pravega.client.segment.impl.Segment in project pravega by pravega.

the class StreamSegmentsTest method findSegmentsToMerge.

private Map<Segment, Segment> findSegmentsToMerge(StreamSegments streamSegments, HashMap<Segment, Integer> counts) {
    Map<Segment, Segment> toMerge = new HashMap<>();
    Segment previous = null;
    for (Segment segment : new LinkedHashSet<>(streamSegments.getSegments())) {
        if (previous != null) {
            if (counts.get(previous) + counts.get(segment) <= 4) {
                toMerge.put(previous, segment);
                previous = null;
            } else {
                previous = segment;
            }
        } else {
            previous = segment;
        }
    }
    return toMerge;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Segment(io.pravega.client.segment.impl.Segment)

Example 99 with Segment

use of io.pravega.client.segment.impl.Segment in project pravega by pravega.

the class MockController method getCurrentSegments.

private KeyValueTableSegments getCurrentSegments(KeyValueTableInfo kvt) {
    List<Segment> segmentsInStream = getSegmentsForKeyValueTable(kvt);
    TreeMap<Double, SegmentWithRange> segments = new TreeMap<>();
    for (int i = 0; i < segmentsInStream.size(); i++) {
        SegmentWithRange s = createRange(kvt.getScope(), kvt.getKeyValueTableName(), segmentsInStream.size(), i);
        segments.put(s.getRange().getHigh(), s);
    }
    return new KeyValueTableSegments(segments);
}
Also used : SegmentWithRange(io.pravega.client.stream.impl.SegmentWithRange) TreeMap(java.util.TreeMap) KeyValueTableSegments(io.pravega.client.tables.impl.KeyValueTableSegments) CreateSegment(io.pravega.shared.protocol.netty.WireCommands.CreateSegment) Segment(io.pravega.client.segment.impl.Segment) DeleteSegment(io.pravega.shared.protocol.netty.WireCommands.DeleteSegment)

Example 100 with Segment

use of io.pravega.client.segment.impl.Segment in project pravega by pravega.

the class EventStreamReaderTest method testEndOfSegmentWithoutSuccessors.

@Test(timeout = 10000)
public void testEndOfSegmentWithoutSuccessors() throws ReaderNotInReaderGroupException {
    AtomicLong clock = new AtomicLong();
    MockSegmentStreamFactory segmentStreamFactory = new MockSegmentStreamFactory();
    Orderer orderer = new Orderer();
    ReaderGroupStateManager groupState = Mockito.mock(ReaderGroupStateManager.class);
    @Cleanup EventStreamReaderImpl<byte[]> reader = new EventStreamReaderImpl<>(segmentStreamFactory, segmentStreamFactory, new ByteArraySerializer(), groupState, orderer, clock::get, ReaderConfig.builder().build(), createWatermarkReaders(), Mockito.mock(Controller.class));
    Segment segment = Segment.fromScopedName("Foo/Bar/0");
    Mockito.when(groupState.acquireNewSegmentsIfNeeded(eq(0L), any())).thenReturn(ImmutableMap.of(new SegmentWithRange(segment, 0, 1), 0L)).thenReturn(Collections.emptyMap());
    Mockito.when(groupState.getEndOffsetForSegment(any(Segment.class))).thenReturn(Long.MAX_VALUE);
    Mockito.when(groupState.handleEndOfSegment(any())).thenReturn(true);
    SegmentOutputStream stream = segmentStreamFactory.createOutputStreamForSegment(segment, segmentSealedCallback, writerConfig, DelegationTokenProviderFactory.createWithEmptyToken());
    ByteBuffer buffer = writeInt(stream, 1);
    EventRead<byte[]> read = reader.readNextEvent(0);
    byte[] event = read.getEvent();
    assertEquals(buffer, ByteBuffer.wrap(event));
    read = reader.readNextEvent(0);
    assertNull(read.getEvent());
    read = reader.readNextEvent(0);
    assertNull(read.getEvent());
    assertEquals(0, reader.getReaders().size());
    assertEquals(1, reader.getRanges().size());
    Mockito.when(groupState.getCheckpoint()).thenReturn("CP1");
    read = reader.readNextEvent(0);
    assertTrue(read.isCheckpoint());
    read = reader.readNextEvent(0);
    assertNull(read.getEvent());
    assertEquals(0, reader.getRanges().size());
    reader.close();
}
Also used : MockSegmentStreamFactory(io.pravega.client.stream.mock.MockSegmentStreamFactory) MockController(io.pravega.client.stream.mock.MockController) Controller(io.pravega.client.control.impl.Controller) Cleanup(lombok.Cleanup) ByteBuffer(java.nio.ByteBuffer) Segment(io.pravega.client.segment.impl.Segment) AtomicLong(java.util.concurrent.atomic.AtomicLong) SegmentOutputStream(io.pravega.client.segment.impl.SegmentOutputStream) Test(org.junit.Test)

Aggregations

Segment (io.pravega.client.segment.impl.Segment)285 Test (org.junit.Test)200 Cleanup (lombok.Cleanup)125 HashMap (java.util.HashMap)79 Controller (io.pravega.client.control.impl.Controller)74 Stream (io.pravega.client.stream.Stream)69 MockController (io.pravega.client.stream.mock.MockController)67 EventWriterConfig (io.pravega.client.stream.EventWriterConfig)57 StreamCut (io.pravega.client.stream.StreamCut)57 PravegaNodeUri (io.pravega.shared.protocol.netty.PravegaNodeUri)53 AtomicLong (java.util.concurrent.atomic.AtomicLong)53 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)51 SegmentOutputStream (io.pravega.client.segment.impl.SegmentOutputStream)50 MockSegmentStreamFactory (io.pravega.client.stream.mock.MockSegmentStreamFactory)46 SegmentOutputStreamFactory (io.pravega.client.segment.impl.SegmentOutputStreamFactory)44 StreamCutImpl (io.pravega.client.stream.impl.StreamCutImpl)42 MockConnectionFactoryImpl (io.pravega.client.stream.mock.MockConnectionFactoryImpl)41 ArrayList (java.util.ArrayList)40 Map (java.util.Map)40 CompletableFuture (java.util.concurrent.CompletableFuture)37