use of io.pravega.client.stream.Position in project pravega by pravega.
the class ReaderGroupImpl method getUnreadBytes.
private long getUnreadBytes(Map<Stream, Map<Segment, Long>> positions, Map<Segment, Long> endSegments) {
log.debug("Compute unread bytes from position {}", positions);
final List<CompletableFuture<Long>> futures = new ArrayList<>(positions.size());
for (Entry<Stream, Map<Segment, Long>> streamPosition : positions.entrySet()) {
StreamCut fromStreamCut = new StreamCutImpl(streamPosition.getKey(), streamPosition.getValue());
StreamCut toStreamCut = computeEndStreamCut(streamPosition.getKey(), endSegments);
futures.add(getRemainingBytes(streamPosition.getKey(), fromStreamCut, toStreamCut));
}
return Futures.getAndHandleExceptions(allOfWithResults(futures).thenApply(listOfLong -> {
return listOfLong.stream().mapToLong(i -> i).sum();
}), RuntimeException::new);
}
use of io.pravega.client.stream.Position in project pravega by pravega.
the class EventProcessorGroupTest method testShutdown.
@Test(timeout = 10000)
public void testShutdown() throws CheckpointStoreException {
this.requestEventProcessors = system.createEventProcessorGroup(requestConfig, checkpointStore, rebalanceExecutor);
requestEventProcessors.awaitRunning();
assertTrue(requestEventProcessors.isRunning());
Position mockReaderPosition = mock(Position.class);
doReturn(ImmutableMap.of("reader1", mockReaderPosition)).when(checkpointStore).sealReaderGroup("host1", "scaleGroup");
requestEventProcessors.stopAsync();
requestEventProcessors.awaitTerminated();
verify(checkpointStore, times(1)).sealReaderGroup("host1", "scaleGroup");
verify(checkpointStore, times(1)).removeReader(anyString(), anyString(), anyString());
verify(checkpointStore, times(1)).removeReaderGroup("host1", "scaleGroup");
verify(mockReaderGroup, times(1)).readerOffline(anyString(), any());
verify(mockReaderGroup, times(1)).close();
verify(writer, times(1)).close();
}
use of io.pravega.client.stream.Position in project pravega by pravega.
the class CheckpointStoreTests method folderOperationTests.
@Test(timeout = 30000)
public void folderOperationTests() throws CheckpointStoreException {
final String process1 = "process1";
final String readerGroup1 = "rg1";
final String readerGroup2 = "rg2";
final String reader1 = "reader1";
final String reader2 = "reader2";
Set<String> processes = checkpointStore.getProcesses();
Assert.assertEquals(0, processes.size());
checkpointStore.addReaderGroup(process1, readerGroup1);
List<String> result = checkpointStore.getReaderGroups(process1);
Assert.assertNotNull(result);
Assert.assertEquals(1, result.size());
Assert.assertEquals(readerGroup1, result.get(0));
processes = checkpointStore.getProcesses();
Assert.assertEquals(1, processes.size());
checkpointStore.addReader(process1, readerGroup1, reader1);
Map<String, Position> resultMap = checkpointStore.getPositions(process1, readerGroup1);
Assert.assertNotNull(resultMap);
Assert.assertEquals(1, resultMap.size());
Assert.assertNull(resultMap.get(reader1));
Position position = new PositionImpl(Collections.emptyMap());
checkpointStore.setPosition(process1, readerGroup1, reader1, position);
resultMap = checkpointStore.getPositions(process1, readerGroup1);
Assert.assertNotNull(resultMap);
Assert.assertEquals(1, resultMap.size());
Assert.assertNotNull(resultMap.get(reader1));
Assert.assertEquals(position, resultMap.get(reader1));
try {
checkpointStore.setPosition(process1, readerGroup1, "randomReader", position);
Assert.assertTrue(false);
} catch (CheckpointStoreException cse) {
Assert.assertEquals(CheckpointStoreException.Type.NoNode, cse.getType());
}
try {
checkpointStore.removeReaderGroup(process1, readerGroup1);
Assert.assertFalse(true);
} catch (CheckpointStoreException cse) {
Assert.assertEquals(CheckpointStoreException.Type.Active, cse.getType());
}
result = checkpointStore.getReaderGroups(process1);
Assert.assertNotNull(result);
Assert.assertEquals(1, result.size());
Assert.assertEquals(readerGroup1, result.get(0));
checkpointStore.addReader(process1, readerGroup1, reader2);
resultMap = checkpointStore.getPositions(process1, readerGroup1);
Assert.assertNotNull(resultMap);
Assert.assertEquals(2, resultMap.size());
Assert.assertNotNull(resultMap.get(reader1));
Assert.assertNull(resultMap.get(reader2));
checkpointStore.addReaderGroup(process1, readerGroup2);
result = checkpointStore.getReaderGroups(process1);
Assert.assertNotNull(result);
Assert.assertEquals(2, result.size());
Map<String, Position> map = checkpointStore.sealReaderGroup(process1, readerGroup2);
Assert.assertNotNull(map);
Assert.assertEquals(0, map.size());
try {
checkpointStore.addReader(process1, readerGroup2, "randomReader");
Assert.assertTrue(false);
} catch (CheckpointStoreException cse) {
Assert.assertEquals(CheckpointStoreException.Type.Sealed, cse.getType());
}
try {
checkpointStore.addReader(process1, "dummyReaderGroup", "randomReader");
Assert.assertTrue(false);
} catch (CheckpointStoreException cse) {
Assert.assertEquals(CheckpointStoreException.Type.NoNode, cse.getType());
}
try {
checkpointStore.sealReaderGroup(process1, "dummyReaderGroup");
Assert.assertTrue(false);
} catch (CheckpointStoreException cse) {
Assert.assertEquals(CheckpointStoreException.Type.NoNode, cse.getType());
}
checkpointStore.removeReaderGroup(process1, readerGroup2);
result = checkpointStore.getReaderGroups(process1);
Assert.assertNotNull(result);
Assert.assertEquals(1, result.size());
Assert.assertEquals(readerGroup1, result.get(0));
try {
checkpointStore.addReader(process1, readerGroup1, reader1);
} catch (CheckpointStoreException cse) {
Assert.assertEquals(CheckpointStoreException.Type.NodeExists, cse.getType());
}
map = checkpointStore.sealReaderGroup(process1, readerGroup1);
Assert.assertNotNull(map);
Assert.assertEquals(2, map.size());
try {
checkpointStore.removeReaderGroup(process1, readerGroup1);
} catch (CheckpointStoreException cse) {
Assert.assertEquals(CheckpointStoreException.Type.NodeNotEmpty, cse.getType());
}
try {
checkpointStore.addReader(process1, readerGroup1, "dummyReader");
} catch (CheckpointStoreException cse) {
Assert.assertEquals(CheckpointStoreException.Type.Sealed, cse.getType());
}
checkpointStore.removeReader(process1, readerGroup1, reader1);
checkpointStore.removeReader(process1, readerGroup1, "randomReader");
resultMap = checkpointStore.getPositions(process1, readerGroup1);
Assert.assertNotNull(resultMap);
Assert.assertEquals(1, resultMap.size());
Assert.assertNull(resultMap.get(reader2));
checkpointStore.removeReader(process1, readerGroup1, reader2);
resultMap = checkpointStore.getPositions(process1, readerGroup1);
Assert.assertNotNull(resultMap);
Assert.assertEquals(0, resultMap.size());
try {
checkpointStore.addReaderGroup(process1, readerGroup1);
Assert.assertTrue(false);
} catch (CheckpointStoreException cse) {
Assert.assertEquals(CheckpointStoreException.Type.NodeExists, cse.getType());
}
result = checkpointStore.getReaderGroups(process1);
Assert.assertNotNull(result);
Assert.assertEquals(1, result.size());
Assert.assertEquals(readerGroup1, result.get(0));
checkpointStore.removeReaderGroup(process1, readerGroup1);
result = checkpointStore.getReaderGroups(process1);
Assert.assertNotNull(result);
Assert.assertEquals(0, result.size());
}
use of io.pravega.client.stream.Position in project pravega by pravega.
the class SerializationTest method testPosition.
@Test
public void testPosition() {
PositionImpl pos = new PositionImpl(ImmutableMap.of(new SegmentWithRange(Segment.fromScopedName("foo/bar/0"), 0, 0.5), 9999999L, new SegmentWithRange(Segment.fromScopedName("foo/bar/1"), 0.5, 1.0), -1L));
ByteBuffer bytes = pos.toBytes();
Position pos1 = Position.fromBytes(bytes);
assertEquals(pos, pos1);
}
use of io.pravega.client.stream.Position in project pravega by pravega.
the class SerializationTest method testPositionImplBackwardCompatibility.
@Test
public void testPositionImplBackwardCompatibility() throws Exception {
PositionImpl pos = new PositionImpl(ImmutableMap.of(new SegmentWithRange(Segment.fromScopedName("foo/bar/1"), 0, 1), 9999999L));
// Serialize via the old serialization logic.
// Note: the older serialization logic does not work with -1L as offset.
final byte[] bufOld = new PositionSerializerR1().serialize(new PositionR1(pos)).array();
// deserialize it using latest revision and ensure compatibility.
Position newp = Position.fromBytes(ByteBuffer.wrap(bufOld));
assertEquals(pos, newp);
}
Aggregations