2017-04-22 64 views
0

我正在爲elasticsearch 5.3編寫集成測試。無法覆蓋ES集成測試中的節點設置

public class ProtectedWordsIndexTests extends ESIntegTestCase { 
    private final WordDelimiterActionListener wordsListener = 
    WordDelimiterActionListener.getInstance(); 
    private final static String INDEX_NAME = "protected_words"; 
    private final static String TYPE_NAME = "word"; 
    private final static String FILTER_NAME = "my_word_delimiter"; 

    @Override 
    protected Collection<Class<? extends Plugin>> nodePlugins() { 
    return Collections.singleton(WordDelimiterPlugin.class); 
    } 

    @Override 
    protected Settings nodeSettings(int nodeOrdinal) { 
    return builder() 
     .put("plugin.types", TYPE_NAME) 
     .put("plugin.dynamic_word_delimiter.refresh_interval", "500ms") 
     .put(super.nodeSettings(nodeOrdinal)) 
     .build(); 
    } 

    public void testAddWordToIndex() throws Exception { 
    Settings indexSettings = builder() 
     .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) 
     .put("index.analysis.filter.my_word_delimiter.type", "dynamic_word_delimiter") 
     .build(); 
    TokenFilterFactory filterFactory = filterFactory(indexSettings, FILTER_NAME); 

    createIndex(INDEX_NAME); 
    ensureGreen(); 
    client().prepareIndex(INDEX_NAME, TYPE_NAME, "1") 
     .setSource("word", "1tb") 
     .execute(); 

    Thread.sleep(TimeValue.timeValueSeconds(1).getMillis()); 

    Set<String> protectedWords = wordsListener.getProtectedWords(); 
    assertTrue(protectedWords.size() == 1); 
    } 
} 

當我運行testAddWordToIndex()我收到以下錯誤:

"java.lang.IllegalArgumentException: unknown setting [plugin.dynamic_word_delimiter.refresh_interval] please check that any required plugins are installed, or check the breaking changes documentation for removed settings"

如果我刪除以下部分,增加的刷新間隔比默認的多,測試通過。所以我不能重寫這個。

.put("plugin.dynamic_word_delimiter.refresh_interval", "500ms")

默認刷新間隔在這裏宣佈:

public class WordDelimiterRunnable extends AbstractRunnable { 
    public static final TimeValue REFRESH_INTERVAL = TimeValue.timeValueSeconds(20); 
    public static final String INDEX_NAME = "protected_words"; 
    public static final String INDEX_TYPE = "word"; 
    public static final int RESULTS_SIZE = 10000; 

    private volatile boolean running; 
    private final Client client; 
    private final String index; 
    private final long interval; 
    private final String type; 

    public WordDelimiterRunnable(Client client, Settings settings) { 
    this.client = client; 
    this.index = settings.get("plugin.dynamic_word_delimiter.protected_words_index", INDEX_NAME); 
    this.type = settings.get("plugin.dynamic_word_delimiter.protected_words_type", INDEX_TYPE); 
    this.interval = settings.getAsTime("plugin.dynamic_word_delimiter.refresh_interval", REFRESH_INTERVAL).getMillis(); 
    } 
    // more code here 
} 
+0

我沒有試過這個,因此評論,但也許它與put()的順序有關?我會嘗試做'return builder()。put(super.nodeSettings(nodeOrdinal))。put(「plugin.types」,TYPE_NAME).put(「plugin.dynamic_word_delimiter.refresh_interval」,「500ms」)。build(); '如果您還沒有 –

+0

感謝您的評論。想到這一點,並嘗試過,沒有奏效。 – Michael

+0

'.put(「plugin.types」,TYPE_NAME)'通常需要插件的類名稱。從例外中說它沒有加載插件。如果你有插件的類名,你可以試試 –

回答