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 21, 2024
1 parent 02af284 commit caea317
Show file tree
Hide file tree
Showing 2 changed files with 27 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,22 @@
/*
* 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 SearchLookupTest 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 caea317

Please sign in to comment.