Skip to content

Commit a8a4d0f

Browse files
committed
fix watcher tests, _status is now status and watcher_stats api changed
1 parent 62cd890 commit a8a4d0f

File tree

9 files changed

+62
-51
lines changed

9 files changed

+62
-51
lines changed

src/Nest/XPack/Watcher/AcknowledgeWatch/AcknowledgeWatchResponse.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Nest
88
{
99
public interface IAcknowledgeWatchResponse : IResponse
1010
{
11-
[JsonProperty("_status")]
11+
[JsonProperty("status")]
1212
WatchStatus Status { get; }
1313
}
1414

src/Nest/XPack/Watcher/ActivateWatch/ActivateWatchResponse.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ namespace Nest
55
{
66
public interface IActivateWatchResponse : IResponse
77
{
8+
[JsonProperty("status")]
89
ActivationStatus Status { get; }
910
}
1011

1112
public class ActivateWatchResponse : ResponseBase, IActivateWatchResponse
1213
{
13-
[JsonProperty("_status")]
14+
[JsonProperty("status")]
1415
public ActivationStatus Status { get; internal set; }
1516
}
1617

src/Nest/XPack/Watcher/DeactivateWatch/DeactivateWatchResponse.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ namespace Nest
44
{
55
public interface IDeactivateWatchResponse : IResponse
66
{
7+
[JsonProperty("status")]
78
ActivationStatus Status { get; }
89
}
910

1011
public class DeactivateWatchResponse : ResponseBase, IDeactivateWatchResponse
1112
{
12-
[JsonProperty("_status")]
13+
[JsonProperty("status")]
1314
public ActivationStatus Status { get; internal set; }
1415
}
1516
}

src/Nest/XPack/Watcher/GetWatch/GetWatchResponse.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public interface IGetWatchResponse : IResponse
1111
[JsonProperty("_id")]
1212
string Id { get; }
1313

14-
[JsonProperty("_status")]
14+
[JsonProperty("status")]
1515
WatchStatus Status { get; }
1616

1717
[JsonProperty("watch")]

src/Nest/XPack/Watcher/WatcherStats/WatcherStatsResponse.cs

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,43 @@ namespace Nest
88
{
99
[JsonObject]
1010
public interface IWatcherStatsResponse : IResponse
11+
{
12+
[JsonProperty("cluster_name")]
13+
string ClusterName { get; }
14+
15+
[JsonProperty("manually_stopped")]
16+
bool ManuallyStopped { get; }
17+
18+
[JsonProperty("stats")]
19+
IReadOnlyCollection<WatcherNodeStats> Stats { get; }
20+
21+
}
22+
23+
public class WatcherStatsResponse : ResponseBase, IWatcherStatsResponse
24+
{
25+
public IReadOnlyCollection<WatcherNodeStats> Stats { get; internal set; } = EmptyReadOnly<WatcherNodeStats>.Collection;
26+
27+
public bool ManuallyStopped { get; internal set; }
28+
29+
public string ClusterName { get; internal set; }
30+
}
31+
32+
public class WatcherNodeStats
1133
{
1234
[JsonProperty("watcher_state")]
13-
WatcherState WatcherState { get; }
35+
public WatcherState WatcherState { get; internal set; }
1436

1537
[JsonProperty("watch_count")]
16-
long WatchCount { get; }
38+
public long WatchCount { get; internal set; }
1739

1840
[JsonProperty("execution_thread_pool")]
19-
ExecutionThreadPool ExecutionThreadPool { get; }
41+
public ExecutionThreadPool ExecutionThreadPool { get; internal set; }
2042

2143
[JsonProperty("current_watches")]
22-
IReadOnlyCollection<WatchRecordStats> CurrentWatches { get; }
44+
public IReadOnlyCollection<WatchRecordStats> CurrentWatches { get; internal set; } = EmptyReadOnly<WatchRecordStats>.Collection;
2345

2446
[JsonProperty("queued_watches")]
25-
IReadOnlyCollection<WatchRecordQueuedStats> QueuedWatches { get; }
26-
27-
[JsonProperty("manually_stopped")]
28-
bool ManuallyStopped { get; }
47+
public IReadOnlyCollection<WatchRecordQueuedStats> QueuedWatches { get; internal set; } = EmptyReadOnly<WatchRecordQueuedStats>.Collection;
2948
}
3049

3150
[JsonConverter(typeof(StringEnumConverter))]
@@ -44,21 +63,6 @@ public enum WatcherState
4463
Stopping,
4564
}
4665

47-
public class WatcherStatsResponse : ResponseBase, IWatcherStatsResponse
48-
{
49-
public WatcherState WatcherState { get; internal set; }
50-
51-
public long WatchCount { get; internal set; }
52-
53-
public ExecutionThreadPool ExecutionThreadPool { get; internal set; }
54-
55-
public IReadOnlyCollection<WatchRecordStats> CurrentWatches { get; internal set; }
56-
57-
public IReadOnlyCollection<WatchRecordQueuedStats> QueuedWatches { get; internal set; }
58-
59-
public bool ManuallyStopped { get; internal set; }
60-
}
61-
6266
public class WatchRecordQueuedStats
6367
{
6468
[JsonProperty("watch_id")]

src/Tests/XPack/License/GetLicense/GetLicenseApiTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected override void ExpectResponse(IGetLicenseResponse response)
3737
var l = response.License;
3838
l.Should().NotBeNull();
3939
l.ExpiryDate.Should().BeAfter(DateTime.UtcNow.AddYears(-2));
40-
l.IssueDate.Should().BeAfter(DateTime.UtcNow.AddYears(-2));
40+
l.IssueDate.Should().BeAfter(DateTime.UtcNow.AddYears(-30));
4141
l.IssueDateInMilliseconds.Should().BeGreaterThan(0);
4242
l.ExpiryDateInMilliseconds.Should().BeGreaterThan(0);
4343
l.IssuedTo.Should().NotBeNullOrWhiteSpace();

src/Tests/XPack/Watcher/GetWatch/GetWatchApiTests.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ public class GetWatchApiTests : ApiIntegrationTestBase<XPackCluster, IGetWatchRe
1313
{
1414
public GetWatchApiTests(XPackCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
1515

16-
protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
16+
protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values) => PutWatch(client, values);
17+
18+
public static void PutWatch(IElasticClient client, CallUniqueValues values)
1719
{
1820
foreach (var callUniqueValue in values)
1921
{
@@ -53,8 +55,7 @@ protected override void IntegrationSetup(IElasticClient client, CallUniqueValues
5355
)
5456
.Transform(ctt => ctt
5557
.Script(st => st
56-
.Inline("return [ time : ctx.trigger.scheduled_time ]")
57-
.Lang("groovy")
58+
.Inline("return [ 'time' : ctx.trigger.scheduled_time ]")
5859
)
5960
)
6061
)
@@ -71,7 +72,7 @@ protected override void IntegrationSetup(IElasticClient client, CallUniqueValues
7172
);
7273

7374
if (!putWatchResponse.IsValid)
74-
throw new Exception("Problem setting up integration test");
75+
throw new Exception($"Problem setting up integration test: {putWatchResponse.DebugInformation}");
7576
}
7677
}
7778

@@ -147,11 +148,15 @@ protected override void ExpectResponse(IGetWatchResponse response)
147148

148149
public class GetNonExistentWatchApiTests : ApiIntegrationTestBase<XPackCluster, IGetWatchResponse, IGetWatchRequest, GetWatchDescriptor, GetWatchRequest>
149150
{
151+
152+
//TODO this setup should not be necessary but in 6.0.0-alpha1 if no `.watches` index exists the response is actually an error
153+
protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values) => GetWatchApiTests.PutWatch(client, values);
154+
150155
public GetNonExistentWatchApiTests(XPackCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
151156

152157
protected override LazyResponses ClientUsage() => Calls(
153-
fluent: (client, f) => client.GetWatch(CallIsolatedValue, f),
154-
fluentAsync: (client, f) => client.GetWatchAsync(CallIsolatedValue, f),
158+
fluent: (client, f) => client.GetWatch(CallIsolatedValue + "x", f),
159+
fluentAsync: (client, f) => client.GetWatchAsync(CallIsolatedValue + "x", f),
155160
request: (client, r) => client.GetWatch(r),
156161
requestAsync: (client, r) => client.GetWatchAsync(r)
157162
);
@@ -160,22 +165,22 @@ protected override LazyResponses ClientUsage() => Calls(
160165
protected override int ExpectStatusCode => 404;
161166
protected override HttpMethod HttpMethod => HttpMethod.GET;
162167

163-
protected override string UrlPath => $"/_xpack/watcher/watch/{CallIsolatedValue}";
168+
protected override string UrlPath => $"/_xpack/watcher/watch/{CallIsolatedValue + "x"}";
164169

165170
protected override bool SupportsDeserialization => true;
166171

167-
protected override GetWatchDescriptor NewDescriptor() => new GetWatchDescriptor(CallIsolatedValue);
172+
protected override GetWatchDescriptor NewDescriptor() => new GetWatchDescriptor(CallIsolatedValue + "x");
168173

169174
protected override object ExpectJson => null;
170175

171176
protected override Func<GetWatchDescriptor, IGetWatchRequest> Fluent => f => f;
172177

173-
protected override GetWatchRequest Initializer => new GetWatchRequest(CallIsolatedValue);
178+
protected override GetWatchRequest Initializer => new GetWatchRequest(CallIsolatedValue + "x");
174179

175180
protected override void ExpectResponse(IGetWatchResponse response)
176181
{
177182
response.Found.Should().BeFalse();
178-
response.Id.Should().Be(CallIsolatedValue);
183+
response.Id.Should().Be(CallIsolatedValue + "x");
179184
response.Status.Should().BeNull();
180185
response.Watch.Should().BeNull();
181186
}

src/Tests/XPack/Watcher/PutWatch/PutWatchApiTests.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,7 @@ protected override LazyResponses ClientUsage() => Calls(
179179
{
180180
script = new
181181
{
182-
inline = "return [ time : ctx.trigger.scheduled_time ]",
183-
lang = "groovy"
182+
inline = "return [ 'time' : ctx.trigger.scheduled_time ]",
184183
}
185184
}
186185
}
@@ -404,8 +403,7 @@ protected override LazyResponses ClientUsage() => Calls(
404403
)
405404
.Transform(ctt => ctt
406405
.Script(st => st
407-
.Inline("return [ time : ctx.trigger.scheduled_time ]")
408-
.Lang("groovy")
406+
.Inline("return [ 'time' : ctx.trigger.scheduled_time ]")
409407
)
410408
)
411409
)
@@ -598,10 +596,7 @@ protected override LazyResponses ClientUsage() => Calls(
598596
},
599597
Timeout = "10s",
600598
},
601-
new InlineScriptTransform("return [ time : ctx.trigger.scheduled_time ]")
602-
{
603-
Lang = "groovy"
604-
}
599+
new InlineScriptTransform("return [ 'time' : ctx.trigger.scheduled_time ]")
605600
}
606601
},
607602
Condition = new GreaterThanOrEqualArrayCondition("ctx.payload.search.aggregations.top_project_tags.buckets", "doc_count", 1),

src/Tests/XPack/Watcher/WatcherStats/WatcherStatsApiTests.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using Elasticsearch.Net;
34
using FluentAssertions;
45
using Nest;
@@ -84,14 +85,18 @@ protected override LazyResponses ClientUsage() => Calls(
8485

8586
protected override void ExpectResponse(IWatcherStatsResponse response)
8687
{
87-
response.WatchCount.Should().BeGreaterThan(0);
88-
response.WatcherState.Should().Be(WatcherState.Started);
88+
response.ClusterName.Should().NotBeNullOrWhiteSpace();
89+
response.Stats.Should().NotBeEmpty();
90+
var nodeStats = response.Stats.First();
8991

90-
response.ExecutionThreadPool.Should().NotBeNull();
92+
nodeStats.WatchCount.Should().BeGreaterThan(0);
93+
nodeStats.WatcherState.Should().Be(WatcherState.Started);
94+
95+
nodeStats.ExecutionThreadPool.Should().NotBeNull();
9196

9297
// TODO: Would be good if we can test these too
93-
response.CurrentWatches.Should().NotBeNull();
94-
response.QueuedWatches.Should().NotBeNull();
98+
nodeStats.CurrentWatches.Should().NotBeNull();
99+
nodeStats.QueuedWatches.Should().NotBeNull();
95100
}
96101
}
97102
}

0 commit comments

Comments
 (0)