Skip to content

Commit

Permalink
iter
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Büscher committed Mar 20, 2020
1 parent 017fb83 commit 28b307a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@

package org.elasticsearch.client.asyncsearch;

import org.elasticsearch.client.TimedRequest;
import org.elasticsearch.client.Validatable;

import java.util.Objects;

public class DeleteAsyncSearchRequest extends TimedRequest {
public class DeleteAsyncSearchRequest implements Validatable {

private final String id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,20 @@

package org.elasticsearch.client.asyncsearch;

import org.elasticsearch.client.TimedRequest;
import org.elasticsearch.client.Validatable;
import org.elasticsearch.client.ValidationException;
import org.elasticsearch.common.unit.TimeValue;

import java.util.Objects;
import java.util.Optional;

public class GetAsyncSearchRequest extends TimedRequest {
public class GetAsyncSearchRequest implements Validatable {

private TimeValue waitForCompletion;
private TimeValue keepAlive;

public static final long MIN_KEEPALIVE = TimeValue.timeValueMinutes(1).millis();

private final String id;

public GetAsyncSearchRequest(String id) {
Expand All @@ -55,6 +60,18 @@ public void setKeepAlive(TimeValue keepAlive) {
this.keepAlive = keepAlive;
}

@Override
public Optional<ValidationException> validate() {
final ValidationException validationException = new ValidationException();
if (keepAlive != null && keepAlive.getMillis() < MIN_KEEPALIVE) {
validationException.addValidationError("keep_alive must be greater than 1 minute, got: " + keepAlive.toString());
}
if (validationException.validationErrors().isEmpty()) {
return Optional.empty();
}
return Optional.of(validationException);
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.elasticsearch.client.asyncsearch;

import org.elasticsearch.client.ValidationException;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.test.ESTestCase;

import java.util.concurrent.TimeUnit;

public class GetAsyncSearchRequestTests extends ESTestCase {

public void testValidation() {
GetAsyncSearchRequest getAsyncSearchRequest = new GetAsyncSearchRequest(randomAlphaOfLength(10));
getAsyncSearchRequest.setKeepAlive(new TimeValue(0));
assertTrue(getAsyncSearchRequest.validate().isPresent());
ValidationException validationException = getAsyncSearchRequest.validate().get();
assertEquals(1, validationException.validationErrors().size());
assertEquals("Validation Failed: 1: keep_alive must be greater than 1 minute, got: 0s;", validationException.getMessage());

getAsyncSearchRequest.setKeepAlive(new TimeValue(1, TimeUnit.MINUTES));
assertFalse(getAsyncSearchRequest.validate().isPresent());
}
}

0 comments on commit 28b307a

Please sign in to comment.