Skip to content

Use fixture to test the repository-gcs plugin#28788

Merged
tlrx merged 2 commits intoelastic:masterfrom
tlrx:use-fixture-for-repository-gcs
Mar 9, 2018
Merged

Use fixture to test the repository-gcs plugin#28788
tlrx merged 2 commits intoelastic:masterfrom
tlrx:use-fixture-for-repository-gcs

Conversation

@tlrx
Copy link
Copy Markdown
Member

@tlrx tlrx commented Feb 22, 2018

This commit adds a GoogleCloudStorageFixture that uses the logic of a GoogleCloudStorageTestServer (added in #28576) to emulate a remote Google Cloud Storage service.

By adding this fixture and a new integration test, we should be able to catch more bugs when upgrading the client library. In consequence the old REST test RepositoryGcsClientYamlTestSuiteIT has been removed. Sadly the GoogleCloudStorageTestServer has to be adapted for a better handling of batch requests. The fixture is started by the googleCloudStorageFixture task and a custom Service Account file is created and added to the Elasticsearch keystore before the integration test.

The fixture resides in the repository-gcs plugin project.

This commit adds a GoogleCloudStorageFixture that uses the
logic of a GoogleCloudStorageTestServer (added in elastic#28576)
to emulate a remote Google Cloud Storage service.

By adding this fixture and a new integration test, we should
be able to catch more bugs when upgrading the client library.

In consequence the old REST test RepositoryGcsClientYamlTestSuiteIT
has been removed. The GoogleCloudStorageTestServer has to be
adapted a bit for batch requests.

The fixture is started by the googleCloudStorageFixture task
and a custom Service Account file is created and added to the
Elasticsearch keystore for each test.
@tlrx tlrx added >test Issues or PRs that are addressing/adding tests review :Distributed/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs v7.0.0 labels Feb 22, 2018
@tlrx tlrx requested review from rjernst and ywelsch February 22, 2018 16:24
Copy link
Copy Markdown
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great @tlrx! Just a few suggestions.

}

/** A service account file that points to the Google Cloud Storage service emulated by the fixture **/
File serviceAccountFile = new File(project.buildDir, "/generated-resources/service_account_test.json")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first / is not necessary.

' "private_key": "-----BEGIN PRIVATE KEY-----\\n' + encodedKey + '\\n-----END PRIVATE KEY-----\\n",\n' +
' "client_email": "integration_test@appspot.gserviceaccount.com",\n' +
' "client_id": "123456789101112130594",\n' +
" \"auth_uri\": \"http://${ -> googleCloudStorageFixture.addressAndPort }/o/oauth2/auth\",\n" +
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the closures are necessary here, since setText takes String and thus these will immediately be resolved.

import static org.apache.http.entity.ContentType.APPLICATION_JSON;
import static org.hamcrest.Matchers.containsString;

public class GoogleCloudStorageIT extends ESRestTestCase {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything that prevents this from still being in a yaml test?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really. I thought we reserved YAML tests to test the REST API.

I reverted this change and added back the yaml test in a more complete fashion.

*/
GoogleCloudStorageTestServer(final String endpoint, final boolean prefixWithEndpoint) {
this.handlers = defaultHandlers(endpoint, prefixWithEndpoint, buckets);
GoogleCloudStorageTestServer(final String endpoint) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long term (not in this PR) I think it would be good to move this into the fixture, and use a more pure unit testing mock for the service calls inside the unit tests.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

I created the issue #28960 to track this.

@tlrx tlrx merged commit 4756790 into elastic:master Mar 9, 2018
@tlrx tlrx deleted the use-fixture-for-repository-gcs branch March 9, 2018 12:58
@tlrx
Copy link
Copy Markdown
Member Author

tlrx commented Mar 9, 2018

Thanks @rjernst

tlrx added a commit that referenced this pull request Mar 9, 2018
This commit adds a GoogleCloudStorageFixture that uses the
logic of a GoogleCloudStorageTestServer (added in #28576)
to emulate a remote Google Cloud Storage service.

By adding this fixture and a more complete integration test, we 
should be able to catch more bugs when upgrading the client library.

The fixture is started by the googleCloudStorageFixture task
and a custom Service Account file is created and added to the
Elasticsearch keystore for each test.
@tlrx tlrx added the v6.3.0 label Mar 9, 2018
@tlrx
Copy link
Copy Markdown
Member Author

tlrx commented Mar 9, 2018

This change has been backported to 6.x in be8ae87

sebasjm pushed a commit to sebasjm/elasticsearch that referenced this pull request Mar 10, 2018
This commit adds a GoogleCloudStorageFixture that uses the
logic of a GoogleCloudStorageTestServer (added in elastic#28576)
to emulate a remote Google Cloud Storage service.

By adding this fixture and a more complete integration test, we 
should be able to catch more bugs when upgrading the client library.

The fixture is started by the googleCloudStorageFixture task
and a custom Service Account file is created and added to the
Elasticsearch keystore for each test.
jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Mar 12, 2018
* master: (28 commits)
  Maybe die before failing engine (elastic#28973)
  Remove special handling for _all in nodes info
  Remove Booleans use from XContent and ToXContent (elastic#28768)
  Update Gradle Testing Docs (elastic#28970)
  Make primary-replica resync failures less lenient (elastic#28534)
  Remove temporary file 10_basic.yml~
  Use different pipeline id in test. (pipelines do not get removed between tests extending from ESIntegTestCase)
  Use fixture to test the repository-gcs plugin (elastic#28788)
  Use String.join() to describe a list of tasks (elastic#28941)
  Fixed incorrect test try-catch statement
  Plugins: Consolidate plugin and module loading code (elastic#28815)
  percolator: Take `matchAllDocs` and `verified` of the sub result into account when analyzing a function_score query.
  Build: Remove rest tests on archive distribution projects (elastic#28952)
  Remove FastStringReader in favor of vanilla StringReader (elastic#28944)
  Remove FastCharArrayReader and FastCharArrayWriter (elastic#28951)
  Continue registering pipelines after one pipeline parse failure. (elastic#28752)
  Build: Fix ability to ignore when no tests are run (elastic#28930)
  [rest-api-spec] update doc link for /_rank_eval
  Switch XContentBuilder from BytesStreamOutput to ByteArrayOutputStream (elastic#28945)
  Factor UnknownNamedObjectException into its own class (elastic#28931)
  ...
tlrx added a commit to tlrx/elasticsearch that referenced this pull request Mar 29, 2018
This commit adds a new fixture that emulates a S3 service in order to
improve the existing integration tests. This is very similar to what has
 been made for Google Cloud Storage in elastic#28788, and such tests would have
 helped a lot to catch bugs like elastic#22534.

The AmazonS3Fixture is brittle and only implements the very necessary
stuff for the S3 repository to work, but at least it works and can be
adapted for specific tests needs.
tlrx added a commit that referenced this pull request Apr 3, 2018
This commit adds a new fixture that emulates a S3 service in order to
improve the existing integration tests. This is very similar to what has
 been made for Google Cloud Storage in #28788, and such tests would 
have helped a lot to catch bugs like #22534.

The AmazonS3Fixture is brittle and only implements the very necessary
stuff for the S3 repository to work, but at least it works and can be
adapted for specific tests needs.
tlrx added a commit to tlrx/elasticsearch that referenced this pull request Apr 6, 2018
This commit adds a new fixture that emulates an
Azure Storage service in order to improve the
existing integration tests. This is very similar
to what has been made for Google Cloud Storage
in elastic#28788 and for Amazon S3 in elastic#29296, and it
would have helped a lot to catch bugs like elastic#22534.
tlrx added a commit that referenced this pull request Apr 6, 2018
This commit adds a new fixture that emulates an
Azure Storage service in order to improve the
existing integration tests. This is very similar
to what has been made for Google Cloud Storage
in #28788 and for Amazon S3 in #29296, and it
would have helped a lot to catch bugs like #22534.
tlrx added a commit that referenced this pull request Apr 30, 2018
Similarly to what has been done in for the repository-s3 plugin, 
this commit moves the fixture test into a dedicated 
repository-gcs/qa/google-cloud-storage project.

It also exposes some environment variables which allows to 
execute the integration tests against the real Google Cloud 
Storage service. When the environment variables are not 
defined, the integration tests are executed using the fixture 
added in #28788. Related to #29349.
tlrx added a commit that referenced this pull request Apr 30, 2018
Similarly to what has been done in for the repository-s3 plugin,
this commit moves the fixture test into a dedicated
repository-gcs/qa/google-cloud-storage project.

It also exposes some environment variables which allows to
execute the integration tests against the real Google Cloud
Storage service. When the environment variables are not
defined, the integration tests are executed using the fixture
added in #28788. Related to #29349.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Distributed/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs >test Issues or PRs that are addressing/adding tests v6.3.0 v7.0.0-beta1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants