-
Notifications
You must be signed in to change notification settings - Fork 2k
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
base: main
Are you sure you want to change the base?
Removing blocking from FileAsyncApiTests file #42922
Conversation
API change check API changes are not detected in this pull request. |
There was a problem hiding this 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.*; |
There was a problem hiding this comment.
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.
...e/azure-storage-file-share/src/test/java/com/azure/storage/file/share/FileAsyncApiTests.java
Outdated
Show resolved
Hide resolved
|
||
StepVerifier | ||
.create(createFileMono.thenMany(pollerMono | ||
.flatMapMany(poller -> poller.take(1).doOnNext(it -> assertNotNull(it.getValue().getCopyId()))))) |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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
...e/azure-storage-file-share/src/test/java/com/azure/storage/file/share/FileAsyncApiTests.java
Outdated
Show resolved
Hide resolved
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(); |
There was a problem hiding this comment.
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));
}
StepVerifier | ||
.create(createFileMono.then(Mono.defer( | ||
() -> setPlaybackPollerFluxPollInterval(primaryFileAsyncClient.beginCopy(sourceURL, options, null)) | ||
.then(Mono.error(new ShareStorageException("LeaseNotPresentWithFileOperation", null, null)))))) | ||
.verifyError(ShareStorageException.class); |
There was a problem hiding this comment.
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.
.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)))) |
There was a problem hiding this comment.
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.
primaryFileAsyncClient.create(1024) | ||
.then(createLeaseClient(primaryFileAsyncClient).acquireLease()) | ||
.flatMap(leaseId -> primaryFileAsyncClient | ||
.deleteWithResponse(new ShareRequestConditions().setLeaseId(testResourceNamer.randomUuid()))) | ||
.as(StepVerifier::create) | ||
.verifyError(ShareStorageException.class); |
There was a problem hiding this comment.
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.
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())) |
There was a problem hiding this comment.
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);
/check-enforcer override |
/azp run java - storage - tests |
Azure Pipelines successfully started running 1 pipeline(s). |
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:
General Guidelines and Best Practices
Testing Guidelines