Skip to content

Commit

Permalink
Added wait for solr index to prevent intermittent solr test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
tdl-jturner committed Aug 14, 2019
1 parent f085b37 commit 6a7c93a
Showing 1 changed file with 34 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,18 @@ protected void waitForDone(CompletableFuture<?> completableFuture) {
}
}


protected void waitForSolrIndex(E obj) {
int maxWait=30;
for(int i=0;i<=maxWait;i++) {
if(getCasquatchDao().getAllBySolr(this.entityClass,obj).size()>0) return;
try {
Thread.sleep(1000);
}
catch(Exception e) {
return;
}
}
}

private E prepCache() {
E obj = prepObject();
Expand Down Expand Up @@ -398,10 +409,11 @@ public void testGetAllBySolrQuery() throws InterruptedException {
E obj = prepObject();

if(getCasquatchDao().checkFeature(CasquatchDao.FEATURES.SOLR)) {
Thread.sleep(1000);
waitForSolrIndex(obj);
List<E> tstObj = this.getCasquatchDao().getAllBySolr(this.entityClass, "*:*");
assertEquals(1, tstObj.size());
assertEquals(obj, tstObj.get(0));
assertNotNull(tstObj);
assert(tstObj.size()>0);
assert(tstObj.contains(obj));
}
else {
assertThrows(DriverException.class, () -> this.getCasquatchDao().getAllBySolr(this.entityClass, obj));
Expand All @@ -415,9 +427,9 @@ public void testGetCountBySolrQuery() throws InterruptedException {
E obj = prepObject();

if(getCasquatchDao().checkFeature(CasquatchDao.FEATURES.SOLR)) {
Thread.sleep(1000);
waitForSolrIndex(obj);
Long count = this.getCasquatchDao().getCountBySolr(this.entityClass,"*:*");
assertEquals(1, (long) count);
assert(count > 0);
}
else {
assertThrows(DriverException.class, () -> this.getCasquatchDao().getAllBySolr(this.entityClass, obj));
Expand All @@ -431,10 +443,11 @@ public void testGetAllBySolrQueryWithOptions() throws InterruptedException {
E obj = prepObject();

if(getCasquatchDao().checkFeature(CasquatchDao.FEATURES.SOLR)) {
Thread.sleep(1000);
waitForSolrIndex(obj);
List<E> tstObj = this.getCasquatchDao().getAllBySolr(this.entityClass,"*:*",queryOptions.withConsistencyLevel("LOCAL_ONE").withAllColumns());
assertEquals(1, tstObj.size());
assertEquals(obj, tstObj.get(0));
assertNotNull(tstObj);
assert(tstObj.size()>0);
assert(tstObj.contains(obj));
}
else {
assertThrows(DriverException.class, () -> this.getCasquatchDao().getAllBySolr(this.entityClass, obj));
Expand All @@ -448,9 +461,9 @@ public void testGetCountBySolrQueryWithOptions() throws InterruptedException {
E obj = prepObject();

if(getCasquatchDao().checkFeature(CasquatchDao.FEATURES.SOLR)) {
Thread.sleep(1000);
waitForSolrIndex(obj);
Long count = this.getCasquatchDao().getCountBySolr(this.entityClass,"*:*",queryOptions.withConsistencyLevel("LOCAL_ONE").withAllColumns());
assertEquals(1, (long) count);
assert(count > 0);
}
else {
assertThrows(DriverException.class, () -> this.getCasquatchDao().getAllBySolr(this.entityClass, obj));
Expand All @@ -465,10 +478,11 @@ public void testGetAllBySolrObject() throws InterruptedException {
E obj = prepObject();

if(getCasquatchDao().checkFeature(CasquatchDao.FEATURES.SOLR_OBJECT)) {
Thread.sleep(1000);
waitForSolrIndex(obj);
List<E> tstObj = this.getCasquatchDao().getAllBySolr(this.entityClass, obj);
assertEquals(1, tstObj.size());
assertEquals(obj, tstObj.get(0));
assertNotNull(tstObj);
assert(tstObj.size()>0);
assert(tstObj.contains(obj));
}
else {
assertThrows(DriverException.class, () -> this.getCasquatchDao().getAllBySolr(this.entityClass, obj));
Expand All @@ -482,7 +496,7 @@ public void testGetCountBySolrObject() throws InterruptedException {
E obj = prepObject();

if(getCasquatchDao().checkFeature(CasquatchDao.FEATURES.SOLR_OBJECT)) {
Thread.sleep(1000);
waitForSolrIndex(obj);
Long count = this.getCasquatchDao().getCountBySolr(this.entityClass,obj);
assertEquals(1, (long) count);
}
Expand All @@ -498,10 +512,11 @@ public void testGetAllBySolrObjectWithOptions() throws InterruptedException {
E obj = prepObject();

if(getCasquatchDao().checkFeature(CasquatchDao.FEATURES.SOLR_OBJECT)) {
Thread.sleep(1000);
waitForSolrIndex(obj);
List<E> tstObj = this.getCasquatchDao().getAllBySolr(this.entityClass,obj,queryOptions.withConsistencyLevel("LOCAL_ONE").withAllColumns());
assertEquals(1, tstObj.size());
assertEquals(obj, tstObj.get(0));
assertNotNull(tstObj);
assert(tstObj.size()>0);
assert(tstObj.contains(obj));
}
else {
assertThrows(DriverException.class, () -> this.getCasquatchDao().getAllBySolr(this.entityClass, obj));
Expand All @@ -515,7 +530,7 @@ public void testGetCountBySolrObjectWithOptions() throws InterruptedException {
E obj = prepObject();

if(getCasquatchDao().checkFeature(CasquatchDao.FEATURES.SOLR_OBJECT)) {
Thread.sleep(1000);
waitForSolrIndex(obj);
Long count = this.getCasquatchDao().getCountBySolr(this.entityClass,obj,queryOptions.withConsistencyLevel("LOCAL_ONE").withAllColumns());
assertEquals(1, (long) count);
}
Expand Down

0 comments on commit 6a7c93a

Please sign in to comment.