-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RemoteStoreStatsTrackerFactoryTests and RemoteStoreTestsHelper
Signed-off-by: Bhumika Saini <sabhumik@amazon.com>
- Loading branch information
1 parent
4f9d48a
commit 98d6242
Showing
11 changed files
with
138 additions
and
63 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
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
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
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
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
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
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
74 changes: 74 additions & 0 deletions
74
server/src/test/java/org/opensearch/index/remote/RemoteStoreStatsTrackerFactoryTests.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,74 @@ | ||
/* | ||
* 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.index.remote; | ||
|
||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.core.index.shard.ShardId; | ||
import org.opensearch.index.shard.IndexShard; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
import static org.opensearch.index.remote.RemoteStoreTestsHelper.createIndexShard; | ||
|
||
public class RemoteStoreStatsTrackerFactoryTests extends OpenSearchTestCase { | ||
private ShardId shardId; | ||
private IndexShard indexShard; | ||
private RemoteStoreStatsTrackerFactory remoteStoreStatsTrackerFactory; | ||
|
||
@Override | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
shardId = new ShardId("index", "uuid", 0); | ||
indexShard = createIndexShard(shardId, true); | ||
remoteStoreStatsTrackerFactory = new RemoteStoreStatsTrackerFactory(Settings.EMPTY); | ||
} | ||
|
||
public void testAfterIndexShardCreatedForRemoteBackedIndex() { | ||
remoteStoreStatsTrackerFactory.afterIndexShardCreated(indexShard); | ||
assertNotNull(remoteStoreStatsTrackerFactory.getRemoteSegmentTransferTracker(indexShard.shardId())); | ||
} | ||
|
||
public void testAfterIndexShardCreatedForNonRemoteBackedIndex() { | ||
indexShard = createIndexShard(shardId, false); | ||
remoteStoreStatsTrackerFactory.afterIndexShardCreated(indexShard); | ||
assertNull(remoteStoreStatsTrackerFactory.getRemoteSegmentTransferTracker(indexShard.shardId())); | ||
} | ||
|
||
public void testAfterIndexShardClosed() { | ||
remoteStoreStatsTrackerFactory.afterIndexShardCreated(indexShard); | ||
assertNotNull(remoteStoreStatsTrackerFactory.getRemoteSegmentTransferTracker(shardId)); | ||
remoteStoreStatsTrackerFactory.afterIndexShardClosed(shardId, indexShard, indexShard.indexSettings().getSettings()); | ||
assertNull(remoteStoreStatsTrackerFactory.getRemoteSegmentTransferTracker(shardId)); | ||
} | ||
|
||
public void testUpdateMovingAverageWindowSize() { | ||
remoteStoreStatsTrackerFactory.afterIndexShardCreated(indexShard); | ||
|
||
ShardId shardId2 = new ShardId("index", "uuid", 1); | ||
IndexShard indexShard2 = createIndexShard(shardId2, true); | ||
remoteStoreStatsTrackerFactory.afterIndexShardCreated(indexShard2); | ||
|
||
int defaultSize = RemoteStorePressureSettings.Defaults.MOVING_AVERAGE_WINDOW_SIZE; | ||
assertEquals(defaultSize, remoteStoreStatsTrackerFactory.getMovingAverageWindowSize()); | ||
assertFalse(remoteStoreStatsTrackerFactory.getRemoteSegmentTransferTracker(shardId).isUploadBytesAverageReady()); | ||
assertFalse(remoteStoreStatsTrackerFactory.getRemoteSegmentTransferTracker(shardId).isUploadBytesPerSecAverageReady()); | ||
assertFalse(remoteStoreStatsTrackerFactory.getRemoteSegmentTransferTracker(shardId).isUploadTimeMsAverageReady()); | ||
assertFalse(remoteStoreStatsTrackerFactory.getRemoteSegmentTransferTracker(shardId2).isUploadBytesAverageReady()); | ||
assertFalse(remoteStoreStatsTrackerFactory.getRemoteSegmentTransferTracker(shardId2).isUploadBytesPerSecAverageReady()); | ||
assertFalse(remoteStoreStatsTrackerFactory.getRemoteSegmentTransferTracker(shardId2).isUploadTimeMsAverageReady()); | ||
|
||
int updatedSize = 0; | ||
assertThrows( | ||
IllegalArgumentException.class, | ||
() -> remoteStoreStatsTrackerFactory.updateMovingAverageWindowSize( | ||
RemoteSegmentTransferTracker::updateMovingAverageWindowSize, | ||
updatedSize | ||
) | ||
); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
server/src/test/java/org/opensearch/index/remote/RemoteStoreTestsHelper.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,40 @@ | ||
/* | ||
* 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.index.remote; | ||
|
||
import org.opensearch.cluster.metadata.IndexMetadata; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.core.index.shard.ShardId; | ||
import org.opensearch.index.IndexSettings; | ||
import org.opensearch.index.shard.IndexShard; | ||
import org.opensearch.index.store.Store; | ||
import org.opensearch.indices.replication.common.ReplicationType; | ||
import org.opensearch.test.IndexSettingsModule; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
/** | ||
* Helper functions for Remote Store tests | ||
*/ | ||
public class RemoteStoreTestsHelper { | ||
static IndexShard createIndexShard(ShardId shardId, boolean remoteStoreEnabled) { | ||
Settings settings = Settings.builder() | ||
.put(IndexMetadata.SETTING_REPLICATION_TYPE, ReplicationType.SEGMENT) | ||
.put(IndexMetadata.SETTING_REMOTE_STORE_ENABLED, String.valueOf(remoteStoreEnabled)) | ||
.build(); | ||
IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("test_index", settings); | ||
Store store = mock(Store.class); | ||
IndexShard indexShard = mock(IndexShard.class); | ||
when(indexShard.indexSettings()).thenReturn(indexSettings); | ||
when(indexShard.shardId()).thenReturn(shardId); | ||
when(indexShard.store()).thenReturn(store); | ||
return indexShard; | ||
} | ||
} |
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
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