Permalink
Browse files

Make mock nested transactions explicit

  • Loading branch information...
1 parent e77816e commit 2430392064f903fcfa68b4b328ca85874dd51d6e @pangloss committed Sep 25, 2012
@@ -174,7 +174,7 @@ def add_edges_to(label, to_vertices, props = {})
has_props = !props.empty?
edge_ids = []
counter = 0
- graph.transaction do |commit, rollback|
+ graph.transaction(nesting: true) do |commit, rollback|
v.each do |from_v|
to_vertices.each do |to_v|
counter += 1
View
@@ -7,6 +7,7 @@ class ElementExists < UserError; end
class LogicError < Error; end
class ClientError < LogicError; end
class TransactionConcludedError < ClientError; end
+ class NestedTransactionError < ClientError; end
class NestedTransactionRollback < ClientError; end
class NestedMockTransactionRollback < NestedTransactionRollback; end
class MockTransactionRollback < ClientError; end
@@ -34,8 +34,12 @@ def in_transaction?
# Also considering a 3rd callback that could be used to get info about the
# current transaction stack like depth, number of commits/rollbacks, possibly the number of
# mutations it wraps and even some event registration stuff could be made available.
- def transaction
- commit, rollback = start_transaction!
+ #
+ # opts:
+ # nesting: true -- allow mock nested transactions
+ # nesting: false -- (default) raise an exception instead of starting a nested transaction
+ def transaction(opts = {})
+ commit, rollback = start_transaction! opts
begin
r = yield commit, rollback
commit.call
@@ -55,15 +59,17 @@ def threadlocal_graph_info
graphs[blueprints_graph.object_id] ||= {}
end
- def start_transaction!
+ def start_transaction!(opts)
tgi = threadlocal_graph_info
tx_depth = tgi[:tx_depth] ||= 0
tgi[:tx_depth] += 1
if blueprints_graph.is_a? TransactionalGraph
if tx_depth == 0
base_tx_finalizers
- else
+ elsif opts[:nesting] == true
nested_tx_finalizers
+ else
+ fail NestedTransactionError
end
else
if tx_depth == 0
@@ -24,7 +24,7 @@ def bulk_job(size = nil, target_graph = nil)
target_graph.in_bulk_job = true
size ||= target_graph.bulk_job_size
counter = 0
- target_graph.transaction do |commit, rollback|
+ target_graph.transaction(nesting: true) do |commit, rollback|
each_slice(size) do |slice|
print counter if Pacer.verbose?
counter += size
@@ -288,7 +288,7 @@
subject { graph.index 'missing_edge', :edge, :create => true }
its(:name) { should == 'missing_edge' }
after do
- graph.transaction do
+ graph.transaction(nesting: true) do
graph.drop_index 'missing_edge'
end
end
@@ -302,7 +302,7 @@
subject { graph.index 'missing_vertex', :vertex, :create => true }
its(:name) { should == 'missing_vertex' }
after do
- graph.transaction do
+ graph.transaction(nesting: true) do
graph.drop_index 'missing_vertex'
end
end

0 comments on commit 2430392

Please sign in to comment.