Skip to content

Commit f7d62f1

Browse files
committed
Add testing
1 parent 1b3917c commit f7d62f1

File tree

4 files changed

+267
-0
lines changed

4 files changed

+267
-0
lines changed

server/src/internalClusterTest/java/org/elasticsearch/indices/stats/IndexStatsIT.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,10 +567,12 @@ public void testSimpleStats() throws Exception {
567567
// make sure that number of requests in progress is 0
568568
assertThat(stats.getIndex("test1").getTotal().getIndexing().getTotal().getIndexCurrent(), equalTo(0L));
569569
assertThat(stats.getIndex("test1").getTotal().getIndexing().getTotal().getDeleteCurrent(), equalTo(0L));
570+
assertThat(stats.getIndex("test1").getTotal().getSearch().getTotal().getDfsCurrent(), equalTo(0L));
570571
assertThat(stats.getIndex("test1").getTotal().getSearch().getTotal().getFetchCurrent(), equalTo(0L));
571572
assertThat(stats.getIndex("test1").getTotal().getSearch().getTotal().getQueryCurrent(), equalTo(0L));
572573
assertThat(stats.getIndex("test2").getTotal().getIndexing().getTotal().getIndexCurrent(), equalTo(0L));
573574
assertThat(stats.getIndex("test2").getTotal().getIndexing().getTotal().getDeleteCurrent(), equalTo(0L));
575+
assertThat(stats.getIndex("test2").getTotal().getSearch().getTotal().getDfsCurrent(), equalTo(0L));
574576
assertThat(stats.getIndex("test2").getTotal().getSearch().getTotal().getFetchCurrent(), equalTo(0L));
575577
assertThat(stats.getIndex("test2").getTotal().getSearch().getTotal().getQueryCurrent(), equalTo(0L));
576578

server/src/test/java/org/elasticsearch/index/shard/SearchOperationListenerTests.java

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public class SearchOperationListenerTests extends ESTestCase {
3131

3232
// this test also tests if calls are correct if one or more listeners throw exceptions
3333
public void testListenersAreExecuted() {
34+
AtomicInteger onDfs = new AtomicInteger();
35+
AtomicInteger preDfs = new AtomicInteger();
36+
AtomicInteger failedDfs = new AtomicInteger();
3437
AtomicInteger preQuery = new AtomicInteger();
3538
AtomicInteger failedQuery = new AtomicInteger();
3639
AtomicInteger onQuery = new AtomicInteger();
@@ -44,6 +47,25 @@ public void testListenersAreExecuted() {
4447
AtomicInteger validateSearchContext = new AtomicInteger();
4548
AtomicInteger timeInNanos = new AtomicInteger(randomIntBetween(0, 10));
4649
SearchOperationListener listener = new SearchOperationListener() {
50+
@Override
51+
public void onPreDfsPhase(SearchContext searchContext) {
52+
assertNotNull(searchContext);
53+
preDfs.incrementAndGet();
54+
}
55+
56+
@Override
57+
public void onFailedDfsPhase(SearchContext searchContext) {
58+
assertNotNull(searchContext);
59+
failedDfs.incrementAndGet();
60+
}
61+
62+
@Override
63+
public void onDfsPhase(SearchContext searchContext, long tookInNanos) {
64+
assertEquals(timeInNanos.get(), tookInNanos);
65+
assertNotNull(searchContext);
66+
onDfs.incrementAndGet();
67+
}
68+
4769
@Override
4870
public void onPreQueryPhase(SearchContext searchContext) {
4971
assertNotNull(searchContext);
@@ -139,11 +161,31 @@ public void validateReaderContext(ReaderContext readerContext, TransportRequest
139161
logger
140162
);
141163
try (SearchContext ctx = new TestSearchContext((SearchExecutionContext) null)) {
164+
compositeListener.onDfsPhase(ctx, timeInNanos.get());
165+
assertEquals(0, preDfs.get());
166+
assertEquals(0, preFetch.get());
167+
assertEquals(0, preQuery.get());
168+
assertEquals(0, failedDfs.get());
169+
assertEquals(0, failedFetch.get());
170+
assertEquals(0, failedQuery.get());
171+
assertEquals(2, onDfs.get());
172+
assertEquals(0, onQuery.get());
173+
assertEquals(0, onFetch.get());
174+
assertEquals(0, newContext.get());
175+
assertEquals(0, newScrollContext.get());
176+
assertEquals(0, freeContext.get());
177+
assertEquals(0, freeScrollContext.get());
178+
assertEquals(0, validateSearchContext.get());
179+
180+
142181
compositeListener.onQueryPhase(ctx, timeInNanos.get());
182+
assertEquals(0, preDfs.get());
143183
assertEquals(0, preFetch.get());
144184
assertEquals(0, preQuery.get());
185+
assertEquals(0, failedDfs.get());
145186
assertEquals(0, failedFetch.get());
146187
assertEquals(0, failedQuery.get());
188+
assertEquals(2, onDfs.get());
147189
assertEquals(2, onQuery.get());
148190
assertEquals(0, onFetch.get());
149191
assertEquals(0, newContext.get());
@@ -153,10 +195,29 @@ public void validateReaderContext(ReaderContext readerContext, TransportRequest
153195
assertEquals(0, validateSearchContext.get());
154196

155197
compositeListener.onFetchPhase(ctx, timeInNanos.get());
198+
assertEquals(0, preDfs.get());
156199
assertEquals(0, preFetch.get());
157200
assertEquals(0, preQuery.get());
201+
assertEquals(0, failedDfs.get());
158202
assertEquals(0, failedFetch.get());
159203
assertEquals(0, failedQuery.get());
204+
assertEquals(2, onDfs.get());
205+
assertEquals(2, onQuery.get());
206+
assertEquals(2, onFetch.get());
207+
assertEquals(0, newContext.get());
208+
assertEquals(0, newScrollContext.get());
209+
assertEquals(0, freeContext.get());
210+
assertEquals(0, freeScrollContext.get());
211+
assertEquals(0, validateSearchContext.get());
212+
213+
compositeListener.onPreDfsPhase(ctx);
214+
assertEquals(2, preDfs.get());
215+
assertEquals(0, preFetch.get());
216+
assertEquals(0, preQuery.get());
217+
assertEquals(0, failedDfs.get());
218+
assertEquals(0, failedFetch.get());
219+
assertEquals(0, failedQuery.get());
220+
assertEquals(2, onDfs.get());
160221
assertEquals(2, onQuery.get());
161222
assertEquals(2, onFetch.get());
162223
assertEquals(0, newContext.get());
@@ -166,10 +227,13 @@ public void validateReaderContext(ReaderContext readerContext, TransportRequest
166227
assertEquals(0, validateSearchContext.get());
167228

168229
compositeListener.onPreQueryPhase(ctx);
230+
assertEquals(2, preDfs.get());
169231
assertEquals(0, preFetch.get());
170232
assertEquals(2, preQuery.get());
233+
assertEquals(0, failedDfs.get());
171234
assertEquals(0, failedFetch.get());
172235
assertEquals(0, failedQuery.get());
236+
assertEquals(2, onDfs.get());
173237
assertEquals(2, onQuery.get());
174238
assertEquals(2, onFetch.get());
175239
assertEquals(0, newContext.get());
@@ -179,10 +243,29 @@ public void validateReaderContext(ReaderContext readerContext, TransportRequest
179243
assertEquals(0, validateSearchContext.get());
180244

181245
compositeListener.onPreFetchPhase(ctx);
246+
assertEquals(2, preDfs.get());
247+
assertEquals(2, preFetch.get());
248+
assertEquals(2, preQuery.get());
249+
assertEquals(0, failedDfs.get());
250+
assertEquals(0, failedFetch.get());
251+
assertEquals(0, failedQuery.get());
252+
assertEquals(2, onDfs.get());
253+
assertEquals(2, onQuery.get());
254+
assertEquals(2, onFetch.get());
255+
assertEquals(0, newContext.get());
256+
assertEquals(0, newScrollContext.get());
257+
assertEquals(0, freeContext.get());
258+
assertEquals(0, freeScrollContext.get());
259+
assertEquals(0, validateSearchContext.get());
260+
261+
compositeListener.onFailedDfsPhase(ctx);
262+
assertEquals(2, preDfs.get());
182263
assertEquals(2, preFetch.get());
183264
assertEquals(2, preQuery.get());
265+
assertEquals(2, failedDfs.get());
184266
assertEquals(0, failedFetch.get());
185267
assertEquals(0, failedQuery.get());
268+
assertEquals(2, onDfs.get());
186269
assertEquals(2, onQuery.get());
187270
assertEquals(2, onFetch.get());
188271
assertEquals(0, newContext.get());
@@ -192,10 +275,13 @@ public void validateReaderContext(ReaderContext readerContext, TransportRequest
192275
assertEquals(0, validateSearchContext.get());
193276

194277
compositeListener.onFailedFetchPhase(ctx);
278+
assertEquals(2, preDfs.get());
195279
assertEquals(2, preFetch.get());
196280
assertEquals(2, preQuery.get());
281+
assertEquals(2, failedDfs.get());
197282
assertEquals(2, failedFetch.get());
198283
assertEquals(0, failedQuery.get());
284+
assertEquals(2, onDfs.get());
199285
assertEquals(2, onQuery.get());
200286
assertEquals(2, onFetch.get());
201287
assertEquals(0, newContext.get());
@@ -205,10 +291,13 @@ public void validateReaderContext(ReaderContext readerContext, TransportRequest
205291
assertEquals(0, validateSearchContext.get());
206292

207293
compositeListener.onFailedQueryPhase(ctx);
294+
assertEquals(2, preDfs.get());
208295
assertEquals(2, preFetch.get());
209296
assertEquals(2, preQuery.get());
297+
assertEquals(2, failedDfs.get());
210298
assertEquals(2, failedFetch.get());
211299
assertEquals(2, failedQuery.get());
300+
assertEquals(2, onDfs.get());
212301
assertEquals(2, onQuery.get());
213302
assertEquals(2, onFetch.get());
214303
assertEquals(0, newContext.get());
@@ -218,10 +307,13 @@ public void validateReaderContext(ReaderContext readerContext, TransportRequest
218307
assertEquals(0, validateSearchContext.get());
219308

220309
compositeListener.onNewReaderContext(mock(ReaderContext.class));
310+
assertEquals(2, preDfs.get());
221311
assertEquals(2, preFetch.get());
222312
assertEquals(2, preQuery.get());
313+
assertEquals(2, failedDfs.get());
223314
assertEquals(2, failedFetch.get());
224315
assertEquals(2, failedQuery.get());
316+
assertEquals(2, onDfs.get());
225317
assertEquals(2, onQuery.get());
226318
assertEquals(2, onFetch.get());
227319
assertEquals(2, newContext.get());
@@ -231,10 +323,13 @@ public void validateReaderContext(ReaderContext readerContext, TransportRequest
231323
assertEquals(0, validateSearchContext.get());
232324

233325
compositeListener.onNewScrollContext(mock(ReaderContext.class));
326+
assertEquals(2, preDfs.get());
234327
assertEquals(2, preFetch.get());
235328
assertEquals(2, preQuery.get());
329+
assertEquals(2, failedDfs.get());
236330
assertEquals(2, failedFetch.get());
237331
assertEquals(2, failedQuery.get());
332+
assertEquals(2, onDfs.get());
238333
assertEquals(2, onQuery.get());
239334
assertEquals(2, onFetch.get());
240335
assertEquals(2, newContext.get());
@@ -244,10 +339,13 @@ public void validateReaderContext(ReaderContext readerContext, TransportRequest
244339
assertEquals(0, validateSearchContext.get());
245340

246341
compositeListener.onFreeReaderContext(mock(ReaderContext.class));
342+
assertEquals(2, preDfs.get());
247343
assertEquals(2, preFetch.get());
248344
assertEquals(2, preQuery.get());
345+
assertEquals(2, failedDfs.get());
249346
assertEquals(2, failedFetch.get());
250347
assertEquals(2, failedQuery.get());
348+
assertEquals(2, onDfs.get());
251349
assertEquals(2, onQuery.get());
252350
assertEquals(2, onFetch.get());
253351
assertEquals(2, newContext.get());
@@ -257,10 +355,13 @@ public void validateReaderContext(ReaderContext readerContext, TransportRequest
257355
assertEquals(0, validateSearchContext.get());
258356

259357
compositeListener.onFreeScrollContext(mock(ReaderContext.class));
358+
assertEquals(2, preDfs.get());
260359
assertEquals(2, preFetch.get());
261360
assertEquals(2, preQuery.get());
361+
assertEquals(2, failedDfs.get());
262362
assertEquals(2, failedFetch.get());
263363
assertEquals(2, failedQuery.get());
364+
assertEquals(2, onDfs.get());
264365
assertEquals(2, onQuery.get());
265366
assertEquals(2, onFetch.get());
266367
assertEquals(2, newContext.get());
@@ -282,10 +383,13 @@ public void validateReaderContext(ReaderContext readerContext, TransportRequest
282383
assertThat(expected.getSuppressed()[0], not(sameInstance(expected)));
283384
}
284385
}
386+
assertEquals(2, preDfs.get());
285387
assertEquals(2, preFetch.get());
286388
assertEquals(2, preQuery.get());
389+
assertEquals(2, failedDfs.get());
287390
assertEquals(2, failedFetch.get());
288391
assertEquals(2, failedQuery.get());
392+
assertEquals(2, onDfs.get());
289393
assertEquals(2, onQuery.get());
290394
assertEquals(2, onFetch.get());
291395
assertEquals(2, newContext.get());

server/src/test/java/org/elasticsearch/search/SearchServiceSingleNodeTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ public void testSearchWhileIndexDeleted() throws InterruptedException {
443443
assertEquals(0, service.getActiveContexts());
444444

445445
SearchStats.Stats totalStats = indexShard.searchStats().getTotal();
446+
assertEquals(0, totalStats.getDfsCurrent());
446447
assertEquals(0, totalStats.getQueryCurrent());
447448
assertEquals(0, totalStats.getScrollCurrent());
448449
assertEquals(0, totalStats.getFetchCurrent());
@@ -1223,6 +1224,7 @@ public void testSearchWhileIndexDeletedDoesNotLeakSearchContext() throws Executi
12231224
assertEquals(0, service.getActiveContexts());
12241225

12251226
SearchStats.Stats totalStats = indexShard.searchStats().getTotal();
1227+
assertEquals(0, totalStats.getDfsCurrent());
12261228
assertEquals(0, totalStats.getQueryCurrent());
12271229
assertEquals(0, totalStats.getScrollCurrent());
12281230
assertEquals(0, totalStats.getFetchCurrent());

0 commit comments

Comments
 (0)