Skip to content

Commit

Permalink
Add unit test for deprecated constructor
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Ross <[email protected]>
  • Loading branch information
andrross committed Feb 22, 2024
1 parent a6778ac commit 49ddd28
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@

public class QueryShardContextTests extends OpenSearchTestCase {

private static final int SHARD_ID = 0;

public void testFailIfFieldMappingNotFound() {
QueryShardContext context = createQueryShardContext(IndexMetadata.INDEX_UUID_NA_VALUE, null);
context.setAllowUnmappedFields(false);
Expand Down Expand Up @@ -307,9 +309,9 @@ public void testFielddataLookupOneFieldManyReferences() throws IOException {
assertEquals(Arrays.asList(expectedFirstDoc.toString(), expectedSecondDoc.toString()), collect("field", queryShardContext));
}

public void testSearchLookupShardId() throws IOException {
public void testSearchLookupShardId() {
SearchLookup searchLookup = createQueryShardContext("uuid", null, null).lookup();
assertEquals(0, searchLookup.shardId());
assertEquals(SHARD_ID, searchLookup.shardId());
}

public static QueryShardContext createQueryShardContext(String indexUuid, String clusterAlias) {
Expand Down Expand Up @@ -348,7 +350,7 @@ private static QueryShardContext createQueryShardContext(
}
final long nowInMillis = randomNonNegativeLong();
return new QueryShardContext(
0,
SHARD_ID,
indexSettings,
BigArrays.NON_RECYCLING_INSTANCE,
null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.search.lookup;

import org.opensearch.index.mapper.MapperService;
import org.opensearch.test.OpenSearchTestCase;

import static org.mockito.Mockito.mock;

public class SearchLookupTests extends OpenSearchTestCase {
public void testDeprecatedConstructorShardId() {
final SearchLookup searchLookup = new SearchLookup(mock(MapperService.class), (a, b) -> null);
assertThrows(IllegalStateException.class, searchLookup::shardId);
}
}

0 comments on commit 49ddd28

Please sign in to comment.