예제 #1
0
        public void RepeatingTimer_Overflow2()
        {
            ISubscription    sub     = null;
            IOperatorContext context = Scheduler.CreateContext();

            var state       = Scheduler.CreateStateContainer();
            var checkpoints = new[]
            {
                OnSave(152, state)
            };

            // Create new subscription allow the timer to fire twice.
            var res1 = Scheduler.CreateObserver <long>();

            Scheduler.ScheduleAbsolute(100, () => { sub = Subscribable.Timer(TimeSpan.MinValue).Apply(Scheduler, checkpoints).Subscribe(res1, context); });
            Scheduler.ScheduleAbsolute(155, () => sub.Dispose());

            // Create new subscription and load the state.
            var res2 = Scheduler.CreateObserver <long>();

            Scheduler.ScheduleAbsolute(200, () => sub = Subscribable.Timer(TimeSpan.MinValue).Subscribe(res2, context, state));
            Scheduler.ScheduleAbsolute(255, () => sub.Dispose());

            Scheduler.Start();

            res1.Messages.AssertEqual(
                new[]
            {
                OnNext(100, 0L),
                OnCompleted(100, 0L),
            });
            res2.Messages.AssertEqual(Array.Empty <Recorded <Notification <long> > >());
        }
예제 #2
0
            /// <summary>
            /// Sets the operator's context as passed through all Operators of the current subscription in IRP.
            /// </summary>
            /// <param name="context">The context being passed.</param>
            public override void SetContext(IOperatorContext context)
            {
                Debug.Assert(context != null, "MockWeatherAlertSubscription expecting a non-null operator context.");

                context.TraceSource.TraceInformation("MockWeatherAlertSubscription IOperatorContext received.");
                _operatorContext = context;
            }
예제 #3
0
 public void SetContext(IOperatorContext context)
 {
     if (_asOperator != null)
     {
         _asOperator.SetContext(context);
     }
 }
예제 #4
0
        public override void SetContext(IOperatorContext context)
        {
            base.SetContext(context);

            _uri     = context.InstanceId;
            _manager = new Manager(this);
        }
예제 #5
0
        /// <summary>
        /// Starts the test scheduler and uses the specified virtual time to create, subscribe and dispose the subscription to the sequence
        /// obtained through the factory function. Scheduler is passed to the subscription using the provided operator context.
        /// Default virtual times are used for <see cref="ReactiveTest.Created">factory invocation</see> and <see cref="ReactiveTest.Subscribed">sequence subscription</see>.
        /// </summary>
        /// <typeparam name="T">The element type of the observable sequence being tested.</typeparam>
        /// <param name="scheduler">The scheduler.</param>
        /// <param name="context">The context.</param>
        /// <param name="create">Factory method to create an observable sequence.</param>
        /// <param name="created">The created time.</param>
        /// <param name="subscribed">The subscribed time.</param>
        /// <param name="disposed">Virtual time at which to dispose the subscription.</param>
        /// <param name="recovery">Optional state container to reload state from at subscription time.</param>
        /// <returns>
        /// Observer with timestamped recordings of notification messages that were received during the virtual time window when the subscription to the source sequence was active.
        /// </returns>
        public static ITestableObserver <T> Start <T>(
            this TestScheduler scheduler,
            IOperatorContext context,
            Func <ISubscribable <T> > create,
            long created,
            long subscribed,
            long disposed,
            IOperatorStateContainer recovery = null)
        {
            if (scheduler == null)
            {
                throw new ArgumentNullException(nameof(scheduler));
            }

            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (create == null)
            {
                throw new ArgumentNullException(nameof(create));
            }

            if (created > subscribed)
            {
                throw new ArgumentOutOfRangeException(nameof(created));
            }

            if (subscribed > disposed)
            {
                throw new ArgumentOutOfRangeException(nameof(subscribed));
            }

            var source       = default(ISubscribable <T>);
            var subscription = default(ISubscription);
            var observer     = scheduler.CreateObserver <T>();

            scheduler.ScheduleAbsolute(default(object), created, (s, state) => source = create());
            scheduler.ScheduleAbsolute(
                default(object),
                subscribed,
                (s, state) =>
            {
                subscription = source.Subscribe(observer);

                var reader = default(IOperatorStateReaderFactory);

                if (recovery != null)
                {
                    reader = recovery.CreateReader();
                }

                new SubscriptionInitializeVisitor(subscription).Initialize(context, reader);
            });
            scheduler.ScheduleAbsolute(default(object), disposed, (s, state) => subscription.Dispose());
            scheduler.Start();
            return(observer);
        }
예제 #6
0
        private static void InitializeCore(ISubscription subscription, IOperatorContext context)
        {
            SubscribeCore(subscription);

            SetContextCore(subscription, context);

            StartCore(subscription);
        }
예제 #7
0
            public override void SetContext(IOperatorContext context)
            {
                base.SetContext(context);

                context.TryGetInt32CheckGreaterThanZeroOrUseMaxValue(MAXINNERSUBCOUNTSETTING, out _maxInnerCount);

                _context = context;
            }
예제 #8
0
        public override void SetContext(IOperatorContext context)
        {
            Debug.Assert(context != null);

            _scheduler = context.Scheduler;
            _id        = context.InstanceId;

            base.SetContext(context);
        }
예제 #9
0
            public override void SetContext(IOperatorContext context)
            {
                base.SetContext(context);

                if (!context.TryGetElement("StreamManager", out _streamManager))
                {
                    throw new InvalidOperationException("Need stream manager.");
                }
            }
예제 #10
0
                public override void SetContext(IOperatorContext context)
                {
                    if (!Params._onSubscribe)
                    {
                        Params._exception();
                    }

                    context.Scheduler.Schedule(new ActionTask(() => Output.OnError(new NotSupportedException())));
                }
예제 #11
0
        /// <summary>
        /// Initializes the operators in the <paramref name="subscription"/> by setting the specified operator context and starting the operators.
        /// </summary>
        /// <param name="subscription">The subscription to initialize and start.</param>
        /// <param name="context">Operator context to set on the operators in the subscription.</param>
        public static void Initialize(ISubscription subscription, IOperatorContext context)
        {
            if (subscription == null)
            {
                throw new ArgumentNullException(nameof(subscription));
            }

            InitializeCore(subscription, context);
        }
예제 #12
0
 public void SetContext(IOperatorContext context)
 {
     Debug.Assert(context != null);
     context.TryGetElement <TestObserverStoreConnection>(
         TestObserverStoreConnection.ContextHandle,
         out _observerStore);
     Debug.Assert(_observerStore != null);
     Recorder.Scheduler = context.Scheduler;
 }
            public override void SetContext(IOperatorContext context)
            {
                Assert.IsFalse(IsDisposed);
                Assert.AreEqual(1, subscribed);
                Assert.AreEqual(0, Interlocked.Exchange(ref contextSet, 1));
                Assert.AreEqual(0, started);
                Assert.AreEqual(0, stateSavedOnce);

                base.SetContext(context);
            }
예제 #14
0
 /// <summary>
 /// Sets the operator context for the timeline observable.
 /// </summary>
 /// <param name="context">The operator context.</param>
 /// <remarks>
 /// This operator is only expected to work with the remoting
 /// framework, specifically, a test query evaluator implementation
 /// designed to enable this operator.
 /// </remarks>
 public override void SetContext(IOperatorContext context)
 {
     _scheduler = (ITestScheduler)context.Scheduler;
     context.TryGetElement <TimelineStoreConnection>(TimelineStoreConnection.ContextHandle, out var eventTimelines);
     Debug.Assert(eventTimelines != null);
     eventTimelines.TryGetValue(Params._uri.ToCanonicalString(), out _events);
     context.TryGetElement <TestSubscriptionStoreConnection>(TestSubscriptionStoreConnection.ContextHandle, out _subscriptionStore);
     Debug.Assert(_subscriptionStore != null);
     base.SetContext(context);
 }
예제 #15
0
 public override void SetContext(IOperatorContext context)
 {
     if (!context.TryGetElement <MessageRouter>(MessageRouter.ContextHandle, out var messageRouter))
     {
         throw new InvalidOperationException("Could not retrieve the message router from the operator context.");
     }
     _topicObserver = new TopicObserver(Params._topic, messageRouter, this);
     _scheduler     = context.Scheduler;
     base.SetContext(context);
 }
예제 #16
0
            /// <summary>
            /// Sets the operator context to locate the host services to perform cleanup.
            /// </summary>
            /// <param name="context">Host operator context.</param>
            public override void SetContext(IOperatorContext context)
            {
                base.SetContext(context);

                // Note to maintainers: if the following cast fails, the environment is incorrectly configured,
                // or this operator got reused outside its intended operation environment. For more information,
                // see ExpressionRewriteHelpers.GetExpressionWithSubscriptionCleanupHook where this operator
                // gets included in instrumented subscription expressions.
                //_hostContext = (HostOperatorContext)context;
                //_subscriptionUri = context.InstanceId;
            }
예제 #17
0
        /// <summary>
        /// Initializes the operators in the subscription using the specified operator context, optionally applying state to them.
        /// </summary>
        /// <param name="context">Operator context to set on the operators in the subscription.</param>
        /// <param name="state">State reader factory to read operator state from. This parameter can be left <c>null</c>.</param>
        public void Initialize(IOperatorContext context, IOperatorStateReaderFactory state)
        {
            Subscribe();
            SetContext(context);

            if (state != null)
            {
                LoadState(state);
            }

            Start();
        }
예제 #18
0
                public override void SetContext(IOperatorContext context)
                {
                    base.SetContext(context);

                    if (context.ExecutionEnvironment.GetSubject <T, T>(Params.Item1) is not PartitionedMultiSubject <T> obs)
                    {
                        throw new InvalidOperationException();
                    }

                    var sub = obs.Subscribe(Output, Params.Item2);

                    new SubscriptionInitializeVisitor(sub).Initialize(context);
                    _subscription.Subscription = sub;
                }
예제 #19
0
            public override void SetContext(IOperatorContext context)
            {
                Debug.Assert(context != null);

                base.SetContext(context);

                //
                // TODO: Upon integrating this work with the rest of IRP, make this accessible through a property instead.
                //

                if (!context.TryGetElement("PersistedObjectSpace", out _storage))
                {
                    _storage = new VolatilePersistedObjectSpace();
                }
            }
예제 #20
0
            /// <summary>
            /// Sets the context.
            /// </summary>
            /// <param name="context">The context.</param>
            public override void SetContext(IOperatorContext context)
            {
                Debug.Assert(context != null, "Context should not be null.");

                base.SetContext(context);

                _context = context;

                if (Params._absoluteDueTime != null)
                {
                    _context.TraceSource.Timer_Periodic_Absolute_Created(_id, _context.InstanceId, Params._absoluteDueTime.Value, Params._period.Value);
                }
                else
                {
                    _context.TraceSource.Timer_Periodic_Relative_Created(_id, _context.InstanceId, Params._relativeDueTime.Value, Params._period.Value);
                }
            }
        /// <summary>
        /// Tries to retrieve an Int32 setting from the context.
        /// </summary>
        /// <param name="context">The operator context to get a setting from.</param>
        /// <param name="key">The key of the setting to retrieve.</param>
        /// <param name="check">Function to check the obtained setting value. If this check doesn't pass for the retrieved setting value, the specified <paramref name="defaultValue"/> is used.</param>
        /// <param name="defaultValue">Default setting value to use if the <paramref name="check"/> doesn't pass or no setting value is found.</param>
        /// <param name="value">Resulting value of the setting. This could be the <paramref name="defaultValue"/> if the setting was not found or the <paramref name="check"/> didn't pass.</param>
        /// <param name="message">Message to supply when logging an error for an invalid setting, as determined by <paramref name="check"/>.</param>
        /// <returns>true if a valid setting was found; otherwise, false.</returns>
        public static bool TryGetInt32(this IOperatorContext context, string key, Func <int, bool> check, int defaultValue, out int value, string message = "")
        {
            var success = false;

            if (context.TryGetElement(key, out int res))
            {
                success = check(res);

                if (!success)
                {
                    var trace = context.TraceSource;
                    if (trace != null)
                    {
                        trace.Invalid_Setting(key, res.ToString(CultureInfo.InvariantCulture), context.InstanceId, defaultValue.ToString(CultureInfo.InvariantCulture), message);
                    }
                }
            }

            value = success ? res : defaultValue;
            return(success);
        }
예제 #22
0
        public void RepeatingTimer_SimpleSaveAndLoad()
        {
            ISubscription    sub     = null;
            IOperatorContext context = Scheduler.CreateContext();

            var state       = Scheduler.CreateStateContainer();
            var checkpoints = new[]
            {
                OnSave(152, state)
            };

            // Create new subscription allow the timer to fire twice.
            var res1 = Scheduler.CreateObserver <long>();

            Scheduler.ScheduleAbsolute(100, () => sub = Subscribable.Timer(TimeSpan.Zero, TimeSpan.FromTicks(50)).Apply(Scheduler, checkpoints).Subscribe(res1, context));
            Scheduler.ScheduleAbsolute(155, () => sub.Dispose());

            // Create new subscription and load the state.
            var res2 = Scheduler.CreateObserver <long>();

            Scheduler.ScheduleAbsolute(200, () => sub = Subscribable.Timer(TimeSpan.Zero, TimeSpan.FromTicks(50)).Subscribe(res2, context, state));
            Scheduler.ScheduleAbsolute(255, () => sub.Dispose());

            Scheduler.Start();

            res1.Messages.AssertEqual(
                new[]
            {
                OnNext(100, 0L),
                OnNext(150, 1L)
            });
            res2.Messages.AssertEqual(new[]
            {
                OnNext(200, 2L),
                OnNext(250, 3L)
            });
        }
예제 #23
0
 /// <summary>
 /// Sets the operator's context in which it operates. The context contains things
 /// like the reactive service, scheduler, and so on.
 /// </summary>
 /// <param name="context">Context in which the operator operates.</param>
 public virtual void SetContext(IOperatorContext context)
 {
 }
예제 #24
0
 public void SetContext(IOperatorContext context)
 {
     Debug.Assert(context is IHostedOperatorContext);
     _context = (IHostedOperatorContext)context;
 }
        /// <summary>
        /// Sets the operator's context in which it operates.
        /// </summary>
        /// <param name="context">Context in which the operator operates.</param>
        public override void SetContext(IOperatorContext context)
        {
            base.SetContext(context);

            _context = context;
        }
 /// <summary>
 /// This method is called before the subscription is started.
 /// </summary>
 /// <param name="context">The operator context.</param>
 public virtual void SetContext(IOperatorContext context) => _context = context;
예제 #27
0
 public override void SetContext(IOperatorContext context)
 {
     Debug.Assert(context != null, "Context should not be null.");
     _context        = context;
     _childScheduler = context.Scheduler.CreateChildScheduler();
 }
예제 #28
0
            public override void SetContext(IOperatorContext context)
            {
                base.SetContext(context);

                context.TryGetInt32CheckGreaterThanZeroOrUseMaxValue(MAXGROUPCOUNTSETTING, out _maxGroupCount);
            }
예제 #29
0
 public void SetContext(IOperatorContext context)
 {
     _scheduler = context.Scheduler;
 }
예제 #30
0
 public override void SetContext(IOperatorContext context)
 {
     // Throws if not a test scheduler is used.
     _scheduler = (TestScheduler)context.Scheduler;
 }