Move HDFS-repo YAML to Rest tests#140142
Conversation
|
Pinging @elastic/es-data-management (Team:Data Management) |
DaveCTurner
left a comment
There was a problem hiding this comment.
I like it. Left a few comments about ways we can strengthen these tests a bit - not technically necessary to make this change but nice to have if you don't mind doing a bit more work. Also a few other comments.
| try { | ||
| client().performRequest(new Request("GET", "/_snapshot/" + repoName)); | ||
| fail("repository [" + repoName + "] must not exists"); | ||
| } catch (ResponseException e) { | ||
| assertEquals(404, e.getResponse().getStatusLine().getStatusCode()); | ||
| } |
There was a problem hiding this comment.
suggest expectThrows() for this pattern
|
|
||
| MiniDFSCluster.Builder builder = new MiniDFSCluster.Builder(cfg); | ||
| builder.nameNodePort(explicitPort); | ||
| builder.nameNodePort(0); |
| public class RepositoryHdfsRestIT extends AbstractRepositoryHdfsRestIT { | ||
|
|
||
| public static HdfsFixture hdfsFixture = new HdfsFixture(); | ||
| static final HdfsFixture hdfs = new HdfsFixture(); |
There was a problem hiding this comment.
nit: would prefer to keep the old name hdfsFixture here
| @Override | ||
| public void testCreateGetDeleteRepository() throws IOException { | ||
| super.testCreateGetDeleteRepository(); | ||
| } | ||
|
|
||
| @Override | ||
| public void testCreateAndVerifyRepository() throws IOException { | ||
| super.testCreateAndVerifyRepository(); | ||
| } | ||
|
|
||
| @Override | ||
| public void testCreateListDeleteSnapshots() throws IOException { | ||
| super.testCreateListDeleteSnapshots(); | ||
| } | ||
|
|
||
| @Override | ||
| public void testCreateReadOnlyRepo() throws IOException { | ||
| super.testCreateReadOnlyRepo(); | ||
| } | ||
|
|
||
| @Override | ||
| public void testRestore() throws IOException { | ||
| super.testRestore(); | ||
| } |
There was a problem hiding this comment.
Why override these methods if we're just deferring right back to super()?
There was a problem hiding this comment.
Maybe it's me only, but running individual tests in intellij does not work well when I try to execute one from the abstract class. Running from abstract class always goes into intellij runner, not gradle. So I keep them for convenience.
| public void testCreateGetDeleteRepository() throws IOException { | ||
| final var repoName = randomIdentifier(); | ||
| final var path = "test/" + randomIdentifier(); | ||
| for (int i = 0; i < 10; i++) { |
There was a problem hiding this comment.
Twice should be enough right?
There was a problem hiding this comment.
Switched to at least twice
| } | ||
|
|
||
| final var listSnapshots = listAllSnapshots(repoName); | ||
| assertEquals(snapshotNames.size(), ((List<?>) listSnapshots.get("snapshots")).size()); |
There was a problem hiding this comment.
Could we sometimes unregister and re-register the repo at this point to confirm the snapshots persist across that?
| final var path = "/user/elasticsearch/existing/readonly-repository"; | ||
| registerHdfsRepository(hdfsUri0(), repoName, path, false, true); | ||
| final var listSnapshots = listAllSnapshots(repoName); | ||
| assertEquals(1, ((List<?>) listSnapshots.get("snapshots")).size()); |
There was a problem hiding this comment.
Where does this 1 snapshot come from?
There was a problem hiding this comment.
From existing path "/user/elasticsearch/existing/readonly-repository". I tried random path and it didn't work (obviously), then used same path as YAML and it worked, and I was happy with that.
From fixture
There was a problem hiding this comment.
I will extract hardcoded path from fixture into test
There was a problem hiding this comment.
👍 thanks, I was looking for the string existing/readonly-repository but drew a blank
| assertEquals(snapshotNames.size(), ((List<?>) listSnapshots.get("snapshots")).size()); | ||
|
|
||
| for (var snapshotName : snapshotNames) { | ||
| deleteSnapshot(repoName, snapshotName, false); |
There was a problem hiding this comment.
Could we confirm that if we delete a snapshot then it's not returned when you list the repository?
There was a problem hiding this comment.
Done. Now asserting that remaining snapshots does not contain deleted ones in a loop.
| deleteRepository(repoName); | ||
| } | ||
|
|
||
| public void testCreateReadOnlyRepo() throws IOException { |
There was a problem hiding this comment.
Could we confirm in this case that creating or deleting a snapshot fails with an appropriate error?
There was a problem hiding this comment.
Stumbled over error codes. I was expecting 400, but got 500. Fixing in separate PR #140200, once merged will proceed with current one
| final var indexRecovery = getIndexRecovery(indexName); | ||
| final var shard0 = indexName + ".shards.0."; | ||
| assertEquals("SNAPSHOT", indexRecovery.get(shard0 + "type")); | ||
| assertEquals("DONE", indexRecovery.get(shard0 + "stage")); | ||
| assertEquals(Integer.valueOf(1), indexRecovery.get(shard0 + "index.files.recovered")); | ||
| assertTrue((int) indexRecovery.get(shard0 + "index.size.recovered_in_bytes") >= 0); | ||
| assertEquals(Integer.valueOf(0), indexRecovery.get(shard0 + "index.files.reused")); | ||
| assertEquals(Integer.valueOf(0), indexRecovery.get(shard0 + "index.size.reused_in_bytes")); |
There was a problem hiding this comment.
I'd kinda like us to verify that a document indexed before creating the snapshot is visible to searches at this point.
There was a problem hiding this comment.
Hm, which document, my understanding original test created only index without documents.
There was a problem hiding this comment.
Yes I think this was an unnecessary omission, ideally we'd confirm that the snapshotted data was actually restored and not just an empty index. Not essential, just a nice-to-have.
|
Oh yeah one more thing, we have a YAML test that verifies that you can't create a HDFS repository with a |
|
Thanks David, I'll address all of above. |
396f643 to
6fd907c
Compare
|
Hold on, forgot 'file://' url test. |
|
Ready for review |
| final var indexRecovery = getIndexRecovery(indexName); | ||
| final var shard0 = indexName + ".shards.0."; | ||
| assertEquals("SNAPSHOT", indexRecovery.get(shard0 + "type")); | ||
| assertEquals("DONE", indexRecovery.get(shard0 + "stage")); | ||
| assertEquals(Integer.valueOf(1), indexRecovery.get(shard0 + "index.files.recovered")); | ||
| assertTrue((int) indexRecovery.get(shard0 + "index.size.recovered_in_bytes") >= 0); | ||
| assertEquals(Integer.valueOf(0), indexRecovery.get(shard0 + "index.files.reused")); | ||
| assertEquals(Integer.valueOf(0), indexRecovery.get(shard0 + "index.size.reused_in_bytes")); |
There was a problem hiding this comment.
Yes I think this was an unnecessary omission, ideally we'd confirm that the snapshotted data was actually restored and not just an empty index. Not essential, just a nice-to-have.
Move HDFS repository tests from YAML to Rest. I keep original structure of tests, with slight changes around grouping create/get/delete into a single test. Assertions are the same.
There is a substantial time gap between finding free port and binding it in HDFS fixture, that can lead to
java.net.BindException: Address already in use. https://gradle-enterprise.elastic.co/s/inqfl34rgjszo/failures#1. With Rest tests there is no need for early port binding. HDFS binds to ephemeral port that can be queried at repository creation time.