예제 #1
0
  @Test
  public void deleteTest() throws ExecutionException, InterruptedException {
    final String target = "test-target";
    final String idx = "test-index";
    final String tp = "test-type";
    final String id = "1234";
    final String othertp = "othertest-type";

    // create target index if it doesn't exist
    if (!ln.es.admin().indices().prepareExists(target).execute().actionGet().exists()) {
      final CreateIndexResponse cir =
          ln.es.admin().indices().prepareCreate(target).execute().actionGet();
      if (!cir.acknowledged()) throw new RuntimeException("failed to create index " + target);
    }

    final IndexResponse ir =
        ln.es.prepareIndex(idx, tp, id).setSource("{\"children\":[1,2,3]}").execute().actionGet();

    ln.log.info(
        "Indexed /{}/{}/{} as version {} into ES", new Object[] {idx, tp, id, ir.version()});

    final IndexResponse ir1 =
        ln.es
            .prepareIndex(idx, tp, "1")
            .setSource("{\"cheese\":\"gorgonzola\"}")
            .execute()
            .actionGet();

    ln.log.info("Indexed /{}/{}/1 as version {} into ES", new Object[] {idx, tp, ir1.version()});

    final IndexResponse ir2 =
        ln.es
            .prepareIndex(idx, tp, "2")
            .setSource("{\"cheese\":\"mozarella\"}")
            .execute()
            .actionGet();

    ln.log.info("Indexed /{}/{}/2 as version {} into ES", new Object[] {idx, tp, ir2.version()});

    final IndexResponse ir3 =
        ln.es
            .prepareIndex(idx, othertp, "3")
            .setSource("{\"cheese\":\"limburger\"}")
            .execute()
            .actionGet();

    ln.log.info(
        "Indexed /{}/{}/3 as version {} into ES", new Object[] {idx, othertp, ir3.version()});

    final List<Future<DegraphmalizeResult>> actions = new ArrayList<Future<DegraphmalizeResult>>();

    actions.add(
        ln.d.degraphmalize(
            DegraphmalizeRequestType.UPDATE,
            DegraphmalizeRequestScope.DOCUMENT,
            new ID(idx, tp, id, ir.version()),
            ln.callback));
    actions.add(
        ln.d.degraphmalize(
            DegraphmalizeRequestType.UPDATE,
            DegraphmalizeRequestScope.DOCUMENT,
            new ID(idx, tp, "1", ir1.version()),
            ln.callback));
    actions.add(
        ln.d.degraphmalize(
            DegraphmalizeRequestType.UPDATE,
            DegraphmalizeRequestScope.DOCUMENT,
            new ID(idx, tp, "2", ir2.version()),
            ln.callback));
    actions.add(
        ln.d.degraphmalize(
            DegraphmalizeRequestType.UPDATE,
            DegraphmalizeRequestScope.DOCUMENT,
            new ID(idx, othertp, "3", ir3.version()),
            ln.callback));

    for (final Future<DegraphmalizeResult> a : actions) {
      DegraphmalizeResult result = a.get();
      ln.log.info("Degraphmalize complete for : " + result.root());
    }

    GraphUtilities.dumpGraph(new ObjectMapper(), ln.G);

    actions.clear();
    actions.add(
        ln.d.degraphmalize(
            DegraphmalizeRequestType.DELETE,
            DegraphmalizeRequestScope.DOCUMENT_ANY_VERSION,
            new ID(idx, tp, id, 0),
            ln.callback));
    for (final Future<DegraphmalizeResult> a : actions) {
      DegraphmalizeResult result = a.get();
      ln.log.info("Degraphmalize of {}: {}", result.root(), result);
    }

    actions.clear();
    actions.add(
        ln.d.degraphmalize(
            DegraphmalizeRequestType.DELETE,
            DegraphmalizeRequestScope.TYPE_IN_INDEX,
            new ID(idx, tp, null, 0),
            ln.callback));
    for (final Future<DegraphmalizeResult> a : actions) {
      DegraphmalizeResult result = a.get();
      ln.log.info("Degraphmalize of {}: {}", result.root(), result);
    }

    // Only the vertex of the othertp type should be present.
    Iterable<Vertex> iterable = GraphUtilities.findVerticesInIndex(ln.G, idx);
    assertThat(Iterables.size(iterable)).isEqualTo(1);

    actions.clear();
    actions.add(
        ln.d.degraphmalize(
            DegraphmalizeRequestType.DELETE,
            DegraphmalizeRequestScope.INDEX,
            new ID(idx, null, null, 0),
            ln.callback));
    for (final Future<DegraphmalizeResult> a : actions) {
      DegraphmalizeResult result = a.get();
      ln.log.info("Degraphmalize of {}: {}", result.root(), result);
    }

    // No more vertices
    Iterable<Vertex> iterable2 = GraphUtilities.findVerticesInIndex(ln.G, idx);
    assertThat(Iterables.size(iterable2)).isEqualTo(0);

    // Cleanup index
    if (!ln.es.admin().indices().delete(new DeleteIndexRequest(idx)).actionGet().acknowledged()) {
      throw new RuntimeException("failed to delete index " + target);
    }
  }
예제 #2
0
  @Test
  public void fullTest() throws ExecutionException, InterruptedException, DegraphmalizerException {
    final String target = "test-target";
    final String idx = "test-index";
    final String tp = "test-type";
    final String id = "1234";

    // create target index if it doesn't exist
    if (!ln.es.admin().indices().prepareExists(target).execute().actionGet().exists()) {
      final CreateIndexResponse cir =
          ln.es.admin().indices().prepareCreate(target).execute().actionGet();
      if (!cir.acknowledged()) throw new RuntimeException("failed to create index " + target);
    }

    final IndexResponse ir =
        ln.es.prepareIndex(idx, tp, id).setSource("{\"children\":[1,2,3]}").execute().actionGet();

    ln.log.info(
        "Indexed /{}/{}/{} as version {} into ES", new Object[] {idx, tp, id, ir.version()});

    final IndexResponse ir1 =
        ln.es
            .prepareIndex(idx, tp, "1")
            .setSource("{\"cheese\":\"gorgonzola\"}")
            .execute()
            .actionGet();

    ln.log.info("Indexed /{}/{}/1 as version {} into ES", new Object[] {idx, tp, ir1.version()});

    final IndexResponse ir2 =
        ln.es
            .prepareIndex(idx, tp, "2")
            .setSource("{\"cheese\":\"mozarella\"}")
            .execute()
            .actionGet();

    ln.log.info("Indexed /{}/{}/2 as version {} into ES", new Object[] {idx, tp, ir2.version()});

    // degraphmalize "1" and wait for and print result
    final List<Future<DegraphmalizeResult>> actions = new ArrayList<Future<DegraphmalizeResult>>();

    actions.add(
        ln.d.degraphmalize(
            DegraphmalizeRequestType.UPDATE,
            DegraphmalizeRequestScope.DOCUMENT,
            new ID(idx, tp, id, ir.version()),
            ln.callback));
    actions.add(
        ln.d.degraphmalize(
            DegraphmalizeRequestType.UPDATE,
            DegraphmalizeRequestScope.DOCUMENT,
            new ID(idx, tp, "1", ir1.version()),
            ln.callback));
    actions.add(
        ln.d.degraphmalize(
            DegraphmalizeRequestType.UPDATE,
            DegraphmalizeRequestScope.DOCUMENT,
            new ID(idx, tp, "2", ir2.version()),
            ln.callback));

    for (final Future<DegraphmalizeResult> a : actions) {
      DegraphmalizeResult result = a.get();
      ln.log.info("Degraphmalize complete for : " + result.root());
    }

    ObjectMapper mapper = new ObjectMapper();
    for (final Future<DegraphmalizeResult> a : actions) {
      final DegraphmalizeResult degraphmalizeResult = a.get();
      // Get first node in results
      final ObjectNode result = toJSON(mapper, degraphmalizeResult.results().get(0).get());

      assertThat(result.get("properties").has("nodes-in")).isTrue();
      assertThat(result.get("properties").has("nodes-out")).isTrue();

      if (degraphmalizeResult.root().id().equals("1234")) {
        assertThat(numberOfChildren(result, "nodes-out")).isZero();
        assertThat(numberOfChildren(result, "nodes-in")).isEqualTo(3);
      }

      if (degraphmalizeResult.root().id().equals("1")) {
        assertThat(numberOfChildren(result, "nodes-out")).isEqualTo(1);
        assertThat(numberOfChildren(result, "nodes-in")).isZero();
      }
    }

    GraphUtilities.dumpGraph(new ObjectMapper(), ln.G);
    // Cleanup index
    if (!ln.es.admin().indices().delete(new DeleteIndexRequest(idx)).actionGet().acknowledged()) {
      throw new RuntimeException("failed to delete index " + target);
    }
  }