From 3171bdd67d653e3489b7fd399b9c93317e8ef650 Mon Sep 17 00:00:00 2001 From: Victor Colin Amador Date: Thu, 24 Jun 2021 14:28:32 -0700 Subject: [PATCH 1/3] Fixed an issue that made `TableClient.listEntities()` and `TableServiceClient.listTables()` throw a `ClassCastException` when passing a non-null value for `timeout`. --- .../java/com/azure/data/tables/TableAsyncClient.java | 8 +++++--- .../main/java/com/azure/data/tables/TableClient.java | 3 +-- .../azure/data/tables/TableServiceAsyncClient.java | 8 +++++--- .../com/azure/data/tables/TableServiceClient.java | 3 +-- .../azure/data/tables/implementation/TableUtils.java | 12 ------------ 5 files changed, 12 insertions(+), 22 deletions(-) diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClient.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClient.java index f514dbb5aee02..1135ef8e226bd 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClient.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClient.java @@ -58,6 +58,7 @@ import reactor.core.scheduler.Schedulers; import java.net.URI; +import java.time.Duration; import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.Arrays; @@ -68,6 +69,7 @@ import static com.azure.core.util.CoreUtils.isNullOrEmpty; import static com.azure.core.util.FluxUtil.monoError; import static com.azure.core.util.FluxUtil.withContext; +import static com.azure.data.tables.implementation.TableUtils.applyOptionalTimeout; import static com.azure.data.tables.implementation.TableUtils.swallowExceptionForStatusCode; import static com.azure.data.tables.implementation.TableUtils.toTableServiceError; @@ -718,10 +720,10 @@ public PagedFlux listEntities(ListEntitiesOptions options) { token -> withContext(context -> listEntitiesNextPage(token, context, options, TableEntity.class))); } - PagedFlux listEntities(ListEntitiesOptions options, Context context) { + PagedFlux listEntities(ListEntitiesOptions options, Context context, Duration timeout) { return new PagedFlux<>( - () -> listEntitiesFirstPage(context, options, TableEntity.class), - token -> listEntitiesNextPage(token, context, options, TableEntity.class)); + () -> applyOptionalTimeout(listEntitiesFirstPage(context, options, TableEntity.class), timeout), + token -> applyOptionalTimeout(listEntitiesNextPage(token, context, options, TableEntity.class), timeout)); } private Mono> listEntitiesFirstPage(Context context, diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClient.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClient.java index acf152ded049f..1ed5be2fcd6d1 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClient.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClient.java @@ -26,7 +26,6 @@ import java.time.Duration; import java.util.List; -import static com.azure.data.tables.implementation.TableUtils.applyOptionalTimeout; import static com.azure.data.tables.implementation.TableUtils.blockWithOptionalTimeout; /** @@ -466,7 +465,7 @@ public PagedIterable listEntities() { */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedIterable listEntities(ListEntitiesOptions options, Duration timeout, Context context) { - return new PagedIterable<>(applyOptionalTimeout(client.listEntities(options, context), timeout)); + return new PagedIterable<>(client.listEntities(options, context, timeout)); } /** diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClient.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClient.java index 4a4c505fd0701..4c1637af87ecb 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClient.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClient.java @@ -52,11 +52,13 @@ import reactor.core.publisher.Mono; import java.net.URI; +import java.time.Duration; import java.util.List; import java.util.stream.Collectors; import static com.azure.core.util.FluxUtil.monoError; import static com.azure.core.util.FluxUtil.withContext; +import static com.azure.data.tables.implementation.TableUtils.applyOptionalTimeout; import static com.azure.data.tables.implementation.TableUtils.swallowExceptionForStatusCode; /** @@ -391,10 +393,10 @@ public PagedFlux listTables(ListTablesOptions options) { token -> withContext(context -> listTablesNextPage(token, context, options))); } - PagedFlux listTables(ListTablesOptions options, Context context) { + PagedFlux listTables(ListTablesOptions options, Context context, Duration timeout) { return new PagedFlux<>( - () -> listTablesFirstPage(context, options), - token -> listTablesNextPage(token, context, options)); + () -> applyOptionalTimeout(listTablesFirstPage(context, options), timeout), + token -> applyOptionalTimeout(listTablesNextPage(token, context, options), timeout)); } private Mono> listTablesFirstPage(Context context, ListTablesOptions options) { diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClient.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClient.java index b25d8b80c63b3..48ee3e29c3b55 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClient.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClient.java @@ -26,7 +26,6 @@ import java.time.Duration; import static com.azure.core.util.FluxUtil.monoError; -import static com.azure.data.tables.implementation.TableUtils.applyOptionalTimeout; import static com.azure.data.tables.implementation.TableUtils.blockWithOptionalTimeout; /** @@ -301,7 +300,7 @@ public PagedIterable listTables() { */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedIterable listTables(ListTablesOptions options, Duration timeout, Context context) { - return new PagedIterable<>(applyOptionalTimeout(client.listTables(options, context), timeout)); + return new PagedIterable<>(client.listTables(options, context, timeout)); } /** diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableUtils.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableUtils.java index 9ee9a7da101a0..8de459fc96a91 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableUtils.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableUtils.java @@ -122,18 +122,6 @@ public static Flux applyOptionalTimeout(Flux publisher, Duration timeo return timeout == null ? publisher : publisher.timeout(timeout); } - /** - * Applies a timeout to a {@link PagedFlux publisher} if the given timeout is not null. - * - * @param publisher {@link PagedFlux} to apply optional timeout to. - * @param timeout Optional timeout. - * @param Return type of the {@link PagedFlux}. - * @return {@link PagedFlux} with an applied timeout, if any. - */ - public static PagedFlux applyOptionalTimeout(PagedFlux publisher, Duration timeout) { - return timeout == null ? publisher : (PagedFlux) publisher.timeout(timeout); - } - /** * Blocks an asynchronous response with an optional timeout. * From 323bf2ccda0d35bf1f78ef07f17c38fa08373513 Mon Sep 17 00:00:00 2001 From: Victor Colin Amador Date: Thu, 24 Jun 2021 14:33:34 -0700 Subject: [PATCH 2/3] Updated CHANGELOG. --- sdk/tables/azure-data-tables/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/tables/azure-data-tables/CHANGELOG.md b/sdk/tables/azure-data-tables/CHANGELOG.md index 0d60388a11425..f298aa6ee05bc 100644 --- a/sdk/tables/azure-data-tables/CHANGELOG.md +++ b/sdk/tables/azure-data-tables/CHANGELOG.md @@ -5,6 +5,7 @@ ### Bug fixes - Fixed issue where HTTP headers set in a `ClientOptions` object passed to a client builder would not be set on a client instantiated by said builder. - Fixed an issue where a `connectionString` with an account name and key would override a `sasToken`'s authentication settings in client builders. +- Fixed an issue that made `TableClient.listEntities()` and `TableServiceClient.listTables()` throw a `ClassCastException` when passing a non-null value for `timeout`. ## 12.0.0 (2021-06-11) From 9d17c2f4701fd93d10128e114f8e9fc85b3c5906 Mon Sep 17 00:00:00 2001 From: Victor Colin Amador Date: Thu, 24 Jun 2021 17:01:53 -0700 Subject: [PATCH 3/3] Removed unused import. --- .../java/com/azure/data/tables/implementation/TableUtils.java | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableUtils.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableUtils.java index 8de459fc96a91..f98603f5318f6 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableUtils.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableUtils.java @@ -4,7 +4,6 @@ import com.azure.core.exception.HttpResponseException; import com.azure.core.http.HttpResponse; -import com.azure.core.http.rest.PagedFlux; import com.azure.core.http.rest.Response; import com.azure.core.http.rest.SimpleResponse; import com.azure.core.util.CoreUtils;