protected void CreateData() { var baseDate = DateTime.Now; var occurrenceDateStart = baseDate.AddMinutes(-30); var occurrenceDateMid = baseDate; var occurrenceDateEnd = baseDate.AddMinutes(30); _stackRepository.Add(StackData.GenerateStack(id: TestConstants.StackId, organizationId: TestConstants.OrganizationId, projectId: TestConstants.ProjectId)); var occurrenceDates = new List <DateTime> { occurrenceDateStart, occurrenceDateEnd, baseDate.AddMinutes(-10), baseDate.AddMinutes(-20), occurrenceDateMid, occurrenceDateMid, occurrenceDateMid, baseDate.AddMinutes(20), baseDate.AddMinutes(10), baseDate.AddSeconds(1), occurrenceDateEnd, occurrenceDateStart }; foreach (var date in occurrenceDates) { var ev = _repository.Add(EventData.GenerateEvent(projectId: TestConstants.ProjectId, organizationId: TestConstants.OrganizationId, stackId: TestConstants.StackId, occurrenceDate: date)); _ids.Add(Tuple.Create(ev.Id, date)); } }
public void MarkAsRegressedTest() { RemoveData(); _repository.Add(StackData.GenerateStack(id: TestConstants.StackId, projectId: TestConstants.ProjectId, organizationId: TestConstants.OrganizationId, dateFixed: DateTime.Now.SubtractMonths(1))); _client.Refresh(); var stack = _repository.GetById(TestConstants.StackId); Assert.NotNull(stack); Assert.False(stack.IsRegressed); Assert.NotNull(stack.DateFixed); _repository.MarkAsRegressed(TestConstants.StackId); _client.Refresh(); stack = _repository.GetById(TestConstants.StackId); Assert.NotNull(stack); Assert.True(stack.IsRegressed); Assert.Null(stack.DateFixed); }
public void CanCreateUpdateRemove() { _repository.RemoveAll(); Assert.Equal(0, _repository.Count()); var stack = StackData.GenerateStack(projectId: TestConstants.ProjectId, organizationId: TestConstants.OrganizationId); Assert.Null(stack.Id); _repository.Add(stack); Assert.NotNull(stack.Id); _client.Refresh(); stack = _repository.GetById(stack.Id); Assert.NotNull(stack); stack.Description = "New Description"; _repository.Save(stack); _repository.Remove(stack.Id); }
protected override void CreateData() { var baseDate = DateTimeOffset.Now; var occurrenceDateStart = baseDate.AddMinutes(-30); var occurrenceDateMid = baseDate; var occurrenceDateEnd = baseDate.AddMinutes(30); _stackRepository.Add(ErrorStackData.GenerateErrorStack(id: TestConstants.ErrorStackId, organizationId: TestConstants.OrganizationId, projectId: TestConstants.ProjectId)); _ids.Add(Tuple.Create(ObjectId.GenerateNewId().ToString(), occurrenceDateStart)); Repository.Add(EventData.GenerateEvent(id: _ids.Last().Item1, projectId: TestConstants.ProjectId, organizationId: TestConstants.OrganizationId, stackId: TestConstants.ErrorStackId, occurrenceDate: _ids.Last().Item2, nestingLevel: 5, minimiumNestingLevel: 1)); _ids.Add(Tuple.Create(ObjectId.GenerateNewId().ToString(), occurrenceDateEnd)); Repository.Add(EventData.GenerateEvent(id: _ids.Last().Item1, projectId: TestConstants.ProjectId, organizationId: TestConstants.OrganizationId, stackId: TestConstants.ErrorStackId, occurrenceDate: _ids.Last().Item2, nestingLevel: 5, minimiumNestingLevel: 1)); _ids.Add(Tuple.Create(ObjectId.GenerateNewId().ToString(), baseDate.AddMinutes(-10))); Repository.Add(EventData.GenerateEvent(id: _ids.Last().Item1, projectId: TestConstants.ProjectId, organizationId: TestConstants.OrganizationId, stackId: TestConstants.ErrorStackId, occurrenceDate: _ids.Last().Item2, nestingLevel: 5, minimiumNestingLevel: 1)); _ids.Add(Tuple.Create(ObjectId.GenerateNewId().ToString(), baseDate.AddMinutes(-20))); Repository.Add(EventData.GenerateEvent(id: _ids.Last().Item1, projectId: TestConstants.ProjectId, organizationId: TestConstants.OrganizationId, stackId: TestConstants.ErrorStackId, occurrenceDate: _ids.Last().Item2, nestingLevel: 5, minimiumNestingLevel: 1)); _ids.Add(Tuple.Create(ObjectId.GenerateNewId().ToString(), occurrenceDateMid)); Repository.Add(EventData.GenerateEvent(id: _ids.Last().Item1, projectId: TestConstants.ProjectId, organizationId: TestConstants.OrganizationId, stackId: TestConstants.ErrorStackId, occurrenceDate: _ids.Last().Item2, nestingLevel: 5, minimiumNestingLevel: 1)); _ids.Add(Tuple.Create(ObjectId.GenerateNewId().ToString(), occurrenceDateMid)); Repository.Add(EventData.GenerateEvent(id: _ids.Last().Item1, projectId: TestConstants.ProjectId, organizationId: TestConstants.OrganizationId, stackId: TestConstants.ErrorStackId, occurrenceDate: _ids.Last().Item2, nestingLevel: 5, minimiumNestingLevel: 1)); _ids.Add(Tuple.Create(ObjectId.GenerateNewId().ToString(), occurrenceDateMid)); Repository.Add(EventData.GenerateEvent(id: _ids.Last().Item1, projectId: TestConstants.ProjectId, organizationId: TestConstants.OrganizationId, stackId: TestConstants.ErrorStackId, occurrenceDate: _ids.Last().Item2, nestingLevel: 5, minimiumNestingLevel: 1)); _ids.Add(Tuple.Create(ObjectId.GenerateNewId().ToString(), baseDate.AddMinutes(20))); Repository.Add(EventData.GenerateEvent(id: _ids.Last().Item1, projectId: TestConstants.ProjectId, organizationId: TestConstants.OrganizationId, stackId: TestConstants.ErrorStackId, occurrenceDate: _ids.Last().Item2, nestingLevel: 5, minimiumNestingLevel: 1)); _ids.Add(Tuple.Create(ObjectId.GenerateNewId().ToString(), baseDate.AddMinutes(10))); Repository.Add(EventData.GenerateEvent(id: _ids.Last().Item1, projectId: TestConstants.ProjectId, organizationId: TestConstants.OrganizationId, stackId: TestConstants.ErrorStackId, occurrenceDate: _ids.Last().Item2, nestingLevel: 5, minimiumNestingLevel: 1)); _ids.Add(Tuple.Create(ObjectId.GenerateNewId().ToString(), baseDate.AddSeconds(1))); Repository.Add(EventData.GenerateEvent(id: _ids.Last().Item1, projectId: TestConstants.ProjectId, organizationId: TestConstants.OrganizationId, stackId: TestConstants.ErrorStackId, occurrenceDate: _ids.Last().Item2, nestingLevel: 5, minimiumNestingLevel: 1)); _ids.Add(Tuple.Create(ObjectId.GenerateNewId().ToString(), occurrenceDateEnd)); Repository.Add(EventData.GenerateEvent(id: _ids.Last().Item1, projectId: TestConstants.ProjectId, organizationId: TestConstants.OrganizationId, stackId: TestConstants.ErrorStackId, occurrenceDate: _ids.Last().Item2, nestingLevel: 5, minimiumNestingLevel: 1)); _ids.Add(Tuple.Create(ObjectId.GenerateNewId().ToString(), occurrenceDateStart)); Repository.Add(EventData.GenerateEvent(id: _ids.Last().Item1, projectId: TestConstants.ProjectId, organizationId: TestConstants.OrganizationId, stackId: TestConstants.ErrorStackId, occurrenceDate: _ids.Last().Item2, nestingLevel: 5, minimiumNestingLevel: 1)); }
private void CreateStacks() { ElasticSearchConfiguration.ConfigureMapping(_client, true); var serializer = JsonSerializer.CreateDefault(new JsonSerializerSettings { ContractResolver = new LowerCaseUnderscorePropertyNamesContractResolver() }); foreach (var file in Directory.GetFiles(@"..\..\Search\Data\", "stack*.json", SearchOption.AllDirectories)) { using (var stream = new FileStream(file, FileMode.Open)) { using (var streamReader = new StreamReader(stream)) { var stack = serializer.Deserialize(streamReader, typeof(Stack)) as Stack; Assert.NotNull(stack); _repository.Add(stack); } } } _client.Refresh(); }
private void CreateStacks() { ElasticSearchConfiguration.ConfigureMapping(_client, true); var serializer = IoC.GetInstance <JsonSerializer>(); foreach (var file in Directory.GetFiles(@"..\..\Search\Data\", "stack*.json", SearchOption.AllDirectories)) { if (file.EndsWith("summary.json")) { continue; } using (var stream = new FileStream(file, FileMode.Open)) { using (var streamReader = new StreamReader(stream)) { var stack = serializer.Deserialize(streamReader, typeof(Stack)) as Stack; Assert.NotNull(stack); _repository.Add(stack); } } } _client.Refresh(); }
public override void Process(EventContext ctx) { if (String.IsNullOrEmpty(ctx.Event.StackId)) { if (_stackRepository == null) { throw new InvalidOperationException("You must pass a non-null stackRepository parameter to the constructor."); } // only add default signature info if no other signature info has been added if (ctx.StackSignatureData.Count == 0) { ctx.StackSignatureData.Add("Type", ctx.Event.Type); if (!String.IsNullOrEmpty(ctx.Event.Source)) { ctx.StackSignatureData.Add("Source", ctx.Event.Source); } } string signatureHash = ctx.StackSignatureData.Values.Any(v => v != null) ? ctx.StackSignatureData.Values.ToSHA1() : null; ctx.SetProperty("__SignatureHash", signatureHash); ctx.Stack = _stackRepository.GetStackBySignatureHash(ctx.Event.ProjectId, signatureHash); if (ctx.Stack == null) { Log.Trace().Message("Creating new error stack.").Write(); ctx.IsNew = true; ctx.Event.IsFirstOccurrence = true; string title = _formattingPluginManager.GetStackTitle(ctx.Event); var stack = new Stack { OrganizationId = ctx.Event.OrganizationId, ProjectId = ctx.Event.ProjectId, SignatureInfo = new SettingsDictionary(ctx.StackSignatureData), SignatureHash = signatureHash, Title = title != null?title.Truncate(1000) : null, Tags = ctx.Event.Tags ?? new TagSet(), Type = ctx.Event.Type, TotalOccurrences = 1, FirstOccurrence = ctx.Event.Date.UtcDateTime, LastOccurrence = ctx.Event.Date.UtcDateTime }; ctx.Stack = _stackRepository.Add(stack, true); } Log.Trace().Message("Updating error's ErrorStackId to: {0}", ctx.Stack.Id).Write(); ctx.Event.StackId = ctx.Stack.Id; } else { ctx.Stack = _stackRepository.GetById(ctx.Event.StackId, true); if (ctx.Stack == null || ctx.Stack.ProjectId != ctx.Event.ProjectId) { throw new ApplicationException("Invalid StackId."); } ctx.SetProperty("__SignatureHash", ctx.Stack.SignatureHash); } if (!ctx.IsNew && ctx.Event.Tags != null && ctx.Event.Tags.Count > 0) { if (ctx.Stack.Tags == null) { ctx.Stack.Tags = new TagSet(); } List <string> newTags = ctx.Event.Tags.Where(t => !ctx.Stack.Tags.Contains(t)).ToList(); if (newTags.Count > 0) { ctx.Stack.Tags.AddRange(newTags); _stackRepository.Save(ctx.Stack, true); } } // sync the fixed and hidden flags to the error occurrence ctx.Event.IsFixed = ctx.Stack.DateFixed.HasValue; ctx.Event.IsHidden = ctx.Stack.IsHidden; }
public override void ProcessBatch(ICollection <EventContext> contexts) { var stacks = new Dictionary <string, Tuple <bool, Stack> >(); foreach (var ctx in contexts) { if (String.IsNullOrEmpty(ctx.Event.StackId)) { // only add default signature info if no other signature info has been added if (ctx.StackSignatureData.Count == 0) { ctx.StackSignatureData.Add("Type", ctx.Event.Type); if (!String.IsNullOrEmpty(ctx.Event.Source)) { ctx.StackSignatureData.Add("Source", ctx.Event.Source); } } string signatureHash = ctx.StackSignatureData.Values.ToSHA1(); ctx.SignatureHash = signatureHash; Tuple <bool, Stack> value; if (stacks.TryGetValue(signatureHash, out value)) { ctx.Stack = value.Item2; } else { ctx.Stack = _stackRepository.GetStackBySignatureHash(ctx.Event.ProjectId, signatureHash); if (ctx.Stack != null) { stacks.Add(signatureHash, Tuple.Create(false, ctx.Stack)); } } if (ctx.Stack == null) { Log.Trace().Message("Creating new event stack.").Write(); ctx.IsNew = true; string title = _formattingPluginManager.GetStackTitle(ctx.Event); var stack = new Stack { OrganizationId = ctx.Event.OrganizationId, ProjectId = ctx.Event.ProjectId, SignatureInfo = new SettingsDictionary(ctx.StackSignatureData), SignatureHash = signatureHash, Title = title != null?title.Truncate(1000) : null, Tags = ctx.Event.Tags ?? new TagSet(), Type = ctx.Event.Type, TotalOccurrences = 1, FirstOccurrence = ctx.Event.Date.UtcDateTime, LastOccurrence = ctx.Event.Date.UtcDateTime }; ctx.Stack = stack; stacks.Add(signatureHash, Tuple.Create(true, ctx.Stack)); } } else { ctx.Stack = _stackRepository.GetById(ctx.Event.StackId, true); if (ctx.Stack == null || ctx.Stack.ProjectId != ctx.Event.ProjectId) { ctx.SetError("Invalid StackId."); continue; } ctx.SignatureHash = ctx.Stack.SignatureHash; if (!stacks.ContainsKey(ctx.Stack.SignatureHash)) { stacks.Add(ctx.Stack.SignatureHash, Tuple.Create(false, ctx.Stack)); } else { stacks[ctx.Stack.SignatureHash] = Tuple.Create(false, ctx.Stack); } } if (!ctx.IsNew && ctx.Event.Tags != null && ctx.Event.Tags.Count > 0) { if (ctx.Stack.Tags == null) { ctx.Stack.Tags = new TagSet(); } List <string> newTags = ctx.Event.Tags.Where(t => !ctx.Stack.Tags.Contains(t)).ToList(); if (newTags.Count > 0) { ctx.Stack.Tags.AddRange(newTags); // make sure the stack gets saved if (!stacks.ContainsKey(ctx.Stack.SignatureHash)) { stacks.Add(ctx.Stack.SignatureHash, Tuple.Create(true, ctx.Stack)); } else { stacks[ctx.Stack.SignatureHash] = Tuple.Create(true, stacks[ctx.Stack.SignatureHash].Item2); } } } ctx.Event.IsFirstOccurrence = ctx.IsNew; // sync the fixed and hidden flags to the error occurrence ctx.Event.IsFixed = ctx.Stack.DateFixed.HasValue; ctx.Event.IsHidden = ctx.Stack.IsHidden; } var stacksToAdd = stacks.Where(kvp => kvp.Value.Item1 && String.IsNullOrEmpty(kvp.Value.Item2.Id)).Select(kvp => kvp.Value.Item2).ToList(); if (stacksToAdd.Count > 0) { _stackRepository.Add(stacksToAdd, true, sendNotification: stacksToAdd.Count == 1); if (stacksToAdd.Count > 1) { _publisher.Publish(new EntityChanged { ChangeType = ChangeType.Added, Type = typeof(Stack).Name, OrganizationId = contexts.First().Organization.Id, ProjectId = contexts.First().Project.Id }); } } var stacksToSave = stacks.Where(kvp => kvp.Value.Item1 && !String.IsNullOrEmpty(kvp.Value.Item2.Id)).Select(kvp => kvp.Value.Item2).ToList(); if (stacksToSave.Count > 0) { _stackRepository.Save(stacksToSave, true, sendNotification: false); // notification will get sent later in the update stats step } // Set stack ids after they have been saved and created contexts.ForEach(ctx => { ctx.Event.StackId = ctx.Stack != null ? ctx.Stack.Id : null; }); }
public override void Process(EventContext ctx) { if (String.IsNullOrEmpty(ctx.Event.StackId)) { if (_stackRepository == null) { throw new InvalidOperationException("You must pass a non-null stackRepository parameter to the constructor."); } // only add default signature info if no other signature info has been added if (ctx.StackSignatureData.Count == 0) { ctx.StackSignatureData.Add("Type", ctx.Event.Type); if (!String.IsNullOrEmpty(ctx.Event.Source)) { ctx.StackSignatureData.Add("Source", ctx.Event.Source); } } string signatureHash = ctx.StackSignatureData.Values.Any(v => v != null) ? ctx.StackSignatureData.Values.ToSHA1() : null; ctx.SetProperty("__SignatureHash", signatureHash); ctx.Event.SummaryHtml = _pluginManager.GetEventSummaryHtml(ctx.Event); ctx.StackInfo = _stackRepository.GetStackInfoBySignatureHash(ctx.Event.ProjectId, signatureHash); if (ctx.StackInfo == null) { Log.Trace().Message("Creating new error stack.").Write(); ctx.IsNew = true; var stack = new Stack { OrganizationId = ctx.Event.OrganizationId, ProjectId = ctx.Event.ProjectId, SignatureInfo = new SettingsDictionary(ctx.StackSignatureData), SignatureHash = signatureHash, Title = _pluginManager.GetStackTitle(ctx.Event), SummaryHtml = _pluginManager.GetStackSummaryHtml(ctx.Event), Tags = ctx.Event.Tags ?? new TagSet(), TotalOccurrences = 1, FirstOccurrence = ctx.Event.Date.UtcDateTime, LastOccurrence = ctx.Event.Date.UtcDateTime }; ctx.Stack = _stackRepository.Add(stack, true); ctx.StackInfo = new StackInfo { Id = stack.Id, DateFixed = stack.DateFixed, OccurrencesAreCritical = stack.OccurrencesAreCritical }; // new 404 stack id added, invalidate 404 id cache if (ctx.Event.IsNotFound) { _stackRepository.InvalidateNotFoundIdsCache(ctx.Event.ProjectId); } } Log.Trace().Message("Updating error's ErrorStackId to: {0}", ctx.StackInfo.Id).Write(); ctx.Event.StackId = ctx.StackInfo.Id; } else { ctx.Stack = _stackRepository.GetById(ctx.Event.StackId); // TODO: Update unit tests to work with this check. //if (stack == null || stack.ProjectId != error.ProjectId) // throw new InvalidOperationException("Invalid ErrorStackId."); if (ctx.Stack == null) { return; } if (ctx.Event.Tags != null && ctx.Event.Tags.Count > 0) { if (ctx.Stack.Tags == null) { ctx.Stack.Tags = new TagSet(); } List <string> newTags = ctx.Event.Tags.Where(t => !ctx.Stack.Tags.Contains(t)).ToList(); if (newTags.Count > 0) { ctx.Stack.Tags.AddRange(newTags); _stackRepository.Save(ctx.Stack); } } ctx.StackInfo = new StackInfo { Id = ctx.Stack.Id, DateFixed = ctx.Stack.DateFixed, OccurrencesAreCritical = ctx.Stack.OccurrencesAreCritical, IsHidden = ctx.Stack.IsHidden }; } // sync the fixed and hidden flags to the error occurrence ctx.Event.IsFixed = ctx.StackInfo.DateFixed.HasValue; ctx.Event.IsHidden = ctx.StackInfo.IsHidden; }