1
+ /*
2
+ * Licensed to Elastic Search and Shay Banon under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. Elastic Search licenses this
6
+ * file to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+
20
+ package org .elasticsearch .test .integration .search .basic ;
21
+
22
+ import org .elasticsearch .action .search .SearchResponse ;
23
+ import org .elasticsearch .index .query .xcontent .QueryBuilders ;
24
+ import org .elasticsearch .node .Node ;
25
+ import org .elasticsearch .test .integration .AbstractNodesTests ;
26
+ import org .testng .annotations .AfterMethod ;
27
+ import org .testng .annotations .Test ;
28
+
29
+ import static org .elasticsearch .common .settings .ImmutableSettings .*;
30
+ import static org .hamcrest .MatcherAssert .*;
31
+ import static org .hamcrest .Matchers .*;
32
+
33
+ public class SearchWhileCreatingIndexTests extends AbstractNodesTests {
34
+
35
+ @ AfterMethod public void closeAll () {
36
+ closeAllNodes ();
37
+ }
38
+
39
+ /**
40
+ * This test basically verifies that search with a single shard active (cause we indexed to it) and other
41
+ * shards possibly not active at all (cause they haven't allocated) will still work.
42
+ */
43
+ @ Test public void searchWhileCreatingIndex () {
44
+ Node node = startNode ("node1" );
45
+
46
+ try {
47
+ node .client ().admin ().indices ().prepareDelete ("test" ).execute ().actionGet ();
48
+ } catch (Exception e ) {
49
+ // ignore
50
+ }
51
+
52
+ for (int i = 0 ; i < 20 ; i ++) {
53
+ node .client ().admin ().indices ().prepareCreate ("test" ).setSettings (settingsBuilder ().put ("number_of_shards" , 10 )).execute ().actionGet ();
54
+
55
+ node .client ().prepareIndex ("test" , "type1" ).setSource ("field" , "test" ).execute ().actionGet ();
56
+ node .client ().admin ().indices ().prepareRefresh ().execute ().actionGet ();
57
+
58
+ SearchResponse searchResponse = node .client ().prepareSearch ("test" ).setQuery (QueryBuilders .termQuery ("field" , "test" )).execute ().actionGet ();
59
+ assertThat (searchResponse .hits ().totalHits (), equalTo (1l ));
60
+
61
+ node .client ().admin ().indices ().prepareDelete ("test" ).execute ().actionGet ();
62
+ }
63
+
64
+ try {
65
+ node .client ().admin ().indices ().prepareDelete ("test" ).execute ().actionGet ();
66
+ } catch (Exception e ) {
67
+ // ignore
68
+ }
69
+ }
70
+ }
0 commit comments