2323import org .elasticsearch .Version ;
2424import org .elasticsearch .action .admin .indices .mapping .put .PutMappingRequest ;
2525import org .elasticsearch .cluster .ClusterService ;
26+ import org .elasticsearch .cluster .ClusterState ;
2627import org .elasticsearch .cluster .metadata .IndexMetaData ;
2728import org .elasticsearch .cluster .metadata .MetaData ;
2829import org .elasticsearch .common .ParseFieldMatcher ;
6263import org .elasticsearch .test .ESTestCase ;
6364import org .elasticsearch .test .TestSearchContext ;
6465import org .elasticsearch .test .VersionUtils ;
66+ import org .elasticsearch .test .cluster .TestClusterService ;
6567import org .elasticsearch .threadpool .ThreadPool ;
6668import org .elasticsearch .threadpool .ThreadPoolModule ;
6769import org .joda .time .DateTime ;
@@ -95,6 +97,10 @@ public abstract class BaseQueryTestCase<QB extends AbstractQueryBuilder<QB>> ext
9597 private static IndexQueryParserService queryParserService ;
9698 private static Index index ;
9799
100+ protected static Index getIndex () {
101+ return index ;
102+ }
103+
98104 private static String [] currentTypes ;
99105
100106 protected static String [] getCurrentTypes () {
@@ -109,30 +115,33 @@ protected static String[] getCurrentTypes() {
109115 */
110116 @ BeforeClass
111117 public static void init () throws IOException {
118+ Version version = VersionUtils .randomVersionBetween (random (), Version .V_1_0_0 , Version .CURRENT );
112119 Settings settings = Settings .settingsBuilder ()
113120 .put ("name" , BaseQueryTestCase .class .toString ())
114121 .put ("path.home" , createTempDir ())
115- .put (IndexMetaData .SETTING_VERSION_CREATED , VersionUtils .randomVersionBetween (random (),
116- Version .V_1_0_0 , Version .CURRENT ))
117122 .build ();
118-
119- index = new Index ("test" );
123+ Settings indexSettings = Settings .settingsBuilder ()
124+ .put (IndexMetaData .SETTING_VERSION_CREATED , version ).build ();
125+ index = new Index (randomAsciiOfLengthBetween (1 , 10 ));
126+ final TestClusterService clusterService = new TestClusterService ();
127+ clusterService .setState (new ClusterState .Builder (clusterService .state ()).metaData (new MetaData .Builder ().put (
128+ new IndexMetaData .Builder (index .name ()).settings (indexSettings ).numberOfShards (1 ).numberOfReplicas (0 ))));
120129 injector = new ModulesBuilder ().add (
121130 new EnvironmentModule (new Environment (settings )),
122131 new SettingsModule (settings ),
123132 new ThreadPoolModule (new ThreadPool (settings )),
124133 new IndicesQueriesModule (),
125134 new ScriptModule (settings ),
126- new IndexSettingsModule (index , settings ),
127- new IndexCacheModule (settings ),
128- new AnalysisModule (settings , new IndicesAnalysisService (settings )),
129- new SimilarityModule (settings ),
135+ new IndexSettingsModule (index , indexSettings ),
136+ new IndexCacheModule (indexSettings ),
137+ new AnalysisModule (indexSettings , new IndicesAnalysisService (indexSettings )),
138+ new SimilarityModule (indexSettings ),
130139 new IndexNameModule (index ),
131140 new AbstractModule () {
132141 @ Override
133142 protected void configure () {
134143 Multibinder .newSetBinder (binder (), ScoreFunctionParser .class );
135- bind (ClusterService .class ).toProvider (Providers .of (( ClusterService ) null ));
144+ bind (ClusterService .class ).toProvider (Providers .of (clusterService ));
136145 bind (CircuitBreakerService .class ).to (NoneCircuitBreakerService .class );
137146 bind (NamedWriteableRegistry .class ).asEagerSingleton ();
138147 }
0 commit comments