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

Removing blocking from FileAsyncApiTests file #42922

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

gunjansingh-msft
Copy link
Contributor

Description

Please add an informative description that covers that changes made by the pull request and link all relevant issues.

If an SDK is being regenerated based on a new swagger spec, a link to the pull request containing these swagger spec changes has been included above.

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

@github-actions github-actions bot added the Storage Storage Service (Queues, Blobs, Files) label Nov 13, 2024
@azure-sdk
Copy link
Collaborator

API change check

API changes are not detected in this pull request.

Copy link
Contributor

@ibrandes ibrandes left a comment

Choose a reason for hiding this comment

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

Looking good so far! Make sure to re-record the tests you added the missing .verifyComplete() step to so we can get a good idea of what CI looks like.

import com.azure.storage.file.share.models.ShareSnapshotInfo;
import com.azure.storage.file.share.models.ShareStorageException;
import com.azure.storage.file.share.models.ShareTokenIntent;
import com.azure.storage.file.share.models.*;
Copy link
Contributor

Choose a reason for hiding this comment

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

typically, we never want to use * imports. intellij likes to add these automatically sometimes even if you have "Use single class import" checked, but you can (mostly) ensure it never does this by going to Settings > Editor > Code Style > Java, and changing "Class count to use import with *" and "Names count to use static import with *" to 1000. While you're there, you can also make sure "Use single class import" is checked.

Screenshot 2024-11-13 083957


StepVerifier
.create(createFileMono.thenMany(pollerMono
.flatMapMany(poller -> poller.take(1).doOnNext(it -> assertNotNull(it.getValue().getCopyId())))))
Copy link
Contributor

Choose a reason for hiding this comment

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

right now, this test is failing because .doOnNext() emits a mono, and .expectComplete() assumes nothing else is emitted. also, nesting the PollerFlux in a mono is a little awkward.

you can change it to

Flux<AsyncPollResponse<ShareFileCopyInfo, Void>> poller = optionsMono.flatMapMany(
            options -> setPlaybackPollerFluxPollInterval(primaryFileAsyncClient.beginCopy(sourceURL, options, null)));

        StepVerifier.create(createFileMono.thenMany(poller))
            .assertNext(it -> assertNotNull(it.getValue().getCopyId()))
            .expectComplete()
            .verify(Duration.ofMinutes(1));

setPlaybackPollerFluxPollInterval(primaryFileAsyncClient.beginCopy(sourceURL, options, null))))
.verifyErrorSatisfies(throwable -> {
ShareStorageException e = assertInstanceOf(ShareStorageException.class, throwable);
assertEquals("LeaseNotPresentWithFileOperation", e.getErrorCode());
Copy link
Contributor

Choose a reason for hiding this comment

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

This fails because you are comparing e.getErrorCode() (which returns a ShareErrorCode object) to a string. You can change e.getErrorCode() to e.getErrorCode().toString() and it should pass

Comment on lines 1073 to 1082
StepVerifier.create(leaseIdMono.flatMapMany(leaseId -> {
ShareRequestConditions conditions = new ShareRequestConditions().setLeaseId(leaseId);
ShareFileCopyOptions options = new ShareFileCopyOptions().setDestinationRequestConditions(conditions);
PollerFlux<ShareFileCopyInfo, Void> poller
= setPlaybackPollerFluxPollInterval(primaryFileAsyncClient.beginCopy(sourceURL, options, null));
return poller.take(1).flatMap(response -> {
assertNotNull(response.getValue().getCopyId());
return Mono.just(response);
});
})).expectNextCount(1).verifyComplete();
Copy link
Contributor

Choose a reason for hiding this comment

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

We can also make use of returning just the PollerFlux here instead of doing anything extra to it:

@Test
    public void startCopyWithOptionsLease() {
        String sourceURL = primaryFileAsyncClient.getFileUrl();
        Mono<String> leaseIdMono
            = primaryFileAsyncClient.create(1024).then(createLeaseClient(primaryFileAsyncClient).acquireLease());

        StepVerifier.create(leaseIdMono.flatMapMany(leaseId -> {
            ShareRequestConditions conditions = new ShareRequestConditions().setLeaseId(leaseId);
            ShareFileCopyOptions options = new ShareFileCopyOptions().setDestinationRequestConditions(conditions);
            return setPlaybackPollerFluxPollInterval(primaryFileAsyncClient.beginCopy(sourceURL, options, null));
        })).assertNext(it -> assertNotNull(it.getValue().getCopyId())).expectComplete().verify(Duration.ofMinutes(1));
    }

Comment on lines 1094 to 1098
StepVerifier
.create(createFileMono.then(Mono.defer(
() -> setPlaybackPollerFluxPollInterval(primaryFileAsyncClient.beginCopy(sourceURL, options, null))
.then(Mono.error(new ShareStorageException("LeaseNotPresentWithFileOperation", null, null))))))
.verifyError(ShareStorageException.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not checking if the copy actually throws the error, as the error is thrown manually on line 1097. We want to change this to:

StepVerifier
            .create(createFileMono.thenMany(
                setPlaybackPollerFluxPollInterval(primaryFileAsyncClient.beginCopy(sourceURL, options, null))))
            .verifyErrorSatisfies(r -> {
                ShareStorageException e = assertInstanceOf(ShareStorageException.class, r);
                assertEquals("LeaseNotPresentWithFileOperation", e.getErrorCode().getValue());
            });

This ensures that the copy actually throws the error.

Comment on lines 576 to 580
.create(primaryFileAsyncClient.create(DATA.getDefaultDataSizeLong())
.then(createLeaseClient(primaryFileAsyncClient).acquireLease())
.flatMap(leaseId -> primaryFileAsyncClient.uploadFromFile(uploadFile,
new ShareRequestConditions().setLeaseId(testResourceNamer.randomUuid())))
.then(Mono.error(new ShareStorageException("Lease ID mismatch", null, null))))
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't want to manually throw an error, as that doesn't check if the error actually occurs when making the call. Check my previous comment to see how to change this.

Comment on lines 1191 to 1196
primaryFileAsyncClient.create(1024)
.then(createLeaseClient(primaryFileAsyncClient).acquireLease())
.flatMap(leaseId -> primaryFileAsyncClient
.deleteWithResponse(new ShareRequestConditions().setLeaseId(testResourceNamer.randomUuid())))
.as(StepVerifier::create)
.verifyError(ShareStorageException.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

Although this works, I think it is important to follow the normal structure of StepVerifier we've been using for other tests unless absolutely necessary.

Comment on lines 1501 to 1507
StepVerifier.create(primaryFileAsyncClient.createWithResponse(1024, null, null, null, null)
.then()
.then(primaryFileAsyncClient.uploadFromFile(uploadFile).then())
.then(createLeaseClient(primaryFileAsyncClient).acquireLease())
.then(primaryFileAsyncClient
.listRanges(null, new ShareRequestConditions().setLeaseId(testResourceNamer.randomUuid()))
.then()))
Copy link
Contributor

Choose a reason for hiding this comment

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

There are several redundant statements here - you can remove the then()'s and change the last .then( to .thenMany(

StepVerifier.create(primaryFileAsyncClient.createWithResponse(1024, null, null, null, null)
            .then(primaryFileAsyncClient.uploadFromFile(uploadFile))
            .then(createLeaseClient(primaryFileAsyncClient).acquireLease())
            .thenMany(primaryFileAsyncClient
                .listRanges(null, new ShareRequestConditions().setLeaseId(testResourceNamer.randomUuid()))))
            .verifyError(ShareStorageException.class);

@gunjansingh-msft
Copy link
Contributor Author

/check-enforcer override

@gunjansingh-msft
Copy link
Contributor Author

/azp run java - storage - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Storage Storage Service (Queues, Blobs, Files)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants