Skip to content

Commit

Permalink
Migrate discovery-ec2 YAML tests to Java REST tests (#118427) (#118448
Browse files Browse the repository at this point in the history
)

Really just to create a starting point for a more comprehensive Java
REST test suite, the test itself is not very interesting.
  • Loading branch information
DaveCTurner authored Dec 11, 2024
1 parent aea8255 commit d2fbb0d
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 54 deletions.
8 changes: 1 addition & 7 deletions plugins/discovery-ec2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import org.elasticsearch.gradle.internal.info.BuildParams
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/
apply plugin: 'elasticsearch.legacy-yaml-rest-test'
apply plugin: 'elasticsearch.internal-cluster-test'
apply plugin: 'elasticsearch.internal-java-rest-test'

esplugin {
description 'The EC2 discovery plugin allows to use AWS API for the unicast discovery mechanism.'
Expand All @@ -31,12 +31,6 @@ dependencies {
api "joda-time:joda-time:2.10.10"
}

restResources {
restApi {
include '_common', 'cluster', 'nodes'
}
}

tasks.named("dependencyLicenses").configure {
mapping from: /aws-java-sdk-.*/, to: 'aws-java-sdk'
mapping from: /jackson-.*/, to: 'jackson'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

package org.elasticsearch.discovery.ec2;

import org.elasticsearch.client.Request;
import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.junit.ClassRule;

import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;

import static org.hamcrest.Matchers.hasItem;

public class DiscoveryEc2PluginLoadedIT extends ESRestTestCase {

@ClassRule
public static ElasticsearchCluster cluster = ElasticsearchCluster.local().plugin("discovery-ec2").build();

@Override
protected String getTestRestCluster() {
return cluster.getHttpAddresses();
}

public void testPluginLoaded() throws IOException {
final var nodesInfoResponse = assertOKAndCreateObjectPath(client().performRequest(new Request("GET", "/_nodes/plugins")));
for (final var nodeId : nodesInfoResponse.evaluateMapKeys("nodes")) {
final var pluginCount = asInstanceOf(List.class, nodesInfoResponse.evaluateExact("nodes", nodeId, "plugins")).size();
final var pluginNames = new HashSet<String>();
for (int i = 0; i < pluginCount; i++) {
pluginNames.add(
Objects.requireNonNull(nodesInfoResponse.evaluateExact("nodes", nodeId, "plugins", Integer.toString(i), "name"))
);
}
assertThat(pluginNames, hasItem("discovery-ec2"));
}
}

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,24 @@ public <T> T evaluate(String path) throws IOException {
/**
* Returns the object corresponding to the provided path if present, null otherwise
*/
@SuppressWarnings("unchecked")
public <T> T evaluate(String path, Stash stash) throws IOException {
String[] parts = parsePath(path);
return evaluateExact(stash, parsePath(path));
}

/**
* Returns the object corresponding to the provided path if present, null otherwise
*/
public <T> T evaluateExact(String... path) throws IOException {
return evaluateExact(Stash.EMPTY, path);
}

/**
* Returns the object corresponding to the provided path if present, null otherwise
*/
@SuppressWarnings("unchecked")
public <T> T evaluateExact(Stash stash, String... path) throws IOException {
Object result = this.object;
for (String part : parts) {
for (String part : path) {
result = evaluate(part, result, stash);
if (result == null) {
return null;
Expand Down

0 comments on commit d2fbb0d

Please sign in to comment.