-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Bukhtawar Khan <bukhtawa@amazon.com>
- Loading branch information
Showing
2 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
.../opensearch/common/blobstore/transfer/stream/RateLimitingOffsetRangeInputStreamTests.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,46 @@ | ||
/* | ||
* 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.common.blobstore.transfer.stream; | ||
|
||
import org.apache.lucene.store.Directory; | ||
import org.apache.lucene.store.IOContext; | ||
import org.apache.lucene.store.NIOFSDirectory; | ||
import org.apache.lucene.store.RateLimiter; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
|
||
import java.io.IOException; | ||
|
||
public class RateLimitingOffsetRangeInputStreamTests extends ResettableCheckedInputStreamBaseTest { | ||
|
||
private Directory directory; | ||
|
||
@Override | ||
@Before | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
directory = new NIOFSDirectory(testFile.getParent()); | ||
} | ||
|
||
@Override | ||
protected OffsetRangeInputStream getOffsetRangeInputStream(long size, long position) throws IOException { | ||
return new RateLimitingOffsetRangeInputStream( | ||
new OffsetRangeIndexInputStream(directory.openInput(testFile.getFileName().toString(), IOContext.DEFAULT), size, position), | ||
() -> new RateLimiter.SimpleRateLimiter(randomIntBetween(10, 20)), | ||
(t) -> {} | ||
); | ||
} | ||
|
||
@Override | ||
@After | ||
public void tearDown() throws Exception { | ||
directory.close(); | ||
super.tearDown(); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
server/src/test/java/org/opensearch/repositories/blobstore/BlobStoreRemoteTransferTests.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,80 @@ | ||
/* | ||
* 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.repositories.blobstore; | ||
|
||
import org.opensearch.cluster.metadata.RepositoryMetadata; | ||
import org.opensearch.cluster.service.ClusterService; | ||
import org.opensearch.common.settings.ClusterSettings; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.env.Environment; | ||
import org.opensearch.env.TestEnvironment; | ||
import org.opensearch.indices.recovery.RecoverySettings; | ||
import org.opensearch.repositories.Repository; | ||
import org.opensearch.repositories.fs.FsRepository; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Path; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class BlobStoreRemoteTransferTests extends OpenSearchTestCase { | ||
|
||
private BlobStoreRepository repository; | ||
|
||
public void testDefaultThrottlingValues() throws Exception { | ||
repository = (BlobStoreRepository) createRepository(); | ||
try (ByteArrayInputStream input = new ByteArrayInputStream("foo".getBytes(StandardCharsets.UTF_8))) { | ||
InputStream is = repository.maybeRateLimitRemoteDownloadTransfers(input); | ||
assertBusy(() -> { | ||
is.read(); | ||
assertThat(repository.getRemoteDownloadThrottleTimeInNanos(), equalTo(0L)); | ||
assertThat(repository.getRemoteUploadThrottleTimeInNanos(), equalTo(0L)); | ||
}); | ||
|
||
} | ||
} | ||
|
||
/** Create a {@link Repository} with a random name **/ | ||
protected Repository createRepository() { | ||
Settings settings = Settings.builder().put("location", randomAlphaOfLength(10)).build(); | ||
RepositoryMetadata repositoryMetadata = new RepositoryMetadata(randomAlphaOfLength(10), FsRepository.TYPE, settings); | ||
final ClusterService clusterService = BlobStoreTestUtil.mockClusterService(repositoryMetadata); | ||
final FsRepository repository = new FsRepository( | ||
repositoryMetadata, | ||
createEnvironment(), | ||
xContentRegistry(), | ||
clusterService, | ||
new RecoverySettings(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)) | ||
) { | ||
@Override | ||
protected void assertSnapshotOrGenericThread() { | ||
// eliminate thread name check as we create repo manually | ||
} | ||
}; | ||
clusterService.addStateApplier(event -> repository.updateState(event.state())); | ||
// Apply state once to initialize repo properly like RepositoriesService would | ||
repository.updateState(clusterService.state()); | ||
repository.start(); | ||
return repository; | ||
} | ||
|
||
/** Create a {@link Environment} with random path.home and path.repo **/ | ||
private Environment createEnvironment() { | ||
Path home = createTempDir(); | ||
return TestEnvironment.newEnvironment( | ||
Settings.builder() | ||
.put(Environment.PATH_HOME_SETTING.getKey(), home.toAbsolutePath()) | ||
.put(Environment.PATH_REPO_SETTING.getKey(), home.resolve("repo").toAbsolutePath()) | ||
.build() | ||
); | ||
} | ||
} |