diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy index cd7fc8fa877..957e845aa57 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy @@ -147,7 +147,6 @@ class ClusterFormationTasks { setup = configureStopTask(taskName(task, node, 'stopPrevious'), project, setup, node) setup = configureExtractTask(taskName(task, node, 'extract'), project, setup, node, configuration) setup = configureWriteConfigTask(taskName(task, node, 'configure'), project, setup, node, seedNode) - setup = configureExtraConfigFilesTask(taskName(task, node, 'extraConfig'), project, setup, node) setup = configureCopyPluginsTask(taskName(task, node, 'copyPlugins'), project, setup, node) // install modules @@ -162,6 +161,10 @@ class ClusterFormationTasks { setup = configureInstallPluginTask(taskName(task, node, actionName), project, setup, node, plugin.getValue()) } + // sets up any extra config files that need to be copied over to the ES instance; + // its run after plugins have been installed, as the extra config files may belong to plugins + setup = configureExtraConfigFilesTask(taskName(task, node, 'extraConfig'), project, setup, node) + // extra setup commands for (Map.Entry command : node.config.setupCommands.entrySet()) { // the first argument is the actual script name, relative to home diff --git a/plugins/discovery-file/build.gradle b/plugins/discovery-file/build.gradle index 36fd87e37a9..3b78f06505e 100644 --- a/plugins/discovery-file/build.gradle +++ b/plugins/discovery-file/build.gradle @@ -17,6 +17,10 @@ * under the License. */ +import org.elasticsearch.gradle.test.ClusterConfiguration +import org.elasticsearch.gradle.test.ClusterFormationTasks +import org.elasticsearch.gradle.test.NodeInfo + esplugin { description 'Discovery file plugin enables unicast discovery from hosts stored in a file.' classname 'org.elasticsearch.discovery.file.FileBasedDiscoveryPlugin' @@ -27,3 +31,29 @@ bundlePlugin { into 'config' } } + +task setupSeedNodeAndUnicastHostsFile(type: DefaultTask) { + mustRunAfter(precommit) +} +// setup the initial cluster with one node that will serve as the seed node +// for unicast discovery +ClusterConfiguration config = new ClusterConfiguration(project) +config.clusterName = 'discovery-file-test-cluster' +List nodes = ClusterFormationTasks.setup(project, setupSeedNodeAndUnicastHostsFile, config) +File srcUnicastHostsFile = file('build/cluster/unicast_hosts.txt') + +// write the unicast_hosts.txt file to a temporary location to be used by the second cluster +setupSeedNodeAndUnicastHostsFile.doLast { + // write the unicast_hosts.txt file to a temp file in the build directory + srcUnicastHostsFile.setText(nodes.get(0).transportUri(), 'UTF-8') +} + +// second cluster, which will connect to the first via the unicast_hosts.txt file +integTest { + dependsOn(setupSeedNodeAndUnicastHostsFile) + cluster { + clusterName = 'discovery-file-test-cluster' + extraConfigFile 'discovery-file/unicast_hosts.txt', srcUnicastHostsFile + } + finalizedBy ':plugins:discovery-file:setupSeedNodeAndUnicastHostsFile#stop' +} diff --git a/plugins/discovery-file/src/test/resources/rest-api-spec/test/discovery_file/10_basic.yaml b/plugins/discovery-file/src/test/resources/rest-api-spec/test/discovery_file/10_basic.yaml index 74ba6b54e3c..138115da112 100644 --- a/plugins/discovery-file/src/test/resources/rest-api-spec/test/discovery_file/10_basic.yaml +++ b/plugins/discovery-file/src/test/resources/rest-api-spec/test/discovery_file/10_basic.yaml @@ -1,13 +1,13 @@ # Integration tests for file-based discovery # -"Discovery File loaded": +"Ensure cluster formed successfully with discovery file": + # make sure both nodes joined the cluster + - do: + cluster.health: + wait_for_nodes: 2 + + # make sure the cluster was formed with the correct name - do: cluster.state: {} - # Get master node id - - set: { master_node: master } - - - do: - nodes.info: {} - - - match: { nodes.$master.plugins.0.name: discovery-file } + - match: { cluster_name: 'discovery-file-test-cluster' } # correct cluster name, we formed the cluster we expected to