Ejemplo n.º 1
0
 public MyVector(Reconciler rec, DataKind kind, int min, int?max)
     : base(rec, null)
 {
     _kind = kind;
     _min  = min;
     _max  = max;
 }
Ejemplo n.º 2
0
 // Contstuct a representation for a key-typed column loaded from a text file. Key values are assumed to be contiguous.
 public MyKey(Reconciler rec, DataKind kind, int oridinal, ulong minKeyValue, ulong?maxKeyValue = null)
     : base(rec, null)
 {
     _kind        = kind;
     _oridinal    = oridinal;
     _minKeyValue = minKeyValue;
     _maxKeyValue = maxKeyValue;
 }
        public async Task GivenSequencesWithAPreviousAndTargetSequenceThenTheReconcilerIsInvokedOnceForEachAggregateAboveThePreviousAndBelowTheTargetSequenceAsync()
        {
            const int ExpectedInvocations = 1;
            int       eventsReconciling   = 0;
            int       eventsReconciled    = 0;

            SequencedEvents[] sequences = new[]
            {
                new SequencedEvents(1, CreateEvents()),
                new SequencedEvents(2, CreateEvents()),
                new SequencedEvents(3, CreateEvents()),
                new SequencedEvents(4, CreateEvents()),
                new SequencedEvents(5, CreateEvents()),
            };

            ulong previous = 1;
            ulong target   = 4;

            SequencedEvents[] expected = sequences
                                         .Where(aggregate => aggregate.Sequence > previous && aggregate.Sequence <= target)
                                         .ToArray();

            var aggregates = expected.ToDictionary(sequence => sequence.Aggregate, sequence => 0);

            _ = EventStore
                .Setup(store => store.ReadAsync(
                           It.Is <ulong>(value => value == previous),
                           It.IsAny <CancellationToken?>(),
                           It.IsAny <ushort>()))
                .ReturnsAsync(expected);

            _ = EventStore
                .Setup(store => store.ReadAsync(
                           It.Is <ulong>(value => value > previous),
                           It.IsAny <CancellationToken?>(),
                           It.IsAny <ushort>()))
                .ReturnsAsync(Enumerable.Empty <SequencedEvents>());

            _ = Reconciler
                .Setup(reconciler => reconciler.ReconcileAsync(
                           It.IsAny <IEnumerable <DomainEvent> >(),
                           It.IsAny <CancellationToken?>()))
                .Callback <IEnumerable <DomainEvent>, CancellationToken?>((value, _) => aggregates[value.First().Aggregate]++);

            instance.EventsReconciling += (sender, e) => Task.FromResult(eventsReconciling++);
            instance.EventsReconciled  += (sender, e) => Task.FromResult(eventsReconciled++);

            _ = await instance.ReconcileAsync(previous : previous, target : target);

            int invocations = expected.Length;
            int skips       = sequences.Length - invocations;

            Assert.Equal(invocations, eventsReconciling);
            Assert.Equal(invocations, eventsReconciled);
            Assert.All(aggregates.Values, value => Assert.Equal(ExpectedInvocations, value));
        }
        public async Task GivenSequencesThenTheReconcilerIsInvokedOnceForEachAggregate()
        {
            const int ExpectedInvocations = 1;
            int       eventsReconciling   = 0;
            int       eventsReconciled    = 0;

            SequencedEvents[] sequences = new[]
            {
                new SequencedEvents(1, CreateEvents()),
                new SequencedEvents(2, CreateEvents()),
                new SequencedEvents(3, CreateEvents()),
            };

            var aggregates = sequences.ToDictionary(sequence => sequence.Aggregate, sequence => 0);

            _ = EventStore
                .Setup(store => store.ReadAsync(
                           It.Is <ulong>(value => value == ulong.MinValue),
                           It.IsAny <CancellationToken?>(),
                           It.IsAny <ushort>()))
                .ReturnsAsync(sequences);

            _ = EventStore
                .Setup(store => store.ReadAsync(
                           It.Is <ulong>(value => value > ulong.MinValue),
                           It.IsAny <CancellationToken?>(),
                           It.IsAny <ushort>()))
                .ReturnsAsync(Enumerable.Empty <SequencedEvents>());

            _ = Reconciler
                .Setup(reconciler => reconciler.ReconcileAsync(
                           It.IsAny <IEnumerable <DomainEvent> >(),
                           It.IsAny <CancellationToken?>()))
                .Callback <IEnumerable <DomainEvent>, CancellationToken?>((value, _) => aggregates[value.First().Aggregate]++);

            instance.EventsReconciling += (sender, e) => Task.FromResult(eventsReconciling++);
            instance.EventsReconciled  += (sender, e) => Task.FromResult(eventsReconciled++);

            _ = await instance.ReconcileAsync();

            Assert.Equal(sequences.Length, eventsReconciling);
            Assert.Equal(sequences.Length, eventsReconciled);
            Assert.All(aggregates.Values, value => Assert.Equal(ExpectedInvocations, value));
        }
Ejemplo n.º 5
0
        public void MultipleNestedCustomComponents_CreatesCorrectElementTree()
        {
            var component1 = UIComponentDefinition.Create("Test1", converter.Convert(@"
            function render(props)
	            return (
                    <Button id={""level1""}> 
                        <Button id={""level2""}>
                            {props.children}
                        </Button>
                    </Button>
                )
            end"));

            this.index.Components.Add("Test1", component1);

            var component2 = UIComponentDefinition.Create("Test2", converter.Convert(@"
            function render(props)
	            return (
                    <Test1>
                        <Button>
		                    <Text
			                    textAnchor={""MiddleCenter""}
                                alignByGeometry={""false""}
                                text={props.test}
                            />
                        </Button>
                    </Test1>
                )
            end"));

            var rootElement = Element.Create(component2, new PropCollection(new Dictionary <string, object>()
            {
                { "test", "some text" }
            }));

            Reconciler.CreateElementTree(rootElement);

            Assert.AreEqual(1, rootElement.Children.Count);
            Assert.AreEqual("Test1", rootElement.Children.First().Component.Name);
        }
Ejemplo n.º 6
0
 private sealed class AKey <T> : Key <T>, IDeps { public AKey(Reconciler rec, PipelineColumn[] dependencies) : base(rec, dependencies)
                                                  {
                                                      Deps = dependencies;
                                                  }
Ejemplo n.º 7
0
 private sealed class AVarVector <T> : VarVector <T>, IDeps { public AVarVector(Reconciler rec, PipelineColumn[] dependencies) : base(rec, dependencies)
                                                              {
                                                                  Deps = dependencies;
                                                              }
Ejemplo n.º 8
0
 public MyScalar(Reconciler rec, DataKind kind, int ordinal)
     : base(rec, null)
 {
     _kind    = kind;
     _ordinal = ordinal;
 }
Ejemplo n.º 9
0
 internal Context(Reconciler rec)
 {
     Contracts.AssertValue(rec);
     _rec = rec;
 }
        private async Task ProcessJobInfoAsync(Guid activityId, IPolicyAgentDocumentForTenant doc, CancellationToken cancellationToken)
        {
            DateTime now = DateTime.UtcNow;
            TimeSpan completedTaskAgeThreshold = this.GetCompletedTaskAgeThreshold();

            // get the ones that are claimed by this service (which is the Repair Executor (RE))
            var repairTasks = await repairManager
                              .GetRepairTaskListAsync(activityId, null, RepairTaskStateFilter.Default, this.environment.ServiceName)
                              .ConfigureAwait(false);

            // Count completed tasks that are going to be ignored because they are too old
            int oldCompletedTaskCount = repairTasks.Count(t => IsOldCompletedRepairTask(t, now, completedTaskAgeThreshold));

            // Keep all of the rest (active or recent)
            repairTasks = repairTasks.Where(t => !IsOldCompletedRepairTask(t, now, completedTaskAgeThreshold)).ToList();

            // get all the unclaimed repair tasks too... some may not match, we'll evaluate and ignore them later
            var unclaimedRepairTasks = await repairManager
                                       .GetRepairTaskListAsync(activityId, null, RepairTaskStateFilter.Created, null)
                                       .ConfigureAwait(false);

            foreach (var unclaimedRepairTask in unclaimedRepairTasks)
            {
                repairTasks.Add(unclaimedRepairTask);
            }

            traceType.WriteInfo(
                "Processing repair tasks (count: {0}; ignored completed tasks older than {1}: {2})",
                repairTasks.Count,
                completedTaskAgeThreshold,
                oldCompletedTaskCount);

            // Dump each task separately to avoid exceeding the ETW event size limit
            for (int i = 0; i < repairTasks.Count; ++i)
            {
                traceType.WriteInfo("Repair task {0} of {1}:{2}{3}", i + 1, repairTasks.Count, Environment.NewLine, repairTasks[i].ToJson());
            }

            var coordinatorContext = new CoordinatorContext {
                Doc = doc
            };

            ActionHelper.CreateMappedWorkItems(doc.Jobs, repairTasks, coordinatorContext);

            var reconciler = new Reconciler(
                this.environment,
                this.policyAgentClient,
                this.repairManager,
                this.repairActionProvider);

            await reconciler.ReconcileAsync(activityId, coordinatorContext).ConfigureAwait(false);

            await ActionHelper.ApplyPoliciesAsync(activityId, actionPolicies, coordinatorContext).ConfigureAwait(false);

            // Publish state after reconcile + policy phases have completed
            coordinatorContext.MarkFinished();
            coordinatorCommandProcessor.CoordinatorContext = coordinatorContext;

            var blockingPolicy = await this.jobBlockingPolicyManager.GetPolicyAsync();

            if (blockingPolicy == JobBlockingPolicy.BlockAllJobs)
            {
                traceType.WriteInfo("All actions are blocked by job blocking policy");
            }
            else
            {
                var actionsToExecute = ActionHelper.GetActions(activityId, coordinatorContext);
                await ActionHelper.ExecuteActionsAsync(activityId, this.actionTraceType, actionsToExecute).ConfigureAwait(false);

                // Send all job responses (if any) as a single batch response
                await policyAgentClient.SendJobResponseAsync(
                    activityId,
                    doc.JobDocumentIncarnation,
                    reconciler.GetJobStepResponses(),
                    "Automated response by Service Fabric Infrastructure Service",
                    cancellationToken).ConfigureAwait(false);
            }
        }
Ejemplo n.º 11
0
 public static Reconciler ExcludeExtensions(this Reconciler recon, params string[] extensions)
 {
     recon.AddFilter(new FileExtensionFilter(extensions));
     return(recon);
 }