Skip to content

Commit

Permalink
failure is now mark_failure, added aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
subvertallchris committed Jan 2, 2015
1 parent 0f7d2dd commit ff6fa26
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
17 changes: 8 additions & 9 deletions lib/neo4j/transaction.rb
Expand Up @@ -10,18 +10,21 @@ def register_instance
end

# Marks this transaction as failed, which means that it will unconditionally be rolled back when close() is called.
def failure
def mark_failed
@failure = true
end
alias_method :failure, :mark_failed

# If it has been marked as failed
def failure?
def failed?
!!@failure
end
alias_method :failure?, :failed?

def expired
def mark_expired
@expired = true
end
alias_method :expired, :mark_expired

def expired?
!!@expired
Expand Down Expand Up @@ -59,11 +62,7 @@ def close
return if @pushed_nested >= 0
fail "Can't commit transaction, already committed" if @pushed_nested < -1
Neo4j::Transaction.unregister(self)
if failure?
_delete_tx
else
_commit_tx
end
failed? ? _delete_tx : _commit_tx
end
end

Expand All @@ -88,7 +87,7 @@ def run(run_in_tx = true)
puts "Java Exception in a transaction, cause: #{e.cause}"
e.cause.print_stack_trace
end
tx.failure unless tx.nil?
tx.mark_failed unless tx.nil?
raise
ensure
tx.close unless tx.nil?
Expand Down
4 changes: 2 additions & 2 deletions spec/neo4j-server/e2e/cypher_transaction_spec.rb
Expand Up @@ -53,7 +53,7 @@ module Neo4j::Server
Neo4j::Transaction.run do |tx|
node[:name] = 'foo'
expect(node[:name]).to eq('foo')
tx.failure
tx.mark_failed
end

expect(node['name']).to eq('andreas')
Expand All @@ -62,7 +62,7 @@ module Neo4j::Server
it 'can continue operations after transaction is rolled back' do
node = Neo4j::Node.create(name: 'andreas')
Neo4j::Transaction.run do |tx|
tx.failure
tx.mark_failed
node[:name] = 'foo'
expect(node[:name]).to eq('foo')
end
Expand Down
10 changes: 5 additions & 5 deletions spec/shared_examples/node_with_tx.rb
Expand Up @@ -92,7 +92,7 @@
id = Neo4j::Transaction.run do
Neo4j::Transaction.run do |tx|
i = Neo4j::Node.create.neo_id
tx.failure
tx.mark_failed
i
end
end
Expand All @@ -104,7 +104,7 @@
i = Neo4j::Transaction.run do
Neo4j::Node.create.neo_id
end
tx.failure
tx.mark_failed
i
end
expect(Neo4j::Node.load(id)).to eq(nil)
Expand All @@ -122,7 +122,7 @@
it 'rolls back the transaction if failure is called' do
node = Neo4j::Transaction.run do |tx|
a = Neo4j::Node.create
tx.failure
tx.mark_failed
a
end
expect(node).not_to exist
Expand All @@ -147,7 +147,7 @@
Neo4j::Transaction.run do |tx|
node[:name] = 'bar'
expect(node[:name]).to eq('bar')
tx.failure
tx.mark_failed
end
expect(node[:name]).to eq('foo')
end
Expand All @@ -160,7 +160,7 @@
Neo4j::Transaction.run do |tx|
node1.create_rel(:knows, node2)
expect(node1.node(dir: :outgoing, type: :knows)).to eq(node2)
tx.failure
tx.mark_failed
end

expect(node1.node(dir: :outgoing, type: :knows)).to be_nil
Expand Down

0 comments on commit ff6fa26

Please sign in to comment.