Skip to content

Commit

Permalink
Fix unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Sachin Kale <[email protected]>
  • Loading branch information
Sachin Kale committed Apr 2, 2024
1 parent 7aa04dc commit 3337fa7
Showing 1 changed file with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
import org.opensearch.common.blobstore.stream.write.WritePriority;
import org.opensearch.common.blobstore.support.PlainBlobMetadata;
import org.opensearch.common.collect.Tuple;
import org.opensearch.common.settings.ClusterSettings;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.core.action.ActionListener;
import org.opensearch.core.index.Index;
import org.opensearch.core.index.shard.ShardId;
Expand Down Expand Up @@ -55,7 +54,6 @@
import static org.opensearch.index.remote.RemoteStoreDataEnums.DataCategory.TRANSLOG;
import static org.opensearch.index.remote.RemoteStoreDataEnums.DataType.METADATA;
import static org.opensearch.index.translog.transfer.TranslogTransferMetadata.METADATA_SEPARATOR;
import static org.opensearch.indices.RemoteStoreSettings.CLUSTER_REMOTE_TRANSLOG_TRANSFER_TIMEOUT_SETTING;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.ArgumentMatchers.anySet;
Expand Down Expand Up @@ -195,17 +193,28 @@ public void onUploadFailed(TransferSnapshot transferSnapshot, Exception ex) {

public void testTransferSnapshotOnUploadTimeout() throws Exception {
doAnswer(invocationOnMock -> {
Thread.sleep(5);
Set<TransferFileSnapshot> transferFileSnapshots = invocationOnMock.getArgument(0);
ActionListener<TransferFileSnapshot> listener = invocationOnMock.getArgument(2);
Runnable runnable = () -> {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
for (TransferFileSnapshot transferFileSnapshot : transferFileSnapshots) {
listener.onResponse(transferFileSnapshot);
}
};
Thread t = new Thread(runnable);
t.start();
return null;
}).when(transferService).uploadBlobs(anySet(), anyMap(), any(ActionListener.class), any(WritePriority.class));
FileTransferTracker fileTransferTracker = new FileTransferTracker(
new ShardId("index", "indexUUid", 0),
remoteTranslogTransferTracker
);
RemoteStoreSettings remoteStoreSettings = new RemoteStoreSettings(
Settings.builder().put(CLUSTER_REMOTE_TRANSLOG_TRANSFER_TIMEOUT_SETTING.getKey(), "1ms").build(),
new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)
);
RemoteStoreSettings remoteStoreSettings = mock(RemoteStoreSettings.class);
when(remoteStoreSettings.getClusterRemoteTranslogTransferTimeout()).thenReturn(new TimeValue(1));
TranslogTransferManager translogTransferManager = new TranslogTransferManager(
shardId,
transferService,
Expand Down

0 comments on commit 3337fa7

Please sign in to comment.