Search in sources :

Example 1 with SegmentWithRange

use of io.pravega.client.stream.impl.SegmentWithRange in project pravega by pravega.

the class ModelHelperTest method encodeSegmentWithRange.

@Test
public void encodeSegmentWithRange() {
    SegmentWithRange segment = ModelHelper.encode(createSegmentRange(.25, .75));
    assertEquals("testStream", segment.getSegment().getStreamName());
    assertEquals("testScope", segment.getSegment().getScope());
    assertEquals(.25, segment.getRange().getLow(), 0.0);
    assertEquals(.75, segment.getRange().getHigh(), 0.0);
}
Also used : SegmentWithRange(io.pravega.client.stream.impl.SegmentWithRange) Test(org.junit.Test)

Example 2 with SegmentWithRange

use of io.pravega.client.stream.impl.SegmentWithRange in project pravega by pravega.

the class KeyValueTableSegmentsTests method createSegmentMap.

private TreeMap<Double, SegmentWithRange> createSegmentMap() {
    final int rangeIncrease = 10;
    int totalRangeLength = 0;
    val ranges = new ArrayList<Integer>();
    for (int i = 0; i < SEGMENT_COUNT; i++) {
        int rangeLength = (ranges.size() == 0 ? 0 : ranges.get(i - 1)) + rangeIncrease;
        ranges.add(rangeLength);
        totalRangeLength += rangeLength;
    }
    val result = new TreeMap<Double, SegmentWithRange>();
    int rangeLow = 0;
    for (int i = 0; i < ranges.size(); i++) {
        int rangeLength = ranges.get(i);
        int rangeHigh = rangeLow + rangeLength;
        val segment = new Segment(SCOPE_NAME, STREAM_NAME, i);
        val segmentWithRange = new SegmentWithRange(segment, (double) rangeLow / totalRangeLength, (double) rangeHigh / totalRangeLength);
        result.put(segmentWithRange.getRange().getHigh(), segmentWithRange);
        rangeLow = rangeHigh;
    }
    return result;
}
Also used : lombok.val(lombok.val) ArrayList(java.util.ArrayList) SegmentWithRange(io.pravega.client.stream.impl.SegmentWithRange) TreeMap(java.util.TreeMap) Segment(io.pravega.client.segment.impl.Segment)

Example 3 with SegmentWithRange

use of io.pravega.client.stream.impl.SegmentWithRange in project pravega by pravega.

the class AbstractControllerMetadataCommandsTest method testControllerMetadataViewReaderInfoCommand.

@Test
public void testControllerMetadataViewReaderInfoCommand() throws Exception {
    final String process = UUID.randomUUID().toString();
    final String readerGroup = UUID.randomUUID().toString();
    final String reader = UUID.randomUUID().toString();
    ZKHelper zkHelper = ZKHelper.create(SETUP_UTILS.getZkTestServer().getConnectString(), "pravega-cluster");
    CheckpointStore checkpointStore = zkHelper.getCheckPointStore();
    checkpointStore.addReaderGroup(process, readerGroup);
    checkpointStore.addReader(process, readerGroup, reader);
    Position position = new PositionImpl(ImmutableMap.of(new SegmentWithRange(Segment.fromScopedName("testScope/testStream/0"), 0, 0.5), 9999999L, new SegmentWithRange(Segment.fromScopedName("testScope/testStream/1"), 0.5, 1.0), -1L));
    checkpointStore.setPosition(process, readerGroup, reader, position);
    String commandResult = TestUtils.executeCommand("controller-metadata get-reader " + process + " " + readerGroup + " " + reader, STATE.get());
    Assert.assertTrue(commandResult.contains("testScope/testStream"));
}
Also used : ZKHelper(io.pravega.cli.admin.utils.ZKHelper) Position(io.pravega.client.stream.Position) PositionImpl(io.pravega.client.stream.impl.PositionImpl) SegmentWithRange(io.pravega.client.stream.impl.SegmentWithRange) CheckpointStore(io.pravega.controller.store.checkpoint.CheckpointStore) Test(org.junit.Test)

Example 4 with SegmentWithRange

use of io.pravega.client.stream.impl.SegmentWithRange in project pravega by pravega.

the class ReaderGroupManagerImplTest method testCreateReaderGroupWithNewConfig.

@Test
public void testCreateReaderGroupWithNewConfig() {
    ReaderGroupConfig config = ReaderGroupConfig.builder().startFromStreamCuts(ImmutableMap.<Stream, StreamCut>builder().put(createStream("s2"), createStreamCut("s2", 0)).build()).retentionType(ReaderGroupConfig.StreamDataRetention.MANUAL_RELEASE_AT_USER_STREAMCUT).build();
    ReaderGroupConfig expectedConfig = ReaderGroupConfig.cloneConfig(config, UUID.randomUUID(), 0L);
    when(controller.createReaderGroup(anyString(), anyString(), any(ReaderGroupConfig.class))).thenReturn(CompletableFuture.completedFuture(expectedConfig));
    // Create a ReaderGroup
    ReaderGroupConfig newConfig = ReaderGroupConfig.builder().stream(createStream("s1"), createStreamCut("s1", 2)).build();
    assertThrows(ConfigMismatchException.class, () -> readerGroupManager.createReaderGroup(GROUP_NAME, newConfig));
    verify(clientFactory, never()).createStateSynchronizer(anyString(), any(Serializer.class), any(Serializer.class), any(SynchronizerConfig.class));
    Map<SegmentWithRange, Long> segments = ImmutableMap.<SegmentWithRange, Long>builder().put(new SegmentWithRange(new Segment(SCOPE, "s2", 0), 0.0, 1.0), 10L).build();
    ReaderGroupState.ReaderGroupStateInit initState = new ReaderGroupState.ReaderGroupStateInit(expectedConfig, segments, new HashMap<>(), false);
    verify(synchronizer, never()).initialize(initState);
}
Also used : ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) SegmentWithRange(io.pravega.client.stream.impl.SegmentWithRange) ReaderGroupState(io.pravega.client.stream.impl.ReaderGroupState) SynchronizerConfig(io.pravega.client.state.SynchronizerConfig) Segment(io.pravega.client.segment.impl.Segment) Serializer(io.pravega.client.stream.Serializer) Test(org.junit.Test)

Example 5 with SegmentWithRange

use of io.pravega.client.stream.impl.SegmentWithRange in project pravega by pravega.

the class MockController method getSegmentsWithRanges.

@Synchronized
List<SegmentWithRange> getSegmentsWithRanges(Stream stream) {
    StreamConfiguration config = getStreamConfig(stream);
    Preconditions.checkArgument(config != null, "Stream must be created first");
    ScalingPolicy scalingPolicy = config.getScalingPolicy();
    if (scalingPolicy.getScaleType() != ScalingPolicy.ScaleType.FIXED_NUM_SEGMENTS) {
        throw new IllegalArgumentException("Dynamic scaling not supported with a mock controller");
    }
    List<SegmentWithRange> result = new ArrayList<>();
    for (int i = 0; i < scalingPolicy.getMinNumSegments(); i++) {
        result.add(createRange(stream.getScope(), stream.getStreamName(), scalingPolicy.getMinNumSegments(), i));
    }
    return result;
}
Also used : ScalingPolicy(io.pravega.client.stream.ScalingPolicy) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) ArrayList(java.util.ArrayList) SegmentWithRange(io.pravega.client.stream.impl.SegmentWithRange) Synchronized(lombok.Synchronized)

Aggregations

SegmentWithRange (io.pravega.client.stream.impl.SegmentWithRange)15 Segment (io.pravega.client.segment.impl.Segment)8 TreeMap (java.util.TreeMap)7 StreamSegments (io.pravega.client.stream.impl.StreamSegments)5 SegmentRange (io.pravega.controller.stream.api.grpc.v1.Controller.SegmentRange)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)3 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)3 TxnSegments (io.pravega.client.stream.impl.TxnSegments)3 KeyValueTableSegments (io.pravega.client.tables.impl.KeyValueTableSegments)3 Map (java.util.Map)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Preconditions (com.google.common.base.Preconditions)2 Strings (com.google.common.base.Strings)2 ManagedChannel (io.grpc.ManagedChannel)2 ManagedChannelBuilder (io.grpc.ManagedChannelBuilder)2 Code (io.grpc.Status.Code)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2 MoreCallCredentials (io.grpc.auth.MoreCallCredentials)2