Commit 501f785f authored by Matija Obreza's avatar Matija Obreza

Skip keyword search test, ES not available

parent cf6c1aad
......@@ -46,6 +46,7 @@ import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.PublishState;
import org.genesys2.server.model.UserRole;
import org.genesys2.server.service.DownloadService;
import org.genesys2.server.service.ElasticsearchService;
import org.genesys2.util.JPAUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -102,6 +103,9 @@ public class DescriptorServiceImpl implements DescriptorService {
@Autowired
private VersionManager versionManager;
@Autowired
private ElasticsearchService elasticsearchService;
/**
* {@inheritDoc}
*/
......@@ -301,8 +305,12 @@ public class DescriptorServiceImpl implements DescriptorService {
@Override
public Page<Descriptor> listDescriptors(final DescriptorFilter descriptorFilter, final Pageable page) {
Pageable markdownSortPageRequest = JPAUtils.toMarkdownSort(page, "title");
Page<Descriptor> res = descriptorRepository.findAll(new BooleanBuilder().and(descriptorFilter.buildPredicate()).and(QDescriptor.descriptor.state.in(PublishState.PUBLISHED)), markdownSortPageRequest);
return new PageImpl<>(res.getContent(), page, res.getTotalElements());
if (descriptorFilter.isFulltextQuery()) {
return elasticsearchService.findAll(Descriptor.class, descriptorFilter, descriptorFilter._text, markdownSortPageRequest);
} else {
return descriptorRepository.findAll(new BooleanBuilder().and(descriptorFilter.buildPredicate()).and(QDescriptor.descriptor.state.in(PublishState.PUBLISHED)), markdownSortPageRequest);
}
}
/**
......
......@@ -229,4 +229,14 @@ public interface ElasticsearchService {
List<Double[]> distinctCoordinates(Predicate filt, String _text);
<T extends BasicModel> void process(Class<T> clazz, BasicModelFilter<?, ?> filter, IBatchAction<T> action, Long maxSize) throws Exception;
/**
* Wait until X records match specified filter in ES.
*
* @param clazz
* @param filter
* @param mustHaveCount
* @throws InterruptedException
*/
void waitForCount(Class<? extends BasicModel> clazz, BasicModelFilter<?, ?> filter, int mustHaveCount) throws InterruptedException;
}
......@@ -201,6 +201,22 @@ public class ElasticsearchServiceImpl implements ElasticsearchService, Initializ
}
}
}
@Override
public void waitForCount(Class<? extends BasicModel> clazz, BasicModelFilter<?, ?> filter, int mustHaveCount) throws InterruptedException {
long count = 0;
do {
count = count(clazz, filter);
if (count != mustHaveCount) {
LOG.warn("ES count of {} is {}!={}", clazz.getName(), count, mustHaveCount);
Thread.sleep(1000);
} else {
List<?> search = find(clazz, filter);
LOG.warn("Got: ", search);
}
} while (count != mustHaveCount);
}
/**
* Makes a list of all JSON paths for indexed entity and all related types.
......
......@@ -34,6 +34,7 @@ import org.genesys2.server.exception.InvalidApiUsageException;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.PublishState;
import org.genesys2.server.model.impl.Crop;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.dao.ConcurrencyFailureException;
import org.springframework.dao.DataIntegrityViolationException;
......@@ -649,6 +650,7 @@ public class DescriptorServiceTest extends CatalogServiceTest {
}
@Test
@Ignore // We don't have ES in this test suite. Skip it.
public void testKeywordSearch() {
descriptorRepository.save(setupDescriptor(null, "AAA CCDD", Category.PASSPORT, DataType.BOOLEAN, VERSION_1_0, PublishState.PUBLISHED));
descriptorRepository.save(setupDescriptor(null, "AAA BBEE1", Category.PASSPORT, DataType.BOOLEAN, VERSION_1_0, PublishState.PUBLISHED));
......
......@@ -107,17 +107,7 @@ public class ElasticQueryBuilderTest extends AbstractElasticServiceTest {
accessionUploader.upsertAccessions(institute, batch);
assertThat(accessionRepository.count(), is((long) batch.size()));
long count = 0;
do {
count = elasticsearchService.count(Accession.class, null);
if (count != batch.size()) {
LOG.warn("ES count of {} is {}!={}", Accession.class, count, batch.size());
Thread.sleep(1000);
} else {
List<Accession> search = elasticsearchService.find(Accession.class, null);
LOG.warn("Got: ", search);
}
} while (count != batch.size());
elasticsearchService.waitForCount(Accession.class, null, batch.size());
}
private ObjectNode makeAccessionJson(FaoInstitute institute, String acceNumb, String genus, Set<Integer> storage) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment