static AzureQueueDefaultPolicies()
 {
     MaxQueueOperationRetries = 5;
     PauseBetweenQueueOperationRetries = TimeSpan.FromMilliseconds(100);
     QueueOperationRetryPolicy = new LinearRetry(PauseBetweenQueueOperationRetries, MaxQueueOperationRetries); // 5 x 100ms
     QueueOperationTimeout = PauseBetweenQueueOperationRetries.Multiply(MaxQueueOperationRetries).Multiply(6);    // 3 sec
 }
        public void Multiply()
        {
            var oneMinute = new TimeSpan(0, 1, 0);
            var fourMinutes = new TimeSpan(0, 4, 0);

            Assert.AreEqual(fourMinutes, oneMinute.Multiply(4));
        }
        public void AddIteration(TimeSpan ts)
        {
            if (Min>ts)
            {
                Min = ts;
            }

            if (Max<=ts)
            {
                Max = ts;
            }
            i++;
            Total = Total.Add(ts);
            Average = Total.Multiply(1/(double)i);
        }
Beispiel #4
0
        private void RunLoggerPerfTest(string testName, int n, int logCode, TimeSpan target, TraceLogger logger)
        {
            var stopwatch = new Stopwatch();
            stopwatch.Start();
            for (int i = 0; i < n; i++)
            {
                logger.Warn(logCode, "msg " + i);
            }
            var elapsed = stopwatch.Elapsed;
            string msg = testName + " : Elapsed time = " + elapsed;

            // Wait until the BulkMessageInterval time interval expires before wring the final log message - should cause bulk message flush
            while (stopwatch.Elapsed <= TraceLogger.BulkMessageInterval)
            {
                Thread.Sleep(10);
            }

            Console.WriteLine(msg);
            logger.Info(logCode, msg);
            Assert.IsTrue(elapsed < target.Multiply(timingFactor), "{0}: Elapsed time {1} exceeds target time {2}", testName, elapsed, target);
        }
Beispiel #5
0
 private void RunLogWriterPerfTest(string testName, int n, int logCode, TimeSpan target, ITraceTelemetryConsumer log)
 {
     var stopwatch = new Stopwatch();
     stopwatch.Start();
     for (int i = 0; i < n; i++)
     {
         log.TrackTrace(string.Format( "{0}|{1}|{2}|{3}", TraceLogger.LoggerType.Runtime, testName, "msg " + i, logCode), Severity.Info);
     }
     stopwatch.Stop();
     var elapsed = stopwatch.Elapsed;
     Console.WriteLine(testName + " : Elapsed time = " + elapsed);
     Assert.IsTrue(elapsed < target.Multiply(timingFactor), "{0}: Elapsed time {1} exceeds target time {2}", testName, elapsed, target);
 }
Beispiel #6
0
 private static bool EqualMaxResponseTime(TimeSpan value1, TimeSpan value2)
 {
     return value1.Divide(2) <= value2 && value1.Multiply(2) >= value2;
 }
        // ---------- Utility functions ----------

        private void RunPerfTest(int n, string testName, TimeSpan target,
            Func<IEchoTaskGrain, Task> actionNoState,
            Func<IPersistenceTestGrain, Task> actionMemory,
            Func<IMemoryStorageTestGrain, Task> actionMemoryStore,
            Func<IAzureStorageTestGrain, Task> actionAzureTable)
        {
            IEchoTaskGrain[] noStateGrains = new IEchoTaskGrain[n];
            IPersistenceTestGrain[] memoryGrains = new IPersistenceTestGrain[n];
            IAzureStorageTestGrain[] azureStoreGrains = new IAzureStorageTestGrain[n];
            IMemoryStorageTestGrain[] memoryStoreGrains = new IMemoryStorageTestGrain[n];

            for (int i = 0; i < n; i++)
            {
                Guid id = Guid.NewGuid();
                noStateGrains[i] = GrainClient.GrainFactory.GetGrain<IEchoTaskGrain>(id);
                memoryGrains[i] = GrainClient.GrainFactory.GetGrain<IPersistenceTestGrain>(id);
                azureStoreGrains[i] = GrainClient.GrainFactory.GetGrain<IAzureStorageTestGrain>(id);
                memoryStoreGrains[i] = GrainClient.GrainFactory.GetGrain<IMemoryStorageTestGrain>(id);
            }

            TimeSpan baseline, elapsed;

            elapsed = baseline = TestUtils.TimeRun(n, TimeSpan.Zero, testName + " (No state)",
                () => RunIterations(testName, n, i => actionNoState(noStateGrains[i])));

            elapsed = TestUtils.TimeRun(n, baseline, testName + " (Local Memory Store)",
                () => RunIterations(testName, n, i => actionMemory(memoryGrains[i])));

            elapsed = TestUtils.TimeRun(n, baseline, testName + " (Dev Store Grain Store)",
                () => RunIterations(testName, n, i => actionMemoryStore(memoryStoreGrains[i])));

            elapsed = TestUtils.TimeRun(n, baseline, testName + " (Azure Table Store)",
                () => RunIterations(testName, n, i => actionAzureTable(azureStoreGrains[i])));

            if (elapsed > target.Multiply(timingFactor))
            {
                string msg = string.Format("{0}: Elapsed time {1} exceeds target time {2}", testName, elapsed, target);

                if (elapsed > target.Multiply(2.0 * timingFactor))
                {
                    Assert.Fail(msg);
                }
                else
                {
                    Assert.Inconclusive(msg);
                }
            }
        }
        private async Task MissingActivation_Runner(int grainId, TimeSpan lazyDeregistrationDelay, bool forceCreationInSecondary = false)
        {
            logger.Info("\n\n\n SMissingActivation_Runner.\n\n\n");

            var realGrainId = grainId;

            ITestGrain grain;

            var isMultipleSilosPresent = testCluster.SecondarySilos != null && testCluster.SecondarySilos.Count > 0;

            if (!isMultipleSilosPresent && forceCreationInSecondary)
            {
                throw new InvalidOperationException("If 'forceCreationInSecondary' is true multiple silos must be present, check the test!");
            }

            var grainSiloAddress = String.Empty;
            var primarySiloAddress = testCluster.Primary.SiloAddress.ToString();
            var secondarySiloAddress = isMultipleSilosPresent ? testCluster.SecondarySilos[0].SiloAddress.ToString() : String.Empty;

            //
            // We only doing this for multiple silos.
            //

            if (isMultipleSilosPresent && forceCreationInSecondary)
            {
                //
                // Make sure that we proceeding with a grain which is created in the secondary silo for first!
                //

                while (true)
                {
                    output.WriteLine($"GetGrain: {realGrainId}");

                    grain = GrainClient.GrainFactory.GetGrain<ITestGrain>(realGrainId);

                    grainSiloAddress = await grain.GetRuntimeInstanceId();

                    if (grainSiloAddress != secondarySiloAddress)
                    {
                        output.WriteLine($"GetGrain: {realGrainId} Primary, skipping.");

                        realGrainId++;
                    }
                    else
                    {
                        output.WriteLine($"GetGrain: {realGrainId} Secondary, proceeding.");

                        break;
                    }
                }
            }
            else
            {
                grain = GrainClient.GrainFactory.GetGrain<ITestGrain>(realGrainId);
            }

            await grain.SetLabel("hello_" + grainId);
            var grainReference = ((GrainReference)await grain.GetGrainReference()).GrainId;

            // Call again to make sure the grain is in all silo caches
            for (int i = 0; i < 10; i++)
            {
                var label = await grain.GetLabel();
            }

            // Now we know that there's an activation; try both silos and deactivate it incorrectly
            int primaryActivation = await testCluster.Primary.TestHook.UnregisterGrainForTesting(grainReference);
            int secondaryActivation = 0;

            if (isMultipleSilosPresent)
            {
                secondaryActivation = await testCluster.SecondarySilos[0].TestHook.UnregisterGrainForTesting(grainReference);
            }

            Assert.Equal(1, primaryActivation + secondaryActivation);

            // If we try again, we shouldn't find any
            primaryActivation = await testCluster.Primary.TestHook.UnregisterGrainForTesting(grainReference);
            secondaryActivation = 0;

            if (isMultipleSilosPresent)
            {
                secondaryActivation = await testCluster.SecondarySilos[0].TestHook.UnregisterGrainForTesting(grainReference);
            }

            Assert.Equal(0, primaryActivation + secondaryActivation);

            if (lazyDeregistrationDelay > TimeSpan.Zero)
            {
                // Wait a bit
                TimeSpan pause = lazyDeregistrationDelay.Multiply(2);
                logger.Info($"Pausing for {0} because we are using lazy deregistration", pause);
                await Task.Delay(pause);
            }

            // Now send a message again; it should fail);
            var firstEx = await Assert.ThrowsAsync<OrleansException>(() => grain.GetLabel());
            Assert.Contains("Non-existent activation", firstEx.Message);
            logger.Info("Got 1st Non-existent activation Exception, as expected.");

            // Try again; it should succeed or fail, based on doLazyDeregistration
            if (lazyDeregistrationDelay > TimeSpan.Zero || forceCreationInSecondary)
            {
                var newLabel = "";

                newLabel = await grain.GetLabel();

                // Since a new instance returned, we've to check that the label is no more prefixed with "hello_"
                Assert.Equal(grainId.ToString(), newLabel);

                logger.Info($"After 2nd call. newLabel = '{newLabel}'");

                if (forceCreationInSecondary)
                {
                    grainSiloAddress = await grain.GetRuntimeInstanceId();

                    output.WriteLine(grainSiloAddress == primarySiloAddress ? "Recreated in Primary" : "Recreated in Secondary");
                    logger.Info(grainSiloAddress == primarySiloAddress ? "Recreated in Primary" : "Recreated in Secondary");
                }
            }
            else
            {
                var secondEx = await Assert.ThrowsAsync<OrleansException>(() => grain.GetLabel());
                logger.Info("Got 2nd exception - " + secondEx.GetBaseException().Message);
                Assert.True(secondEx.Message.Contains("duplicate activation") || secondEx.Message.Contains("Non-existent activation")
                               || secondEx.Message.Contains("Forwarding failed"),
                        "2nd exception message: " + secondEx);
                logger.Info("Got 2nd exception, as expected.");
            }
        }
        //[Fact]
        //public void Persistence_Silo_StorageProvider_SimpleSQL(Type providerType)
        //{
        //    List<SiloHandle> silos = testingHost.GetActiveSilos().ToList();
        //    foreach (var silo in silos)
        //    {
        //        string provider = providerType.FullName;
        //        List<string> providers = silo.Silo.TestHook.GetStorageProviderNames().ToList();
        //        Assert.IsTrue(providers.Contains(provider), "No storage provider found: {0}", provider);
        //    }
        //}

        #region Utility functions
        // ---------- Utility functions ----------

        void RunPerfTest(int n, string testName, TimeSpan target,
            Func<ISimpleSQLStorageTestGrain, Task> actionSimpleSQL)
        {
            ISimpleSQLStorageTestGrain[] simpleSQLStoreGrains = new ISimpleSQLStorageTestGrain[n];

            for (int i = 0; i < n; i++)
            {
                Guid id = Guid.NewGuid();
                simpleSQLStoreGrains[i] = GrainClient.GrainFactory.GetGrain<ISimpleSQLStorageTestGrain>(id);
            }

            TimeSpan baseline = new TimeSpan(0, 0, 5), elapsed;

            elapsed = TimeRun(n, baseline, testName + " (SimpleSQL Store)",
                () => RunIterations(testName, n, i => actionSimpleSQL(simpleSQLStoreGrains[i])));

            if (elapsed > target.Multiply(timingFactor))
            {
                string msg = string.Format("{0}: Elapsed time {1} exceeds target time {2}", testName, elapsed, target);

                if (elapsed > target.Multiply(2.0 * timingFactor))
                {
                    Assert.True(false,msg);
                }
                else
                {
                    //this is from xunit
                    //throw new SkipException(msg);
                }
            }
        }
        public void updateTimeslots(ref List<Timeslot> timeslots, ref Dictionary<string,int> pointsources, DateTime ecoStart, TimeSpan timeslotLen)
        {
            int timeslot = 0;
            TimeSpan ts = DateTime.Now - ecoStart;
            stackPanel.Children.Clear();
            stackPanel.Children.Add(new Label() { Content = "Altijd", FontWeight = FontWeights.Bold });
            foreach (KeyValuePair<String, int> kvp in pointsources)
            {
                stackPanel.Children.Add(new Label() { Content = String.Format("{0} ({1})", kvp.Key.Trim('%').UppercaseFirst(), kvp.Value) });
            }

            if (ts > TimeSpan.Zero)
            {
                timeslot = (int)(ts.Ticks / timeslotLen.Ticks);
            }
            if (timeslot >= 0 && timeslot < timeslots.Count && ts > TimeSpan.Zero)
            {
                stackPanel.Children.Add(new Label() { Content = "Nu", FontWeight = FontWeights.Bold });
                foreach (KeyValuePair<String, int> kvp in timeslots[timeslot].Items)
                {
                    stackPanel.Children.Add(new Label() { Content = String.Format("{0} ({1})", kvp.Key.Trim('%').UppercaseFirst(), kvp.Value) });
                }
            }
            if (ts <= TimeSpan.Zero)
            {
                timeslot = -1;
            }
            TimeSpan timeToNext = ecoStart.Add(timeslotLen.Multiply(timeslot + 1)).Subtract(DateTime.Now);
            string minleft = timeToNext.TotalMinutes < 0.5 ? "<1" : timeToNext.TotalMinutes.ToString("F0");
            if (timeslot+1 >= 0 && timeslot+1 < timeslots.Count)
            {
                stackPanel.Children.Add(new Label() { Content = String.Format("Straks (nog {0} min)", minleft), FontWeight = FontWeights.Bold });
                foreach (KeyValuePair<String, int> kvp in timeslots[timeslot + 1].Items)
                {
                    stackPanel.Children.Add(new Label() { Content = String.Format("{0} ({1})", kvp.Key.Trim('%').UppercaseFirst(), kvp.Value) });
                }
            }
        }
Beispiel #11
0
        private void AnimateTiles(EnterMode mode, XDirection xDirection, ZDirection zDirection, TimeSpan duration, Action callback)
        {
            // If the control has not been rendered or it's empty, cancel the animation
            if (this.ActualWidth <= 0 || this.ActualHeight <= 0 || this._positions == null || this._positions.Count <= 0) return;

            // Get the visible tiles for the current configuration
            // Tiles that are partially visible are also counted
            var visibleitems = this._positions.Where(x => x.Value.X + x.Key.ActualWidth >= 0 && x.Value.X <= this.ActualWidth &&
                                                     x.Value.Y + x.Key.ActualHeight >= 0 && x.Value.Y <= this.ActualHeight);

            // No visible tiles, do nothing
            if (visibleitems.Count() <= 0) return;

            // The Y coordinate of the lowest element is useful 
            // when we animate from bottom to top
            double lowestX = visibleitems.Max(el => el.Value.X);

            // Store the animations to group them in one Storyboard in the end
            var animations = new List<Timeline>();

            foreach (var tilePosition in visibleitems)
            {
                // To make syntax lighter
                var tile = tilePosition.Key;
                var position = tilePosition.Value;
                var projection = tile.Projection as PlaneProjection;

                double rotationFrom, rotationTo, opacityTo;

                // Reset all children's opacity regardless of their animations
                if (mode == EnterMode.Exit)
                {
                    tile.Opacity = 1;
                    opacityTo = 0;
                    rotationFrom = 0;
                    rotationTo = zDirection == ZDirection.BackToFront ? -90 : 90;
                }
                else
                {
                    tile.Opacity = 0;
                    opacityTo = 1;
                    rotationFrom = zDirection == ZDirection.BackToFront ? -90 : 90;
                    rotationTo = 0;
                }

                // Used to determine begin time - depends if we're moving from bottom or from top
                double relativeX;

                if (xDirection == XDirection.LeftToRight)
                {
                    // The lowest element should have relativeY == 0
                    relativeX = lowestX - position.X;
                }
                else
                {
                    relativeX = position.X;
                }

                var easing = new QuadraticEase() { EasingMode = EasingMode.EaseInOut };

                var rotationAnimation = new DoubleAnimation { From = rotationFrom, To = rotationTo, EasingFunction = easing };
                rotationAnimation.Duration = duration;
                rotationAnimation.BeginTime = duration.Multiply(this.GetBeginTimeFactorFavorite(relativeX, position.Y, mode));
                rotationAnimation.SetTargetAndProperty(projection, PlaneProjection.RotationYProperty);

                var opacityAnimation = new DoubleAnimation { To = opacityTo, EasingFunction = easing };
                // The opacity animation takes the last 60% of the rotation animation
                opacityAnimation.Duration = duration.Multiply(0.6);
                opacityAnimation.BeginTime = rotationAnimation.BeginTime;
                if (mode == EnterMode.Exit)
                    opacityAnimation.BeginTime += duration - opacityAnimation.Duration.TimeSpan;
                opacityAnimation.SetTargetAndProperty(tile, UIElement.OpacityProperty);

                animations.Add(rotationAnimation);
                animations.Add(opacityAnimation);
            }

            // Begin all animations
            var sb = new Storyboard();
            sb.Completed += (sender, args) =>
            {
                if (callback != null)
                {
                    callback();
                }
            };

            foreach (var a in animations)
                sb.Children.Add(a);
            sb.Begin();
        }