Skip to content

Commit

Permalink
Use exists method to filter out empty Solr documents
Browse files Browse the repository at this point in the history
Also remove temporary logging added to run on CI
  • Loading branch information
ke4 committed Nov 21, 2024
1 parent 04b983a commit ebd7a02
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
10 changes: 1 addition & 9 deletions app/src/main/java/uk/ac/ebi/atlas/solr/SingleCellSolrUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import com.google.common.collect.ImmutableSet;
import org.apache.solr.common.SolrDocumentList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import uk.ac.ebi.atlas.solr.cloud.SolrCloudCollectionProxyFactory;
import uk.ac.ebi.atlas.solr.cloud.collections.SingleCellAnalyticsCollectionProxy;
Expand All @@ -20,9 +18,6 @@
@Component
public class SingleCellSolrUtils {

// TODO: only for debugging on our CI - Please remove before merging this PR!!!!!
private static final Logger LOGGER = LoggerFactory.getLogger(SingleCellSolrUtils.class);

private final SingleCellAnalyticsCollectionProxy singleCellAnalyticsCollectionProxy;

private static final int MAX_ROWS = 10000;
Expand All @@ -36,6 +31,7 @@ public ImmutableSet<String> fetchedRandomCellTypesByCellIDs(ImmutableSet<String>
SolrQueryBuilder<SingleCellAnalyticsCollectionProxy> queryBuilder = new SolrQueryBuilder<>();
queryBuilder
.addQueryFieldByTerm(CELL_ID, cellIDs)
.exists(CTW_CELL_TYPE)
.setFieldList(CTW_CELL_TYPE)
.setRows(MAX_ROWS);

Expand Down Expand Up @@ -63,11 +59,7 @@ private ImmutableSet<String> getRandomCellTypesFromQueryResult(
SolrDocumentList solrDocumentList,
String schemaFieldName,
int numberOfCellTypes) {
LOGGER.info("Solr Document list: {}", solrDocumentList.toString());
return Arrays.stream(new Random().ints(numberOfCellTypes, 0, solrDocumentList.size()).toArray())
// TODO: only for debugging on our CI - Please remove it before merging this PR!!!!!
.peek(index -> LOGGER.info("SolrDocument at index({}): {}", index, solrDocumentList.get(index)))
.peek(index -> LOGGER.info("SolrDocument's fieldValue({}): {}", schemaFieldName, solrDocumentList.get(index).getFieldValue(schemaFieldName)))
.mapToObj(index -> solrDocumentList.get(index).getFieldValue(schemaFieldName).toString())
.collect(toImmutableSet());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExtendWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.web.WebAppConfiguration;
import uk.ac.ebi.atlas.configuration.TestConfig;
import uk.ac.ebi.atlas.solr.SingleCellSolrUtils;
import uk.ac.ebi.atlas.solr.cloud.SolrCloudCollectionProxyFactory;
import uk.ac.ebi.atlas.testutils.JdbcUtils;
import uk.ac.ebi.atlas.solr.SingleCellSolrUtils;

import javax.inject.Inject;
import javax.sql.DataSource;
Expand All @@ -32,9 +29,6 @@
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class OrganismPartSearchDaoIT {

// TODO: only for debugging on our CI - Please remove before merging this PR!!!!!
private static final Logger LOGGER = LoggerFactory.getLogger(OrganismPartSearchDaoIT.class);

@Inject
private JdbcUtils jdbcUtils;

Expand Down Expand Up @@ -118,13 +112,11 @@ void whenValidCellIdsButInvalidCellTypesProvidedReturnEmptySetOfOrganismPart() {
assertThat(organismParts).isEmpty();
}

// TODO: only for debugging on our CI - Please change back to @Test before merging this PR!!!!!
@RepeatedTest(100)
@Test
void whenValidCellIdsAndValidCellTypesProvidedReturnSetOfOrganismPart() {
var randomListOfCellIDs =
ImmutableSet.copyOf(
new HashSet<>(jdbcUtils.fetchRandomListOfCells(3)));
LOGGER.info("Random list of cell IDs: {}", randomListOfCellIDs);
ImmutableSet<String> cellTypes = solrUtils.fetchedRandomCellTypesByCellIDs(randomListOfCellIDs, 1);

var organismParts = subject.searchOrganismPart(randomListOfCellIDs, cellTypes);
Expand Down

0 comments on commit ebd7a02

Please sign in to comment.