Example #1
0
  /** A query must also work and deliver only the queried results. */
  @Test
  public void testWithQuery() {

    // make sure target directory exists and is empty
    File dumpDir = new File("/tmp/query");
    if (dumpDir.exists()) {
      for (File c : dumpDir.listFiles()) {
        c.delete();
      }
      dumpDir.delete();
    }
    dumpDir.mkdir();

    String clusterName =
        client()
            .admin()
            .cluster()
            .prepareHealth()
            .setWaitForGreenStatus()
            .execute()
            .actionGet()
            .getClusterName();
    String filename_0 = "/tmp/query/" + clusterName + "_users_0.json.gz";
    String filename_1 = "/tmp/query/" + clusterName + "_users_1.json.gz";
    ExportResponse response =
        executeDumpRequest(
            "{\"directory\": \"/tmp/query\", \"query\": {\"match\": {\"name\":\"bus\"}}}");

    assertEquals(0, response.getFailedShards());
    List<Map<String, Object>> infos = getExports(response);
    assertEquals(2, infos.size());

    List<String> lines_0 = readLinesFromGZIP(filename_0);
    assertEquals(0, lines_0.size());
    List<String> lines_1 = readLinesFromGZIP(filename_1);
    assertEquals(1, lines_1.size());
    assertEquals(
        "{\"_id\":\"4\",\"_source\":{\"name\":\"bus\"},\"_version\":1,\"_index\":\"users\",\"_type\":\"d\"}",
        lines_1.get(0));
  }
Example #2
0
  /** Dump request must also work with multiple nodes. */
  @Test
  public void testWithMultipleNodes() {

    // make sure target directory exists and is empty
    File dumpDir = new File("/tmp/multipleNodes");
    if (dumpDir.exists()) {
      for (File c : dumpDir.listFiles()) {
        c.delete();
      }
      dumpDir.delete();
    }
    dumpDir.mkdir();

    // Prepare a second node and wait for relocation
    String node2 = cluster().startNode();
    client(node2)
        .index(new IndexRequest("users", "d").source("{\"name\": \"motorbike\"}"))
        .actionGet();
    client(node2)
        .admin()
        .cluster()
        .prepareHealth()
        .setWaitForGreenStatus()
        .setWaitForNodes("2")
        .setWaitForRelocatingShards(0)
        .execute()
        .actionGet();

    // Do dump request
    String source = "{\"force_overwrite\": true, \"directory\":\"/tmp/multipleNodes\"}";
    ExportRequest exportRequest = new ExportRequest();
    exportRequest.source(source);
    ExportResponse response = client().execute(DumpAction.INSTANCE, exportRequest).actionGet();

    // The two shard results are from different nodes and have no failures
    assertEquals(0, response.getFailedShards());
    List<Map<String, Object>> infos = getExports(response);
    assertNotSame(infos.get(0).get("node_id"), infos.get(1).get("node_id"));
  }