Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Dockerfile-jruby
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ARG JAVA_VERSION

FROM jruby:9.4-jdk${JAVA_VERSION}

ENV JAVA_VERSION=$JAVA_VERSION

# Installing packages
RUN apt-get update && apt-get upgrade -y && apt-get install -y git python3-pip

# Installing boltkit
RUN pip3 install --user git+https://github.com/klobuczek/[email protected]#egg=boltkit
RUN echo "export PATH=/root/.local/bin:$PATH" >> ~/.bashrc

WORKDIR /app
COPY . .
RUN ./bin/setup

CMD ["bundle exec rspec spec"]
24 changes: 24 additions & 0 deletions Dockerfile-ruby
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
ARG JAVA_VERSION

FROM ruby:3.4

ENV JAVA_VERSION=$JAVA_VERSION

# Adding Java package
RUN apt install -y wget apt-transport-https gpg
RUN wget -qO - https://packages.adoptium.net/artifactory/api/gpg/key/public | gpg --dearmor | tee /etc/apt/trusted.gpg.d/adoptium.gpg > /dev/null
RUN echo "deb https://packages.adoptium.net/artifactory/deb $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" | tee /etc/apt/sources.list.d/adoptium.list

# Installing packages
RUN echo "Installing Java $JAVA_VERSION"
RUN apt-get update && apt-get upgrade -y && apt-get install -y python3-pip temurin-$JAVA_VERSION-jdk

# Installing boltkit
RUN pip3 install --user git+https://github.com/klobuczek/[email protected]#egg=boltkit --break-system-packages
RUN echo "export PATH=/root/.local/bin:$PATH" >> ~/.bashrc

WORKDIR /app
COPY . .
RUN ./bin/setup

CMD ["bundle exec rspec spec"]
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,23 @@ At this moment [The Neo4j Drivers Manual v4.4](https://neo4j.com/docs/java-manua
This gem includes 2 different implementations: java driver wrapper and pure ruby driver

$ bin/setup

## Testing

## Testing with docker

The tests can be run with docker:

$ docker compose run ruby-driver bash
$ bundle exec rspec spec

or for jruby

$ docker compose run jruby-driver bash
$ bundle exec rspec spec

To test different versions of neo4j, set the environment variable `NEO4J_VERSION` to the version you want to test.
Keep in mind to change JAVA_VERSION in the Dockerfile if you want to test with different java versions.

## Testing natively

To run the tests the following tools need to be installed:

Expand Down Expand Up @@ -80,4 +95,3 @@ Suggestions, improvements, bug reports and pull requests are welcome on GitHub a
## License

The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

9 changes: 7 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ end.spec 'neo4j-ruby-driver' do
active_support_version = ENV['ACTIVE_SUPPORT_VERSION']
dependency 'activesupport', active_support_version&.length&.positive? ? "~> #{active_support_version}" : '>= 7.1'
# dependency 'async-rspec', '>= 0', :dev
dependency 'pry', '>= 0', :dev
dependency 'ffaker', '>= 0', :dev
dependency 'hoe', '>= 0', :dev
dependency 'hoe-bundler', '>= 0', :dev
Expand All @@ -32,6 +33,7 @@ end.spec 'neo4j-ruby-driver' do
dependency 'rspec-mocks', '>= 0', :dev
dependency 'zeitwerk', '>= 2.1.10'


spec_extras[:require_paths] = ['lib', jruby? ? 'jruby' : 'ruby']

self.clean_globs += %w[Gemfile Gemfile.lock *.gemspec lib/org lib/*_jars.rb]
Expand All @@ -47,10 +49,13 @@ end.spec 'neo4j-ruby-driver' do
spec_extras[:requirements] = ->(requirements) { requirements << 'jar org.neo4j.driver, neo4j-java-driver-all, 5.27.0' }
spec_extras[:platform] = 'java'
else
dependency 'async', '< 2.13'
dependency 'async', '>= 0'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do your changes work with async < 2.13?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not. I will adjust PR.

dependency 'async-io', '>= 0'
dependency 'connection_pool', '>= 0'
dependency 'csv', '>= 0'

if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.4')
dependency "csv", "~> 3.0" # CSV stdlib was moved in Ruby 3.4 to separate gem
end
end
end

Expand Down
43 changes: 43 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
version: '3'
x-environment: &environment
TEST_NEO4J_HOST: neo4j
TEST_NEO4J_PORT: 7687
TEST_NEO4J_USER: neo4j
TEST_NEO4J_PASS: pass
TEST_NEO4J_SCHEME: bolt
TEST_NEO4J_DATABASE: neo4j
NEO4J_VERSION: 5.26.0

services:
ruby-driver:
build:
context: .
dockerfile: Dockerfile-ruby
args:
JAVA_VERSION: 21
volumes:
- .:/app
links:
- neo4j
environment:
<<: *environment
jruby-driver:
build:
context: .
dockerfile: Dockerfile-jruby
args:
JAVA_VERSION: 21
volumes:
- .:/app
links:
- neo4j
environment:
<<: *environment
neo4j:
image: neo4j:4.4.5-enterprise
ports:
- 7474:7474
- 7687:7687
environment:
- NEO4J_AUTH=neo4j/pass
- NEO4J_ACCEPT_LICENSE_AGREEMENT=yes
4 changes: 2 additions & 2 deletions docs/dev_manual_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
# Example 4. Hello World
######################################

Neo4j::Driver::GraphDatabase.driver('bolt://localhost:7687',
Neo4j::Driver::AuthTokens.basic('neo4j', 'password')) do |driver|
Neo4j::Driver::GraphDatabase.driver("bolt://#{ENV['TEST_NEO4J_HOST']}:7687",
Neo4j::Driver::AuthTokens.basic('neo4j', 'pass')) do |driver|
driver.session do |session|
greeting = session.write_transaction do |tx|
result = tx.run("CREATE (a:Greeting) SET a.message = $message RETURN a.message + ', from node ' + id(a)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Internal
module Handlers
module Pulln
class AutoPullResponseHandler < BasicPullResponseHandler
delegate :signal, to: :@records
delegate :signal, to: :@queue_notification
LONG_MAX_VALUE = 2 ** 63 - 1

def initialize(query, run_response_handler, connection, metadata_extractor, completion_listener, fetch_size)
Expand All @@ -19,7 +19,8 @@ def initialize(query, run_response_handler, connection, metadata_extractor, comp
@low_record_watermark = fetch_size * 0.3
end

@records = ::Async::Queue.new
@queue_notification = ::Async::Notification.new
@records = ::Async::Queue.new(available: @queue_notification)
@auto_pull_enabled = true

install_record_and_summary_consumers
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/load_csv_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

RSpec.describe 'LoadCsv', csv: true do
let(:iris_class_names) { %w[Iris-setosa Iris-versicolor Iris-virginica] }
let(:file) { Tempfile.new('', 'tmp') }
let(:file) { Tempfile.new('', '/tmp') }
let(:file_path) { file.path }
let(:iris_data) do
%w[sepal_length,sepal_width,petal_length,petal_width,class_name
Expand Down
3 changes: 1 addition & 2 deletions spec/neo4j/driver/util/cc/cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ def driver(bolt_uri)
def core_member?(driver)
driver.session(default_access_mode: Neo4j::Driver::AccessMode::READ) do |session|
%w[LEADER FOLLOWER].include?(
session.run("CALL dbms.cluster.role($database)", database: 'neo4j')
.single.first
session.run("CALL dbms.cluster.role($database)", database: database).single.first
)
end
end
Expand Down
8 changes: 8 additions & 0 deletions spec/neo4j/driver/util/cc/cluster_control.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module CC
class ClusterControl
class << self
def install_cluster(neo4j_version, cores, read_replicas, password, port, path)
debug("Installing cluster at #{path}")
execute_command('neoctrl-cluster', 'install', '--cores', cores, '--read-replicas', read_replicas,
'--password', password, '--initial-port', port, neo4j_version, path)
end
Expand All @@ -20,22 +21,27 @@ def start_cluster(path)
end

def start_cluster_member(path)
debug("Starting cluster member")
execute_command('neoctrl-start', path)
end

def stop_cluster(path)
debug("Stopping cluster")
execute_command('neoctrl-cluster', 'stop', path) unless debug?
end

def stop_cluster_member(path)
debug("Stopping cluster member")
execute_command('neoctrl-stop', path)
end

def kill_cluster(path)
debug("Killing cluster")
execute_command('neoctrl-cluster', 'stop', '--kill', path)
end

def kill_cluster_member(path)
debug("Killing cluster member")
execute_command('neoctrl-stop', '--kill', path)
end

Expand Down Expand Up @@ -66,6 +72,8 @@ def output_line(type, base, increment, i)
def output_lines(type, base, increment, n)
n.times.map(&method(:output_line).curry.call(type, base, increment))
end

alias debug puts
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion spec/neo4j/driver/util/cc/shared_cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def start
# sleep(10)

@cluster.members = members
debug("Cluster started: #{members}.")
debug("Cluster started:")
members.each { |member| debug(" #{member.bolt_uri}") }
end

def start_member(member)
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
require 'rspec/its'
require 'support/driver_helper'
require 'support/neo4j_cleaner'
require 'pry'

RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
Expand Down
6 changes: 3 additions & 3 deletions spec/support/cluster_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
require 'neo4j/driver/util/cc/shared_cluster'

RSpec.shared_context 'cluster_extension' do
USER = 'neo4j'
PASSWORD = 'password'
NEO4J_VERSION = ENV['NEO4J_VERSION'] || '4.4.26'
USER = ENV.fetch('TEST_NEO4J_USER', 'neo4j')
PASSWORD = ENV.fetch('TEST_NEO4J_PASS', 'password')
NEO4J_VERSION = ENV.fetch('NEO4J_VERSION', '4.4.26')
CLUSTER_DIR = File.absolute_path("db/neo4j/test-cluster#{NEO4J_VERSION}")
INITIAL_PORT = 20_000

Expand Down
10 changes: 4 additions & 6 deletions spec/support/driver_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ def basic_auth_token
Neo4j::Driver::AuthTokens.basic(neo4j_user, neo4j_password)
end

def neo4j_user
ENV.fetch('TEST_NEO4J_USER', 'neo4j')
end
def neo4j_user = ENV.fetch('TEST_NEO4J_USER', 'neo4j')

def neo4j_password
ENV.fetch('TEST_NEO4J_PASS', 'password')
end
def neo4j_password = ENV.fetch('TEST_NEO4J_PASS', 'password')

def database = ENV.fetch('TEST_NEO4J_DATABASE', 'neo4j')

def driver
self.single_driver ||= Neo4j::Driver::GraphDatabase.driver(
Expand Down
Loading