6
6
package org .elasticsearch .multi_node ;
7
7
8
8
import org .apache .http .HttpStatus ;
9
+ import org .apache .http .entity .ContentType ;
10
+ import org .apache .http .entity .StringEntity ;
9
11
import org .apache .http .util .EntityUtils ;
10
12
import org .elasticsearch .client .Request ;
11
13
import org .elasticsearch .client .Response ;
14
+ import org .elasticsearch .common .Strings ;
12
15
import org .elasticsearch .common .settings .SecureString ;
13
16
import org .elasticsearch .common .settings .Settings ;
14
17
import org .elasticsearch .common .util .concurrent .ThreadContext ;
18
+ import org .elasticsearch .common .xcontent .XContentBuilder ;
15
19
import org .elasticsearch .common .xcontent .XContentHelper ;
16
20
import org .elasticsearch .common .xcontent .json .JsonXContent ;
17
21
import org .elasticsearch .common .xcontent .support .XContentMapValues ;
33
37
import java .util .List ;
34
38
import java .util .Map ;
35
39
import java .util .concurrent .TimeUnit ;
36
- import java .util .stream .Collectors ;
37
40
41
+ import static org .elasticsearch .common .xcontent .XContentFactory .jsonBuilder ;
38
42
import static org .elasticsearch .xpack .core .security .authc .support .UsernamePasswordToken .basicAuthHeaderValue ;
39
43
import static org .hamcrest .Matchers .equalTo ;
40
44
import static org .hamcrest .Matchers .isOneOf ;
@@ -73,6 +77,31 @@ public void clearRollupMetadata() throws Exception {
73
77
74
78
public void testBigRollup () throws Exception {
75
79
final int numDocs = 200 ;
80
+ String dateFormat = "strict_date_optional_time" ;
81
+
82
+ // create the test-index index
83
+ try (XContentBuilder builder = jsonBuilder ()) {
84
+ builder .startObject ();
85
+ {
86
+ builder .startObject ("mappings" ).startObject ("_doc" )
87
+ .startObject ("properties" )
88
+ .startObject ("timestamp" )
89
+ .field ("type" , "date" )
90
+ .field ("format" , dateFormat )
91
+ .endObject ()
92
+ .startObject ("value" )
93
+ .field ("type" , "integer" )
94
+ .endObject ()
95
+ .endObject ()
96
+ .endObject ().endObject ();
97
+ }
98
+ builder .endObject ();
99
+ final StringEntity entity = new StringEntity (Strings .toString (builder ), ContentType .APPLICATION_JSON );
100
+ Request req = new Request ("PUT" , "rollup-docs" );
101
+ req .setEntity (entity );
102
+ client ().performRequest (req );
103
+ }
104
+
76
105
77
106
// index documents for the rollup job
78
107
final StringBuilder bulk = new StringBuilder ();
@@ -88,13 +117,15 @@ public void testBigRollup() throws Exception {
88
117
bulkRequest .addParameter ("refresh" , "true" );
89
118
bulkRequest .setJsonEntity (bulk .toString ());
90
119
client ().performRequest (bulkRequest );
120
+
91
121
// create the rollup job
92
122
final Request createRollupJobRequest = new Request ("PUT" , "/_xpack/rollup/job/rollup-job-test" );
123
+ int pageSize = randomIntBetween (2 , 50 );
93
124
createRollupJobRequest .setJsonEntity ("{"
94
125
+ "\" index_pattern\" :\" rollup-*\" ,"
95
126
+ "\" rollup_index\" :\" results-rollup\" ,"
96
- + "\" cron\" :\" */1 * * * * ?\" ," // fast cron and big page size so test runs quickly
97
- + "\" page_size\" :20 ,"
127
+ + "\" cron\" :\" */1 * * * * ?\" ," // fast cron so test runs quickly
128
+ + "\" page_size\" :" + pageSize + " ,"
98
129
+ "\" groups\" :{"
99
130
+ " \" date_histogram\" :{"
100
131
+ " \" field\" :\" timestamp\" ,"
@@ -142,7 +173,8 @@ public void testBigRollup() throws Exception {
142
173
" \" date_histo\" : {\n " +
143
174
" \" date_histogram\" : {\n " +
144
175
" \" field\" : \" timestamp\" ,\n " +
145
- " \" interval\" : \" 1h\" \n " +
176
+ " \" interval\" : \" 1h\" ,\n " +
177
+ " \" format\" : \" date_time\" \n " +
146
178
" },\n " +
147
179
" \" aggs\" : {\n " +
148
180
" \" the_max\" : {\n " +
@@ -226,7 +258,7 @@ private void assertRollUpJob(final String rollupJob) throws Exception {
226
258
227
259
}
228
260
229
- private void waitForRollUpJob (final String rollupJob ,String [] expectedStates ) throws Exception {
261
+ private void waitForRollUpJob (final String rollupJob , String [] expectedStates ) throws Exception {
230
262
assertBusy (() -> {
231
263
final Request getRollupJobRequest = new Request ("GET" , "_xpack/rollup/job/" + rollupJob );
232
264
Response getRollupJobResponse = client ().performRequest (getRollupJobRequest );
@@ -317,10 +349,4 @@ private void deleteAllJobs() throws Exception {
317
349
}
318
350
}
319
351
}
320
-
321
- private static String responseEntityToString (Response response ) throws Exception {
322
- try (BufferedReader reader = new BufferedReader (new InputStreamReader (response .getEntity ().getContent (), StandardCharsets .UTF_8 ))) {
323
- return reader .lines ().collect (Collectors .joining ("\n " ));
324
- }
325
- }
326
352
}
0 commit comments