コード例 #1
0
  @Test
  public void testSimpleIndexBasic() {
    Node node1 = graphDb().createNode();
    Object key1 = 1;

    assertTrue(!index.getNodesFor(key1).iterator().hasNext());

    index.index(node1, key1);

    IndexHits hits = index.getNodesFor(key1);
    Iterator<Node> itr = hits.iterator();
    assertEquals(node1, itr.next());
    assertEquals(1, hits.size());
    assertTrue(!itr.hasNext());

    index.remove(node1, key1);
    assertTrue(!index.getNodesFor(key1).iterator().hasNext());

    index.index(node1, key1);
    Node node2 = graphDb().createNode();
    Object key2 = 2;
    index.index(node2, key2);

    itr = index.getNodesFor(key1).iterator();
    assertEquals(node1, itr.next());
    assertTrue(!itr.hasNext());
    itr = index.getNodesFor(key2).iterator();
    assertEquals(node2, itr.next());
    assertTrue(!itr.hasNext());

    index.remove(node1, key1);
    index.remove(node2, key2);
    assertTrue(!index.getNodesFor(key1).iterator().hasNext());
    assertTrue(!index.getNodesFor(key2).iterator().hasNext());

    node1.delete();
    node2.delete();
  }
コード例 #2
0
  @Test
  public void testSimple() {
    Node node1 = graphDb().createNode();

    assertTrue(!index().getNodes("a_property", 1).iterator().hasNext());

    index().index(node1, "a_property", 1);

    Iterator<Node> itr = index().getNodes("a_property", 1).iterator();
    assertEquals(node1, itr.next());
    assertTrue(!itr.hasNext());

    index().removeIndex(node1, "a_property", 1);
    assertTrue(!index().getNodes("a_property", 1).iterator().hasNext());

    index().index(node1, "a_property", 1);
    Node node2 = graphDb().createNode();
    index().index(node2, "a_property", 1);

    IndexHits<Node> hits = index().getNodes("a_property", 1);
    assertEquals(2, hits.size());
    itr = hits.iterator();
    assertTrue(itr.next() != null);
    assertTrue(itr.next() != null);
    assertTrue(!itr.hasNext());
    assertTrue(!itr.hasNext());

    index().removeIndex(node1, "a_property", 1);
    index().removeIndex(node2, "a_property", 1);
    assertTrue(!index().getNodes("a_property", 1).iterator().hasNext());
    itr = index().getNodes("a_property", 1).iterator();
    assertTrue(!itr.hasNext());
    restartTx();
    node1.delete();
    node2.delete();
  }