我正在重寫我們的集成測試以使用Elasticsearch 2.2.0。 我有一個抽象的測試用例類延伸org.elasticsearch.test.ESIntegTestCase
:Elasticsearch 2.2.0 ESIntegTestCase:ensureYellow()導致「超時等待黃色」
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.SUITE, numDataNodes = 1)
@ThreadLeakScope(ThreadLeakScope.Scope.NONE)
public abstract class AbstractApplicationTest extends ESIntegTestCase {
...
@Override
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.settingsBuilder()
.put(super.nodeSettings(nodeOrdinal))
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1)
.put(Node.HTTP_ENABLED, true)
.put("script.groovy.sandbox.enabled", true)
.put("script.engine.groovy.inline.search", true)
.put("script.engine.groovy.inline.update", "true")
.put("script.inline", true)
.put("script.update", true)
.put("script.indexed", true)
.put("script.default_lang", "groovy")
.build();
}
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return pluginList(GroovyPlugin.class, DeleteByQueryPlugin.class, AnalysisICUPlugin.class);
}
@Before
public void setUpElastic() throws Exception {
// add the index and the mappings
prepareCreate("bokun")
.setSettings(Settings.builder().loadFromSource(loadFromClasspath("indices/settings.json")))
.addMapping(AccommodationSearchIndex.INDEX_ACCOMMODATION_TYPE, loadFromClasspath("indices/accommodation.json"))
.addMapping(AccommodationSearchIndex.INDEX_ROOM_TYPE, loadFromClasspath("indices/room.json"))
...
.execute().actionGet();
ensureYellow();
}
...
}
我的測試用例類擴展這個抽象類。它有6個測試,並且在上述調用ensureYellow()
期間,其中3-4個測試失敗,並顯示「超時等待黃色」消息。
如果我執行索引請求時註釋掉ensureYellow()
電話,然後我得到「unavailable_shards_exception」從Elasticsearch:
{
"took": 60001,
"errors": true,
"items": [{
"index": {
"_index": "bokun",
"_type": "activity_availability",
"_id": "20_20160309",
"status": 503,
"error": {
"type": "unavailable_shards_exception",
"reason": "[bokun][2] primary shard is not active Timeout: [1m], request: [shard bulk {[bokun][2]}]"
}
}
}, {
"index": {
"_index": "bokun",
"_type": "activity_availability",
"_id": "20_20160310",
"status": 503,
"error": {
"type": "unavailable_shards_exception",
"reason": "[bokun][1] primary shard is not active Timeout: [1m], request: [shard bulk {[bokun][1]}]"
}
}
},
...
{
"index": {
"_index": "bokun",
"_type": "activity_availability",
"_id": "20_20160322",
"status": 503,
"error": {
"type": "unavailable_shards_exception",
"reason": "[bokun][0] primary shard is not active Timeout: [1m], request: [shard bulk {[bokun][0]}]"
}
}
}, {
"index": {
"_index": "bokun",
"_type": "activity",
"_id": "12",
"status": 503,
"error": {
"type": "unavailable_shards_exception",
"reason": "[bokun][2] primary shard is not active Timeout: [1m], request: [shard bulk {[bokun][2]}]"
}
}
}]
}
測試用例範圍爲ESIntegTestCase.Scope.SUITE
,這意味着集羣將每個創建SUITE而不是測試,然後我在每次測試之前創建索引並添加映射。我假設在每次測試後索引被刪除,因爲這page陳述:
默認情況下,測試運行與每個測試套件獨特的羣集。當然,所有的索引和模板都會在每次測試之間刪除。
有沒有人知道我在做什麼錯在這裏?
P.S.我正在使用SBT來運行我的測試。