Skip to content

Commit

Permalink
CosmosClientException update (#11311)
Browse files Browse the repository at this point in the history
* CosmosClientException Update

Co-authored-by: Annie Liang <xinlian@microsoft.com>
  • Loading branch information
xinlian12 and Annie Liang authored May 20, 2020
1 parent 87fff96 commit 2bb973b
Show file tree
Hide file tree
Showing 132 changed files with 661 additions and 868 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,33 +45,33 @@
<Field name="defaultEncryptionAlgorithm"/>
<Bug pattern="UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD"/>
</Match>

<!-- Defines native api, doesn't follow java style.-->
<Match>
<Class name="~com\.azure\.identity\.implementation\.WindowsCredentialApi(.+)"/>
<Bug pattern="UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD,
UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD,
NM_FIELD_NAMING_CONVENTION"/>
</Match>

<!-- Exception needs to be caught here.-->
<Match>
<Class name="~com\.azure\.identity\.implementation\.VisualStudioCacheAccessor"/>
<Bug pattern="REC_CATCH_EXCEPTION"/>
</Match>

<!-- Exception needs to be caught here.-->
<Match>
<Class name="~com\.azure\.identity\.IntelliJCredential"/>
<Bug pattern="REC_CATCH_EXCEPTION"/>
</Match>

<!-- Accesses native api, doesn't follow java style.-->
<Match>
<Class name="~com\.azure\.identity\.implementation\.LinuxKeyRingAccessor(.+)"/>
<Bug pattern="UWF_UNWRITTEN_FIELD"/>
</Match>

<!-- Accesses native api, doesn't follow java style.-->
<Match>
<Class name="com.azure.identity.implementation.WindowsCredentialAccessor"/>
Expand Down Expand Up @@ -1215,28 +1215,28 @@

<!-- Bug: https://github.com/Azure/azure-sdk-for-java/issues/9088 -->
<Match>
<Class name="com.azure.cosmos.CosmosClientException"/>
<Class name="com.azure.cosmos.CosmosException"/>
<Field name="cosmosError"/>
<Bug pattern="SE_BAD_FIELD"/>
</Match>

<!-- Bug: https://github.com/Azure/azure-sdk-for-java/issues/9088 -->
<Match>
<Class name="com.azure.cosmos.CosmosClientException"/>
<Class name="com.azure.cosmos.CosmosException"/>
<Field name="cosmosDiagnostics"/>
<Bug pattern="SE_BAD_FIELD"/>
</Match>

<!-- Bug: https://github.com/Azure/azure-sdk-for-java/issues/9088 -->
<Match>
<Class name="com.azure.cosmos.CosmosClientException"/>
<Class name="com.azure.cosmos.CosmosException"/>
<Field name="requestTimeline"/>
<Bug pattern="SE_BAD_FIELD"/>
</Match>

<!-- Bug: https://github.com/Azure/azure-sdk-for-java/issues/9088 -->
<Match>
<Class name="com.azure.cosmos.CosmosClientException"/>
<Class name="com.azure.cosmos.CosmosException"/>
<Field name="requestUri"/>
<Bug pattern="SE_BAD_FIELD"/>
</Match>
Expand Down Expand Up @@ -2010,7 +2010,7 @@
<Package name="~com\.azure\.management(\.[^.]+)*\.samples(\.[^.]+)*"/>
<Bug pattern="REC_CATCH_EXCEPTION"/>
</Match>

<!-- Exclude from spring related classes -->
<Match>
<Or>
Expand All @@ -2022,14 +2022,14 @@
RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE,
RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE"/>
</Match>


<!-- These fields are designed to be not written. They are for deserializing. -->
<Match>
<Class name="com.azure.identity.implementation.LinuxKeyRingAccessor$GError"/>
<Bug pattern="UWF_UNWRITTEN_FIELD"/>
</Match>

<!-- These fields use File Reader with default encoding, java 8 doesn't support passing in encoding type. -->
<Match>
<Class name="com.azure.identity.implementation.IntelliJCacheAccessor"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.azure.cosmos.CosmosAsyncContainer;
import com.azure.cosmos.CosmosAsyncDatabase;
import com.azure.cosmos.CosmosClientBuilder;
import com.azure.cosmos.CosmosClientException;
import com.azure.cosmos.CosmosException;
import com.azure.cosmos.DirectConnectionConfig;
import com.azure.cosmos.GatewayConnectionConfig;
import com.azure.cosmos.implementation.HttpConstants;
Expand Down Expand Up @@ -243,7 +243,7 @@ private void createClients() {
boolean databaseCreated = false;
try {
cosmosAsyncDatabase = asyncClient.getDatabase(this.configuration.getDatabaseId()).read().block().getDatabase();
} catch (CosmosClientException e) {
} catch (CosmosException e) {
if (e.getStatusCode() == HttpConstants.StatusCodes.NOTFOUND) {
cosmosAsyncDatabase = asyncClient.createDatabase(this.configuration.getDatabaseId()).block().getDatabase();
logger.info("Database {} is created for this test on host {}", this.configuration.getDatabaseId(), endpoint);
Expand All @@ -256,7 +256,7 @@ private void createClients() {

try {
cosmosAsyncContainer = cosmosAsyncDatabase.getContainer(this.configuration.getCollectionId()).read().block().getContainer();
} catch (CosmosClientException e) {
} catch (CosmosException e) {
if (e.getStatusCode() == HttpConstants.StatusCodes.NOTFOUND) {
cosmosAsyncContainer =
cosmosAsyncDatabase.createContainer(this.configuration.getCollectionId(), Configuration.DEFAULT_PARTITION_KEY_PATH, this.configuration.getThroughput()).block().getContainer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.azure.cosmos.CosmosAsyncContainer;
import com.azure.cosmos.CosmosAsyncDatabase;
import com.azure.cosmos.CosmosClientBuilder;
import com.azure.cosmos.CosmosClientException;
import com.azure.cosmos.CosmosException;
import com.azure.cosmos.DirectConnectionConfig;
import com.azure.cosmos.GatewayConnectionConfig;
import com.azure.cosmos.implementation.HttpConstants;
Expand Down Expand Up @@ -87,7 +87,7 @@ abstract class AsyncBenchmark<T> {
).read().doOnError(error ->
logger.error("Database {} creation failed due to ", this.configuration.getDatabaseId(), error)
).block().getDatabase();
} catch (CosmosClientException e) {
} catch (CosmosException e) {
if (e.getStatusCode() == HttpConstants.StatusCodes.NOTFOUND) {
cosmosAsyncDatabase = cosmosClient.createDatabase(cfg.getDatabaseId()).block().getDatabase();
logger.info("Database {} is created for this test", this.configuration.getDatabaseId());
Expand All @@ -103,7 +103,7 @@ abstract class AsyncBenchmark<T> {
).read().doOnError(error ->
logger.error("Database {} creation failed due to ", this.configuration.getDatabaseId(), error)
).block().getContainer();
} catch (CosmosClientException e) {
} catch (CosmosException e) {
if (e.getStatusCode() == HttpConstants.StatusCodes.NOTFOUND) {
cosmosAsyncContainer = cosmosAsyncDatabase.createContainer(
this.configuration.getCollectionId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.azure.cosmos.ConnectionMode;
import com.azure.cosmos.CosmosClient;
import com.azure.cosmos.CosmosClientBuilder;
import com.azure.cosmos.CosmosClientException;
import com.azure.cosmos.CosmosException;
import com.azure.cosmos.CosmosContainer;
import com.azure.cosmos.CosmosDatabase;
import com.azure.cosmos.DirectConnectionConfig;
Expand Down Expand Up @@ -120,7 +120,7 @@ public T apply(T o, Throwable throwable) {
try {
cosmosDatabase = cosmosClient.getDatabase(this.configuration.getDatabaseId()).read().getDatabase();
logger.info("Database {} is created for this test", this.configuration.getDatabaseId());
} catch (CosmosClientException e) {
} catch (CosmosException e) {
if (e.getStatusCode() == HttpConstants.StatusCodes.NOTFOUND) {
cosmosDatabase = cosmosClient.createDatabase(cfg.getDatabaseId()).getDatabase();
databaseCreated = true;
Expand All @@ -131,7 +131,7 @@ public T apply(T o, Throwable throwable) {

try {
cosmosContainer = cosmosDatabase.getContainer(this.configuration.getCollectionId()).read().getContainer();
} catch (CosmosClientException e) {
} catch (CosmosException e) {
if (e.getStatusCode() == HttpConstants.StatusCodes.NOTFOUND) {
cosmosContainer = cosmosDatabase.createContainer(this.configuration.getCollectionId(), Configuration.DEFAULT_PARTITION_KEY_PATH, this.configuration.getThroughput()).getContainer();
logger.info("Collection {} is created for this test", this.configuration.getCollectionId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.azure.cosmos.CosmosAsyncDatabase;
import com.azure.cosmos.models.CosmosAsyncItemResponse;
import com.azure.cosmos.CosmosClientBuilder;
import com.azure.cosmos.CosmosClientException;
import com.azure.cosmos.CosmosException;
import com.azure.cosmos.models.CosmosContainerProperties;
import com.azure.cosmos.util.CosmosPagedFlux;
import com.azure.cosmos.models.FeedOptions;
Expand Down Expand Up @@ -146,8 +146,8 @@ private void log(Object object) {
}

private void log(String msg, Throwable throwable) {
if (throwable instanceof CosmosClientException) {
log(msg + ": " + ((CosmosClientException) throwable).getStatusCode());
if (throwable instanceof CosmosException) {
log(msg + ": " + ((CosmosException) throwable).getStatusCode());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.azure.cosmos.models.CosmosAsyncContainerResponse;
import com.azure.cosmos.CosmosAsyncDatabase;
import com.azure.cosmos.CosmosClientBuilder;
import com.azure.cosmos.CosmosClientException;
import com.azure.cosmos.CosmosException;
import com.azure.cosmos.models.CosmosContainerProperties;
import com.azure.cosmos.models.CosmosContainerRequestOptions;
import com.azure.cosmos.implementation.CosmosItemProperties;
Expand Down Expand Up @@ -145,10 +145,10 @@ public static CosmosAsyncContainer createNewCollection(CosmosAsyncClient client,
throw new IllegalArgumentException(String.format("Collection %s already exists in database %s.", collectionName, databaseName));
}
} catch (RuntimeException ex) {
if (ex instanceof CosmosClientException) {
CosmosClientException cosmosClientException = (CosmosClientException) ex;
if (ex instanceof CosmosException) {
CosmosException cosmosException = (CosmosException) ex;

if (cosmosClientException.getStatusCode() != 404) {
if (cosmosException.getStatusCode() != 404) {
throw ex;
}
} else {
Expand Down Expand Up @@ -187,10 +187,10 @@ public static CosmosAsyncContainer createNewLeaseCollection(CosmosAsyncClient cl
}
}
} catch (RuntimeException ex) {
if (ex instanceof CosmosClientException) {
CosmosClientException cosmosClientException = (CosmosClientException) ex;
if (ex instanceof CosmosException) {
CosmosException cosmosException = (CosmosException) ex;

if (cosmosClientException.getStatusCode() != 404) {
if (cosmosException.getStatusCode() != 404) {
throw ex;
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
package com.azure.cosmos.rx.examples.multimaster;

import com.azure.cosmos.implementation.AsyncDocumentClient;
import com.azure.cosmos.CosmosClientException;
import com.azure.cosmos.CosmosException;
import com.azure.cosmos.implementation.Database;
import com.azure.cosmos.implementation.DocumentCollection;
import com.azure.cosmos.implementation.ResourceResponse;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

public class Helpers {
Expand All @@ -26,8 +25,8 @@ static public Mono<Database> createDatabaseIfNotExists(AsyncDocumentClient clien
return client.readDatabase("/dbs/" + databaseName, null)
.onErrorResume(
e -> {
if (e instanceof CosmosClientException) {
CosmosClientException dce = (CosmosClientException) e;
if (e instanceof CosmosException) {
CosmosException dce = (CosmosException) e;
if (dce.getStatusCode() == 404) {
// if doesn't exist create it

Expand All @@ -47,8 +46,8 @@ static public Mono<DocumentCollection> createCollectionIfNotExists(AsyncDocument
return client.readCollection(createDocumentCollectionUri(databaseName, collectionName), null)
.onErrorResume(
e -> {
if (e instanceof CosmosClientException) {
CosmosClientException dce = (CosmosClientException) e;
if (e instanceof CosmosException) {
CosmosException dce = (CosmosException) e;
if (dce.getStatusCode() == 404) {
// if doesn't exist create it

Expand All @@ -68,8 +67,8 @@ static public Mono<DocumentCollection> createCollectionIfNotExists(AsyncDocument
return client.readCollection(createDocumentCollectionUri(databaseName, collection.getId()), null)
.onErrorResume(
e -> {
if (e instanceof CosmosClientException) {
CosmosClientException dce = (CosmosClientException) e;
if (e instanceof CosmosException) {
CosmosException dce = (CosmosException) e;
if (dce.getStatusCode() == 404) {
// if doesn't exist create it

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import com.azure.cosmos.BridgeInternal;
import com.azure.cosmos.models.ConflictResolutionPolicy;
import com.azure.cosmos.CosmosClientException;
import com.azure.cosmos.CosmosException;
import com.azure.cosmos.models.FeedResponse;
import com.azure.cosmos.implementation.Resource;
import com.azure.cosmos.implementation.AsyncDocumentClient;
Expand Down Expand Up @@ -491,8 +491,8 @@ private Mono<Document> tryInsertDocument(AsyncDocumentClient client, String coll
}

private boolean hasDocumentClientException(Throwable e, int statusCode) {
if (e instanceof CosmosClientException) {
CosmosClientException dce = (CosmosClientException) e;
if (e instanceof CosmosException) {
CosmosException dce = (CosmosException) e;
return dce.getStatusCode() == statusCode;
}

Expand All @@ -501,7 +501,7 @@ private boolean hasDocumentClientException(Throwable e, int statusCode) {

private boolean hasDocumentClientExceptionCause(Throwable e) {
while (e != null) {
if (e instanceof CosmosClientException) {
if (e instanceof CosmosException) {
return true;
}

Expand All @@ -512,8 +512,8 @@ private boolean hasDocumentClientExceptionCause(Throwable e) {

private boolean hasDocumentClientExceptionCause(Throwable e, int statusCode) {
while (e != null) {
if (e instanceof CosmosClientException) {
CosmosClientException dce = (CosmosClientException) e;
if (e instanceof CosmosException) {
CosmosException dce = (CosmosException) e;
return dce.getStatusCode() == statusCode;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


import com.azure.cosmos.implementation.AsyncDocumentClient;
import com.azure.cosmos.CosmosClientException;
import com.azure.cosmos.CosmosException;
import com.azure.cosmos.implementation.Document;
import com.azure.cosmos.models.FeedOptions;
import com.azure.cosmos.models.FeedResponse;
Expand Down Expand Up @@ -136,7 +136,7 @@ void deleteAll() {
this.client.deleteDocument(document.getSelfLink(), null)
.subscribeOn(schedulerForBlockingWork).single().block();
} catch (RuntimeException exEx) {
CosmosClientException dce = getDocumentClientExceptionCause(exEx);
CosmosException dce = getDocumentClientExceptionCause(exEx);

if (dce.getStatusCode() != 404) {
logger.info("Error occurred while deleting {} from {}", dce, client.getWriteEndpoint());
Expand All @@ -147,11 +147,11 @@ void deleteAll() {
logger.info("Deleted all documents from region {}", this.client.getWriteEndpoint());
}

private CosmosClientException getDocumentClientExceptionCause(Throwable e) {
private CosmosException getDocumentClientExceptionCause(Throwable e) {
while (e != null) {

if (e instanceof CosmosClientException) {
return (CosmosClientException) e;
if (e instanceof CosmosException) {
return (CosmosException) e;
}

e = e.getCause();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@
// Licensed under the MIT License.
package com.azure.cosmos.rx.examples;

import com.azure.cosmos.BridgeInternal;
import com.azure.cosmos.ConnectionMode;
import com.azure.cosmos.DirectConnectionConfig;
import com.azure.cosmos.implementation.ConnectionPolicy;
import com.azure.cosmos.ConsistencyLevel;
import com.azure.cosmos.CosmosClientException;
import com.azure.cosmos.CosmosException;
import com.azure.cosmos.models.DataType;
import com.azure.cosmos.DocumentClientTest;
import com.azure.cosmos.models.FeedResponse;
import com.azure.cosmos.models.IncludedPath;
import com.azure.cosmos.models.Index;
import com.azure.cosmos.models.IndexingPolicy;
import com.azure.cosmos.models.ModelBridgeInternal;
import com.azure.cosmos.models.PartitionKeyDefinition;
import com.azure.cosmos.implementation.AsyncDocumentClient;
import com.azure.cosmos.implementation.Database;
Expand All @@ -30,7 +27,6 @@
import reactor.core.publisher.Mono;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -236,7 +232,7 @@ public void createCollection_toBlocking_CollectionAlreadyExists_Fails() {
collectionForTestObservable.single() // Gets the single result
.block(); // Blocks
assertThat("Should not reach here", false);
} catch (CosmosClientException e) {
} catch (CosmosException e) {
assertThat("Collection already exists.", e.getStatusCode(),
equalTo(409));
}
Expand Down
Loading

0 comments on commit 2bb973b

Please sign in to comment.