-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Remote Translog] Use InputStream that supports mark and reset while …
…uploading translog files (#5868) (#5900) * Use stream that supports mark and reset for translog upload Signed-off-by: Sachin Kale <kalsac@amazon.com>
- Loading branch information
1 parent
29bd1ef
commit d34a34b
Showing
2 changed files
with
84 additions
and
11 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
77 changes: 77 additions & 0 deletions
77
server/src/test/java/org/opensearch/index/translog/transfer/FileSnapshotTests.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,77 @@ | ||
/* | ||
* 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.translog.transfer; | ||
|
||
import org.junit.After; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
public class FileSnapshotTests extends OpenSearchTestCase { | ||
|
||
FileSnapshot fileSnapshot; | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
super.tearDown(); | ||
fileSnapshot.close(); | ||
} | ||
|
||
public void testFileSnapshotPath() throws IOException { | ||
Path file = createTempFile(); | ||
Files.writeString(file, "hello"); | ||
fileSnapshot = new FileSnapshot.TransferFileSnapshot(file, 12); | ||
|
||
assertFileSnapshotProperties(file); | ||
|
||
try (FileSnapshot sameFileSnapshot = new FileSnapshot.TransferFileSnapshot(file, 12)) { | ||
assertEquals(sameFileSnapshot, fileSnapshot); | ||
} | ||
|
||
try (FileSnapshot sameFileDiffPTSnapshot = new FileSnapshot.TransferFileSnapshot(file, 34)) { | ||
assertNotEquals(sameFileDiffPTSnapshot, fileSnapshot); | ||
} | ||
} | ||
|
||
public void testFileSnapshotContent() throws IOException { | ||
Path file = createTempFile(); | ||
Files.writeString(file, "hello"); | ||
fileSnapshot = new FileSnapshot.TransferFileSnapshot(file.getFileName().toString(), Files.readAllBytes(file), 23); | ||
|
||
assertFileSnapshotProperties(file); | ||
|
||
try ( | ||
FileSnapshot sameFileSnapshot = new FileSnapshot.TransferFileSnapshot( | ||
file.getFileName().toString(), | ||
Files.readAllBytes(file), | ||
23 | ||
) | ||
) { | ||
assertEquals(sameFileSnapshot, fileSnapshot); | ||
} | ||
|
||
try ( | ||
FileSnapshot anotherFileSnapshot = new FileSnapshot.TransferFileSnapshot( | ||
file.getFileName().toString(), | ||
Files.readAllBytes(createTempFile()), | ||
23 | ||
) | ||
) { | ||
assertNotEquals(anotherFileSnapshot, fileSnapshot); | ||
} | ||
} | ||
|
||
private void assertFileSnapshotProperties(Path file) throws IOException { | ||
assertEquals(file.getFileName().toString(), fileSnapshot.getName()); | ||
assertEquals(Files.size(file), fileSnapshot.getContentLength()); | ||
assertTrue(fileSnapshot.inputStream().markSupported()); | ||
} | ||
} |