diff --git a/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ConsistencyWriter.java b/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ConsistencyWriter.java index 4afb22e9..a7c149c9 100644 --- a/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ConsistencyWriter.java +++ b/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ConsistencyWriter.java @@ -329,9 +329,10 @@ public class ConsistencyWriter { } //get max global committed lsn from current batch of responses, then update if greater than max of all batches. - long maxGlobalCommittedLsn = (responses != null || !responses.isEmpty()) ? - (Long) responses.stream().map(s -> s.globalCommittedLSN).max(ComparatorUtils.NATURAL_COMPARATOR).get() : - 0l; + long maxGlobalCommittedLsn = (responses != null) ? + (Long) responses.stream().map(s -> s.globalCommittedLSN).max(ComparatorUtils.NATURAL_COMPARATOR).orElse(0L) : + 0L; + maxGlobalCommittedLsnReceived.set(maxGlobalCommittedLsnReceived.get() > maxGlobalCommittedLsn ? maxGlobalCommittedLsnReceived.get() : maxGlobalCommittedLsn); diff --git a/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/AddressResolverTest.java b/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/AddressResolverTest.java index 4c1fadaf..830bd95b 100644 --- a/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/AddressResolverTest.java +++ b/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/AddressResolverTest.java @@ -303,7 +303,6 @@ public class AddressResolverTest { try { resolvedAddresses = this.addressResolver.resolveAsync(request, forceAddressRefresh).toBlocking().value(); } catch (RuntimeException e) { - e.printStackTrace(); throw (Exception) e.getCause(); } finally { assertThat(collectionCacheRefreshed).isEqualTo(collectionCacheRefreshedCount).describedAs("collection cache refresh count mismath"); diff --git a/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/OfferReadReplaceTest.java b/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/OfferReadReplaceTest.java index 21070b62..ce03b490 100644 --- a/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/OfferReadReplaceTest.java +++ b/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/OfferReadReplaceTest.java @@ -55,47 +55,40 @@ public class OfferReadReplaceTest extends TestSuiteBase { @Test(groups = { "emulator" }, timeOut = TIMEOUT) public void readAndReplaceOffer() { - client.readOffers(null).toBlocking().subscribe((offersFeed) -> { - try { - int i; - List offers = offersFeed.getResults(); - for (i = 0; i < offers.size(); i++) { - if (offers.get(i).getOfferResourceId().equals(createdCollection.getResourceId())) { - break; - } + int i; + List offers = offersFeed.getResults(); + for (i = 0; i < offers.size(); i++) { + if (offers.get(i).getOfferResourceId().equals(createdCollection.getResourceId())) { + break; } - - Offer rOffer = client.readOffer(offers.get(i).getSelfLink()).toBlocking().single().getResource(); - int oldThroughput = rOffer.getThroughput(); - - Observable> readObservable = client.readOffer(offers.get(i).getSelfLink()); - - // validate offer read - ResourceResponseValidator validatorForRead = new ResourceResponseValidator.Builder() - .withOfferThroughput(oldThroughput) - .notNullEtag() - .build(); - - validateSuccess(readObservable, validatorForRead); - - // update offer - int newThroughput = oldThroughput + 100; - offers.get(i).setThroughput(newThroughput); - Observable> replaceObservable = client.replaceOffer(offers.get(i)); - - // validate offer replace - ResourceResponseValidator validatorForReplace = new ResourceResponseValidator.Builder() - .withOfferThroughput(newThroughput) - .notNullEtag() - .build(); - - validateSuccess(replaceObservable, validatorForReplace); - - } catch (Exception e) { - e.printStackTrace(); } + Offer rOffer = client.readOffer(offers.get(i).getSelfLink()).toBlocking().single().getResource(); + int oldThroughput = rOffer.getThroughput(); + + Observable> readObservable = client.readOffer(offers.get(i).getSelfLink()); + + // validate offer read + ResourceResponseValidator validatorForRead = new ResourceResponseValidator.Builder() + .withOfferThroughput(oldThroughput) + .notNullEtag() + .build(); + + validateSuccess(readObservable, validatorForRead); + + // update offer + int newThroughput = oldThroughput + 100; + offers.get(i).setThroughput(newThroughput); + Observable> replaceObservable = client.replaceOffer(offers.get(i)); + + // validate offer replace + ResourceResponseValidator validatorForReplace = new ResourceResponseValidator.Builder() + .withOfferThroughput(newThroughput) + .notNullEtag() + .build(); + + validateSuccess(replaceObservable, validatorForReplace); }); } diff --git a/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/TestSuiteBase.java b/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/TestSuiteBase.java index 73f01511..85818023 100644 --- a/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/TestSuiteBase.java +++ b/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/TestSuiteBase.java @@ -680,7 +680,7 @@ public class TestSuiteBase extends DocumentClientTest { try { client.close(); } catch (Exception e) { - e.printStackTrace(); + logger.error("unexpected failure in closing client", e); } }).start(); } @@ -691,7 +691,7 @@ public class TestSuiteBase extends DocumentClientTest { try { client.close(); } catch (Exception e) { - e.printStackTrace(); + logger.error("unexpected failure in closing client", e); } } } diff --git a/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/UserCrudTest.java b/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/UserCrudTest.java index 64109c17..92c9995d 100644 --- a/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/UserCrudTest.java +++ b/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/UserCrudTest.java @@ -134,32 +134,28 @@ public class UserCrudTest extends TestSuiteBase { .build(); validateSuccess(readObservable, validatorForRead); - + client.readUsers(getDatabaseLink(), null).toBlocking().subscribe(users -> { - try { - int initialNumberOfUsers = users.getResults().size(); - //update user - readBackUser.setId(UUID.randomUUID().toString()); + int initialNumberOfUsers = users.getResults().size(); + //update user + readBackUser.setId(UUID.randomUUID().toString()); - Observable> updateObservable = client.upsertUser(getDatabaseLink(), readBackUser, null); + Observable> updateObservable = client.upsertUser(getDatabaseLink(), readBackUser, null); - // validate user upsert - ResourceResponseValidator validatorForUpdate = new ResourceResponseValidator.Builder() - .withId(readBackUser.getId()) - .notNullEtag() - .build(); - - validateSuccess(updateObservable, validatorForUpdate); - - //verify that new user is added due to upsert with changed id - client.readUsers(getDatabaseLink(), null).toBlocking().subscribe(newUsers ->{ - int finalNumberOfUsers = newUsers.getResults().size(); - assertThat(finalNumberOfUsers).isEqualTo(initialNumberOfUsers + 1); - }); - } catch (Exception e) { - e.printStackTrace(); - } - }); + // validate user upsert + ResourceResponseValidator validatorForUpdate = new ResourceResponseValidator.Builder() + .withId(readBackUser.getId()) + .notNullEtag() + .build(); + + validateSuccess(updateObservable, validatorForUpdate); + + //verify that new user is added due to upsert with changed id + client.readUsers(getDatabaseLink(), null).toBlocking().subscribe(newUsers -> { + int finalNumberOfUsers = newUsers.getResults().size(); + assertThat(finalNumberOfUsers).isEqualTo(initialNumberOfUsers + 1); + }); + }); } @Test(groups = { "emulator" }, timeOut = TIMEOUT)