use of io.pravega.controller.store.stream.records.StreamTruncationRecord in project pravega by pravega.
the class StreamMetadataTasksTest method checkTruncateCompleteTest.
@Test(timeout = 10000)
public void checkTruncateCompleteTest() throws ExecutionException, InterruptedException {
final ScalingPolicy policy = ScalingPolicy.fixed(1);
final StreamConfiguration configuration = StreamConfiguration.builder().scalingPolicy(policy).build();
String test = "testTruncate";
streamStorePartialMock.createStream(SCOPE, test, configuration, System.currentTimeMillis(), null, executor).get();
streamStorePartialMock.setState(SCOPE, test, State.ACTIVE, null, executor).get();
streamMetadataTasks.setRequestEventWriter(new EventStreamWriterMock<>());
// region truncate
Map<Long, Long> map = Collections.singletonMap(0L, 1L);
streamMetadataTasks.truncateStream(SCOPE, test, map, 0L);
// wait till configuration is updated
Supplier<Boolean> truncationStarted = () -> !streamStorePartialMock.getTruncationRecord(SCOPE, test, null, executor).join().getObject().isUpdating();
Futures.loop(truncationStarted, () -> Futures.delayedFuture(Duration.ofMillis(100), executor), executor).join();
streamStorePartialMock.setState(SCOPE, test, State.TRUNCATING, null, executor).join();
assertFalse(streamMetadataTasks.isTruncated(SCOPE, test, map, null).get());
VersionedMetadata<StreamTruncationRecord> truncationRecord = streamStorePartialMock.getTruncationRecord(SCOPE, test, null, executor).join();
assertTrue(truncationRecord.getObject().isUpdating());
streamStorePartialMock.completeTruncation(SCOPE, test, truncationRecord, null, executor).join();
assertFalse(streamMetadataTasks.isTruncated(SCOPE, test, map, null).get());
streamStorePartialMock.setState(SCOPE, test, State.ACTIVE, null, executor).join();
assertTrue(streamMetadataTasks.isTruncated(SCOPE, test, map, null).get());
// start next update with different configuration.
Map<Long, Long> map2 = Collections.singletonMap(0L, 10L);
streamMetadataTasks.truncateStream(SCOPE, test, map2, 0L);
Futures.loop(truncationStarted, () -> Futures.delayedFuture(Duration.ofMillis(100), executor), executor).join();
streamStorePartialMock.setState(SCOPE, test, State.TRUNCATING, null, executor).join();
// we should still get complete for previous configuration we attempted to update
assertTrue(streamMetadataTasks.isTruncated(SCOPE, test, map, null).get());
assertFalse(streamMetadataTasks.isTruncated(SCOPE, test, map2, null).get());
// test truncate on a sealed stream
String testStream = "testTruncateSealed";
streamStorePartialMock.createStream(SCOPE, testStream, configuration, System.currentTimeMillis(), null, executor).get();
streamStorePartialMock.setState(SCOPE, testStream, State.ACTIVE, null, executor).get();
streamMetadataTasks.setRequestEventWriter(new EventStreamWriterMock<>());
// region truncate
map = Collections.singletonMap(0L, 1L);
streamMetadataTasks.truncateStream(SCOPE, testStream, map, 0L);
truncationStarted = () -> !streamStorePartialMock.getTruncationRecord(SCOPE, testStream, null, executor).join().getObject().isUpdating();
Futures.loop(truncationStarted, () -> Futures.delayedFuture(Duration.ofMillis(100), executor), executor).join();
truncationRecord = streamStorePartialMock.getTruncationRecord(SCOPE, testStream, null, executor).join();
assertTrue(truncationRecord.getObject().isUpdating());
streamStorePartialMock.completeTruncation(SCOPE, testStream, truncationRecord, null, executor).join();
streamStorePartialMock.setState(SCOPE, testStream, State.SEALED, null, executor).join();
assertFutureThrows("Should throw UnsupportedOperationException", streamMetadataTasks.isTruncated(SCOPE, testStream, map, null), e -> UnsupportedOperationException.class.isAssignableFrom(e.getClass()));
// end region
}
use of io.pravega.controller.store.stream.records.StreamTruncationRecord in project pravega by pravega.
the class PersistentStreamBase method completeTruncation.
@Override
public CompletableFuture<Void> completeTruncation(VersionedMetadata<StreamTruncationRecord> record, OperationContext context) {
Preconditions.checkNotNull(context, "operation context cannot be null");
Preconditions.checkNotNull(record);
Preconditions.checkArgument(record.getObject().isUpdating());
StreamTruncationRecord current = record.getObject();
if (current.isUpdating()) {
StreamTruncationRecord completedProp = StreamTruncationRecord.complete(current);
return Futures.toVoid(setTruncationData(new VersionedMetadata<>(completedProp, record.getVersion()), context));
} else {
// idempotent
return CompletableFuture.completedFuture(null);
}
}
use of io.pravega.controller.store.stream.records.StreamTruncationRecord in project pravega by pravega.
the class StreamMetadataStoreTest method truncationTest.
@Test(timeout = 30000)
public void truncationTest() throws Exception {
final String scope = "ScopeTruncate";
final String stream = "ScopeTruncate";
final ScalingPolicy policy = ScalingPolicy.fixed(2);
final StreamConfiguration configuration = StreamConfiguration.builder().scalingPolicy(policy).build();
long start = System.currentTimeMillis();
store.createScope(scope, null, executor).get();
store.createStream(scope, stream, configuration, start, null, executor).get();
store.setState(scope, stream, State.ACTIVE, null, executor).get();
Map<Long, Long> truncation = new HashMap<>();
truncation.put(0L, 0L);
truncation.put(1L, 0L);
assertTrue(Futures.await(store.startTruncation(scope, stream, truncation, null, executor)));
store.setState(scope, stream, State.TRUNCATING, null, executor).join();
StreamTruncationRecord truncationProperty = store.getTruncationRecord(scope, stream, null, executor).join().getObject();
assertTrue(truncationProperty.isUpdating());
Map<Long, Long> truncation2 = new HashMap<>();
truncation2.put(0L, 1L);
truncation2.put(1L, 1L);
assertFalse(Futures.await(store.startTruncation(scope, stream, truncation2, null, executor)));
VersionedMetadata<StreamTruncationRecord> record = store.getTruncationRecord(scope, stream, null, executor).join();
assertTrue(Futures.await(store.completeTruncation(scope, stream, record, null, executor)));
truncationProperty = store.getTruncationRecord(scope, stream, null, executor).join().getObject();
assertEquals(truncation, truncationProperty.getStreamCut());
assertTrue(truncationProperty.getSpan().size() == 2);
Map<Long, Long> truncation3 = new HashMap<>();
truncation3.put(0L, 2L);
truncation3.put(1L, 2L);
assertTrue(Futures.await(store.startTruncation(scope, stream, truncation3, null, executor)));
record = store.getTruncationRecord(scope, stream, null, executor).join();
assertTrue(Futures.await(store.completeTruncation(scope, stream, record, null, executor)));
store.setState(scope, stream, State.ACTIVE, null, executor).join();
}
use of io.pravega.controller.store.stream.records.StreamTruncationRecord in project pravega by pravega.
the class StreamTestBase method testCreateStream.
@Test(timeout = 30000L)
public void testCreateStream() {
OperationContext context = getContext();
PersistentStreamBase stream = createStream("scope", "stream", System.currentTimeMillis(), 2, 0);
assertEquals(State.ACTIVE, stream.getState(true, context).join());
EpochRecord activeEpoch = stream.getActiveEpoch(true, context).join();
assertEquals(0, activeEpoch.getEpoch());
assertEquals(2, activeEpoch.getSegments().size());
VersionedMetadata<StreamTruncationRecord> truncationRecord = stream.getTruncationRecord(context).join();
assertEquals(StreamTruncationRecord.EMPTY, truncationRecord.getObject());
VersionedMetadata<EpochTransitionRecord> etr = stream.getEpochTransition(context).join();
assertEquals(EpochTransitionRecord.EMPTY, etr.getObject());
VersionedMetadata<CommittingTransactionsRecord> ctr = stream.getVersionedCommitTransactionsRecord(context).join();
assertEquals(CommittingTransactionsRecord.EMPTY, ctr.getObject());
assertEquals(activeEpoch, stream.getEpochRecord(0, context).join());
AssertExtensions.assertFutureThrows("", stream.getEpochRecord(1, context), e -> Exceptions.unwrap(e) instanceof StoreException.DataNotFoundException);
}
Aggregations