Skip to content

Commit 7e890f5

Browse files
authored
Fixes to Tables tests, as well as client documentation and exceptions. (Azure#23336)
* - Ensured that tests exclusive to Storage are not run when testing a Cosmos endpoint. - Fixed tests that failed due to Cosmos not returning a `[email protected]` property in a `TableEntity` alongside the `Timestamp` property, like Storage does. This is apparently intended behavior, so we now treat `Timestamp` as a special case that needs to be always converted to `OffsetDateTime`. - Fixed the `setGetProperty()` tests in `TableServiceClientTest` and `TableServiceAsyncClientTest`, which failed for Storage because properties can take up to 30 seconds to be propagated on Storage accounts. - Updated `TableEntity` documentation to remove all mentions of using its subclasses. - Updated clients to properly map the implementation `TableServiceErrorException` to the public `TableServiceException` in operations such as `getAccessPolicies()`, `getProperties()`, `setProperties()` and `getStatistics()`, including their "withResponse" variants. - Updated client documentation to accurately reflect which exceptions are thrown by service methods. - Fixed batch operations to properly log exceptions other than `TableTransactionFailedException`. * Removed unused import. * Applied PR feedback: - Removed assumption that prevented the `canUseSasTokenToCreateValidTableClient()` tests to run on Cosmos endpoints. - Changed `TableAsyncClient.submitTransactionWithResponse()` to wrap an `IllegalArgumentException` with a `Mono` when no transaction actions are provided. - Updated `submitTransactionAsyncWithSameRowKeys()` tests to check the error's status code instead of just the error message. * Skipping `canUseSasTokenToCreateValidTableClient()` tests for Cosmos endpoints to unblock nightly test runs. Will investigate further until this can be resolved. * Fixed CheckStyle issue.
1 parent 3accf73 commit 7e890f5

File tree

12 files changed

+341
-80
lines changed

12 files changed

+341
-80
lines changed

sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClient.java

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,6 @@ public void close() {
863863
* empty.
864864
* @throws TableServiceException If no {@link TableEntity entity} with the provided {@code partitionKey} and
865865
* {@code rowKey} exists within the table.
866-
* table.
867866
*/
868867
@ServiceMethod(returns = ReturnType.SINGLE)
869868
public Mono<TableEntity> getEntity(String partitionKey, String rowKey) {
@@ -939,12 +938,16 @@ <T extends TableEntity> Mono<Response<T>> getEntityWithResponse(String partition
939938
* Retrieves details about any stored {@link TableAccessPolicies access policies} specified on the table that may
940939
* be used with Shared Access Signatures.
941940
*
941+
* <p>This operation is only supported on Azure Storage endpoints.</p>
942+
*
942943
* <p><strong>Code Samples</strong></p>
943944
* <p>Gets a table's {@link TableAccessPolicies access policies}. Prints out the details of the retrieved
944945
* {@link TableAccessPolicies access policies}.</p>
945946
* {@codesnippet com.azure.data.tables.tableAsyncClient.getAccessPolicies}
946947
*
947948
* @return A {@link Mono} containing the table's {@link TableAccessPolicies access policies}.
949+
*
950+
* @throws TableServiceException If the request is rejected by the service.
948951
*/
949952
@ServiceMethod(returns = ReturnType.SINGLE)
950953
public Mono<TableAccessPolicies> getAccessPolicies() {
@@ -956,13 +959,17 @@ public Mono<TableAccessPolicies> getAccessPolicies() {
956959
* Retrieves details about any stored {@link TableAccessPolicies access policies} specified on the table that may be
957960
* used with Shared Access Signatures.
958961
*
962+
* <p>This operation is only supported on Azure Storage endpoints.</p>
963+
*
959964
* <p><strong>Code Samples</strong></p>
960965
* <p>Gets a table's {@link TableAccessPolicies access policies}. Prints out the details of the
961966
* {@link Response HTTP response} and the retrieved {@link TableAccessPolicies access policies}.</p>
962967
* {@codesnippet com.azure.data.tables.tableAsyncClient.getAccessPoliciesWithResponse}
963968
*
964969
* @return A {@link Mono} containing an {@link Response HTTP response} that in turn contains the table's
965970
* {@link TableAccessPolicies access policies}.
971+
*
972+
* @throws TableServiceException If the request is rejected by the service.
966973
*/
967974
@ServiceMethod(returns = ReturnType.SINGLE)
968975
public Mono<Response<TableAccessPolicies>> getAccessPoliciesWithResponse() {
@@ -975,6 +982,7 @@ Mono<Response<TableAccessPolicies>> getAccessPoliciesWithResponse(Context contex
975982
try {
976983
return tablesImplementation.getTables()
977984
.getAccessPolicyWithResponseAsync(tableName, null, null, context)
985+
.onErrorMap(TableUtils::mapThrowableToTableServiceException)
978986
.map(response -> new SimpleResponse<>(response,
979987
new TableAccessPolicies(response.getValue() == null ? null : response.getValue().stream()
980988
.map(this::toTableSignedIdentifier)
@@ -1008,13 +1016,17 @@ private TableAccessPolicy toTableAccessPolicy(AccessPolicy accessPolicy) {
10081016
* Sets stored {@link TableAccessPolicies access policies} for the table that may be used with Shared Access
10091017
* Signatures.
10101018
*
1019+
* <p>This operation is only supported on Azure Storage endpoints.</p>
1020+
*
10111021
* <p><strong>Code Samples</strong></p>
10121022
* <p>Sets stored {@link TableAccessPolicies access policies} on a table.</p>
10131023
* {@codesnippet com.azure.data.tables.tableAsyncClient.setAccessPolicies#List}
10141024
*
10151025
* @param tableSignedIdentifiers The {@link TableSignedIdentifier access policies} for the table.
10161026
*
10171027
* @return An empty {@link Mono}.
1028+
*
1029+
* @throws TableServiceException If the request is rejected by the service.
10181030
*/
10191031
@ServiceMethod(returns = ReturnType.SINGLE)
10201032
public Mono<Void> setAccessPolicies(List<TableSignedIdentifier> tableSignedIdentifiers) {
@@ -1025,6 +1037,8 @@ public Mono<Void> setAccessPolicies(List<TableSignedIdentifier> tableSignedIdent
10251037
* Sets stored {@link TableAccessPolicies access policies} for the table that may be used with Shared Access
10261038
* Signatures.
10271039
*
1040+
* <p>This operation is only supported on Azure Storage endpoints.</p>
1041+
*
10281042
* <p><strong>Code Samples</strong></p>
10291043
* <p>Sets stored {@link TableAccessPolicies access policies} on a table. Prints out details of the
10301044
* {@link Response HTTP response}.</p>
@@ -1033,6 +1047,8 @@ public Mono<Void> setAccessPolicies(List<TableSignedIdentifier> tableSignedIdent
10331047
* @param tableSignedIdentifiers The {@link TableSignedIdentifier access policies} for the table.
10341048
*
10351049
* @return A {@link Mono} containing the {@link Response HTTP response}.
1050+
*
1051+
* @throws TableServiceException If the request is rejected by the service.
10361052
*/
10371053
@ServiceMethod(returns = ReturnType.SINGLE)
10381054
public Mono<Response<Void>> setAccessPoliciesWithResponse(List<TableSignedIdentifier> tableSignedIdentifiers) {
@@ -1081,6 +1097,7 @@ OffsetDateTime.now will only give back milliseconds (more precise fields are zer
10811097
try {
10821098
return tablesImplementation.getTables()
10831099
.setAccessPolicyWithResponseAsync(tableName, null, null, signedIdentifiers, context)
1100+
.onErrorMap(TableUtils::mapThrowableToTableServiceException)
10841101
.map(response -> new SimpleResponse<>(response, response.getValue()));
10851102
} catch (RuntimeException e) {
10861103
return monoError(logger, e);
@@ -1132,6 +1149,7 @@ private AccessPolicy toAccessPolicy(TableAccessPolicy tableAccessPolicy) {
11321149
* correspond to each {@link TableTransactionAction action} in the transaction.
11331150
*
11341151
* @throws IllegalArgumentException If no {@link TableTransactionAction actions} have been added to the list.
1152+
* @throws TableServiceException If the request is rejected by the service.
11351153
* @throws TableTransactionFailedException If any {@link TableTransactionResult action} within the transaction
11361154
* fails. See the documentation for the client methods in {@link TableClient} to understand the conditions that
11371155
* may cause a given {@link TableTransactionAction action} to fail.
@@ -1168,6 +1186,7 @@ public Mono<TableTransactionResult> submitTransaction(List<TableTransactionActio
11681186
* correspond to each {@link TableTransactionAction action} in the transaction.
11691187
*
11701188
* @throws IllegalArgumentException If no {@link TableTransactionAction actions} have been added to the list.
1189+
* @throws TableServiceException If the request is rejected by the service.
11711190
* @throws TableTransactionFailedException If any {@link TableTransactionAction action} within the transaction
11721191
* fails. See the documentation for the client methods in {@link TableClient} to understand the conditions that
11731192
* may cause a given {@link TableTransactionAction action} to fail.
@@ -1180,8 +1199,8 @@ public Mono<Response<TableTransactionResult>> submitTransactionWithResponse(List
11801199
Mono<Response<TableTransactionResult>> submitTransactionWithResponse(List<TableTransactionAction> transactionActions, Context context) {
11811200
Context finalContext = context == null ? Context.NONE : context;
11821201

1183-
if (transactionActions.size() == 0) {
1184-
throw logger.logExceptionAsError(
1202+
if (transactionActions.isEmpty()) {
1203+
return monoError(logger,
11851204
new IllegalArgumentException("A transaction must contain at least one operation."));
11861205
}
11871206

@@ -1224,18 +1243,23 @@ Mono<Response<TableTransactionResult>> submitTransactionWithResponse(List<TableT
12241243
}
12251244
}
12261245

1227-
return Flux.fromIterable(operations)
1228-
.flatMapSequential(op -> op.prepareRequest(transactionalBatchClient).zipWith(Mono.just(op)))
1229-
.collect(TransactionalBatchRequestBody::new, (body, pair) ->
1230-
body.addChangeOperation(new TransactionalBatchSubRequest(pair.getT2(), pair.getT1())))
1231-
.publishOn(Schedulers.boundedElastic())
1232-
.flatMap(body ->
1233-
transactionalBatchImplementation.submitTransactionalBatchWithRestResponseAsync(body, null,
1234-
finalContext).zipWith(Mono.just(body)))
1235-
.flatMap(pair -> parseResponse(pair.getT2(), pair.getT1()))
1236-
.map(response ->
1237-
new SimpleResponse<>(response.getRequest(), response.getStatusCode(), response.getHeaders(),
1238-
new TableTransactionResult(transactionActions, response.getValue())));
1246+
try {
1247+
return Flux.fromIterable(operations)
1248+
.flatMapSequential(op -> op.prepareRequest(transactionalBatchClient).zipWith(Mono.just(op)))
1249+
.collect(TransactionalBatchRequestBody::new, (body, pair) ->
1250+
body.addChangeOperation(new TransactionalBatchSubRequest(pair.getT2(), pair.getT1())))
1251+
.publishOn(Schedulers.boundedElastic())
1252+
.flatMap(body ->
1253+
transactionalBatchImplementation.submitTransactionalBatchWithRestResponseAsync(body, null,
1254+
finalContext).zipWith(Mono.just(body)))
1255+
.onErrorMap(TableUtils::mapThrowableToTableServiceException)
1256+
.flatMap(pair -> parseResponse(pair.getT2(), pair.getT1()))
1257+
.map(response ->
1258+
new SimpleResponse<>(response.getRequest(), response.getStatusCode(), response.getHeaders(),
1259+
new TableTransactionResult(transactionActions, response.getValue())));
1260+
} catch (RuntimeException e) {
1261+
return monoError(logger, e);
1262+
}
12391263
}
12401264

12411265
private Mono<Response<List<TableTransactionActionResponse>>> parseResponse(TransactionalBatchRequestBody requestBody,

sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClient.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,12 +524,16 @@ public Response<TableEntity> getEntityWithResponse(String partitionKey, String r
524524
* Retrieves details about any stored {@link TableAccessPolicies access policies} specified on the table that may
525525
* be used with Shared Access Signatures.
526526
*
527+
* <p>This operation is only supported on Azure Storage endpoints.</p>
528+
*
527529
* <p><strong>Code Samples</strong></p>
528530
* <p>Gets a table's {@link TableAccessPolicies access policies}. Prints out the details of the retrieved
529531
* {@link TableAccessPolicies access policies}.</p>
530532
* {@codesnippet com.azure.data.tables.tableClient.getAccessPolicies}
531533
*
532534
* @return The table's {@link TableAccessPolicies access policies}.
535+
*
536+
* @throws TableServiceException If the request is rejected by the service.
533537
*/
534538
@ServiceMethod(returns = ReturnType.SINGLE)
535539
public TableAccessPolicies getAccessPolicies() {
@@ -540,6 +544,8 @@ public TableAccessPolicies getAccessPolicies() {
540544
* Retrieves details about any stored {@link TableAccessPolicies access policies} specified on the table that may be
541545
* used with Shared Access Signatures.
542546
*
547+
* <p>This operation is only supported on Azure Storage endpoints.</p>
548+
*
543549
* <p><strong>Code Samples</strong></p>
544550
* <p>Gets a table's {@link TableAccessPolicies access policies}. Prints out the details of the
545551
* {@link Response HTTP response} and the retrieved {@link TableAccessPolicies access policies}.</p>
@@ -550,6 +556,8 @@ public TableAccessPolicies getAccessPolicies() {
550556
* the service call.
551557
*
552558
* @return An {@link Response HTTP response} containing the table's {@link TableAccessPolicies access policies}.
559+
*
560+
* @throws TableServiceException If the request is rejected by the service.
553561
*/
554562
@ServiceMethod(returns = ReturnType.SINGLE)
555563
public Response<TableAccessPolicies> getAccessPoliciesWithResponse(Duration timeout, Context context) {
@@ -560,11 +568,15 @@ public Response<TableAccessPolicies> getAccessPoliciesWithResponse(Duration time
560568
* Sets stored {@link TableAccessPolicies access policies} for the table that may be used with Shared Access
561569
* Signatures.
562570
*
571+
* <p>This operation is only supported on Azure Storage endpoints.</p>
572+
*
563573
* <p><strong>Code Samples</strong></p>
564574
* <p>Sets stored {@link TableAccessPolicies access policies} on a table.</p>
565575
* {@codesnippet com.azure.data.tables.tableClient.setAccessPolicies#List}
566576
*
567577
* @param tableSignedIdentifiers The {@link TableSignedIdentifier access policies} for the table.
578+
*
579+
* @throws TableServiceException If the request is rejected by the service.
568580
*/
569581
@ServiceMethod(returns = ReturnType.SINGLE)
570582
public void setAccessPolicies(List<TableSignedIdentifier> tableSignedIdentifiers) {
@@ -575,6 +587,8 @@ public void setAccessPolicies(List<TableSignedIdentifier> tableSignedIdentifiers
575587
* Sets stored {@link TableAccessPolicies access policies} for the table that may be used with Shared Access
576588
* Signatures.
577589
*
590+
* <p>This operation is only supported on Azure Storage endpoints.</p>
591+
*
578592
* <p><strong>Code Samples</strong></p>
579593
* <p>Sets stored {@link TableAccessPolicies access policies} on a table. Prints out details of the
580594
* {@link Response HTTP response}.</p>
@@ -586,6 +600,8 @@ public void setAccessPolicies(List<TableSignedIdentifier> tableSignedIdentifiers
586600
* the service call.
587601
*
588602
* @return The {@link Response HTTP response}.
603+
*
604+
* @throws TableServiceException If the request is rejected by the service.
589605
*/
590606
@ServiceMethod(returns = ReturnType.SINGLE)
591607
public Response<Void> setAccessPoliciesWithResponse(List<TableSignedIdentifier> tableSignedIdentifiers,
@@ -618,6 +634,7 @@ public Response<Void> setAccessPoliciesWithResponse(List<TableSignedIdentifier>
618634
* {@link TableTransactionResult action} in the transaction.
619635
*
620636
* @throws IllegalArgumentException If no {@link TableTransactionAction actions} have been added to the list.
637+
* @throws TableServiceException If the request is rejected by the service.
621638
* @throws TableTransactionFailedException If any {@link TableTransactionResult action} within the transaction
622639
* fails. See the documentation for the client methods in {@link TableClient} to understand the conditions that
623640
* may cause a given {@link TableTransactionAction action} to fail.
@@ -657,6 +674,7 @@ public TableTransactionResult submitTransaction(List<TableTransactionAction> tra
657674
* {@link TableTransactionAction action} in the transaction.
658675
*
659676
* @throws IllegalArgumentException If no {@link TableTransactionAction actions} have been added to the list.
677+
* @throws TableServiceException If the request is rejected by the service.
660678
* @throws TableTransactionFailedException If any {@link TableTransactionAction action} within the transaction
661679
* fails. See the documentation for the client methods in {@link TableClient} to understand the conditions that
662680
* may cause a given {@link TableTransactionAction action} to fail.

0 commit comments

Comments
 (0)