Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TEST] Close additional clients created while running yaml tests #31575

Merged
merged 1 commit into from
Jun 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
* A {@link NodeSelector} that selects nodes that have a particular value
Expand Down Expand Up @@ -49,6 +50,24 @@ public void select(Iterable<Node> nodes) {
}
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
HasAttributeNodeSelector that = (HasAttributeNodeSelector) o;
return Objects.equals(key, that.key) &&
Objects.equals(value, that.value);
}

@Override
public int hashCode() {
return Objects.hash(key, value);
}

@Override
public String toString() {
return key + "=" + value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestPath;
import org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestSpec;

import java.io.Closeable;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.URI;
Expand All @@ -56,18 +57,18 @@
* {@link RestClient} instance used to send the REST requests. Holds the {@link ClientYamlSuiteRestSpec} used to translate api calls into
* REST calls.
*/
public class ClientYamlTestClient {
public class ClientYamlTestClient implements Closeable {
private static final Logger logger = Loggers.getLogger(ClientYamlTestClient.class);

private static final ContentType YAML_CONTENT_TYPE = ContentType.create("application/yaml");

private final ClientYamlSuiteRestSpec restSpec;
protected final Map<NodeSelector, RestClient> restClients = new HashMap<>();
private final Map<NodeSelector, RestClient> restClients = new HashMap<>();
private final Version esVersion;
private final Version masterVersion;
private final CheckedConsumer<RestClientBuilder, IOException> clientBuilderConsumer;

public ClientYamlTestClient(
ClientYamlTestClient(
final ClientYamlSuiteRestSpec restSpec,
final RestClient restClient,
final List<HttpHost> hosts,
Expand Down Expand Up @@ -202,10 +203,10 @@ protected RestClient getRestClient(NodeSelector nodeSelector) {
RestClientBuilder builder = RestClient.builder(anyClient.getNodes().toArray(new Node[0]));
try {
clientBuilderConsumer.accept(builder);
} catch(IOException e) {
} catch (IOException e) {
throw new UncheckedIOException(e);
}
builder.setNodeSelector(nodeSelector);
builder.setNodeSelector(selector);
return builder.build();
});
}
Expand Down Expand Up @@ -247,4 +248,11 @@ private ClientYamlSuiteRestApi restApi(String apiName) {
}
return restApi;
}

@Override
public void close() throws IOException {
for (RestClient restClient : restClients.values()) {
restClient.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,24 @@ public void select(Iterable<Node> nodes) {
lhs.select(nodes);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ComposeNodeSelector that = (ComposeNodeSelector) o;
return Objects.equals(lhs, that.lhs) &&
Objects.equals(rhs, that.rhs);
}

@Override
public int hashCode() {
return Objects.hash(lhs, rhs);
}

@Override
public String toString() {
// . as in haskell's "compose" operator
Expand Down