Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ESBlobStoreRepositoryIntegTestCase to test the repository-s3 plugin #29315

Merged
merged 3 commits into from
Apr 5, 2018

Conversation

tlrx
Copy link
Member

@tlrx tlrx commented Mar 30, 2018

The test framework contains three base classes for testing blob store repository implementations, but the S3 plugin does not use all of them.

This commit adds the S3BlobStoreRepositoryTests and S3BlobStoreTests classes that extends the base testing classes for S3. It also cleans up the S3BlobStoreTests and S3BlobStoreContainerTests so that they are now based on pure mock S3 clients.

It also removes some usage of socket servers that emulate socket connections in unit tests. It was added to trigger security exceptions, but this won't be needed anymore once #29296 will be merged.

closes #16472

@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 Mar 30, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed

@tlrx tlrx requested a review from ywelsch April 4, 2018 07:37
Copy link
Contributor

@ywelsch ywelsch left a comment

Choose a reason for hiding this comment

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

I think that it's simpler and nicer in MockAmazonS3 to just override the methods that we want to implement (just as we used to before this PR) instead of writing all these when(xyz).then(abc) conditions. I also would prefer not to have this static map within MockAmazonS3, but leave it up to the caller to decide whether to share instances or not. Maybe the map (= storage) could even be passed in when creating the object. @tlrx WDYT ?

@tlrx
Copy link
Member Author

tlrx commented Apr 4, 2018

Thanks for your review @ywelsch. I understand your concern about the mocked methods (even though I like them:)) and I updated the code. I also fixed some corner cases in the way the methods were implemented. Can you have another look please?

Copy link
Contributor

@ywelsch ywelsch left a comment

Choose a reason for hiding this comment

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

I've left a few nits, o.w. LGTM

throw new AmazonS3Exception("[" + blobName + "] already exists.");
public PutObjectResult putObject(final PutObjectRequest request) throws AmazonClientException {
assertThat(request.getBucketName(), equalTo(bucket));
assertThat(request.getBucketName(), equalTo(bucket));
Copy link
Contributor

Choose a reason for hiding this comment

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

don't drink and code 🍻 (same line twice)

Copy link
Member Author

Choose a reason for hiding this comment

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

I never drink while coding, otherwise it would be even worse :)


final List<DeleteObjectsResult.DeletedObject> deletions = new ArrayList<>();
for (DeleteObjectsRequest.KeyVersion key : request.getKeys()) {
if(blobs.remove(key.getKey()) == null){
Copy link
Contributor

Choose a reason for hiding this comment

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

spaces missing after if and before { 🗡


public class S3BlobStoreRepositoryTests extends ESBlobStoreRepositoryIntegTestCase {

private static final ConcurrentMap<String, byte[]> blobs = new ConcurrentHashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be reset after each test (and in particular cleaned up at the end as well). I hate statics but don't see another way to achieve this right now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Of course, thanks for spotting it.

tlrx added 3 commits April 5, 2018 10:14
The test framework contains a base class for testing blob store
repository implementations, but the S3 plugin does not use it.

This commit adds the S3BlobStoreRepositoryTests class that extends the
base testing class for S3. It also cleans up the S3BlobStoreTests and
S3BlobStoreContainerTests so that they are now based on pure mock S3
clients.

It also removes some usage of socket servers that emulate socket
connections in unit tests. It was added to trigger security exceptions,
but this won't be needed anymore once elastic#29296 will be merged.

closes elastic#16472
@tlrx tlrx merged commit d813a05 into elastic:master Apr 5, 2018
@tlrx tlrx deleted the cleanup-s3-tests branch April 5, 2018 11:34
@tlrx
Copy link
Member Author

tlrx commented Apr 5, 2018

Thanks @ywelsch !

tlrx added a commit that referenced this pull request Jun 7, 2018
…in (#29315)

This commit adds the S3BlobStoreRepositoryTests class that extends the
base testing class for S3. It also removes some usage of socket servers
that emulate socket connections in unit tests. It was added to trigger
security exceptions, but this won't be needed anymore since #29296
is merged.
@tlrx
Copy link
Member Author

tlrx commented Jun 7, 2018

This has been backported to 6.x in 5c3a40b

@tlrx tlrx added the v6.4.0 label Jun 7, 2018
jasontedor added a commit that referenced this pull request Jun 8, 2018
* elastic/6.x: (50 commits)
  Painless: Restructure/Clean Up of Spec Documentation (#31013)
  Add support for ignore_unmapped to geo sort (#31153)
  Enable engine factory to be pluggable (#31183)
  Remove vestiges of animal sniffer (#31178)
  Rename elasticsearch-core to core (#31185)
  Move cli sub-project out of server to libs (#31184)
  QA: Fixup rolling restart tests
  QA: Better seed nodes for rolling restart
  [DOCS] Fixes broken link in release notes
  [DOCS] Fixes broken link in auditing settings
  [DOCS] Moves ML content to stack-docs
  [DOCS] Clarifies recommendation for audit index output type (#31146)
  QA: Set better node names on rolling restart tests
  QA: Skip mysterious failing rolling upgrade tests
  Share common parser in some AcknowledgedResponses (#31169)
  Fix random failure on SearchQueryIT#testTermExpansionExceptionOnSpanFailure
  Remove reference to multiple fields with one name (#31127)
  Remove BlobContainer.move() method (#31100)
  [Docs] Correct minor typos in templates.asciidoc (#31167)
  Use ESBlobStoreRepositoryIntegTestCase to test the repository-s3 plugin (#29315)
  ...
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.4.0 v7.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

S3/Azure IT should use ESBlobStoreRepositoryIntegTestCase
4 participants