Skip to content

Commit e292cda

Browse files
author
Greg Bielleman
committed
Merge branch 'hotfix-1.4.1'
2 parents 9986fcb + 1e8060e commit e292cda

File tree

15 files changed

+275
-229
lines changed

15 files changed

+275
-229
lines changed

src/Chocolatey/ServiceControl.install.nuspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<authors>Particular Software</authors>
88
<owners>Particular Software</owners>
99
<projectUrl>http://particular.net</projectUrl>
10+
<licenseUrl>http://particular.net/LicenseAgreement</licenseUrl>
1011
<iconUrl>http://s3.amazonaws.com/nuget.images/ServiceControl_128.png</iconUrl>
1112
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1213
<description>Management extension to NServiceBus</description>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
namespace ServiceControl.UnitTests.Infrastructure
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using NServiceBus;
6+
using NUnit.Framework;
7+
8+
[TestFixture]
9+
public class TransportMessageExtensionsTests
10+
{
11+
[Test]
12+
public void No_headers_should_throw_with_message_id()
13+
{
14+
var message = new TransportMessage(Guid.Empty.ToString(),new Dictionary<string, string>());
15+
var exception = Assert.Throws<Exception>(() => { message.ProcessingEndpointName(); });
16+
Assert.AreEqual("No processing endpoint could be determined for message (00000000-0000-0000-0000-000000000000)",exception.Message);
17+
}
18+
19+
[Test]
20+
public void No_headers_with_message_type_should_throw_with_message_id_and_types()
21+
{
22+
var message = new TransportMessage(Guid.Empty.ToString(), new Dictionary<string, string>
23+
{
24+
{ Headers.EnclosedMessageTypes ,"TheMessageType"}
25+
});
26+
var exception = Assert.Throws<Exception>(() => { message.ProcessingEndpointName(); });
27+
Assert.AreEqual("No processing endpoint could be determined for message (00000000-0000-0000-0000-000000000000) with EnclosedMessageTypes (TheMessageType)", exception.Message);
28+
}
29+
30+
[Test]
31+
public void With_ProcessingEndpoint_header_should_return_processing_endpoint()
32+
{
33+
var message = new TransportMessage(Guid.Empty.ToString(), new Dictionary<string, string>
34+
{
35+
{ Headers.ProcessingEndpoint ,"TheEndpoint"}
36+
});
37+
Assert.AreEqual("TheEndpoint",message.ProcessingEndpointName());
38+
}
39+
40+
[Test]
41+
public void With_FailedQ_header_should_return_FailedQ()
42+
{
43+
var message = new TransportMessage(Guid.Empty.ToString(), new Dictionary<string, string>
44+
{
45+
{ "NServiceBus.FailedQ" ,"TheEndpoint"}
46+
});
47+
Assert.AreEqual("TheEndpoint",message.ProcessingEndpointName());
48+
}
49+
50+
[Test]
51+
public void With_ReplyToAddress_should_return_ReplyToAddress()
52+
{
53+
var message = new TransportMessage
54+
{
55+
ReplyToAddress = new Address("TheEndpoint", "")
56+
};
57+
Assert.AreEqual("TheEndpoint",message.ProcessingEndpointName());
58+
}
59+
}
60+
}

src/ServiceControl.UnitTests/ServiceControl.UnitTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
<Compile Include="Infrastructure\RavenDB\Indexes\InMemoryStoreBuilder.cs" />
9797
<Compile Include="Infrastructure\RavenDB\RavenBootstrapperTests.cs" />
9898
<Compile Include="Infrastructure\RavenDB\TestWithRavenDB.cs" />
99+
<Compile Include="Infrastructure\TransportMessageExtensionsTests.cs" />
99100
<Compile Include="Operations\UpdateLicenseEnricherTest.cs" />
100101
</ItemGroup>
101102
<ItemGroup>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
namespace ServiceControl.CustomChecks
2+
{
3+
using System;
4+
using System.Linq;
5+
using System.Reactive.Concurrency;
6+
using System.Reactive.Linq;
7+
using NServiceBus;
8+
using NServiceBus.Logging;
9+
using Raven.Abstractions.Data;
10+
using Raven.Client;
11+
using INeedInitialization = NServiceBus.INeedInitialization;
12+
13+
public class CustomCheckNotifications : INeedInitialization, IWantToRunWhenBusStartsAndStops, IObserver<IndexChangeNotification>
14+
{
15+
IDocumentStore store;
16+
IBus bus;
17+
int lastCount;
18+
IDisposable subscription;
19+
ILog logging = LogManager.GetLogger(typeof(CustomCheckNotifications));
20+
21+
public CustomCheckNotifications()
22+
{
23+
// Need this because INeedInitialization does not use DI instead use Activator.CreateInstance
24+
}
25+
26+
public CustomCheckNotifications(IDocumentStore store, IBus bus)
27+
{
28+
this.bus = bus;
29+
this.store = store;
30+
}
31+
32+
public void Init()
33+
{
34+
Configure.Component<CustomCheckNotifications>(DependencyLifecycle.SingleInstance);
35+
}
36+
37+
public void OnNext(IndexChangeNotification value)
38+
{
39+
UpdateCount();
40+
}
41+
42+
void UpdateCount()
43+
{
44+
try
45+
{
46+
using (var session = store.OpenSession())
47+
{
48+
var failedCustomCheckCount = session.Query<CustomCheck, CustomChecksIndex>().Count(p => p.Status == Status.Fail);
49+
if (lastCount == failedCustomCheckCount)
50+
return;
51+
lastCount = failedCustomCheckCount;
52+
bus.Publish(new CustomChecksUpdated
53+
{
54+
Failed = lastCount
55+
});
56+
}
57+
}
58+
catch (Exception ex)
59+
{
60+
logging.WarnFormat("Failed to emit CustomCheckUpdated - {0}", ex);
61+
}
62+
63+
}
64+
65+
public void OnError(Exception error)
66+
{
67+
//Ignore
68+
}
69+
70+
public void OnCompleted()
71+
{
72+
//Ignore
73+
}
74+
75+
public void Start()
76+
{
77+
subscription = store.Changes().ForIndex("CustomChecksIndex").SubscribeOn(Scheduler.Default).Subscribe(this);
78+
}
79+
80+
public void Stop()
81+
{
82+
subscription.Dispose();
83+
}
84+
}
85+
}

src/ServiceControl/CustomChecks/CustomChecksComputation.cs

Lines changed: 0 additions & 109 deletions
This file was deleted.

src/ServiceControl/CustomChecks/RaiseCustomCheckChanges.cs

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/ServiceControl/EventLog/EventLogApiModule.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ public EventLogApiModule()
1515
using (var session = Store.OpenSession())
1616
{
1717
RavenQueryStatistics stats;
18-
var results = session.Query<EventLogItem>()
19-
.Statistics(out stats)
18+
var results = session.Query<EventLogItem>().Statistics(out stats).OrderByDescending(p => p.RaisedAt)
2019
.ToArray();
2120

2221
return Negotiate.WithModel(results)

src/ServiceControl/Infrastructure/RavenDB/Expiration/ExpiredDocumentsCleaner.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
[ExportMetadata("Bundle", "customDocumentExpiration")]
2222
public class ExpiredDocumentsCleaner : IStartupTask, IDisposable
2323
{
24-
private readonly ILog logger = LogManager.GetLogger(typeof(ExpiredDocumentsCleaner));
25-
private Timer timer;
24+
ILog logger = LogManager.GetLogger(typeof(ExpiredDocumentsCleaner));
25+
Timer timer;
2626
DocumentDatabase Database { get; set; }
2727
string indexName;
2828
int deleteFrequencyInSeconds;
@@ -75,13 +75,12 @@ void TimerCallback(object state)
7575
},
7676
};
7777

78-
var docsToExpire = 0;
79-
var stopwatch = Stopwatch.StartNew();
8078
try
8179
{
80+
var docsToExpire = 0;
8281
// we may be receiving a LOT of documents to delete, so we are going to skip
8382
// the cache for that, to avoid filling it up very quickly
84-
83+
var stopwatch = Stopwatch.StartNew();
8584
int deletionCount;
8685
using (DocumentCacher.SkipSettingDocumentsInDocumentCache())
8786
using (Database.DisableAllTriggersForCurrentThread())
@@ -94,7 +93,9 @@ void TimerCallback(object state)
9493
doc =>
9594
{
9695
if (documentWithCurrentThresholdTimeReached)
96+
{
9797
return;
98+
}
9899

99100
if (doc.Value<DateTime>("ProcessedAt") >= currentExpiryThresholdTime)
100101
{
@@ -137,10 +138,6 @@ void TimerCallback(object state)
137138
}
138139
finally
139140
{
140-
if (stopwatch.IsRunning)
141-
{
142-
stopwatch.Stop();
143-
}
144141
try
145142
{
146143
timer.Change(TimeSpan.FromSeconds(deleteFrequencyInSeconds), Timeout.InfiniteTimeSpan);

src/ServiceControl/Infrastructure/Settings/Settings.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,7 @@ public static int ExpirationProcessBatchSize
204204
set { expirationProcessBatchSize = value; }
205205
}
206206

207-
public static bool RandomizeProcessedAtDate = SettingsReader<bool>.Read("RandomizeProcessedAtDate");
208-
207+
209208
static readonly ILog Logger = LogManager.GetLogger(typeof(Settings));
210209
public static string ServiceName;
211210

0 commit comments

Comments
 (0)