Ejemplo n.º 1
0
  @Test
  public void shouldCorrectlyUpdateIndexesWhenChangingLabelsAndPropertyAtTheSameTime()
      throws Exception {
    // Given
    GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService();
    Node myNode = createNode(beansAPI, map("name", "Hawking"), LABEL1, LABEL2);
    createIndex(beansAPI, LABEL1, "name");
    createIndex(beansAPI, LABEL2, "name");
    createIndex(beansAPI, LABEL3, "name");

    // When
    try (Transaction tx = beansAPI.beginTx()) {
      myNode.removeLabel(LABEL1);
      myNode.addLabel(LABEL3);
      myNode.setProperty("name", "Einstein");
      tx.success();
    }

    // Then
    assertThat(myNode, inTx(beansAPI, hasProperty("name").withValue("Einstein")));
    assertThat(labels(myNode), containsOnly(LABEL2, LABEL3));

    assertThat(findNodesByLabelAndProperty(LABEL1, "name", "Hawking", beansAPI), isEmpty());
    assertThat(findNodesByLabelAndProperty(LABEL1, "name", "Einstein", beansAPI), isEmpty());

    assertThat(findNodesByLabelAndProperty(LABEL2, "name", "Hawking", beansAPI), isEmpty());
    assertThat(
        findNodesByLabelAndProperty(LABEL2, "name", "Einstein", beansAPI), containsOnly(myNode));

    assertThat(findNodesByLabelAndProperty(LABEL3, "name", "Hawking", beansAPI), isEmpty());
    assertThat(
        findNodesByLabelAndProperty(LABEL3, "name", "Einstein", beansAPI), containsOnly(myNode));
  }
Ejemplo n.º 2
0
 private void removeLabels(Node node, Label... labels) {
   try (Transaction tx = dbRule.getGraphDatabaseService().beginTx()) {
     for (Label label : labels) {
       node.removeLabel(label);
     }
     tx.success();
   }
 }
Ejemplo n.º 3
0
  @Test
  public void shouldHandleLargeAmountsOfNodesAddedAndRemovedInSameTx() throws Exception {
    // Given
    GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI();
    int labelsToAdd = 80;
    int labelsToRemove = 40;

    // When
    Node node;
    try (Transaction tx = db.beginTx()) {
      node = db.createNode();

      // I create a lot of labels, enough to push the store to use two dynamic records
      for (int l = 0; l < labelsToAdd; l++) {
        node.addLabel(label("Label-" + l));
      }

      // and I delete some of them, enough to bring the number of dynamic records needed down to 1
      for (int l = 0; l < labelsToRemove; l++) {
        node.removeLabel(label("Label-" + l));
      }

      tx.success();
    }

    // Then
    try (Transaction ignore = db.beginTx()) {
      // All the labels remaining should be in the label scan store
      for (int l = labelsToAdd - 1; l >= labelsToRemove; l--) {
        Label label = label("Label-" + l);
        assertThat(
            "Should have founnd node when looking for label " + label,
            single(GlobalGraphOperations.at(db).getAllNodesWithLabel(label)),
            equalTo(node));
      }
    }
  }