-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new search sanity tests to ensure that query templates are …
…valid (#70) Also fix the ES 7 docker setup, as it was incorrect (which, side note, means that our tests were not being run in GitHub actions? TODO to investigate that) Also also er comment from Vidya add a createBrowseDao method
- Loading branch information
John Plaisted
authored
Jan 21, 2021
1 parent
203ee1b
commit f13da1c
Showing
13 changed files
with
531 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...rch-dao-integ-testing-7/src/main/java/com/linkedin/metadata/testing/TestBrowseConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.linkedin.metadata.testing; | ||
|
||
import com.linkedin.data.template.RecordTemplate; | ||
import com.linkedin.metadata.dao.browse.BaseBrowseConfig; | ||
import javax.annotation.Nonnull; | ||
|
||
|
||
/** | ||
* Browse config for use in testing, which can wrap another config but use a different index name. | ||
* | ||
* <p>Useful for tests which want to name the index after the test, not the document. | ||
*/ | ||
final class TestBrowseConfig<DOCUMENT extends RecordTemplate> extends BaseBrowseConfig<DOCUMENT> { | ||
private final BaseBrowseConfig<DOCUMENT> _wrapped; | ||
private final String _indexName; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param wrapped the config to wrap | ||
* @param indexName the ES index to use | ||
*/ | ||
TestBrowseConfig(@Nonnull BaseBrowseConfig<DOCUMENT> wrapped, @Nonnull String indexName) { | ||
_wrapped = wrapped; | ||
_indexName = indexName; | ||
} | ||
|
||
@Override | ||
public Class<DOCUMENT> getSearchDocument() { | ||
return _wrapped.getSearchDocument(); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String getBrowseDepthFieldName() { | ||
return _wrapped.getBrowseDepthFieldName(); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String getBrowsePathFieldName() { | ||
return _wrapped.getBrowsePathFieldName(); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String getUrnFieldName() { | ||
return _wrapped.getUrnFieldName(); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String getSortingField() { | ||
return _wrapped.getSortingField(); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String getRemovedField() { | ||
return _wrapped.getRemovedField(); | ||
} | ||
|
||
@Override | ||
public boolean hasFieldInSchema(@Nonnull String fieldName) { | ||
return _wrapped.hasFieldInSchema(fieldName); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String getIndexName() { | ||
return _indexName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...teg-testing-docker-7/src/test/java/com/linkedin/metadata/testing/BadSearchConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.linkedin.metadata.testing; | ||
|
||
import com.linkedin.metadata.dao.exception.ESQueryException; | ||
import com.linkedin.metadata.dao.search.BaseSearchConfig; | ||
import com.linkedin.metadata.dao.search.ESSearchDAO; | ||
import com.linkedin.metadata.testing.annotations.SearchIndexMappings; | ||
import com.linkedin.metadata.testing.annotations.SearchIndexSettings; | ||
import com.linkedin.metadata.testing.annotations.SearchIndexType; | ||
import com.linkedin.testing.BarSearchDocument; | ||
import java.util.Collections; | ||
import java.util.Set; | ||
import javax.annotation.Nonnull; | ||
import org.elasticsearch.ElasticsearchStatusException; | ||
import org.elasticsearch.rest.RestStatus; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
|
||
@ElasticsearchIntegrationTest | ||
public class BadSearchConfigTest { | ||
@SearchIndexType(BarSearchDocument.class) | ||
@SearchIndexSettings("/settings.json") | ||
@SearchIndexMappings("/mappings.json") | ||
public SearchIndex<BarSearchDocument> _searchIndex; | ||
|
||
private static final class SearchConfig extends BaseSearchConfig<BarSearchDocument> { | ||
|
||
@Nonnull | ||
@Override | ||
public Set<String> getFacetFields() { | ||
return Collections.emptySet(); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public Class<BarSearchDocument> getSearchDocument() { | ||
return BarSearchDocument.class; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String getDefaultAutocompleteField() { | ||
return ""; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String getSearchQueryTemplate() { | ||
return "invalid"; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String getAutocompleteQueryTemplate() { | ||
return "invalid"; | ||
} | ||
} | ||
|
||
/** | ||
* Tests that invalid query templates cause an exception when searching via the DAO, ensuring that {@link | ||
* BaseSearchSanityTests#canUseSearchQueryTemplate()} ()} is valid test. | ||
*/ | ||
@Test | ||
public void invalidSearchQueryTemplateDoesThrowOnSearch() { | ||
// given | ||
final ESSearchDAO<BarSearchDocument> dao = _searchIndex.createReadDao(new SearchConfig()); | ||
|
||
// then | ||
final Throwable thrown = catchThrowable(() -> dao.search("", null, null, 0, 1)); | ||
assertThat(thrown).isInstanceOf(ESQueryException.class).hasCauseInstanceOf(ElasticsearchStatusException.class); | ||
assertThat(((ElasticsearchStatusException) thrown.getCause()).status()).isEqualTo(RestStatus.BAD_REQUEST); | ||
} | ||
|
||
/** | ||
* Tests that invalid query templates cause an exception when searching via the DAO, ensuring that {@link | ||
* BaseSearchSanityTests#canUseAutocompleteTemplate()} is valid test. | ||
*/ | ||
@Test | ||
public void invalidAutocompleteQueryTemplateDoesThrowOnSearch() { | ||
// given | ||
final ESSearchDAO<BarSearchDocument> dao = _searchIndex.createReadDao(new SearchConfig()); | ||
|
||
// then | ||
final Throwable thrown = catchThrowable(() -> dao.autoComplete("", null, null, 1)); | ||
assertThat(thrown).isInstanceOf(ESQueryException.class).hasCauseInstanceOf(ElasticsearchStatusException.class); | ||
assertThat(((ElasticsearchStatusException) thrown.getCause()).status()).isEqualTo(RestStatus.BAD_REQUEST); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.