build.gradle 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import org.elasticsearch.gradle.Version
  2. import org.elasticsearch.gradle.test.NodeInfo
  3. import org.elasticsearch.gradle.test.RestIntegTestTask
  4. import java.nio.charset.StandardCharsets
  5. apply plugin: 'elasticsearch.standalone-test'
  6. dependencies {
  7. // "org.elasticsearch.plugin:x-pack-core:${version}" doesn't work with idea because the testArtifacts are also here
  8. testCompile project(path: xpackModule('core'), configuration: 'default')
  9. testCompile project(path: xpackModule('core'), configuration: 'testArtifacts') // to be moved in a later commit
  10. }
  11. // This is a top level task which we will add dependencies to below.
  12. // It is a single task that can be used to backcompat tests against all versions.
  13. task bwcTest {
  14. description = 'Runs backwards compatibility tests.'
  15. group = 'verification'
  16. }
  17. String outputDir = "${buildDir}/generated-resources/${project.name}"
  18. for (Version version : bwcVersions.wireCompatible) {
  19. String baseName = "v${version}"
  20. Task oldClusterTest = tasks.create(name: "${baseName}#oldClusterTest", type: RestIntegTestTask) {
  21. mustRunAfter(precommit)
  22. }
  23. configure(extensions.findByName("${baseName}#oldClusterTestCluster")) {
  24. if (version.before('6.3.0')) {
  25. mavenPlugin 'x-pack', "org.elasticsearch.plugin:x-pack:${version}"
  26. }
  27. bwcVersion = version
  28. numBwcNodes = 3
  29. numNodes = 3
  30. minimumMasterNodes = { 3 }
  31. clusterName = 'rolling-upgrade-basic'
  32. setting 'xpack.security.enabled', 'false'
  33. setting 'xpack.monitoring.enabled', 'false'
  34. setting 'xpack.ml.enabled', 'false'
  35. setting 'xpack.watcher.enabled', 'false'
  36. setting 'xpack.license.self_generated.type', 'basic'
  37. }
  38. Task oldClusterTestRunner = tasks.getByName("${baseName}#oldClusterTestRunner")
  39. oldClusterTestRunner.configure {
  40. systemProperty 'tests.rest.suite', 'old_cluster'
  41. }
  42. Closure configureUpgradeCluster = {String name, Task lastRunner, int stopNode, Closure unicastSeed ->
  43. configure(extensions.findByName("${baseName}#${name}")) {
  44. dependsOn lastRunner, "${baseName}#oldClusterTestCluster#node${stopNode}.stop"
  45. clusterName = 'rolling-upgrade-basic'
  46. unicastTransportUri = { seedNode, node, ant -> unicastSeed() }
  47. minimumMasterNodes = { 3 }
  48. /* Override the data directory so the new node always gets the node we
  49. * just stopped's data directory. */
  50. dataDir = { nodeNumber -> oldClusterTest.nodes[stopNode].dataDir }
  51. setting 'repositories.url.allowed_urls', 'http://snapshot.test*'
  52. setting 'xpack.security.enabled', 'false'
  53. setting 'xpack.monitoring.enabled', 'false'
  54. setting 'xpack.ml.enabled', 'false'
  55. setting 'xpack.watcher.enabled', 'false'
  56. setting 'xpack.license.self_generated.type', 'basic'
  57. setting 'node.name', "upgraded-node-${stopNode}"
  58. }
  59. }
  60. Task oneThirdUpgradedTest = tasks.create(name: "${baseName}#oneThirdUpgradedTest", type: RestIntegTestTask)
  61. configureUpgradeCluster("oneThirdUpgradedTestCluster", oldClusterTestRunner, 0,
  62. // Use all running nodes as seed nodes so there is no race between pinging and the tests
  63. { oldClusterTest.nodes.get(1).transportUri() + ',' + oldClusterTest.nodes.get(2).transportUri() })
  64. Task oneThirdUpgradedTestRunner = tasks.getByName("${baseName}#oneThirdUpgradedTestRunner")
  65. oneThirdUpgradedTestRunner.configure {
  66. systemProperty 'tests.rest.suite', 'mixed_cluster'
  67. systemProperty 'tests.first_round', 'true'
  68. finalizedBy "${baseName}#oldClusterTestCluster#node1.stop"
  69. }
  70. Task twoThirdsUpgradedTest = tasks.create(name: "${baseName}#twoThirdsUpgradedTest", type: RestIntegTestTask)
  71. configureUpgradeCluster("twoThirdsUpgradedTestCluster", oneThirdUpgradedTestRunner, 1,
  72. // Use all running nodes as seed nodes so there is no race between pinging and the tests
  73. { oldClusterTest.nodes.get(2).transportUri() + ',' + oneThirdUpgradedTest.nodes.get(0).transportUri() })
  74. Task twoThirdsUpgradedTestRunner = tasks.getByName("${baseName}#twoThirdsUpgradedTestRunner")
  75. twoThirdsUpgradedTestRunner.configure {
  76. systemProperty 'tests.rest.suite', 'mixed_cluster'
  77. systemProperty 'tests.first_round', 'false'
  78. finalizedBy "${baseName}#oldClusterTestCluster#node2.stop"
  79. }
  80. Task upgradedClusterTest = tasks.create(name: "${baseName}#upgradedClusterTest", type: RestIntegTestTask)
  81. configureUpgradeCluster("upgradedClusterTestCluster", twoThirdsUpgradedTestRunner, 2,
  82. // Use all running nodes as seed nodes so there is no race between pinging and the tests
  83. { oneThirdUpgradedTest.nodes.get(0).transportUri() + ',' + twoThirdsUpgradedTest.nodes.get(0).transportUri() })
  84. Task upgradedClusterTestRunner = tasks.getByName("${baseName}#upgradedClusterTestRunner")
  85. upgradedClusterTestRunner.configure {
  86. systemProperty 'tests.rest.suite', 'upgraded_cluster'
  87. /*
  88. * Force stopping all the upgraded nodes after the test runner
  89. * so they are alive during the test.
  90. */
  91. finalizedBy "${baseName}#oneThirdUpgradedTestCluster#stop"
  92. finalizedBy "${baseName}#twoThirdsUpgradedTestCluster#stop"
  93. }
  94. Task versionBwcTest = tasks.create(name: "${baseName}#bwcTest") {
  95. dependsOn = [upgradedClusterTest]
  96. }
  97. if (project.bwc_tests_enabled) {
  98. bwcTest.dependsOn(versionBwcTest)
  99. }
  100. }
  101. test.enabled = false // no unit tests for rolling upgrades, only the rest integration test
  102. // basic integ tests includes testing bwc against the most recent version
  103. task integTest {
  104. if (project.bwc_tests_enabled) {
  105. for (final def version : bwcVersions.snapshotsWireCompatible) {
  106. dependsOn "v${version}#bwcTest"
  107. }
  108. }
  109. }
  110. check.dependsOn(integTest)
  111. compileTestJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked"
  112. // copy x-pack plugin info so it is on the classpath and security manager has the right permissions
  113. task copyXPackRestSpec(type: Copy) {
  114. dependsOn(project.configurations.restSpec, 'processTestResources')
  115. from project(xpackProject('plugin').path).sourceSets.test.resources
  116. include 'rest-api-spec/api/**'
  117. into project.sourceSets.test.output.resourcesDir
  118. }
  119. task copyXPackPluginProps(type: Copy) {
  120. dependsOn(copyXPackRestSpec)
  121. from project(xpackModule('core')).file('src/main/plugin-metadata')
  122. from project(xpackModule('core')).tasks.pluginProperties
  123. into outputDir
  124. }
  125. project.sourceSets.test.output.dir(outputDir, builtBy: copyXPackPluginProps)
  126. repositories {
  127. maven {
  128. url "https://artifacts.elastic.co/maven"
  129. }
  130. maven {
  131. url "https://snapshots.elastic.co/maven"
  132. }
  133. }