Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed reindexing bug. If neo4j was restarted it would not keep track …
…of newly created nodes. Neo4j.update_index would not work after restart. [#53]
  • Loading branch information
andreas committed Jul 14, 2009
1 parent 469d0b0 commit b16862e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/neo4j/extensions/reindexer.rb
Expand Up @@ -63,8 +63,8 @@ def self.on_neo_started(neo_instance)
else
@index_node = IndexNode.new # cache this so we do not have to look it up always
neo_instance.ref_node.relationships.outgoing(:index_node) << @index_node
Neo4j.event_handler.add(@index_node)
end
Neo4j.event_handler.add(@index_node)
end

def self.on_neo_stopped(neo_instance)
Expand Down
53 changes: 50 additions & 3 deletions test/neo4j/reindexer_spec.rb
Expand Up @@ -35,11 +35,11 @@ class ReindexerTestNode2
before(:all) do
Neo4j.event_handler.add(Neo4j::IndexNode) # incase it has been disabled by an RSpec
end

after(:all) do
Neo4j.event_handler.remove(Neo4j::IndexNode) # avoid side effects on using this extension
end


it "has a reference to a created node" do
#should only have a reference to the reference node
Expand All @@ -66,7 +66,7 @@ class ReindexerTestNode2
ReindexerTestNode.all.nodes.to_a.size.should == 1
ReindexerTestNode2.all.nodes.to_a.size.should == 2
end

it "should return all node instances" do
class TestNode
include Neo4j::NodeMixin
Expand Down Expand Up @@ -153,3 +153,50 @@ class B < A
end

end



describe "Reindex" do
it "should reindex nodes after the neo4j has restarted (lighthouse ticket #53)" do
Neo4j.load_reindexer # since a previous test might have unloaded this extension

undefine_class :TestNode
class TestNode
include Neo4j::NodeMixin
property :name, :age
index :name
end

Neo4j::Transaction.new
Neo4j.start
t1 = TestNode.new
t1.name = 't1'
Neo4j::Transaction.finish


# make sure we can find it
Neo4j::Transaction.new
TestNode.all.nodes.to_a.should include(t1)
Neo4j::Transaction.finish

# now restart neo and check if neo4j still keep track of all created nodes
Neo4j.stop
Neo4j.start

# create another node check if still works
Neo4j::Transaction.new
Neo4j.start
t2 = TestNode.new
t2.name = 't2'
Neo4j::Transaction.finish


# make sure we can find it
Neo4j::Transaction.new
TestNode.all.nodes.to_a.should include(t2)
Neo4j::Transaction.finish

end
end


0 comments on commit b16862e

Please sign in to comment.