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;
}
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);
}
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;
}
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);
}
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();
}
Aggregations