Search in sources :

Example 11 with EventStreamWriterMock

use of io.pravega.controller.mocks.EventStreamWriterMock in project pravega by pravega.

the class TimeoutServiceTest method testPingOwnershipTransfer.

@Test(timeout = 30000)
public void testPingOwnershipTransfer() throws Exception {
    StreamMetadataStore streamStore2 = getStore();
    HostControllerStore hostStore = HostStoreFactory.createInMemoryStore(HostMonitorConfigImpl.dummyConfig());
    BucketStore bucketStore = StreamStoreFactory.createInMemoryBucketStore();
    TaskMetadataStore taskMetadataStore = TaskStoreFactory.createStore(PRAVEGA_ZK_CURATOR_RESOURCE.storeClient, executor);
    SegmentHelper helperMock = SegmentHelperMock.getSegmentHelperMock();
    @Cleanup StreamMetadataTasks streamMetadataTasks2 = new StreamMetadataTasks(streamStore2, bucketStore, taskMetadataStore, helperMock, executor, "2", GrpcAuthHelper.getDisabledAuthHelper());
    @Cleanup StreamTransactionMetadataTasks streamTransactionMetadataTasks2 = new StreamTransactionMetadataTasks(streamStore2, helperMock, executor, "2", TimeoutServiceConfig.defaultConfig(), new LinkedBlockingQueue<>(5), GrpcAuthHelper.getDisabledAuthHelper());
    streamTransactionMetadataTasks2.initializeStreamWriters(new EventStreamWriterMock<>(), new EventStreamWriterMock<>());
    // Create TimeoutService
    TimerWheelTimeoutService timeoutService2 = (TimerWheelTimeoutService) streamTransactionMetadataTasks2.getTimeoutService();
    ControllerService controllerService2 = new ControllerService(kvtStore, kvtMetadataTasks, streamStore2, bucketStore, streamMetadataTasks2, streamTransactionMetadataTasks2, helperMock, executor, null, requestTracker);
    UUID txnId = controllerService.createTransaction(SCOPE, STREAM, LEASE, 9L).thenApply(x -> x.getKey()).join();
    VersionedTransactionData txnData = streamStore.getTransactionData(SCOPE, STREAM, txnId, null, executor).join();
    Assert.assertEquals(txnData.getVersion(), getVersion(0));
    Optional<Throwable> result = timeoutService.getTaskCompletionQueue().poll((long) (0.75 * LEASE), TimeUnit.MILLISECONDS);
    Assert.assertNull(result);
    TxnState txnState = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId, 9L).join();
    Assert.assertEquals(TxnState.State.OPEN, txnState.getState());
    // increasing lease -> total effective lease = 3 * LEASE
    PingTxnStatus pingStatus = controllerService2.pingTransaction(SCOPE, STREAM, txnId, 2 * LEASE, 9L).join();
    Assert.assertEquals(PingTxnStatus.Status.OK, pingStatus.getStatus());
    txnData = streamStore.getTransactionData(SCOPE, STREAM, txnId, null, executor).join();
    Assert.assertEquals(txnData.getVersion(), getVersion(1));
    // timeoutService1 should believe that LEASE has expired and should get non empty completion tasks
    result = timeoutService.getTaskCompletionQueue().poll((long) (1.3 * LEASE + RETRY_DELAY), TimeUnit.MILLISECONDS);
    Assert.assertNotNull(result);
    // the txn may have been attempted to be aborted by timeoutService1 but would have failed. So txn to remain open
    txnState = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId, 9L).join();
    Assert.assertEquals(TxnState.State.OPEN, txnState.getState());
    // timeoutService2 should continue to wait on lease expiry and should get empty completion tasks
    result = timeoutService2.getTaskCompletionQueue().poll(0L, TimeUnit.MILLISECONDS);
    Assert.assertNull(result);
    result = timeoutService2.getTaskCompletionQueue().poll(2 * LEASE + RETRY_DELAY, TimeUnit.MILLISECONDS);
    Assert.assertNotNull(result);
    // now txn should have moved to aborting because timeoutservice2 has initiated abort
    txnState = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId, 9L).join();
    Assert.assertEquals(TxnState.State.ABORTING, txnState.getState());
}
Also used : AssertExtensions(io.pravega.test.common.AssertExtensions) Cleanup(lombok.Cleanup) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) StoreException(io.pravega.controller.store.stream.StoreException) TaskMetadataStore(io.pravega.controller.store.task.TaskMetadataStore) After(org.junit.After) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) ClassRule(org.junit.ClassRule) PravegaZkCuratorResource(io.pravega.controller.PravegaZkCuratorResource) RequestTracker(io.pravega.common.tracing.RequestTracker) UUID(java.util.UUID) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) KVTableMetadataStore(io.pravega.controller.store.kvtable.KVTableMetadataStore) TxnId(io.pravega.controller.stream.api.grpc.v1.Controller.TxnId) Slf4j(lombok.extern.slf4j.Slf4j) CuratorFramework(org.apache.curator.framework.CuratorFramework) Config(io.pravega.controller.util.Config) RetryPolicy(org.apache.curator.RetryPolicy) TxnStatus(io.pravega.controller.store.stream.TxnStatus) VersionedTransactionData(io.pravega.controller.store.stream.VersionedTransactionData) Optional(java.util.Optional) StreamMetadataStore(io.pravega.controller.store.stream.StreamMetadataStore) EventStreamWriterMock(io.pravega.controller.mocks.EventStreamWriterMock) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) GrpcAuthHelper(io.pravega.controller.server.security.auth.GrpcAuthHelper) StreamMetrics(io.pravega.controller.metrics.StreamMetrics) StreamStoreFactory(io.pravega.controller.store.stream.StreamStoreFactory) TransactionMetrics(io.pravega.controller.metrics.TransactionMetrics) SegmentHelper(io.pravega.controller.server.SegmentHelper) Mock(org.mockito.Mock) Exceptions(io.pravega.common.Exceptions) TxnState(io.pravega.controller.stream.api.grpc.v1.Controller.TxnState) CompletableFuture(java.util.concurrent.CompletableFuture) BucketStore(io.pravega.controller.store.stream.BucketStore) RetryOneTime(org.apache.curator.retry.RetryOneTime) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StreamMetadataTasks(io.pravega.controller.task.Stream.StreamMetadataTasks) HostMonitorConfigImpl(io.pravega.controller.store.host.impl.HostMonitorConfigImpl) Before(org.junit.Before) ControllerService(io.pravega.controller.server.ControllerService) SegmentHelperMock(io.pravega.controller.mocks.SegmentHelperMock) Test(org.junit.Test) TableMetadataTasks(io.pravega.controller.task.KeyValueTable.TableMetadataTasks) HostStoreFactory(io.pravega.controller.store.host.HostStoreFactory) TimeUnit(java.util.concurrent.TimeUnit) TaskStoreFactory(io.pravega.controller.store.task.TaskStoreFactory) Version(io.pravega.controller.store.Version) HostControllerStore(io.pravega.controller.store.host.HostControllerStore) StreamTransactionMetadataTasks(io.pravega.controller.task.Stream.StreamTransactionMetadataTasks) State(io.pravega.controller.store.stream.State) ExecutorServiceHelpers(io.pravega.common.concurrent.ExecutorServiceHelpers) Assert(org.junit.Assert) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) TaskMetadataStore(io.pravega.controller.store.task.TaskMetadataStore) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) StreamMetadataStore(io.pravega.controller.store.stream.StreamMetadataStore) SegmentHelper(io.pravega.controller.server.SegmentHelper) VersionedTransactionData(io.pravega.controller.store.stream.VersionedTransactionData) TxnState(io.pravega.controller.stream.api.grpc.v1.Controller.TxnState) Cleanup(lombok.Cleanup) ControllerService(io.pravega.controller.server.ControllerService) HostControllerStore(io.pravega.controller.store.host.HostControllerStore) StreamTransactionMetadataTasks(io.pravega.controller.task.Stream.StreamTransactionMetadataTasks) BucketStore(io.pravega.controller.store.stream.BucketStore) StreamMetadataTasks(io.pravega.controller.task.Stream.StreamMetadataTasks) UUID(java.util.UUID) Test(org.junit.Test)

Example 12 with EventStreamWriterMock

use of io.pravega.controller.mocks.EventStreamWriterMock in project pravega by pravega.

the class TimeoutServiceTest method setUp.

@Before
public void setUp() throws Exception {
    final String hostId = "host";
    // Initialize the executor service.
    executor = ExecutorServiceHelpers.newScheduledThreadPool(5, "test");
    segmentHelper = getSegmentHelper();
    streamStore = getStore();
    HostControllerStore hostStore = HostStoreFactory.createInMemoryStore(HostMonitorConfigImpl.dummyConfig());
    TaskMetadataStore taskMetadataStore = TaskStoreFactory.createStore(PRAVEGA_ZK_CURATOR_RESOURCE.storeClient, executor);
    StreamMetrics.initialize();
    TransactionMetrics.initialize();
    streamMetadataTasks = new StreamMetadataTasks(streamStore, StreamStoreFactory.createInMemoryBucketStore(), taskMetadataStore, SegmentHelperMock.getSegmentHelperMock(), executor, hostId, GrpcAuthHelper.getDisabledAuthHelper());
    streamTransactionMetadataTasks = new StreamTransactionMetadataTasks(streamStore, SegmentHelperMock.getSegmentHelperMock(), executor, hostId, TimeoutServiceConfig.defaultConfig(), new LinkedBlockingQueue<>(5), GrpcAuthHelper.getDisabledAuthHelper());
    streamTransactionMetadataTasks.initializeStreamWriters(new EventStreamWriterMock<>(), new EventStreamWriterMock<>());
    // Create TimeoutService
    timeoutService = (TimerWheelTimeoutService) streamTransactionMetadataTasks.getTimeoutService();
    BucketStore bucketStore = StreamStoreFactory.createInMemoryBucketStore();
    controllerService = new ControllerService(kvtStore, kvtMetadataTasks, streamStore, bucketStore, streamMetadataTasks, streamTransactionMetadataTasks, SegmentHelperMock.getSegmentHelperMock(), executor, null, requestTracker);
    // Create scope and stream
    streamStore.createScope(SCOPE, null, executor).join();
    StreamConfiguration streamConfiguration = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build();
    streamStore.createStream(SCOPE, STREAM, streamConfiguration, System.currentTimeMillis(), null, executor).thenCompose(x -> streamStore.setState(SCOPE, STREAM, State.ACTIVE, null, executor)).join();
}
Also used : AssertExtensions(io.pravega.test.common.AssertExtensions) Cleanup(lombok.Cleanup) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) StoreException(io.pravega.controller.store.stream.StoreException) TaskMetadataStore(io.pravega.controller.store.task.TaskMetadataStore) After(org.junit.After) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) ClassRule(org.junit.ClassRule) PravegaZkCuratorResource(io.pravega.controller.PravegaZkCuratorResource) RequestTracker(io.pravega.common.tracing.RequestTracker) UUID(java.util.UUID) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) KVTableMetadataStore(io.pravega.controller.store.kvtable.KVTableMetadataStore) TxnId(io.pravega.controller.stream.api.grpc.v1.Controller.TxnId) Slf4j(lombok.extern.slf4j.Slf4j) CuratorFramework(org.apache.curator.framework.CuratorFramework) Config(io.pravega.controller.util.Config) RetryPolicy(org.apache.curator.RetryPolicy) TxnStatus(io.pravega.controller.store.stream.TxnStatus) VersionedTransactionData(io.pravega.controller.store.stream.VersionedTransactionData) Optional(java.util.Optional) StreamMetadataStore(io.pravega.controller.store.stream.StreamMetadataStore) EventStreamWriterMock(io.pravega.controller.mocks.EventStreamWriterMock) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) GrpcAuthHelper(io.pravega.controller.server.security.auth.GrpcAuthHelper) StreamMetrics(io.pravega.controller.metrics.StreamMetrics) StreamStoreFactory(io.pravega.controller.store.stream.StreamStoreFactory) TransactionMetrics(io.pravega.controller.metrics.TransactionMetrics) SegmentHelper(io.pravega.controller.server.SegmentHelper) Mock(org.mockito.Mock) Exceptions(io.pravega.common.Exceptions) TxnState(io.pravega.controller.stream.api.grpc.v1.Controller.TxnState) CompletableFuture(java.util.concurrent.CompletableFuture) BucketStore(io.pravega.controller.store.stream.BucketStore) RetryOneTime(org.apache.curator.retry.RetryOneTime) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StreamMetadataTasks(io.pravega.controller.task.Stream.StreamMetadataTasks) HostMonitorConfigImpl(io.pravega.controller.store.host.impl.HostMonitorConfigImpl) Before(org.junit.Before) ControllerService(io.pravega.controller.server.ControllerService) SegmentHelperMock(io.pravega.controller.mocks.SegmentHelperMock) Test(org.junit.Test) TableMetadataTasks(io.pravega.controller.task.KeyValueTable.TableMetadataTasks) HostStoreFactory(io.pravega.controller.store.host.HostStoreFactory) TimeUnit(java.util.concurrent.TimeUnit) TaskStoreFactory(io.pravega.controller.store.task.TaskStoreFactory) Version(io.pravega.controller.store.Version) HostControllerStore(io.pravega.controller.store.host.HostControllerStore) StreamTransactionMetadataTasks(io.pravega.controller.task.Stream.StreamTransactionMetadataTasks) State(io.pravega.controller.store.stream.State) ExecutorServiceHelpers(io.pravega.common.concurrent.ExecutorServiceHelpers) Assert(org.junit.Assert) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) TaskMetadataStore(io.pravega.controller.store.task.TaskMetadataStore) HostControllerStore(io.pravega.controller.store.host.HostControllerStore) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) StreamTransactionMetadataTasks(io.pravega.controller.task.Stream.StreamTransactionMetadataTasks) StreamMetadataTasks(io.pravega.controller.task.Stream.StreamMetadataTasks) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) BucketStore(io.pravega.controller.store.stream.BucketStore) ControllerService(io.pravega.controller.server.ControllerService) Before(org.junit.Before)

Example 13 with EventStreamWriterMock

use of io.pravega.controller.mocks.EventStreamWriterMock in project pravega by pravega.

the class EventProcessorTest method testInitialize.

@Test(timeout = 10000)
public void testInitialize() throws ReinitializationRequiredException, CheckpointStoreException {
    String systemName = "testSystem";
    String readerGroupName = "testReaderGroup";
    EventStreamWriterMock<TestEvent> writer = new EventStreamWriterMock<>();
    int[] input = { 1, 2, 3, 4, 5 };
    CheckpointStore checkpointStore = CheckpointStoreFactory.createInMemoryStore();
    checkpointStore.addReaderGroup(PROCESS, readerGroupName);
    CheckpointConfig checkpointConfig = CheckpointConfig.builder().type(CheckpointConfig.Type.None).build();
    EventProcessorGroupConfig config = EventProcessorGroupConfigImpl.builder().eventProcessorCount(3).readerGroupName(READER_GROUP).streamName(STREAM_NAME).checkpointConfig(checkpointConfig).build();
    createEventProcessorGroupConfig(3);
    EventProcessorSystemImpl system = createMockSystem(systemName, PROCESS, SCOPE, createEventReaders(3, input), writer, readerGroupName);
    EventProcessorConfig<TestEvent> eventProcessorConfig = EventProcessorConfig.<TestEvent>builder().supplier(() -> new StartWritingEventProcessor(false, input)).serializer(new EventSerializer<>()).decider((Throwable e) -> ExceptionHandler.Directive.Stop).config(config).build();
    // Create EventProcessorGroup.
    @Cleanup EventProcessorGroupImpl<TestEvent> group = (EventProcessorGroupImpl<TestEvent>) system.createEventProcessorGroup(eventProcessorConfig, checkpointStore, executor);
    // test idempotent initialize
    group.initialize();
    group.initialize();
    // Await until it is ready.
    group.awaitRunning();
    group.initialize();
    assertEquals(3, group.getEventProcessorMap().values().size());
}
Also used : EventStreamWriterMock(io.pravega.controller.mocks.EventStreamWriterMock) CheckpointConfig(io.pravega.controller.eventProcessor.CheckpointConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CheckpointStore(io.pravega.controller.store.checkpoint.CheckpointStore) Cleanup(lombok.Cleanup) EventProcessorGroupConfig(io.pravega.controller.eventProcessor.EventProcessorGroupConfig) EventSerializer(io.pravega.controller.eventProcessor.EventSerializer) Test(org.junit.Test)

Example 14 with EventStreamWriterMock

use of io.pravega.controller.mocks.EventStreamWriterMock in project pravega by pravega.

the class EventProcessorTest method testEventProcessorWriter.

@Test(timeout = 10000)
public void testEventProcessorWriter() throws ReinitializationRequiredException, CheckpointStoreException {
    int initialCount = 1;
    String systemName = "testSystem";
    String readerGroupName = "testReaderGroup";
    int[] input = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    EventStreamWriterMock<TestEvent> writer = new EventStreamWriterMock<>();
    CheckpointStore checkpointStore = CheckpointStoreFactory.createInMemoryStore();
    checkpointStore.addReaderGroup(PROCESS, readerGroupName);
    CheckpointConfig checkpointConfig = CheckpointConfig.builder().type(CheckpointConfig.Type.None).build();
    EventProcessorGroupConfig config = EventProcessorGroupConfigImpl.builder().eventProcessorCount(1).readerGroupName(READER_GROUP).streamName(STREAM_NAME).checkpointConfig(checkpointConfig).build();
    createEventProcessorGroupConfig(initialCount);
    EventProcessorSystemImpl system = createMockSystem(systemName, PROCESS, SCOPE, createEventReaders(1, input), writer, readerGroupName);
    EventProcessorConfig<TestEvent> eventProcessorConfig = EventProcessorConfig.<TestEvent>builder().supplier(() -> new StartWritingEventProcessor(false, input)).serializer(new EventSerializer<>()).decider((Throwable e) -> ExceptionHandler.Directive.Stop).config(config).build();
    // Create EventProcessorGroup.
    @Cleanup EventProcessorGroupImpl<TestEvent> group = (EventProcessorGroupImpl<TestEvent>) system.createEventProcessorGroup(eventProcessorConfig, checkpointStore, executor);
    // Await until it is ready.
    group.awaitRunning();
    // By now, the events have been written to the Mock EventStreamWriter.
    Integer[] writerList = writer.getEventList().stream().map(TestEvent::getNumber).collect(Collectors.toList()).toArray(new Integer[input.length]);
    // Validate that events are correctly written.
    Assert.assertArrayEquals(input, ArrayUtils.toPrimitive(writerList));
}
Also used : EventStreamWriterMock(io.pravega.controller.mocks.EventStreamWriterMock) CheckpointConfig(io.pravega.controller.eventProcessor.CheckpointConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CheckpointStore(io.pravega.controller.store.checkpoint.CheckpointStore) Cleanup(lombok.Cleanup) EventProcessorGroupConfig(io.pravega.controller.eventProcessor.EventProcessorGroupConfig) EventSerializer(io.pravega.controller.eventProcessor.EventSerializer) Test(org.junit.Test)

Aggregations

EventStreamWriterMock (io.pravega.controller.mocks.EventStreamWriterMock)14 Test (org.junit.Test)13 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)9 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)9 UUID (java.util.UUID)9 GrpcAuthHelper (io.pravega.controller.server.security.auth.GrpcAuthHelper)8 VersionedTransactionData (io.pravega.controller.store.stream.VersionedTransactionData)8 CommitEvent (io.pravega.shared.controller.event.CommitEvent)8 StreamMetadataStore (io.pravega.controller.store.stream.StreamMetadataStore)7 AbortEvent (io.pravega.shared.controller.event.AbortEvent)7 StoreException (io.pravega.controller.store.stream.StoreException)6 ControllerService (io.pravega.controller.server.ControllerService)5 TxnStatus (io.pravega.controller.store.stream.TxnStatus)5 ArrayList (java.util.ArrayList)5 Cleanup (lombok.Cleanup)5 Exceptions (io.pravega.common.Exceptions)4 ExecutorServiceHelpers (io.pravega.common.concurrent.ExecutorServiceHelpers)4 RequestTracker (io.pravega.common.tracing.RequestTracker)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)4