internal void Trace(IGraphReplicaSetLowLevel replicaSet) { TestOutputHelper.WriteLine("replicaSet:"); TestOutputHelper.WriteLine($" InstanceCount={replicaSet.InstanceCount}, EnabledInstanceCount={replicaSet.EnabledInstanceCount}"); for (int instance = 0; instance < replicaSet.InstanceCount; ++instance) { var graph = replicaSet.GraphInstances[instance]; TestOutputHelper.WriteLine($" Graph #{instance}: {graph.GraphName}"); TestOutputHelper.WriteLine($" IsEnabled()={replicaSet.IsEnabled(instance)}"); } }
public GraphClusterTests() { ReplicaSets = new IGraphReplicaSetLowLevel[NumberOfReplicaSets]; for (int replicaSetOrdinal = 0; replicaSetOrdinal < NumberOfReplicaSets; ++replicaSetOrdinal) { var replicaSet = ReplicaSets[replicaSetOrdinal] = A.Fake <IGraphReplicaSetLowLevel>(); A.CallTo(() => replicaSet.Name).Returns(replicaSetOrdinal.ToString()); } Logger = A.Fake <ILogger>(); GraphCluster = new GraphCluster(ReplicaSets, Logger); Queries = new[] { A.Fake <IQuery <int> >() }; Commands = new[] { A.Fake <ICommand>() }; }
private async Task <IValidateAndRepairResults> ValidateGraphImpl( ValidationScope validationScope, params string[] graphReplicaSetNames) { IEnumerable <ContentTypeDefinition> syncableContentTypeDefinitions = _contentDefinitionManager .ListTypeDefinitions() .Where(x => x.Parts.Any(p => p.Name == nameof(GraphSyncPart))); DateTime timestamp = DateTime.UtcNow; IEnumerable <string> graphReplicaSetNamesToValidate = graphReplicaSetNames.Any() ? graphReplicaSetNames : _graphClusterLowLevel.GraphReplicaSetNames; DateTime validateFrom = await GetValidateFromTime(validationScope); var results = new ValidateAndRepairResults(validateFrom); //todo: we could optimise to only get content items from the oc database once for each replica set, // rather than for each instance foreach (string graphReplicaSetName in graphReplicaSetNamesToValidate) { IGraphReplicaSetLowLevel graphReplicaSetLowLevel = _graphClusterLowLevel.GetGraphReplicaSetLowLevel(graphReplicaSetName); IContentItemVersion contentItemVersion = _contentItemVersionFactory.Get(graphReplicaSetName); foreach (IGraph graph in graphReplicaSetLowLevel.GraphInstances) { ValidateAndRepairResult result = results.AddNewValidateAndRepairResult( graphReplicaSetName, graph.Instance, graph.Endpoint.Name, graph.GraphName, graph.DefaultGraph); // make current graph available for when parts/fields call back into ValidateContentItem // seems a little messy, and will make concurrent validation a pita, // but stops part/field syncers needing low level graph access _currentGraph = graph; foreach (ContentTypeDefinition contentTypeDefinition in syncableContentTypeDefinitions) { List <ValidationFailure> syncFailures = await ValidateContentItemsOfContentType( contentItemVersion, contentTypeDefinition, validateFrom, result, validationScope); if (syncFailures.Any()) { await AttemptRepair(syncFailures, contentTypeDefinition, contentItemVersion, result); } } } } if (results.AnyRepairFailures) { return(results); } _logger.LogInformation("Woohoo: graph passed validation or was successfully repaired at {Time}.", timestamp.ToString("O")); _session.Save(new AuditSyncLog(timestamp)); await _session.CommitAsync(); return(results); }