2016-03-09 22 views
1

我正在重寫我們的集成測試以使用Elasticsearch 2.2.0。 我有一個抽象的測試用例類延伸org.elasticsearch.test.ESIntegTestCaseElasticsearch 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來運行我的測試。

回答

1

我已經解決了這個問題。我開始了一個調試器,並在EsIntegTestCase中找到了一個我沒有輸出的日誌語句。所以我修改了日誌配置,然後彈性搜索的實際錯誤開始出現。

問題是不一致的字段映射:

ensureYellow timed out, cluster state: 
version: 8 
state uuid: twZ91SH7QIytVTrQuixDbg 
from_diff: false 
meta data version: 3 
nodes: 
    {node_s0}{H_1t-4MwSKueM5vXRw_P4A}{local}{local[1]}{mode=local}, local, master 
routing_table (version 6): 
-- index [bokun] 
----shard_id [bokun][0] 
--------[bokun][0], node[null], [P], v[3], s[UNASSIGNED], unassigned_info[[reason=ALLOCATION_FAILED], at[2016-03-09T13:07:48.812Z], details[failed to update mappings, failure IllegalArgumentException[Mapper for [translations.excerpt] conflicts with existing mapping in other types: 
[mapper [translations.excerpt] has different [store] values]]]]