* strong potential npe fix

* fix npe & some tests
This commit is contained in:
Mohammad Derakhshani 2019-11-05 21:41:53 -08:00 коммит произвёл GitHub
Родитель a275a95dee
Коммит ee557bfd6d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 55 добавлений и 66 удалений

Просмотреть файл

@ -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);

Просмотреть файл

@ -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");

Просмотреть файл

@ -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<Offer> offers = offersFeed.getResults();
for (i = 0; i < offers.size(); i++) {
if (offers.get(i).getOfferResourceId().equals(createdCollection.getResourceId())) {
break;
}
int i;
List<Offer> 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<ResourceResponse<Offer>> readObservable = client.readOffer(offers.get(i).getSelfLink());
// validate offer read
ResourceResponseValidator<Offer> validatorForRead = new ResourceResponseValidator.Builder<Offer>()
.withOfferThroughput(oldThroughput)
.notNullEtag()
.build();
validateSuccess(readObservable, validatorForRead);
// update offer
int newThroughput = oldThroughput + 100;
offers.get(i).setThroughput(newThroughput);
Observable<ResourceResponse<Offer>> replaceObservable = client.replaceOffer(offers.get(i));
// validate offer replace
ResourceResponseValidator<Offer> validatorForReplace = new ResourceResponseValidator.Builder<Offer>()
.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<ResourceResponse<Offer>> readObservable = client.readOffer(offers.get(i).getSelfLink());
// validate offer read
ResourceResponseValidator<Offer> validatorForRead = new ResourceResponseValidator.Builder<Offer>()
.withOfferThroughput(oldThroughput)
.notNullEtag()
.build();
validateSuccess(readObservable, validatorForRead);
// update offer
int newThroughput = oldThroughput + 100;
offers.get(i).setThroughput(newThroughput);
Observable<ResourceResponse<Offer>> replaceObservable = client.replaceOffer(offers.get(i));
// validate offer replace
ResourceResponseValidator<Offer> validatorForReplace = new ResourceResponseValidator.Builder<Offer>()
.withOfferThroughput(newThroughput)
.notNullEtag()
.build();
validateSuccess(replaceObservable, validatorForReplace);
});
}

Просмотреть файл

@ -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);
}
}
}

Просмотреть файл

@ -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<ResourceResponse<User>> updateObservable = client.upsertUser(getDatabaseLink(), readBackUser, null);
Observable<ResourceResponse<User>> updateObservable = client.upsertUser(getDatabaseLink(), readBackUser, null);
// validate user upsert
ResourceResponseValidator<User> validatorForUpdate = new ResourceResponseValidator.Builder<User>()
.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<User> validatorForUpdate = new ResourceResponseValidator.Builder<User>()
.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)