Пример #1
0
 public Command(
     CommandType t,
     LogProviderCommandPriority priority,
     LJTraceSource trace,
     CancellationToken cancellation,
     IAsyncLogProviderCommandHandler handler)
 {
     Type         = t;
     Priority     = priority;
     Cancellation = cancellation;
     Handler      = handler;
     Perfop       = new LogJoint.Profiling.Operation(trace, this.ToString());
 }
Пример #2
0
 public Command(
     CommandType t,
     LogProviderCommandPriority priority,
     LJTraceSource trace,
     CancellationToken cancellation,
     IAsyncLogProviderCommandHandler handler)
 {
     Type         = t;
     Id           = Interlocked.Increment(ref lastCommandId);
     Priority     = priority;
     Cancellation = cancellation;
     Handler      = handler;
     Perfop       = new Profiling.Operation(trace, this.ToString());
 }
        void TestSyncResults(CommandContext ctx, params string[] expectedSyncResults)
        {
            var cache        = ctx.Cache;
            var cachedRange  = cache.Messages.DatesRange;
            var fullLogRange = ctx.Stats.AvailableTime;
            var datesToTest  = new[]
            {
                fullLogRange.Begin.AddSeconds(-1),
                fullLogRange.Begin.AddTicks(-1),
                fullLogRange.Begin,
                fullLogRange.Begin.AddTicks(+1),
                Mid(fullLogRange.Begin, cachedRange.Begin),
                cachedRange.Begin.AddTicks(-1),
                cachedRange.Begin,
                cachedRange.Begin.AddTicks(+1),
                Mid(cachedRange.Begin, cachedRange.End),
                cachedRange.End.AddTicks(-1),
                cachedRange.End,
                cachedRange.End.AddTicks(+1),
                Mid(cachedRange.End, fullLogRange.End),
                fullLogRange.End.AddTicks(-1),
                fullLogRange.End,
                fullLogRange.End.AddTicks(+1),
                fullLogRange.End.AddSeconds(+1)
            };
            var boundsCache = Substitute.For <IDateBoundsCache>();

            boundsCache.Get(new DateTime()).ReturnsForAnyArgs((DateBoundPositionResponseData)null);
            int dateIdx = 0;

            foreach (var dateToTest in datesToTest)
            {
                foreach (var bound in new[] { ListUtils.ValueBound.Lower, ListUtils.ValueBound.LowerReversed, ListUtils.ValueBound.Upper, ListUtils.ValueBound.UpperReversed })
                {
                    var testId = string.Format("{0}{1}", dateIdx, ToString(bound));

                    var cmd = new GetDateBoundCommand(dateToTest, false, bound, boundsCache);
                    IAsyncLogProviderCommandHandler cmdIntf    = cmd;
                    DateBoundPositionResponseData   syncResult = null;
                    if (cmdIntf.RunSynchronously(ctx))
                    {
                        cmdIntf.Complete(null);
                        Assert.IsTrue(cmd.Task.IsCompleted);
                        syncResult = cmd.Task.Result;
                    }
                    bool expectSyncResult = expectedSyncResults.IndexOf(i => i == testId) != null;
                    Assert.AreEqual(expectSyncResult, syncResult != null, "Result must be sync for test " + testId);

                    cmd     = new GetDateBoundCommand(dateToTest, false, bound, boundsCache);
                    cmdIntf = cmd;
                    cmdIntf.ContinueAsynchronously(ctx);
                    cmdIntf.Complete(null);
                    Assert.IsTrue(cmd.Task.IsCompleted);
                    DateBoundPositionResponseData asyncResult = cmd.Task.Result;

                    if (syncResult != null)
                    {
                        Assert.AreEqual(
                            PositionedMessagesUtils.NormalizeMessagePosition(ctx.Reader, syncResult.Position),
                            PositionedMessagesUtils.NormalizeMessagePosition(ctx.Reader, asyncResult.Position),
                            "Posision mismatch " + testId
                            );
                        Assert.AreEqual(syncResult.IsBeforeBeginPosition, asyncResult.IsBeforeBeginPosition, "IsBeforeBeginPosition mismatch " + testId);
                        Assert.AreEqual(syncResult.IsEndPosition, asyncResult.IsEndPosition, "IsEndPosition mismatch " + testId);
                    }
                }
                ++dateIdx;
            }
        }