public static async Task Run([OrchestrationTrigger] DurableOrchestrationContext context,
                                     ILogger log, ExecutionContext executionContext)
        {
            //config and input
            var config        = executionContext.BuildConfiguration();
            var vmsinScaleSet = int.Parse(config["MaxVmsInScaleSet"]);
            var waitTime      = int.Parse(config["WaitTime"]);
            var input         = new {
                Name  = context.GetInput <Tuple <string, int> >().Item1,
                Scale = context.GetInput <Tuple <string, int> >().Item2
            };

            log.LogInformation($"orchestrate create cluster name {input.Name} with scale {input.Scale}");

            // create resource group
            await context.CreateResourceGroupActivity(input.Name);

            // partition to tasks of provision\wait interleaved calls.
            foreach (var task in input.Scale
                     .PartitionSum(NonZeroInt.Make(vmsinScaleSet))
                     .MakeInterleavedCalls(
                         async t => await context.ProvisionTask(input.Name, t.Item1, t.Item2, await context.CopyStoargeTask(input.Name, t.Item1)),
                         t => context.WaitTask(waitTime)))
            {
                await task();
            }
        }
Ejemplo n.º 2
0
            public void CreatesTagWithSyncNeeded(
                NonEmptyString name, NonZeroInt workspaceId)
            {
                DataSource.Create(name.Get, workspaceId.Get).Wait();

                DataBase.Tags.Received().Create(
                    Arg.Is <IDatabaseTag>(tag => tag.SyncStatus == SyncStatus.SyncNeeded)
                    ).Wait();
            }
Ejemplo n.º 3
0
            public void CreatesTagWithSyncNeeded(
                NonEmptyString name, NonZeroInt workspaceId)
            {
                createTagInteractor(name.Get, workspaceId.Get).Execute().Wait();

                DataSource.Tags.Received().Create(
                    Arg.Is <IThreadSafeTag>(tag => tag.SyncStatus == SyncStatus.SyncNeeded)
                    ).Wait();
            }
Ejemplo n.º 4
0
            public void CreatesTagWithPassedWorkspaceId(NonZeroInt nonZeroint)
            {
                var workspaceId = nonZeroint.Get;

                DataSource.Create("Some tag", workspaceId).Wait();

                DataBase.Tags.Received().Create(
                    Arg.Is <IDatabaseTag>(tag => tag.WorkspaceId == workspaceId)
                    ).Wait();
            }
Ejemplo n.º 5
0
            public void CreatesTagWithPassedWorkspaceId(NonZeroInt nonZeroint)
            {
                var workspaceId = nonZeroint.Get;

                createTagInteractor("Some tag", workspaceId).Execute().Wait();

                DataSource.Tags.Received().Create(
                    Arg.Is <IThreadSafeTag>(tag => tag.WorkspaceId == workspaceId)
                    ).Wait();
            }
Ejemplo n.º 6
0
            public void ThrowsIfStartIndexIsLessThanZero(
                NonEmptyString str, NonZeroInt nonZeroInt)
            {
                var startIndex = nonZeroInt.Get > 0 ? -nonZeroInt.Get : nonZeroInt.Get;

                Action tryingToGetSubstringWithNegativeStartIndex =
                    () => str.Get.UnicodeSafeSubstring(startIndex, 1);

                tryingToGetSubstringWithNegativeStartIndex
                .Should().Throw <ArgumentOutOfRangeException>();
            }
Ejemplo n.º 7
0
            public void ThrowsIfStartIndexIsGreaterThanStringLength(
                NonEmptyString nonEmptyString, NonZeroInt startIndexOffset)
            {
                var str          = nonEmptyString.Get;
                var stringLength = str.LengthInGraphemes();
                var startIndex   = stringLength + Abs(startIndexOffset.Get);

                Action tryingToGetSubstringWithStartIndexGreaterThanStringLength
                    = () => str.Substring(startIndex, 1);

                tryingToGetSubstringWithStartIndexGreaterThanStringLength
                .Should().Throw <ArgumentOutOfRangeException>();
            }
Ejemplo n.º 8
0
            public void DoesNotCreateTheTagIfItAlreadyExists(NonEmptyString name, NonZeroInt workspaceId)
            {
                var mockTag = new MockTag
                {
                    Name        = name.Get,
                    WorkspaceId = workspaceId.Get
                };

                DataSource.Tags
                .GetAll(Arg.Any <Func <IDatabaseTag, bool> >())
                .Returns(Observable.Return <IEnumerable <IThreadSafeTag> >(new[] { mockTag }));

                var createdTag = createTagInteractor(name.Get, workspaceId.Get).Execute().Wait();

                DataSource.Tags.DidNotReceive().Create(
                    Arg.Is <IThreadSafeTag>(tag => tag.SyncStatus == SyncStatus.SyncNeeded)
                    ).Wait();

                createdTag.Should().BeNull();
            }
Ejemplo n.º 9
0
        public void Dividing_the_sum_of_2_monies_is_the_same_as_dividing_each_and_then_adding_the_result(NonZeroInt x, SameCurrency <string> monies)
        {
            var(y, z) = monies;
            var x_ = (int)x;

            Assert.Equal((y + z) / x_, (y / x_) + (z / x_));
            Assert.Equal(y.Add(z).Divide(x_), y.Divide(x_).Add(z.Divide(x_)));
        }
Ejemplo n.º 10
0
 public static int Divide(int x, NonZeroInt y)
 {
     return(x / y);
 }
Ejemplo n.º 11
0
 public Property Deserialize_NonZeroInt_True(NonZeroInt input)
 => JsonSerializer.Deserialize <bool>(input.ToString(), _jsonOptions).ToProperty();
Ejemplo n.º 12
0
 public void EvaluatesDivision(int number, NonZeroInt number2)
 {
     using var scriptHost = BuildScriptHost();
     AssertEvaluation($"{number} / {number2}", number / number2.Item, scriptHost);
 }
Ejemplo n.º 13
0
 public static int Divide(int a, NonZeroInt b)
 {
     return(a / b.Value);
 }
Ejemplo n.º 14
0
 public static int Divide2(int numerator, NonZeroInt denominator)
 {
     return(numerator / denominator.Value);
 }
Ejemplo n.º 15
0
        public void Dividing_3_values_is_the_same_as_dividing_x_by_the_product_of_y_and_z(Money <string> x, NonZeroInt y, NonZeroInt z)
        {
            int y_ = (int)y, z_ = (int)z;

            Assert.Equal(x / (y_ * z_), x / y_ / z_);
            Assert.Equal(x.Divide(y_ * z_), x.Divide(y_).Divide(z_));
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Partitions sum into groups with max elements per group.
 /// </summary>
 /// <param name="this"></param>
 /// <param name="partitionSize"></param>
 /// <returns></returns>
 internal static IEnumerable <Tuple <int, int> > PartitionSum(this int @this, NonZeroInt partitionSize) =>
 Enumerable.Range(0, @this)
 .GroupBy(index => index / partitionSize.IntValue)
 .Select(index => Tuple.Create(index.Key, index.Count()));
Ejemplo n.º 17
0
 public NonZeroRational(NonZeroInt numerator, PositiveInt denominator)
 {
     Item = new Rational(numerator.Item, denominator.Item);
 }