Skip to content

Commit e2327e1

Browse files
author
Hendrik Muhs
committed
reuse timeout from base class
1 parent 0298b7b commit e2327e1

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

x-pack/plugin/data-frame/src/main/java/org/elasticsearch/xpack/dataframe/action/StopDataFrameJobAction.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ public Response newResponse() {
4747
public static class Request extends BaseTasksRequest<Request> implements ToXContent {
4848
private String id;
4949
private final boolean waitForCompletion;
50-
private final TimeValue timeout;
5150

5251
public Request(String id, boolean waitForCompletion, @Nullable TimeValue timeout) {
5352
this.id = ExceptionsHelper.requireNonNull(id, DataFrameField.ID.getPreferredName());
5453
this.waitForCompletion = waitForCompletion;
55-
this.timeout = timeout == null ? DEFAULT_TIMEOUT : timeout;
54+
55+
// use the timeout value already present in BaseTasksRequest
56+
this.setTimeout(timeout == null ? DEFAULT_TIMEOUT : timeout);
5657
}
5758

5859
public Request() {
@@ -63,7 +64,6 @@ public Request(StreamInput in) throws IOException {
6364
super(in);
6465
id = in.readString();
6566
waitForCompletion = in.readBoolean();
66-
timeout = in.readTimeValue();
6767
}
6868

6969
public String getId() {
@@ -74,10 +74,6 @@ public void setId(String id) {
7474
this.id = id;
7575
}
7676

77-
public TimeValue getTimeout() {
78-
return timeout;
79-
}
80-
8177
public boolean waitForCompletion() {
8278
return waitForCompletion;
8379
}
@@ -87,7 +83,6 @@ public void writeTo(StreamOutput out) throws IOException {
8783
super.writeTo(out);
8884
out.writeString(id);
8985
out.writeBoolean(waitForCompletion);
90-
out.writeTimeValue(timeout);
9186
}
9287

9388
@Override
@@ -99,15 +94,16 @@ public ActionRequestValidationException validate() {
9994
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
10095
builder.field(DataFrameField.ID.getPreferredName(), id);
10196
builder.field(DataFrameField.WAIT_FOR_COMPLETION.getPreferredName(), waitForCompletion);
102-
if (timeout != null) {
103-
builder.field(DataFrameField.TIMEOUT.getPreferredName(), timeout);
97+
if (this.getTimeout() != null) {
98+
builder.field(DataFrameField.TIMEOUT.getPreferredName(), this.getTimeout());
10499
}
105100
return builder;
106101
}
107102

108103
@Override
109104
public int hashCode() {
110-
return Objects.hash(id, waitForCompletion, timeout);
105+
// the base class does not implement hashCode, therefore we need to hash timeout ourselves
106+
return Objects.hash(id, waitForCompletion, this.getTimeout());
111107
}
112108

113109
@Override
@@ -120,8 +116,13 @@ public boolean equals(Object obj) {
120116
return false;
121117
}
122118
Request other = (Request) obj;
123-
return Objects.equals(id, other.id) && Objects.equals(waitForCompletion, other.waitForCompletion)
124-
&& Objects.equals(timeout, other.timeout);
119+
120+
// the base class does not implement equals, therefore we need to compare timeout ourselves
121+
if (Objects.equals(this.getTimeout(), other.getTimeout()) == false) {
122+
return false;
123+
}
124+
125+
return Objects.equals(id, other.id) && Objects.equals(waitForCompletion, other.waitForCompletion);
125126
}
126127

127128
@Override

x-pack/plugin/data-frame/src/test/java/org/elasticsearch/xpack/dataframe/action/StopDataFrameJobActionRequestTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,15 @@ protected Request createTestInstance() {
2323
protected Writeable.Reader<Request> instanceReader() {
2424
return Request::new;
2525
}
26+
27+
public void testSameButDifferentTimeout() {
28+
String id = randomAlphaOfLengthBetween(1, 10);
29+
boolean waitForCompletion = randomBoolean();
30+
31+
Request r1 = new Request(id, waitForCompletion, TimeValue.timeValueSeconds(10));
32+
Request r2 = new Request(id, waitForCompletion, TimeValue.timeValueSeconds(20));
33+
34+
assertNotEquals(r1,r2);
35+
assertNotEquals(r1.hashCode(),r2.hashCode());
36+
}
2637
}

0 commit comments

Comments
 (0)