20
20
import org .elasticsearch .common .xcontent .NamedXContentRegistry ;
21
21
import org .elasticsearch .common .xcontent .XContentParser ;
22
22
import org .elasticsearch .common .xcontent .json .JsonXContent ;
23
- import org .elasticsearch .core .Tuple ;
24
23
import org .elasticsearch .search .sort .SortOrder ;
25
24
import org .elasticsearch .snapshots .AbstractSnapshotIntegTestCase ;
26
25
import org .elasticsearch .snapshots .SnapshotInfo ;
@@ -106,31 +105,34 @@ private void doTestPagination(String repoName,
106
105
GetSnapshotsRequest .SortBy sort ,
107
106
SortOrder order ) throws IOException {
108
107
final List <SnapshotInfo > allSnapshotsSorted = allSnapshotsSorted (names , repoName , sort , order );
109
- final Tuple <String , List <SnapshotInfo >> batch1 = sortedWithLimit (repoName , sort , null , 2 , order );
110
- assertEquals (allSnapshotsSorted .subList (0 , 2 ), batch1 .v2 ());
111
- final Tuple <String , List <SnapshotInfo >> batch2 = sortedWithLimit (repoName , sort , batch1 .v1 (), 2 , order );
112
- assertEquals (allSnapshotsSorted .subList (2 , 4 ), batch2 .v2 ());
113
- final int lastBatch = names .size () - batch1 .v2 ().size () - batch2 .v2 ().size ();
114
- final Tuple <String , List <SnapshotInfo >> batch3 = sortedWithLimit (repoName , sort , batch2 .v1 (), lastBatch , order );
115
- assertEquals (batch3 .v2 (), allSnapshotsSorted .subList (batch1 .v2 ().size () + batch2 .v2 ().size (), names .size ()));
116
- final Tuple <String , List <SnapshotInfo >> batch3NoLimit = sortedWithLimit (
108
+ final GetSnapshotsResponse batch1 = sortedWithLimit (repoName , sort , null , 2 , order );
109
+ assertEquals (allSnapshotsSorted .subList (0 , 2 ), batch1 .getSnapshots ());
110
+ final GetSnapshotsResponse batch2 = sortedWithLimit (repoName , sort , batch1 .next (), 2 , order );
111
+ assertEquals (allSnapshotsSorted .subList (2 , 4 ), batch2 .getSnapshots ());
112
+ final int lastBatch = names .size () - batch1 .getSnapshots ().size () - batch2 .getSnapshots ().size ();
113
+ final GetSnapshotsResponse batch3 = sortedWithLimit (repoName , sort , batch2 .next (), lastBatch , order );
114
+ assertEquals (
115
+ batch3 .getSnapshots (),
116
+ allSnapshotsSorted .subList (batch1 .getSnapshots ().size () + batch2 .getSnapshots ().size (), names .size ())
117
+ );
118
+ final GetSnapshotsResponse batch3NoLimit = sortedWithLimit (
117
119
repoName ,
118
120
sort ,
119
- batch2 .v1 (),
121
+ batch2 .next (),
120
122
GetSnapshotsRequest .NO_LIMIT ,
121
123
order
122
124
);
123
- assertNull (batch3NoLimit .v1 ());
124
- assertEquals (batch3 .v2 (), batch3NoLimit .v2 ());
125
- final Tuple < String , List < SnapshotInfo >> batch3LargeLimit = sortedWithLimit (
125
+ assertNull (batch3NoLimit .next ());
126
+ assertEquals (batch3 .getSnapshots (), batch3NoLimit .getSnapshots ());
127
+ final GetSnapshotsResponse batch3LargeLimit = sortedWithLimit (
126
128
repoName ,
127
129
sort ,
128
- batch2 .v1 (),
130
+ batch2 .next (),
129
131
lastBatch + randomIntBetween (1 , 100 ),
130
132
order
131
133
);
132
- assertEquals (batch3 .v2 (), batch3LargeLimit .v2 ());
133
- assertNull (batch3LargeLimit .v1 ());
134
+ assertEquals (batch3 .getSnapshots (), batch3LargeLimit .getSnapshots ());
135
+ assertNull (batch3LargeLimit .next ());
134
136
}
135
137
136
138
public void testSortAndPaginateWithInProgress () throws Exception {
@@ -180,16 +182,23 @@ private static void assertStablePagination(String repoName,
180
182
final List <SnapshotInfo > allSorted = allSnapshotsSorted (allSnapshotNames , repoName , sort , order );
181
183
182
184
for (int i = 1 ; i <= allSnapshotNames .size (); i ++) {
183
- final List <SnapshotInfo > subsetSorted = sortedWithLimit (repoName , sort , null , i , order ).v2 ();
185
+ final List <SnapshotInfo > subsetSorted = sortedWithLimit (repoName , sort , null , i , order ).getSnapshots ();
184
186
assertEquals (subsetSorted , allSorted .subList (0 , i ));
185
187
}
186
188
187
189
for (int j = 0 ; j < allSnapshotNames .size (); j ++) {
188
190
final SnapshotInfo after = allSorted .get (j );
189
191
for (int i = 1 ; i < allSnapshotNames .size () - j ; i ++) {
190
- final List <SnapshotInfo > subsetSorted = sortedWithLimit (
191
- repoName , sort , GetSnapshotsRequest .After .from (after , sort ).asQueryParam (), i , order ).v2 ();
192
+ final GetSnapshotsResponse getSnapshotsResponse =
193
+ sortedWithLimit (repoName , sort , GetSnapshotsRequest .After .from (after , sort ).asQueryParam (), i , order );
194
+ final GetSnapshotsResponse getSnapshotsResponseNumeric = sortedWithLimit (repoName , sort , j + 1 , i , order );
195
+ final List <SnapshotInfo > subsetSorted = getSnapshotsResponse .getSnapshots ();
196
+ assertEquals (subsetSorted , getSnapshotsResponseNumeric .getSnapshots ());
192
197
assertEquals (subsetSorted , allSorted .subList (j + 1 , j + i + 1 ));
198
+ assertEquals (allSnapshotNames .size (), getSnapshotsResponse .totalCount ());
199
+ assertEquals (allSnapshotNames .size () - (j + i + 1 ), getSnapshotsResponse .remaining ());
200
+ assertEquals (getSnapshotsResponseNumeric .totalCount (), getSnapshotsResponse .totalCount ());
201
+ assertEquals (getSnapshotsResponseNumeric .remaining (), getSnapshotsResponse .remaining ());
193
202
}
194
203
}
195
204
}
@@ -203,9 +212,11 @@ private static List<SnapshotInfo> allSnapshotsSorted(Collection<String> allSnaps
203
212
if (order == SortOrder .DESC || randomBoolean ()) {
204
213
request .addParameter ("order" , order .toString ());
205
214
}
206
- final Response response = getRestClient ().performRequest (request );
207
- final List <SnapshotInfo > snapshotInfos = readSnapshotInfos ( response ). v2 ();
215
+ final GetSnapshotsResponse getSnapshotsResponse = readSnapshotInfos ( getRestClient ().performRequest (request ) );
216
+ final List <SnapshotInfo > snapshotInfos = getSnapshotsResponse . getSnapshots ();
208
217
assertEquals (snapshotInfos .size (), allSnapshotNames .size ());
218
+ assertEquals (getSnapshotsResponse .totalCount (), allSnapshotNames .size ());
219
+ assertEquals (0 , getSnapshotsResponse .remaining ());
209
220
for (SnapshotInfo snapshotInfo : snapshotInfos ) {
210
221
assertThat (snapshotInfo .snapshotId ().getName (), is (in (allSnapshotNames )));
211
222
}
@@ -216,20 +227,19 @@ private static Request baseGetSnapshotsRequest(String repoName) {
216
227
return new Request (HttpGet .METHOD_NAME , "/_snapshot/" + repoName + "/*" );
217
228
}
218
229
219
- private static Tuple < String , List < SnapshotInfo >> readSnapshotInfos (Response response ) throws IOException {
230
+ private static GetSnapshotsResponse readSnapshotInfos (Response response ) throws IOException {
220
231
try (InputStream input = response .getEntity ().getContent ();
221
232
XContentParser parser = JsonXContent .jsonXContent .createParser (
222
233
NamedXContentRegistry .EMPTY , DeprecationHandler .THROW_UNSUPPORTED_OPERATION , input )) {
223
- final GetSnapshotsResponse getSnapshotsResponse = GetSnapshotsResponse .fromXContent (parser );
224
- return Tuple .tuple (getSnapshotsResponse .next (), getSnapshotsResponse .getSnapshots ());
234
+ return GetSnapshotsResponse .fromXContent (parser );
225
235
}
226
236
}
227
237
228
- private static Tuple < String , List < SnapshotInfo >> sortedWithLimit (String repoName ,
229
- GetSnapshotsRequest .SortBy sortBy ,
230
- String after ,
231
- int size ,
232
- SortOrder order ) throws IOException {
238
+ private static GetSnapshotsResponse sortedWithLimit (String repoName ,
239
+ GetSnapshotsRequest .SortBy sortBy ,
240
+ String after ,
241
+ int size ,
242
+ SortOrder order ) throws IOException {
233
243
final Request request = baseGetSnapshotsRequest (repoName );
234
244
request .addParameter ("sort" , sortBy .toString ());
235
245
if (size != GetSnapshotsRequest .NO_LIMIT || randomBoolean ()) {
@@ -244,4 +254,22 @@ private static Tuple<String, List<SnapshotInfo>> sortedWithLimit(String repoName
244
254
final Response response = getRestClient ().performRequest (request );
245
255
return readSnapshotInfos (response );
246
256
}
257
+
258
+ private static GetSnapshotsResponse sortedWithLimit (String repoName ,
259
+ GetSnapshotsRequest .SortBy sortBy ,
260
+ int offset ,
261
+ int size ,
262
+ SortOrder order ) throws IOException {
263
+ final Request request = baseGetSnapshotsRequest (repoName );
264
+ request .addParameter ("sort" , sortBy .toString ());
265
+ if (size != GetSnapshotsRequest .NO_LIMIT || randomBoolean ()) {
266
+ request .addParameter ("size" , String .valueOf (size ));
267
+ }
268
+ request .addParameter ("offset" , String .valueOf (offset ));
269
+ if (order == SortOrder .DESC || randomBoolean ()) {
270
+ request .addParameter ("order" , order .toString ());
271
+ }
272
+ final Response response = getRestClient ().performRequest (request );
273
+ return readSnapshotInfos (response );
274
+ }
247
275
}
0 commit comments