forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds unit test for remote routing setup
Signed-off-by: Himshikha Gupta <[email protected]>
- Loading branch information
Himshikha Gupta
committed
Apr 22, 2024
1 parent
d5a17ed
commit 9176015
Showing
3 changed files
with
128 additions
and
3 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
92 changes: 92 additions & 0 deletions
92
...r/src/test/java/org/opensearch/cluster/routing/remote/RemoteRoutingTableServiceTests.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,92 @@ | ||
/* | ||
* 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.cluster.routing.remote; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.opensearch.common.settings.ClusterSettings; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.common.util.FeatureFlags; | ||
import org.opensearch.repositories.FilterRepository; | ||
import org.opensearch.repositories.RepositoriesService; | ||
import org.opensearch.repositories.RepositoryMissingException; | ||
import org.opensearch.repositories.blobstore.BlobStoreRepository; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import static org.mockito.Mockito.*; | ||
import static org.opensearch.common.util.FeatureFlags.REMOTE_ROUTING_TABLE_EXPERIMENTAL; | ||
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_ROUTING_TABLE_REPOSITORY_NAME_ATTRIBUTE_KEY; | ||
|
||
public class RemoteRoutingTableServiceTests extends OpenSearchTestCase { | ||
|
||
private RemoteRoutingTableService remoteRoutingTableService; | ||
private ClusterSettings clusterSettings; | ||
private Supplier<RepositoriesService> repositoriesServiceSupplier; | ||
private RepositoriesService repositoriesService; | ||
private BlobStoreRepository blobStoreRepository; | ||
|
||
@Before | ||
public void setup() { | ||
repositoriesServiceSupplier = mock(Supplier.class); | ||
repositoriesService = mock(RepositoriesService.class); | ||
when(repositoriesServiceSupplier.get()).thenReturn(repositoriesService); | ||
|
||
Settings settings = Settings.builder() | ||
.put(RemoteRoutingTableService.REMOTE_ROUTING_TABLE_ENABLED_SETTING.getKey(), true) | ||
.put("node.attr." + REMOTE_STORE_ROUTING_TABLE_REPOSITORY_NAME_ATTRIBUTE_KEY, "routing_repository") | ||
.build(); | ||
|
||
clusterSettings = new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); | ||
|
||
blobStoreRepository = mock(BlobStoreRepository.class); | ||
when(repositoriesService.repository("routing_repository")).thenReturn(blobStoreRepository); | ||
|
||
Settings nodeSettings = Settings.builder().put(REMOTE_ROUTING_TABLE_EXPERIMENTAL, "true").build(); | ||
FeatureFlags.initializeFeatureFlags(nodeSettings); | ||
|
||
remoteRoutingTableService = new RemoteRoutingTableService( | ||
repositoriesServiceSupplier, | ||
settings, | ||
clusterSettings | ||
); | ||
} | ||
|
||
@After | ||
public void teardown() throws Exception { | ||
super.tearDown(); | ||
remoteRoutingTableService.close(); | ||
} | ||
|
||
|
||
public void testFailInitializationWhenRemoteRoutingDisabled() { | ||
final Settings settings = Settings.builder().build(); | ||
assertThrows( | ||
AssertionError.class, | ||
() -> new RemoteRoutingTableService( | ||
repositoriesServiceSupplier, | ||
settings, | ||
new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS) | ||
) | ||
); | ||
} | ||
|
||
public void testFailStartWhenRepositoryNotSet() { | ||
doThrow(new RepositoryMissingException("repository missing")).when(repositoriesService).repository("routing_repository"); | ||
assertThrows(RepositoryMissingException.class, () -> remoteRoutingTableService.start()); | ||
} | ||
|
||
public void testFailStartWhenNotBlobRepository() { | ||
final FilterRepository filterRepository = mock(FilterRepository.class); | ||
when(repositoriesService.repository("routing_repository")).thenReturn(filterRepository); | ||
assertThrows(AssertionError.class, () -> remoteRoutingTableService.start()); | ||
} | ||
|
||
} |
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