Revision 7458b472cd08a9146d8e7aead66e07ed462c080b authored by Yang Cheng on 25 May 2021, 15:44:59 UTC, committed by GitHub on 25 May 2021, 15:44:59 UTC
1 parent 6cf3d65
Raw File
build.gradle
/*
 * 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 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 or the Server
 * Side Public License, v 1.
 */

import org.apache.tools.ant.taskdefs.condition.Os
import org.elasticsearch.gradle.Architecture
import org.elasticsearch.gradle.OS
import org.elasticsearch.gradle.internal.info.BuildParams
import org.elasticsearch.gradle.internal.test.AntFixture

apply plugin: 'elasticsearch.test-with-dependencies'
apply plugin: 'elasticsearch.jdk-download'
apply plugin: 'elasticsearch.yaml-rest-test'
apply plugin: 'elasticsearch.java-rest-test'
apply plugin: 'elasticsearch.yaml-rest-compat-test'
apply plugin: 'elasticsearch.internal-cluster-test'

esplugin {
  description 'The Reindex module adds APIs to reindex from one index to another or update documents in place.'
  classname 'org.elasticsearch.index.reindex.ReindexPlugin'
}

testClusters.all {
  // Modules who's integration is explicitly tested in integration tests
  module ':modules:parent-join'
  module ':modules:lang-painless'
  // Whitelist reindexing from the local node so we can test reindex-from-remote.
  setting 'reindex.remote.whitelist', '127.0.0.1:*'
}

tasks.named("test").configure {
  /*
   * We have to disable setting the number of available processors as tests in the
   * same JVM randomize processors and will step on each other if we allow them to
   * set the number of available processors as it's set-once in Netty.
   */
  systemProperty 'es.set.netty.runtime.available.processors', 'false'
}

dependencies {
  api project(":client:rest")
  api project(":libs:elasticsearch-ssl-config")
  // for http - testing reindex from remote
  testImplementation project(':modules:transport-netty4')
  // for parent/child testing
  testImplementation project(':modules:parent-join')
}

restResources {
  restApi {
    include '_common', 'cluster', 'nodes', 'indices', 'index', 'get', 'search', 'mget', 'count',
                'update_by_query', 'delete_by_query', 'reindex_rethrottle', 'tasks', 'reindex', 'put_script'
  }
}

tasks.named("thirdPartyAudit").configure {
  ignoreMissingClasses(
          // Commons logging
          'javax.servlet.ServletContextEvent',
          'javax.servlet.ServletContextListener',
          'org.apache.avalon.framework.logger.Logger',
          'org.apache.log.Hierarchy',
          'org.apache.log.Logger',
  )
}

tasks.named("forbiddenPatterns").configure {
  // PKCS#12 file are not UTF-8
  exclude '**/*.p12'
}

// Support for testing reindex-from-remote against old Elasticsearch versions
configurations {
  oldesFixture
  es2
  es1
  es090
}

dependencies {
  oldesFixture project(':test:fixtures:old-elasticsearch')
  /* Right now we just test against the latest version of each major we expect
   * reindex-from-remote to work against. We could randomize the versions but
   * that doesn't seem worth it at this point. */
  es2 'org.elasticsearch.distribution.zip:elasticsearch:2.4.5@zip'
  es1 'org.elasticsearch:elasticsearch:1.7.6@zip'
  es090 'org.elasticsearch:elasticsearch:0.90.13@zip'
}

jdks {
  legacy {
    vendor = 'adoptopenjdk'
    version = '8u242+b08'
    platform = OS.current().name().toLowerCase()
    architecture = Architecture.current().name().toLowerCase()
  }
}

if (Os.isFamily(Os.FAMILY_WINDOWS)) {
  logger.warn("Disabling reindex-from-old tests because we can't get the pid file on windows")
  tasks.named("javaRestTest").configure {
    systemProperty "tests.fromOld", "false"
  }
} else if (rootProject.rootDir.toString().contains(" ")) {
  logger.warn("Disabling reindex-from-old tests because Elasticsearch 1.7 won't start with spaces in the path")
  tasks.named("javaRestTest").configure {
    systemProperty "tests.fromOld", "false"
  }
} else {
  /* Set up tasks to unzip and run the old versions of ES before running the
   * integration tests. */
  def versions = ['2', '1', '090']
  if (Os.isFamily(Os.FAMILY_MAC)) {
    // 0.90 fails sometimes on mac, given that it is so old, let us disable it
    // see: https://github.com/elastic/elasticsearch/issues/51202
    versions = ['2', '1']
  }
  versions.each { version ->
    // TODO Rene: we should be able to replace these unzip tasks with gradle artifact transforms
    TaskProvider<Sync> unzip = tasks.register("unzipEs${version}", Sync) {
      Configuration oldEsDependency = configurations['es' + version]
      dependsOn oldEsDependency
      /* Use a closure here to delay resolution of the dependency until we need
       * it */
      from {
        oldEsDependency.collect { zipTree(it) }
      }
      into temporaryDir
    }

    TaskProvider<AntFixture> fixture = tasks.register("oldEs${version}Fixture", AntFixture) {
      dependsOn project.configurations.oldesFixture, jdks.legacy
      dependsOn unzip
      executable = "${BuildParams.runtimeJavaHome}/bin/java"
      env 'CLASSPATH', "${-> project.configurations.oldesFixture.asPath}"
      // old versions of Elasticsearch need JAVA_HOME
      env 'JAVA_HOME', jdks.legacy.javaHomePath
      // If we are running on certain arm systems we need to explicitly set the stack size to overcome JDK page size bug
      if (Architecture.current() == Architecture.AARCH64) {
        env 'ES_JAVA_OPTS', '-Xss512k'
      }
      args 'oldes.OldElasticsearch',
        baseDir,
        unzip.get().temporaryDir,
        version == '090'
      waitCondition = { fixture, ant ->
        // the fixture writes the ports file when Elasticsearch's HTTP service
        // is ready, so we can just wait for the file to exist
        return fixture.portsFile.exists()
      }
    }

    tasks.named("javaRestTest").configure {
      dependsOn fixture
        systemProperty "tests.fromOld", "true"
        /* Use a closure on the string to delay evaluation until right before we
         * run the integration tests so that we can be sure that the file is
         * ready. */
        nonInputProperties.systemProperty "es${version}.port", "${-> fixture.get().addressAndPort}"
    }
  }
}

tasks.named("yamlRestCompatTest").configure {
  systemProperty 'tests.rest.blacklist', [
    /*type related failures */
    'reindex/20_validation/reindex without source gives useful error message',
    'reindex/85_scripting/Reindex all docs with one doc deletion',
    'delete_by_query/10_basic/Response for version conflict (seq no powered)',
    'update_by_query/10_basic/Response for version conflict (seq no powered)',
    'update_by_query/20_validation/update_by_query without source gives useful error message'
  ].join(',')
}
back to top