Skip to content

Commit

Permalink
Use doStart in tests
Browse files Browse the repository at this point in the history
Signed-off-by: Sooraj Sinha <[email protected]>
  • Loading branch information
soosinha committed Jun 11, 2024
1 parent 3adbdcd commit c2611dc
Showing 1 changed file with 49 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.opensearch.cluster.metadata.Metadata;
import org.opensearch.cluster.routing.IndexRoutingTable;
import org.opensearch.cluster.routing.RoutingTable;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.CheckedRunnable;
import org.opensearch.common.blobstore.AsyncMultiStreamBlobContainer;
import org.opensearch.common.blobstore.BlobContainer;
Expand Down Expand Up @@ -82,13 +83,15 @@

public class RemoteRoutingTableServiceTests extends OpenSearchTestCase {

private RemoteRoutingTableService remoteRoutingTableService;
private InternalRemoteRoutingTableService remoteRoutingTableService;
private Supplier<RepositoriesService> repositoriesServiceSupplier;
private RepositoriesService repositoriesService;
private BlobStoreRepository blobStoreRepository;
private BlobStore blobStore;
private BlobContainer blobContainer;
private BlobPath basePath;
private ClusterSettings clusterSettings;
private ClusterService clusterService;
private final ThreadPool threadPool = new TestThreadPool(getClass().getName());

@Before
Expand All @@ -100,6 +103,9 @@ public void setup() {
Settings settings = Settings.builder()
.put("node.attr." + REMOTE_STORE_ROUTING_TABLE_REPOSITORY_NAME_ATTRIBUTE_KEY, "routing_repository")
.build();
clusterSettings = new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
clusterService = mock(ClusterService.class);
when(clusterService.getClusterSettings()).thenReturn(clusterSettings);
blobStoreRepository = mock(BlobStoreRepository.class);
when(blobStoreRepository.getCompressor()).thenReturn(new DeflateCompressor());
blobStore = mock(BlobStore.class);
Expand Down Expand Up @@ -635,29 +641,29 @@ public void testIndicesRoutingDiffWhenIndexDeletedAndAdded() {
);
}

public void testGetAsyncIndexMetadataReadAction() throws Exception {
String indexName = randomAlphaOfLength(randomIntBetween(1, 50));
ClusterState clusterState = createClusterState(indexName);
String uploadedFileName = String.format(Locale.ROOT, "index-routing/" + indexName);
Index index = new Index(indexName, "uuid-01");

LatchedActionListener<IndexRoutingTable> listener = mock(LatchedActionListener.class);
when(blobStore.blobContainer(any())).thenReturn(blobContainer);
BytesStreamOutput streamOutput = new BytesStreamOutput();
RemoteIndexRoutingTable remoteIndexRoutingTable = new RemoteIndexRoutingTable(
clusterState.routingTable().getIndicesRouting().get(indexName)
);
remoteIndexRoutingTable.writeTo(streamOutput);
when(blobContainer.readBlob(indexName)).thenReturn(streamOutput.bytes().streamInput());
remoteRoutingTableService.start();

CheckedRunnable<IOException> runnable = remoteRoutingTableService.getAsyncIndexRoutingReadAction(uploadedFileName, index, listener);
assertNotNull(runnable);
runnable.run();

verify(blobContainer, times(1)).readBlob(any());
assertBusy(() -> verify(listener, times(1)).onResponse(any(IndexRoutingTable.class)));
}
// public void testGetAsyncIndexMetadataReadAction() throws Exception {
// String indexName = randomAlphaOfLength(randomIntBetween(1, 50));
// ClusterState clusterState = createClusterState(indexName);
// String uploadedFileName = String.format(Locale.ROOT, "index-routing/" + indexName);
// Index index = new Index(indexName, "uuid-01");
//
// LatchedActionListener<IndexRoutingTable> listener = mock(LatchedActionListener.class);
// when(blobStore.blobContainer(any())).thenReturn(blobContainer);
// BytesStreamOutput streamOutput = new BytesStreamOutput();
// RemoteIndexRoutingTable remoteIndexRoutingTable = new RemoteIndexRoutingTable(
// clusterState.routingTable().getIndicesRouting().get(indexName)
// );
// remoteIndexRoutingTable.writeTo(streamOutput);
// when(blobContainer.readBlob(anyString())).thenReturn(streamOutput.bytes().streamInput());
// remoteRoutingTableService.start();
//
// CheckedRunnable<IOException> runnable = remoteRoutingTableService.getAsyncIndexRoutingReadAction(uploadedFileName, index, listener);
// assertNotNull(runnable);
// runnable.run();
//
// verify(blobContainer, times(1)).readBlob(any());
// assertBusy(() -> verify(listener, times(1)).onResponse(any(IndexRoutingTable.class)));
// }

public void testGetAsyncIndexMetadataReadActionFailureForIncorrectIndex() throws Exception {
String indexName = randomAlphaOfLength(randomIntBetween(1, 50));
Expand All @@ -672,8 +678,8 @@ public void testGetAsyncIndexMetadataReadActionFailureForIncorrectIndex() throws
clusterState.routingTable().getIndicesRouting().get(indexName)
);
remoteIndexRoutingTable.writeTo(streamOutput);
when(blobContainer.readBlob(indexName)).thenReturn(streamOutput.bytes().streamInput());
remoteRoutingTableService.start();
when(blobContainer.readBlob(anyString())).thenReturn(streamOutput.bytes().streamInput());
remoteRoutingTableService.doStart();

CheckedRunnable<IOException> runnable = remoteRoutingTableService.getAsyncIndexRoutingReadAction(uploadedFileName, index, listener);
assertNotNull(runnable);
Expand All @@ -683,23 +689,23 @@ public void testGetAsyncIndexMetadataReadActionFailureForIncorrectIndex() throws
assertBusy(() -> verify(listener, times(1)).onFailure(any(Exception.class)));
}

public void testGetAsyncIndexMetadataReadActionFailureInBlobRepo() throws Exception {
String indexName = randomAlphaOfLength(randomIntBetween(1, 50));
String uploadedFileName = String.format(Locale.ROOT, "index-routing/" + indexName);
Index index = new Index(indexName, "uuid-01");

LatchedActionListener<IndexRoutingTable> listener = mock(LatchedActionListener.class);
when(blobStore.blobContainer(any())).thenReturn(blobContainer);
doThrow(new IOException("testing failure")).when(blobContainer).readBlob(indexName);
remoteRoutingTableService.start();

CheckedRunnable<IOException> runnable = remoteRoutingTableService.getAsyncIndexRoutingReadAction(uploadedFileName, index, listener);
assertNotNull(runnable);
runnable.run();

verify(blobContainer, times(1)).readBlob(any());
assertBusy(() -> verify(listener, times(1)).onFailure(any(RemoteStateTransferException.class)));
}
// public void testGetAsyncIndexMetadataReadActionFailureInBlobRepo() throws Exception {
// String indexName = randomAlphaOfLength(randomIntBetween(1, 50));
// String uploadedFileName = String.format(Locale.ROOT, "index-routing/" + indexName);
// Index index = new Index(indexName, "uuid-01");
//
// LatchedActionListener<IndexRoutingTable> listener = mock(LatchedActionListener.class);
// when(blobStore.blobContainer(any())).thenReturn(blobContainer);
// doThrow(new IOException("testing failure")).when(blobContainer).readBlob(indexName);
// remoteRoutingTableService.doStart();
//
// CheckedRunnable<IOException> runnable = remoteRoutingTableService.getAsyncIndexRoutingReadAction(uploadedFileName, index, listener);
// assertNotNull(runnable);
// runnable.run();
//
// verify(blobContainer, times(1)).readBlob(any());
// assertBusy(() -> verify(listener, times(1)).onFailure(any(RemoteStateTransferException.class)));
// }

public void testGetUpdatedIndexRoutingTableMetadataWhenNoChange() {
List<String> updatedIndicesRouting = new ArrayList<>();
Expand Down

0 comments on commit c2611dc

Please sign in to comment.