diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/data/cosmos/JsonSerializable.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/data/cosmos/JsonSerializable.java index 613abb4b0aa0..a70ec3c7e896 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/data/cosmos/JsonSerializable.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/data/cosmos/JsonSerializable.java @@ -5,6 +5,7 @@ import com.azure.data.cosmos.internal.Strings; import com.azure.data.cosmos.internal.Utils; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -32,14 +33,14 @@ public class JsonSerializable { private final static ObjectMapper OBJECT_MAPPER = Utils.getSimpleObjectMapper(); private ObjectMapper om; transient ObjectNode propertyBag = null; - + protected JsonSerializable() { this.propertyBag = OBJECT_MAPPER.createObjectNode(); } /** * Constructor. - * + * * @param jsonString the json string that represents the JsonSerializable. * @param objectMapper the custom object mapper */ @@ -48,10 +49,10 @@ protected JsonSerializable() { this.propertyBag = fromJson(jsonString); this.om = objectMapper; } - + /** * Constructor. - * + * * @param jsonString the json string that represents the JsonSerializable. */ protected JsonSerializable(String jsonString) { @@ -76,7 +77,7 @@ private ObjectMapper getMapper() { void setMapper(ObjectMapper om) { this.om = om; } - + private static void checkForValidPOJO(Class c) { if (c.isAnonymousClass() || c.isLocalClass()) { throw new IllegalArgumentException( @@ -88,6 +89,7 @@ private static void checkForValidPOJO(Class c) { } } + @JsonIgnore public Logger getLogger() { return logger; } @@ -106,7 +108,7 @@ public Map getMap() { /** * Checks whether a property exists. - * + * * @param propertyName the property to look up. * @return true if the property exists. */ @@ -116,7 +118,7 @@ public boolean has(String propertyName) { /** * Removes a value by propertyName. - * + * * @param propertyName the property to remove. */ void remove(String propertyName) { @@ -125,7 +127,7 @@ void remove(String propertyName) { /** * Sets the value of a property. - * + * * @param the type of the object. * @param propertyName the property to set. * @param value the value of the property. @@ -183,7 +185,7 @@ private void internalSetCollection(String propertyName, Collection collec /** * Gets a property value as Object. - * + * * @param propertyName the property to get. * @return the value of the property. */ @@ -194,10 +196,10 @@ public Object get(String propertyName) { return null; } } - + /** * Gets a string value. - * + * * @param propertyName the property to get. * @return the string value. */ @@ -211,7 +213,7 @@ public String getString(String propertyName) { /** * Gets a boolean value. - * + * * @param propertyName the property to get. * @return the boolean value. */ @@ -225,7 +227,7 @@ public Boolean getBoolean(String propertyName) { /** * Gets an integer value. - * + * * @param propertyName the property to get. * @return the boolean value */ @@ -239,7 +241,7 @@ public Integer getInt(String propertyName) { /** * Gets a long value. - * + * * @param propertyName the property to get. * @return the long value */ @@ -253,7 +255,7 @@ public Long getLong(String propertyName) { /** * Gets a double value. - * + * * @param propertyName the property to get. * @return the double value. */ @@ -267,7 +269,7 @@ public Double getDouble(String propertyName) { /** * Gets an object value. - * + * * @param the type of the object. * @param propertyName the property to get. * @param c the class of the object. If c is a POJO class, it must be a member (and not an anonymous or local) @@ -390,7 +392,7 @@ public List getList(String propertyName, Class c, boolean ... convertF /** * Gets an object collection. - * + * * @param the type of the objects in the collection. * @param propertyName the property to get * @param c the class of the object. If c is a POJO class, it must be a member (and not an anonymous or local) @@ -405,7 +407,7 @@ public Collection getCollection(String propertyName, Class c, boolean /** * Gets a JSONObject. - * + * * @param propertyName the property to get. * @return the JSONObject. */ @@ -419,7 +421,7 @@ ObjectNode getObject(String propertyName) { /** * Gets a JSONObject collection. - * + * * @param propertyName the property to get. * @return the JSONObject collection. */ @@ -433,12 +435,12 @@ Collection getCollection(String propertyName) { } } - return result; + return result; } /** * Gets the value of a property identified by an array of property names that forms the path. - * + * * @param propertyNames that form the path to the property to get. * @return the value of the property. */ @@ -462,12 +464,12 @@ public Object getObjectByPath(List propertyNames) { break; } } while (iterator.hasNext()); - + if (value != null && matchedProperties == propertyNames.size()) { return getValue(value); } } - + return null; } @@ -517,7 +519,7 @@ private String toPrettyJson(Object object){ /** * Converts to an Object (only POJOs and JSONObject are supported). - * + * * @param the type of the object. * @param c the class of the object, either a POJO class or JSONObject. If c is a POJO class, it must be a member * (and not an anonymous or local) and a static one. @@ -547,16 +549,16 @@ public T toObject(Class c) { /** * Converts to a JSON string. - * + * * @return the JSON string. */ public String toJson() { return this.toJson(SerializationFormattingPolicy.NONE); } - + /** * Converts to a JSON string. - * + * * @param formattingPolicy the formatting policy to be used. * @return the JSON string. */ @@ -571,10 +573,10 @@ public String toJson(SerializationFormattingPolicy formattingPolicy) { /** * Gets Simple STRING representation of property bag. - * - * For proper conversion to json and inclusion of the default values + * + * For proper conversion to json and inclusion of the default values * use {@link #toJson()}. - * + * * @return string representation of property bag. */ public String toString() { diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/data/cosmos/RequestRateTooLargeException.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/data/cosmos/RequestRateTooLargeException.java index 6105bcce821f..0a798d5a3e54 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/data/cosmos/RequestRateTooLargeException.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/data/cosmos/RequestRateTooLargeException.java @@ -18,7 +18,7 @@ public RequestRateTooLargeException() { } public RequestRateTooLargeException(CosmosError cosmosError, long lsn, String partitionKeyRangeId, Map responseHeaders) { - super(HttpConstants.StatusCodes.NOTFOUND, cosmosError, responseHeaders); + super(HttpConstants.StatusCodes.TOO_MANY_REQUESTS, cosmosError, responseHeaders); BridgeInternal.setLSN(this, lsn); BridgeInternal.setPartitionKeyRangeId(this, partitionKeyRangeId); } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/data/cosmos/ServiceUnavailableException.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/data/cosmos/ServiceUnavailableException.java index 1b4abbe95e46..ccc455370ccb 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/data/cosmos/ServiceUnavailableException.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/data/cosmos/ServiceUnavailableException.java @@ -17,7 +17,7 @@ public class ServiceUnavailableException extends CosmosClientException { } public ServiceUnavailableException(CosmosError cosmosError, long lsn, String partitionKeyRangeId, Map responseHeaders) { - super(HttpConstants.StatusCodes.NOTFOUND, cosmosError, responseHeaders); + super(HttpConstants.StatusCodes.SERVICE_UNAVAILABLE, cosmosError, responseHeaders); BridgeInternal.setLSN(this, lsn); BridgeInternal.setPartitionKeyRangeId(this, partitionKeyRangeId); } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/data/cosmos/internal/directconnectivity/rntbd/RntbdClientChannelPool.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/data/cosmos/internal/directconnectivity/rntbd/RntbdClientChannelPool.java index 54443ae53d8f..8e834d6b75bf 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/data/cosmos/internal/directconnectivity/rntbd/RntbdClientChannelPool.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/data/cosmos/internal/directconnectivity/rntbd/RntbdClientChannelPool.java @@ -157,8 +157,8 @@ public void onTimeout(AcquireTask task) { if (elapsedTime > idleEndpointTimeout) { - if (logger.isWarnEnabled()) { - logger.warn( + if (logger.isDebugEnabled()) { + logger.debug( "{} closing due to inactivity (time elapsed since last request: {} > idleEndpointTimeout: {})", endpoint, Duration.ofNanos(elapsedTime), Duration.ofNanos(idleEndpointTimeout)); } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/data/cosmos/internal/directconnectivity/rntbd/RntbdObjectMapper.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/data/cosmos/internal/directconnectivity/rntbd/RntbdObjectMapper.java index de59bf295b36..6b82c43f93af 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/data/cosmos/internal/directconnectivity/rntbd/RntbdObjectMapper.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/data/cosmos/internal/directconnectivity/rntbd/RntbdObjectMapper.java @@ -81,6 +81,7 @@ static ObjectNode readTree(final ByteBuf in) { throw new CorruptedFrameException(cause); } + @SuppressWarnings("SameParameterValue") static void registerPropertyFilter(final Class type, final Class filter) { checkNotNull(type, "type"); diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/data/cosmos/internal/query/DocumentQueryExecutionContextFactory.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/data/cosmos/internal/query/DocumentQueryExecutionContextFactory.java index 6ba9e1d697cb..bd015915cef8 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/data/cosmos/internal/query/DocumentQueryExecutionContextFactory.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/data/cosmos/internal/query/DocumentQueryExecutionContextFactory.java @@ -55,7 +55,7 @@ public static Flux collectionObs = Flux.empty(); - + if (resourceTypeEnum.isCollectionChild()) { collectionObs = resolveCollection(client, query, resourceTypeEnum, resourceLink).flux(); } @@ -109,7 +109,8 @@ public static Flux 0, "MaxItemCount", "INVALID MaxItemCount %s", initialPageSize); + (initialPageSize > 0 || initialPageSize == -1, "MaxItemCount", "Invalid MaxItemCount %s", + initialPageSize); if (validationError != null) { return Flux.error(validationError); } @@ -144,7 +145,7 @@ public static Flux Flux type, int expectedStatusCode) { + try { + Constructor constructor = type.getDeclaredConstructor(String.class, HttpHeaders.class, String.class); + constructor.setAccessible(true); + final CosmosClientException instance = constructor.newInstance("some-message", null, "some-uri"); + assertEquals(instance.getStatusCode(), expectedStatusCode); + } catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException error) { + String message = lenientFormat("could not create instance of %s due to %s", type, error); + throw new AssertionError(message, error); + } + } + + @DataProvider(name = "subTypes") + private static Object[][] subTypes() { + return new Object[][] { + { BadRequestException.class, BADREQUEST }, + { GoneException.class, GONE }, + { InternalServerErrorException.class, INTERNAL_SERVER_ERROR }, + { RequestTimeoutException.class, REQUEST_TIMEOUT }, + { ConflictException.class, CONFLICT }, + { ForbiddenException.class, FORBIDDEN }, + { InvalidPartitionException.class, GONE }, + { LockedException.class, LOCKED }, + { MethodNotAllowedException.class, METHOD_NOT_ALLOWED }, + { NotFoundException.class, NOTFOUND }, + { PartitionIsMigratingException.class, GONE }, + { PartitionKeyRangeGoneException.class, GONE }, + { PartitionKeyRangeIsSplittingException.class, GONE }, + { PreconditionFailedException.class, PRECONDITION_FAILED }, + { RequestEntityTooLargeException.class, REQUEST_ENTITY_TOO_LARGE }, + { RequestRateTooLargeException.class, TOO_MANY_REQUESTS }, + { RetryWithException.class, RETRY_WITH }, + { ServiceUnavailableException.class, SERVICE_UNAVAILABLE }, + { UnauthorizedException.class, UNAUTHORIZED } + }; + } } diff --git a/sdk/cosmos/pom.xml b/sdk/cosmos/pom.xml index 29a7f2d1d0a8..98e978d1d509 100644 --- a/sdk/cosmos/pom.xml +++ b/sdk/cosmos/pom.xml @@ -39,8 +39,8 @@ Licensed under the MIT License. 4.1.0 1.2.0 1.10.19 - 4.1.38.Final - 2.0.25.Final + 4.1.42.Final + 2.0.26.Final ${project.version} 27.0.1-jre 3.3.0.RELEASE