Skip to content

Commit

Permalink
1 failing spec
Browse files Browse the repository at this point in the history
  • Loading branch information
klobuczek committed Aug 12, 2020
1 parent 70d76c9 commit 111b35b
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 104 deletions.
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ jdk: openjdk11
rvm:
- 2.7.1
- jruby-9.2.11.1
- jruby-9.2.12.0
- jruby-9.2.13.0
env:
global:
- JRUBY_OPTS="--debug -J-Xmx1280m -Xcompile.invokedynamic=false -J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -J-noverify -Xcompile.mode=OFF"
- NEO4J_URL="bolt://localhost:7472"
matrix:
- NEO4J_VERSION=enterprise-3.5.19
- NEO4J_VERSION=enterprise-4.0.6
- NEO4J_VERSION=enterprise-3.5.20
- NEO4J_VERSION=enterprise-4.0.7
- NEO4J_VERSION=enterprise-4.1.1
matrix:
include:
# Testing older versions of ActiveModel
Expand All @@ -36,4 +37,4 @@ matrix:
env: NEO4J_VERSION=community-3.4.18 ACTIVE_MODEL_VERSION=5.2.3

- rvm: jruby-9.2.11.1
env: driver=java NEO4J_VERSION=enterprise-4.0.6
env: driver=java NEO4J_VERSION=enterprise-4.0.7
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ source 'http://rubygems.org'

gemspec

#gem "neo4j-#{ENV['driver'] == 'java' ? 'java' : 'ruby'}-driver", path: '../neo4j-ruby-driver'
gem "neo4j-#{ENV['driver'] == 'java' ? 'java' : 'ruby'}-driver", path: '../neo4j-ruby-driver'

gem 'listen', '< 3.1'

Expand Down
2 changes: 1 addition & 1 deletion activegraph.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ DESCRIPTION
s.add_development_dependency('guard-rspec')
s.add_development_dependency('guard-rubocop')
s.add_development_dependency('neo4j-rake_tasks', '>= 0.3.0')
s.add_development_dependency("neo4j-#{ENV['driver'] == 'java' ? 'java' : 'ruby'}-driver", '~> 1.7.0')
s.add_development_dependency("neo4j-#{ENV['driver'] == 'java' ? 'java' : 'ruby'}-driver", '~> 4.1.0-alpha.1')
s.add_development_dependency('os')
s.add_development_dependency('pry')
s.add_development_dependency('railties', '>= 4.0')
Expand Down
2 changes: 1 addition & 1 deletion lib/active_graph/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def establish_driver
end

def query(*args)
transaction do
transaction(implicit: true) do
super(*args)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/active_graph/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
Neo4j::Driver::Types::Entity.include ActiveGraph::Core::Wrappable
Neo4j::Driver::Types::Entity.prepend ActiveGraph::Core::Entity
Neo4j::Driver::Types::Node.prepend ActiveGraph::Core::Node
Neo4j::Driver::StatementResult.prepend ActiveGraph::Core::Result
Neo4j::Driver::Result.prepend ActiveGraph::Core::Result
Neo4j::Driver::Record.prepend ActiveGraph::Core::Record
27 changes: 14 additions & 13 deletions lib/active_graph/core/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@ module Core
module Result
attr_writer :wrap

def keys
@keys ||= super
end

def wrap?
@wrap
end

def each(&block)
wrap? ? wrapping_each(&block) : super
store if wrap? # TODO: why? This is preventing streaming
@records&.each(&block) || super
end

private

def wrapping_each(&block)
if @records
@records.each(&block)
else
@records = []
method(:each).super_method.call do |record|
record.wrap = wrap?
@records << record
block_given? ? yield(record) : record
end
def store
return if @records
keys
@records = []
# TODO: implement 'each' without block parameter
method(:each).super_method.call do |record|
record.wrap = wrap?
@records << record
end
end
end
Expand Down
25 changes: 15 additions & 10 deletions lib/active_graph/core/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,30 @@ module ActiveGraph
module Core
module Schema
def version
result = query('CALL dbms.components()', {}, skip_instrumentation: true)

# BTW: community / enterprise could be retrieved via `result.first.edition`
result.first[:versions][0]
read_transaction do
# BTW: community / enterprise could be retrieved via `result.first.edition`
query('CALL dbms.components()', {}, skip_instrumentation: true).first[:versions][0]
end
end

def indexes
result = query('CALL db.indexes()', {}, skip_instrumentation: true)
read_transaction do
result = query('CALL db.indexes()', {}, skip_instrumentation: true)

result.map do |row|
{ type: row[:type].to_sym, label: label(result, row), properties: properties(row), state: row[:state].to_sym }
result.map do |row|
{ type: row[:type].to_sym, label: label(result, row), properties: properties(row),
state: row[:state].to_sym }
end
end
end

def constraints
result = query('CALL db.indexes()', {}, skip_instrumentation: true)
read_transaction do
result = query('CALL db.indexes()', {}, skip_instrumentation: true)

result.select(&method(v4?(result) ? :v4_filter : :v3_filter)).map do |row|
{ type: :uniqueness, label: label(result, row), properties: properties(row) }
result.select(&method(v4?(result) ? :v4_filter : :v3_filter)).map do |row|
{ type: :uniqueness, label: label(result, row), properties: properties(row) }
end
end
end

Expand Down
2 changes: 2 additions & 0 deletions lib/active_graph/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ def rails?
defined?(Rails)
end
end

class Rollback < Error; end
end
4 changes: 2 additions & 2 deletions lib/active_graph/shared/persistence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def create_or_update
apply_default_values
result = _persisted_obj ? update_model : create_model

ActiveGraph::Base.transaction(&:failure) if result == false
ActiveGraph::Base.transaction(&:rollback) if result == false

result != false
ensure
Expand Down Expand Up @@ -179,7 +179,7 @@ def update(attributes)
ActiveGraph::Base.transaction do |tx|
self.attributes = process_attributes(attributes)
saved = save
tx.failure unless saved
tx.rollback unless saved
saved
end
end
Expand Down
14 changes: 6 additions & 8 deletions lib/active_graph/transaction.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
module ActiveGraph
module Transaction
def failure
def rollback
super
@failure = true
end

def close
success
super
after_commit_registry.each(&:call) unless @failure
@rolled_back = true
end

def after_commit(&block)
after_commit_registry << block
end

def apply_callbacks
after_commit_registry.each(&:call) unless @rolled_back
end

private

def after_commit_registry
Expand Down
28 changes: 14 additions & 14 deletions lib/active_graph/transactions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ def session(*args)
end
end

def transaction(**config, &block)
send_transaction(:begin_transaction, **config, &block)
end

def write_transaction(**config, &block)
send_transaction(:write_transaction, **config, &block)
end
Expand All @@ -29,28 +25,32 @@ def read_transaction(**config, &block)
send_transaction(:read_transaction, **config, &block)
end

alias transaction write_transaction

private

def send_transaction(method, **config, &block)
return checked_yield(tx, &block) if tx&.open?
return yield tx if tx&.open?
return run_transaction_work(explicit_session, method, **config, &block) if explicit_session&.open?
driver.session do |session|
run_transaction_work(session, method, **config, &block)
end
end

def run_transaction_work(session, method, **config, &block)
implicit = config.delete(:implicit)
session.send(method, **config) do |tx|
self.tx = tx
checked_yield(tx, &block)
end
end

def checked_yield(tx)
yield tx
rescue StandardError => e
tx.failure
raise e
block.call(tx).tap do |result|
if implicit &&
[Core::Result, ActiveGraph::Node::Query::QueryProxy, ActiveGraph::Core::Query]
.any?(&result.method(:is_a?))
result.store
end
end
end.tap { tx.apply_callbacks }
rescue ActiveGraph::Rollback
# rollbacks are silently swallowed
end
end
end
Expand Down
Loading

0 comments on commit 111b35b

Please sign in to comment.