use of io.pravega.client.segment.impl.Segment in project pravega by pravega.
the class ControllerImplTest method testGetSegmentsAtTime.
@Test
public void testGetSegmentsAtTime() throws Exception {
CompletableFuture<Map<Segment, Long>> positions;
positions = controllerClient.getSegmentsAtTime(new StreamImpl("scope1", "stream1"), 0);
assertEquals(2, positions.get().size());
assertEquals(10, positions.get().get(new Segment("scope1", "stream1", 0)).longValue());
assertEquals(20, positions.get().get(new Segment("scope1", "stream1", 1)).longValue());
positions = controllerClient.getSegmentsAtTime(new StreamImpl("scope1", "stream2"), 0);
AssertExtensions.assertFutureThrows("Should throw Exception", positions, throwable -> true);
}
use of io.pravega.client.segment.impl.Segment in project pravega by pravega.
the class ControllerImplTest method testScale.
@Test
public void testScale() throws Exception {
CompletableFuture<Boolean> scaleStream;
StreamImpl stream = new StreamImpl("scope1", "stream1");
scaleStream = controllerClient.scaleStream(stream, new ArrayList<>(), new HashMap<>(), executor).getFuture();
assertTrue(scaleStream.get());
CompletableFuture<StreamSegments> segments = controllerClient.getCurrentSegments("scope1", "stream1");
assertEquals(2, segments.get().getSegments().size());
assertEquals(new Segment("scope1", "stream1", 6), segments.get().getSegmentForKey(0.25));
assertEquals(new Segment("scope1", "stream1", 7), segments.get().getSegmentForKey(0.75));
scaleStream = controllerClient.scaleStream(new StreamImpl("scope1", "stream2"), new ArrayList<>(), new HashMap<>(), executor).getFuture();
AssertExtensions.assertFutureThrows("Should throw Exception", scaleStream, throwable -> true);
scaleStream = controllerClient.scaleStream(new StreamImpl("UNKNOWN", "stream2"), new ArrayList<>(), new HashMap<>(), executor).getFuture();
AssertExtensions.assertFutureThrows("Should throw Exception", scaleStream, throwable -> true);
scaleStream = controllerClient.scaleStream(new StreamImpl("scope1", "UNKNOWN"), new ArrayList<>(), new HashMap<>(), executor).getFuture();
AssertExtensions.assertFutureThrows("Should throw Exception", scaleStream, throwable -> true);
}
use of io.pravega.client.segment.impl.Segment in project pravega by pravega.
the class ControllerImplTest method testGetCurrentSegments.
@Test
public void testGetCurrentSegments() throws Exception {
CompletableFuture<StreamSegments> streamSegments;
streamSegments = controllerClient.getCurrentSegments("scope1", "stream1");
assertTrue(streamSegments.get().getSegments().size() == 2);
assertEquals(new Segment("scope1", "stream1", 6), streamSegments.get().getSegmentForKey(0.2));
assertEquals(new Segment("scope1", "stream1", 7), streamSegments.get().getSegmentForKey(0.6));
streamSegments = controllerClient.getCurrentSegments("scope1", "stream2");
AssertExtensions.assertFutureThrows("Should throw Exception", streamSegments, throwable -> true);
streamSegments = controllerClient.getCurrentSegments("scope1", "sealedStream");
assertTrue(streamSegments.get().getNumberOfSegments() == 0);
}
use of io.pravega.client.segment.impl.Segment in project pravega by pravega.
the class ModelHelperTest method encodeSegmentId.
@Test
public void encodeSegmentId() {
Segment segment = ModelHelper.encode(decode(createSegmentId("stream1", 2L)));
assertEquals("stream1", segment.getStreamName());
assertEquals("scope", segment.getScope());
assertEquals(2L, segment.getSegmentId());
}
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();
ExecutorServiceHelpers.shutdown(executorService);
assertTrue(success.get());
}
Aggregations