无法覆盖ES集成测试中的节点设置

时间:2017-04-22 00:09:10

标签: java elasticsearch elasticsearch-plugin

我正在为elasticsearch 5.3编写集成测试。

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:未知设置   [plugin.dynamic_word_delimiter.refresh_interval]请检查一下   安装了所需的插件,或检查了重大变化   删除设置的文档“

如果删除以下部分并将刷新间隔增加到大于默认值,则测试通过。所以我无法覆盖它。

  

.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
}

1 个答案:

答案 0 :(得分:-1)

您需要使用SettingsModule #registerSettings(Setting)方法注册设置,如下所示: https://www.elastic.co/guide/en/elasticsearch/reference/5.x/breaking_50_settings_changes.html#breaking_50_settings_changes