Skip to content

Commit 0e14e19

Browse files
Finish up work from Niels review
1 parent eee1f34 commit 0e14e19

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

test/external-modules/multi-project/src/javaRestTest/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsMultiProjectIT.java

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -74,56 +74,53 @@ public void testIndicesStats() throws IOException {
7474
ObjectPath statsForProject1 = getAsObjectPathInProject("/_stats", "project-1");
7575
assertThat(statsForProject1.evaluate("_all.total.docs.count"), equalTo(numDocs1Only + numDocs1Of1And2 + numDocs1All));
7676
assertThat(
77-
ObjectPath.<Map<String, Object>>evaluate(statsForProject1, "indices").keySet(),
77+
statsForProject1.<Map<String, Object>>evaluate("indices").keySet(),
7878
containsInAnyOrder("my-index-project-1-only", "my-index-projects-1-and-2", "my-index-all-projects")
7979
);
80-
assertThat(ObjectPath.evaluate(statsForProject1, "indices.my-index-project-1-only.total.docs.count"), equalTo(numDocs1Only));
81-
assertThat(ObjectPath.evaluate(statsForProject1, "indices.my-index-projects-1-and-2.total.docs.count"), equalTo(numDocs1Of1And2));
82-
assertThat(ObjectPath.evaluate(statsForProject1, "indices.my-index-all-projects.total.docs.count"), equalTo(numDocs1All));
80+
assertThat(statsForProject1.evaluate("indices.my-index-project-1-only.total.docs.count"), equalTo(numDocs1Only));
81+
assertThat(statsForProject1.evaluate("indices.my-index-projects-1-and-2.total.docs.count"), equalTo(numDocs1Of1And2));
82+
assertThat(statsForProject1.evaluate("indices.my-index-all-projects.total.docs.count"), equalTo(numDocs1All));
8383

8484
// Check indices stats for project 2.
85-
Map<String, Object> statsForProject2 = getAsOrderedMapInProject("/_stats", "project-2");
85+
ObjectPath statsForProject2 = getAsObjectPathInProject("/_stats", "project-2");
8686
assertThat(
87-
ObjectPath.evaluate(statsForProject2, "_all.total.docs.count"),
87+
statsForProject2.evaluate("_all.total.docs.count"),
8888
equalTo(numDocs2Only + numDocs2Of1And2 + numDocs2Of2AndDefault + numDocs2All)
8989
);
9090
assertThat(
91-
ObjectPath.<Map<String, Object>>evaluate(statsForProject2, "indices").keySet(),
91+
statsForProject2.<Map<String, Object>>evaluate("indices").keySet(),
9292
containsInAnyOrder(
9393
"my-index-project-2-only",
9494
"my-index-projects-1-and-2",
9595
"my-index-projects-2-and-default",
9696
"my-index-all-projects"
9797
)
9898
);
99-
assertThat(ObjectPath.evaluate(statsForProject2, "indices.my-index-all-projects.total.docs.count"), equalTo(numDocs2All));
99+
assertThat(statsForProject2.evaluate("indices.my-index-all-projects.total.docs.count"), equalTo(numDocs2All));
100100

101101
// Check indices stats for default project.
102-
Map<String, Object> statsForDefaultProject = getAsOrderedMap("/_stats");
102+
ObjectPath statsForDefaultProject = getAsObjectPathInDefaultProject("/_stats");
103103
assertThat(
104-
ObjectPath.evaluate(statsForDefaultProject, "_all.total.docs.count"),
104+
statsForDefaultProject.evaluate("_all.total.docs.count"),
105105
equalTo(numDocsDefaultOnly + numDocsDefaultOf2AndDefault + numDocsDefaultAll)
106106
);
107107
assertThat(
108-
ObjectPath.<Map<String, Object>>evaluate(statsForDefaultProject, "indices").keySet(),
108+
statsForDefaultProject.<Map<String, Object>>evaluate("indices").keySet(),
109109
containsInAnyOrder("my-index-default-project-only", "my-index-projects-2-and-default", "my-index-all-projects")
110110
);
111-
assertThat(
112-
ObjectPath.evaluate(statsForDefaultProject, "indices.my-index-all-projects.total.docs.count"),
113-
equalTo(numDocsDefaultAll)
114-
);
111+
assertThat(statsForDefaultProject.evaluate("indices.my-index-all-projects.total.docs.count"), equalTo(numDocsDefaultAll));
115112

116113
// Check single-index stats for each project.
117114
assertThat(
118-
ObjectPath.evaluate(getAsOrderedMapInProject("/my-index-all-projects/_stats", "project-1"), "_all.total.docs.count"),
115+
getAsObjectPathInProject("/my-index-all-projects/_stats", "project-1").evaluate("_all.total.docs.count"),
119116
equalTo(numDocs1All)
120117
);
121118
assertThat(
122-
ObjectPath.evaluate(getAsOrderedMapInProject("/my-index-all-projects/_stats", "project-2"), "_all.total.docs.count"),
119+
getAsObjectPathInProject("/my-index-all-projects/_stats", "project-2").evaluate("_all.total.docs.count"),
123120
equalTo(numDocs2All)
124121
);
125122
assertThat(
126-
ObjectPath.evaluate(getAsOrderedMap("/my-index-all-projects/_stats"), "_all.total.docs.count"),
123+
getAsObjectPathInDefaultProject("/my-index-all-projects/_stats").evaluate("_all.total.docs.count"),
127124
equalTo(numDocsDefaultAll)
128125
);
129126

@@ -135,10 +132,10 @@ public void testIndicesStats() throws IOException {
135132
assertThat(exception.getResponse().getStatusLine().getStatusCode(), equalTo(404));
136133

137134
// Check using a wildcard gets the matching indices for that project.
138-
Map<String, Object> statsWithWildcardForProject1 = getAsOrderedMapInProject("/my-index-project*/_stats", "project-1");
139-
assertThat(ObjectPath.evaluate(statsWithWildcardForProject1, "_all.total.docs.count"), equalTo(numDocs1Only + numDocs1Of1And2));
135+
ObjectPath statsWithWildcardForProject1 = getAsObjectPathInProject("/my-index-project*/_stats", "project-1");
136+
assertThat(statsWithWildcardForProject1.evaluate("_all.total.docs.count"), equalTo(numDocs1Only + numDocs1Of1And2));
140137
assertThat(
141-
ObjectPath.<Map<String, Object>>evaluate(statsWithWildcardForProject1, "indices").keySet(),
138+
statsWithWildcardForProject1.<Map<String, Object>>evaluate("indices").keySet(),
142139
containsInAnyOrder("my-index-project-1-only", "my-index-projects-1-and-2")
143140
);
144141
}
@@ -159,7 +156,11 @@ private int createPopulatedIndex(String projectId, String indexName) throws IOEx
159156
return numDocs;
160157
}
161158

162-
private static Map<String, Object> getAsOrderedMapInProject(String endpoint, String projectId) throws IOException {
163-
return responseAsOrderedMap(client().performRequest(setRequestProjectId(new Request("GET", endpoint), projectId)));
159+
private static ObjectPath getAsObjectPathInProject(String endpoint, String projectId) throws IOException {
160+
return new ObjectPath(responseAsOrderedMap(client().performRequest(setRequestProjectId(new Request("GET", endpoint), projectId))));
161+
}
162+
163+
private static ObjectPath getAsObjectPathInDefaultProject(String endpoint) throws IOException {
164+
return new ObjectPath(getAsMap(endpoint));
164165
}
165166
}

0 commit comments

Comments
 (0)