Ejemplo n.º 1
0
  /** The 'force_overwrite' parameter forces existing files to be overwritten. */
  @Test
  public void testForceOverwrite() {

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

    // initial dump to target directory
    ExportResponse response = executeDumpRequest("{\"directory\": \"/tmp/forceDump\"}");

    List<Map<String, Object>> infos = getExports(response);

    assertEquals(2, infos.size());
    assertEquals(0, response.getShardFailures().length);

    // second attempt to dump will fail
    response = executeDumpRequest("{\"directory\": \"/tmp/forceDump\"}");

    infos = getExports(response);
    assertEquals(0, infos.size());
    assertEquals(2, response.getShardFailures().length);

    // if force_overwrite == true a second dump will succeed
    response = executeDumpRequest("{\"directory\": \"/tmp/forceDump\", \"force_overwrite\":true}");

    infos = getExports(response);
    assertEquals(2, infos.size());
    assertEquals(0, response.getShardFailures().length);
  }
Ejemplo n.º 2
0
  /** Invalid parameters lead to an error response. */
  @Test
  public void testBadParserArgument() {
    ExportResponse response = executeDumpRequest("{\"badparam\":\"somevalue\"}");

    List<Map<String, Object>> infos = getExports(response);
    assertEquals(0, infos.size());
    assertEquals(2, response.getShardFailures().length);
    assertTrue(
        response.getShardFailures()[0].reason().contains("No parser for element [badparam]"));
    assertTrue(
        response.getShardFailures()[1].reason().contains("No parser for element [badparam]"));
  }
Ejemplo n.º 3
0
 /** The target directory must exist */
 @Test
 public void testDirMustExist() {
   ExportResponse response = executeDumpRequest("{\"directory\": \"/tmp/doesnotexist\"}");
   List<Map<String, Object>> infos = getExports(response);
   assertEquals(0, infos.size());
   assertEquals(2, response.getShardFailures().length);
   assertTrue(
       response
           .getShardFailures()[0]
           .reason()
           .contains("Target folder /tmp/doesnotexist does not exist"));
   assertTrue(
       response
           .getShardFailures()[1]
           .reason()
           .contains("Target folder /tmp/doesnotexist does not exist"));
 }
Ejemplo n.º 4
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));
  }
Ejemplo n.º 5
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"));
  }