Skip to content

Commit

Permalink
TimedRequest rocks!
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Dolzhenko committed Oct 3, 2018
1 parent 31ec2b8 commit ccbc485
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
*/
public class TimedRequest implements Validatable {

public static final TimeValue DEFAULT_MASTER_NODE_TIMEOUT = TimeValue.timeValueSeconds(30);

private TimeValue timeout;
private TimeValue masterTimeout;
private TimeValue masterTimeout = DEFAULT_MASTER_NODE_TIMEOUT;

public void setTimeout(TimeValue timeout) {
this.timeout = timeout;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
*/
package org.elasticsearch.client.license;

import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.master.AcknowledgedRequest;
import org.elasticsearch.client.TimedRequest;

public class StartBasicRequest extends AcknowledgedRequest<StartBasicRequest> {
public class StartBasicRequest extends TimedRequest {
private final boolean acknowledge;

public StartBasicRequest() {
Expand All @@ -32,11 +31,6 @@ public StartBasicRequest(boolean acknowledge) {
this.acknowledge = acknowledge;
}

@Override
public ActionRequestValidationException validate() {
return null;
}

public boolean isAcknowledge() {
return acknowledge;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void testStartBasic() {
expectedParams.put("acknowledge", Boolean.TRUE.toString());
}

setRandomTimeout(startBasicRequest::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);
setRandomTimeout(startBasicRequest, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);
setRandomMasterTimeout(startBasicRequest, expectedParams);
Request request = LicenseRequestConverters.startBasic(startBasicRequest);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1572,6 +1572,12 @@ static void setRandomLocal(MasterNodeReadRequest<?> request, Map<String, String>
setRandomLocal(request::local, expectedParams);
}

static void setRandomTimeout(TimedRequest request, TimeValue defaultTimeout, Map<String, String> expectedParams) {
setRandomTimeout(s ->
request.setTimeout(TimeValue.parseTimeValue(s, request.getClass().getName() + ".timeout")),
defaultTimeout, expectedParams);
}

static void setRandomTimeout(Consumer<String> setter, TimeValue defaultTimeout, Map<String, String> expectedParams) {
if (randomBoolean()) {
String timeout = randomTimeValue();
Expand All @@ -1583,9 +1589,19 @@ static void setRandomTimeout(Consumer<String> setter, TimeValue defaultTimeout,
}

static void setRandomMasterTimeout(MasterNodeRequest<?> request, Map<String, String> expectedParams) {
setRandomMasterTimeout(request::masterNodeTimeout, expectedParams);
}

static void setRandomMasterTimeout(TimedRequest request, Map<String, String> expectedParams) {
setRandomMasterTimeout(s ->
request.setMasterTimeout(TimeValue.parseTimeValue(s, request.getClass().getName() + ".masterNodeTimeout")),
expectedParams);
}

static void setRandomMasterTimeout(Consumer<String> setter, Map<String, String> expectedParams) {
if (randomBoolean()) {
String masterTimeout = randomTimeValue();
request.masterNodeTimeout(masterTimeout);
setter.accept(masterTimeout);
expectedParams.put("master_timeout", masterTimeout);
} else {
expectedParams.put("master_timeout", MasterNodeRequest.DEFAULT_MASTER_NODE_TIMEOUT.getStringRep());
Expand Down

0 comments on commit ccbc485

Please sign in to comment.