Search in sources :

Example 46 with Segment

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);
}
Also used : StreamImpl(io.pravega.client.stream.impl.StreamImpl) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Segment(io.pravega.client.segment.impl.Segment) Test(org.junit.Test)

Example 47 with Segment

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);
}
Also used : StreamImpl(io.pravega.client.stream.impl.StreamImpl) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) StreamSegments(io.pravega.client.stream.impl.StreamSegments) Segment(io.pravega.client.segment.impl.Segment) Test(org.junit.Test)

Example 48 with Segment

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

Example 49 with Segment

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

Example 50 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();
    ExecutorServiceHelpers.shutdown(executorService);
    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) StreamSegments(io.pravega.client.stream.impl.StreamSegments) Segment(io.pravega.client.segment.impl.Segment) NoSuchScopeException(io.pravega.client.stream.NoSuchScopeException) PingFailedException(io.pravega.client.stream.PingFailedException) IOException(java.io.IOException) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) TxnFailedException(io.pravega.client.stream.TxnFailedException) RetriesExhaustedException(io.pravega.common.util.RetriesExhaustedException) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) 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