コード例 #1
0
  @Test
  public void testFactoryWithTransportClient() throws IOException {
    // setup client for testing http connection params
    Path baseDir = Paths.get("target/elasticsearch");
    String dataPath = Files.createTempDirectory(baseDir, null).toAbsolutePath().toString();
    Settings build = ImmutableSettings.builder().put("path.data", dataPath).build();
    Node node = nodeBuilder().settings(build).node();

    assertTrue(new ElasticDataStoreFactory().isAvailable());
    scanForPlugins();

    Map<String, Serializable> map = new HashMap<>();
    map.put(ElasticDataStoreFactory.HOSTNAME.key, "localhost");
    map.put(ElasticDataStoreFactory.HOSTPORT.key, String.valueOf(9300));
    map.put(ElasticDataStoreFactory.INDEX_NAME.key, "sample");

    Iterator<DataStoreFactorySpi> ps = getAvailableDataSources();
    ElasticDataStoreFactory fac;
    while (ps.hasNext()) {
      fac = (ElasticDataStoreFactory) ps.next();

      try {
        if (fac.canProcess(map)) {
          source = fac.createDataStore(map);
        }
      } catch (Throwable t) {
        LOGGER.log(Level.WARNING, "Could not acquire " + fac.getDescription() + ":" + t, t);
      }
    }

    assertNotNull(source);
    assertTrue(source instanceof ElasticDataStore);
    node.close();
  }
コード例 #2
0
  @Test
  public void testFactoryWithSearchIndices() throws IOException {
    assertTrue(new ElasticDataStoreFactory().isAvailable());
    scanForPlugins();

    Map<String, Serializable> map = new HashMap<>();
    map.put(ElasticDataStoreFactory.DATA_PATH.key, dataPath);
    map.put(ElasticDataStoreFactory.INDEX_NAME.key, "sample");
    map.put(ElasticDataStoreFactory.SEARCH_INDICES.key, "sample1,sample2");

    Iterator<DataStoreFactorySpi> ps = getAvailableDataSources();
    ElasticDataStoreFactory fac;
    while (ps.hasNext()) {
      fac = (ElasticDataStoreFactory) ps.next();

      try {
        if (fac.canProcess(map)) {
          source = fac.createDataStore(map);
        }
      } catch (Throwable t) {
        LOGGER.log(Level.WARNING, "Could not acquire " + fac.getDescription() + ":" + t, t);
      }
    }

    assertNotNull(source);
    assertTrue(source instanceof ElasticDataStore);
    assertTrue(((ElasticDataStore) source).getSearchIndices().equals("sample1,sample2"));
  }