From 34863fa861ecff3ee562584764fc30298486ab0d Mon Sep 17 00:00:00 2001 From: Nick Saukin Date: Tue, 20 May 2025 14:56:15 +0200 Subject: [PATCH 1/9] Fix notification_config --- jruby/neo4j/driver/ext/config_converter.rb | 2 +- spec/neo4j/driver/dev_manual_examples_spec.rb | 31 ++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/jruby/neo4j/driver/ext/config_converter.rb b/jruby/neo4j/driver/ext/config_converter.rb index 53cc5bdc..778ec5a5 100644 --- a/jruby/neo4j/driver/ext/config_converter.rb +++ b/jruby/neo4j/driver/ext/config_converter.rb @@ -70,7 +70,7 @@ def notification_config(minimum_severity: nil, disabled_categories: nil) org.neo4j.driver.internal.InternalNotificationConfig.new( value_of(org.neo4j.driver.internal.InternalNotificationSeverity, minimum_severity), disabled_categories - &.map { |value| value_of(org.neo4j.driver.internal.InternalNotificationCategory, value) } + &.map { |value| org.neo4j.driver.NotificationCategory.const_get(value.to_s.upcase) } &.then(&java.util.HashSet.method(:new))) end diff --git a/spec/neo4j/driver/dev_manual_examples_spec.rb b/spec/neo4j/driver/dev_manual_examples_spec.rb index ab227471..792b76d9 100644 --- a/spec/neo4j/driver/dev_manual_examples_spec.rb +++ b/spec/neo4j/driver/dev_manual_examples_spec.rb @@ -87,9 +87,15 @@ it { is_expected.to be true } end + + context 'Example 2.12. Notification config' do + let(:config) { { notification_config: { minimum_severity: :warning, disabled_categories: [:hint, :generic] } } } + + it { is_expected.to be true } + end end - context 'Example 2.12. Service unavailable' do + context 'Example 2.13. Service unavailable' do def add_item(driver) session = driver.session session.write_transaction { |tx| tx.run('CREATE (a:Item)') } @@ -293,4 +299,27 @@ def match_person_nodes(tx) expect(add_employees('abc')).to eq(2) end end + + context '5. Notification config' do + subject do + driver.session do |session| + result = session.run( + 'MATCH p=shortestPath((:Person {name: $start})-[*]->(:Person {name: $end})) RETURN p', + start: 'Alice', + end: 'Bob' + ) + result.consume.notifications.first&.code + end + end + + context 'Example 5.1. Default severity and categories' do + it { is_expected.to eq('Neo.ClientNotification.Statement.UnboundedVariableLengthPattern') } + end + + context 'Example 5.2. Custom severity and categories' do + let(:config) { { notification_config: { minimum_severity: :warning, disabled_categories: [:hint, :generic] } } } + + it { is_expected.not_to be nil } + end + end end From c418ace671fe514845d146bbea394874fbb99953 Mon Sep 17 00:00:00 2001 From: Nick Saukin Date: Mon, 26 May 2025 17:31:43 +0200 Subject: [PATCH 2/9] Fix specs --- spec/neo4j/driver/dev_manual_examples_spec.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/spec/neo4j/driver/dev_manual_examples_spec.rb b/spec/neo4j/driver/dev_manual_examples_spec.rb index 792b76d9..baafd7bb 100644 --- a/spec/neo4j/driver/dev_manual_examples_spec.rb +++ b/spec/neo4j/driver/dev_manual_examples_spec.rb @@ -300,7 +300,7 @@ def match_person_nodes(tx) end end - context '5. Notification config' do + context '5. Notification config', concurrency: true do subject do driver.session do |session| result = session.run( @@ -308,18 +308,26 @@ def match_person_nodes(tx) start: 'Alice', end: 'Bob' ) - result.consume.notifications.first&.code + result.consume.notifications.map(&:code) end end + let(:host) { 'localhost' } # work around for https://github.com/neo4j/neo4j-java-driver/issues/1652 + let(:neo4j_user) { ENV.fetch('TEST_NEO4J_USER', 'neo4j') } + let(:neo4j_password) { ENV.fetch('TEST_NEO4J_PASS', 'password') } + let(:auth_tokens) { Neo4j::Driver::AuthTokens.basic(neo4j_user, neo4j_password) } + let(:driver) { Neo4j::Driver::GraphDatabase.driver(uri, auth_tokens, **config) } + context 'Example 5.1. Default severity and categories' do - it { is_expected.to eq('Neo.ClientNotification.Statement.UnboundedVariableLengthPattern') } + let(:config) { {} } + + it { is_expected.to include('Neo.ClientNotification.Statement.UnboundedVariableLengthPattern') } end context 'Example 5.2. Custom severity and categories' do let(:config) { { notification_config: { minimum_severity: :warning, disabled_categories: [:hint, :generic] } } } - it { is_expected.not_to be nil } + it { is_expected.to be_empty } end end end From 72fd11d55fb105a497ceadce69952ccbcc51f50e Mon Sep 17 00:00:00 2001 From: Nick Saukin Date: Mon, 26 May 2025 17:41:51 +0200 Subject: [PATCH 3/9] Simplify check because of different codes among versions --- spec/neo4j/driver/dev_manual_examples_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/neo4j/driver/dev_manual_examples_spec.rb b/spec/neo4j/driver/dev_manual_examples_spec.rb index baafd7bb..9481f498 100644 --- a/spec/neo4j/driver/dev_manual_examples_spec.rb +++ b/spec/neo4j/driver/dev_manual_examples_spec.rb @@ -321,7 +321,7 @@ def match_person_nodes(tx) context 'Example 5.1. Default severity and categories' do let(:config) { {} } - it { is_expected.to include('Neo.ClientNotification.Statement.UnboundedVariableLengthPattern') } + it { is_expected.not_to be_empty } end context 'Example 5.2. Custom severity and categories' do From 16e1d454813793c87e53113d866fa960eeeab83c Mon Sep 17 00:00:00 2001 From: Nick Saukin Date: Wed, 28 May 2025 17:25:47 +0200 Subject: [PATCH 4/9] Use public Java API --- jruby/neo4j/driver/ext/config_converter.rb | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/jruby/neo4j/driver/ext/config_converter.rb b/jruby/neo4j/driver/ext/config_converter.rb index 778ec5a5..493b9253 100644 --- a/jruby/neo4j/driver/ext/config_converter.rb +++ b/jruby/neo4j/driver/ext/config_converter.rb @@ -67,15 +67,21 @@ def trust_strategy(**config) end def notification_config(minimum_severity: nil, disabled_categories: nil) - org.neo4j.driver.internal.InternalNotificationConfig.new( - value_of(org.neo4j.driver.internal.InternalNotificationSeverity, minimum_severity), - disabled_categories - &.map { |value| org.neo4j.driver.NotificationCategory.const_get(value.to_s.upcase) } - &.then(&java.util.HashSet.method(:new))) - end + config = org.neo4j.driver.NotificationConfig.defaultConfig + + if minimum_severity + severity = org.neo4j.driver.NotificationSeverity.const_get(minimum_severity.to_s.upcase) + config = config.enableMinimumSeverity(severity) + end + + if disabled_categories&.any? + categories = disabled_categories.map do |category| + org.neo4j.driver.NotificationCategory.const_get(category.to_s.upcase) + end + config = config.disableCategories(java.util.HashSet.new(categories)) + end - def value_of(klass, value) - klass.value_of(value&.to_s&.upcase).or_else(nil) + config end end end From 1d9575fc2f8af289bf01804c2bbb47a874206613 Mon Sep 17 00:00:00 2001 From: Nick Saukin Date: Wed, 28 May 2025 17:37:32 +0200 Subject: [PATCH 5/9] Disable specs for old server versions --- spec/neo4j/driver/dev_manual_examples_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/neo4j/driver/dev_manual_examples_spec.rb b/spec/neo4j/driver/dev_manual_examples_spec.rb index 9481f498..4cb5ef61 100644 --- a/spec/neo4j/driver/dev_manual_examples_spec.rb +++ b/spec/neo4j/driver/dev_manual_examples_spec.rb @@ -300,7 +300,7 @@ def match_person_nodes(tx) end end - context '5. Notification config', concurrency: true do + context '5. Notification config', version: '>=5', concurrency: true do subject do driver.session do |session| result = session.run( From 44e71677397e1ed3fb9bf99a0f5dbfea1f8fdc1b Mon Sep 17 00:00:00 2001 From: Nick Saukin Date: Wed, 28 May 2025 17:38:21 +0200 Subject: [PATCH 6/9] Add constants --- .../neo4j/driver/notification_classification.rb | 17 +++++++++++++++++ jruby/neo4j/driver/notification_severity.rb | 11 +++++++++++ .../neo4j/driver/notification_classification.rb | 17 +++++++++++++++++ ruby/neo4j/driver/notification_severity.rb | 11 +++++++++++ 4 files changed, 56 insertions(+) create mode 100644 jruby/neo4j/driver/notification_classification.rb create mode 100644 jruby/neo4j/driver/notification_severity.rb create mode 100644 ruby/neo4j/driver/notification_classification.rb create mode 100644 ruby/neo4j/driver/notification_severity.rb diff --git a/jruby/neo4j/driver/notification_classification.rb b/jruby/neo4j/driver/notification_classification.rb new file mode 100644 index 00000000..550abf5d --- /dev/null +++ b/jruby/neo4j/driver/notification_classification.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Neo4j + module Driver + module NotificationClassification + DEPRECATION = :deprecation + GENERIC = :generic + HINT = :hint + PERFORMANCE = :performance + SCHEMA = :schema + SECURITY = :security + TOPOLOGY = :topology + UNRECOGNIZED = :unrecognized + UNSUPPORTED = :unsupported + end + end +end diff --git a/jruby/neo4j/driver/notification_severity.rb b/jruby/neo4j/driver/notification_severity.rb new file mode 100644 index 00000000..7cb60b5b --- /dev/null +++ b/jruby/neo4j/driver/notification_severity.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Neo4j + module Driver + module NotificationSeverity + INFORMATION = :information + OFF = :off + WARNING = :warning + end + end +end diff --git a/ruby/neo4j/driver/notification_classification.rb b/ruby/neo4j/driver/notification_classification.rb new file mode 100644 index 00000000..550abf5d --- /dev/null +++ b/ruby/neo4j/driver/notification_classification.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Neo4j + module Driver + module NotificationClassification + DEPRECATION = :deprecation + GENERIC = :generic + HINT = :hint + PERFORMANCE = :performance + SCHEMA = :schema + SECURITY = :security + TOPOLOGY = :topology + UNRECOGNIZED = :unrecognized + UNSUPPORTED = :unsupported + end + end +end diff --git a/ruby/neo4j/driver/notification_severity.rb b/ruby/neo4j/driver/notification_severity.rb new file mode 100644 index 00000000..7cb60b5b --- /dev/null +++ b/ruby/neo4j/driver/notification_severity.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Neo4j + module Driver + module NotificationSeverity + INFORMATION = :information + OFF = :off + WARNING = :warning + end + end +end From bd6d4c976a447d58deed98b859fa5ca90bf02a46 Mon Sep 17 00:00:00 2001 From: Nick Saukin Date: Wed, 28 May 2025 21:18:41 +0200 Subject: [PATCH 7/9] Remove constants from jruby --- .../neo4j/driver/notification_classification.rb | 17 ----------------- jruby/neo4j/driver/notification_severity.rb | 11 ----------- 2 files changed, 28 deletions(-) delete mode 100644 jruby/neo4j/driver/notification_classification.rb delete mode 100644 jruby/neo4j/driver/notification_severity.rb diff --git a/jruby/neo4j/driver/notification_classification.rb b/jruby/neo4j/driver/notification_classification.rb deleted file mode 100644 index 550abf5d..00000000 --- a/jruby/neo4j/driver/notification_classification.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -module Neo4j - module Driver - module NotificationClassification - DEPRECATION = :deprecation - GENERIC = :generic - HINT = :hint - PERFORMANCE = :performance - SCHEMA = :schema - SECURITY = :security - TOPOLOGY = :topology - UNRECOGNIZED = :unrecognized - UNSUPPORTED = :unsupported - end - end -end diff --git a/jruby/neo4j/driver/notification_severity.rb b/jruby/neo4j/driver/notification_severity.rb deleted file mode 100644 index 7cb60b5b..00000000 --- a/jruby/neo4j/driver/notification_severity.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -module Neo4j - module Driver - module NotificationSeverity - INFORMATION = :information - OFF = :off - WARNING = :warning - end - end -end From 47bcd2c8d5a7e21450729f963f4b16000dd787a5 Mon Sep 17 00:00:00 2001 From: Nick Saukin Date: Wed, 28 May 2025 21:39:46 +0200 Subject: [PATCH 8/9] Refactor --- jruby/neo4j/driver/ext/config_converter.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/jruby/neo4j/driver/ext/config_converter.rb b/jruby/neo4j/driver/ext/config_converter.rb index 493b9253..14929910 100644 --- a/jruby/neo4j/driver/ext/config_converter.rb +++ b/jruby/neo4j/driver/ext/config_converter.rb @@ -70,15 +70,16 @@ def notification_config(minimum_severity: nil, disabled_categories: nil) config = org.neo4j.driver.NotificationConfig.defaultConfig if minimum_severity - severity = org.neo4j.driver.NotificationSeverity.const_get(minimum_severity.to_s.upcase) - config = config.enableMinimumSeverity(severity) + config = config.enableMinimumSeverity( + org.neo4j.driver.NotificationSeverity.java_class.field(minimum_severity.upcase).value(nil) + ) end if disabled_categories&.any? - categories = disabled_categories.map do |category| - org.neo4j.driver.NotificationCategory.const_get(category.to_s.upcase) - end - config = config.disableCategories(java.util.HashSet.new(categories)) + config = config.disableCategories( + disabled_categories + .map { |value| org.neo4j.driver.NotificationClassification.value_of(value.upcase) } + .then(&java.util.HashSet.method(:new))) end config From a37fcb599afb392047faa75b6db457c9f73201cf Mon Sep 17 00:00:00 2001 From: Nick Saukin Date: Thu, 29 May 2025 18:09:09 +0200 Subject: [PATCH 9/9] Reduce changes --- jruby/neo4j/driver/ext/config_converter.rb | 23 ++++++++-------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/jruby/neo4j/driver/ext/config_converter.rb b/jruby/neo4j/driver/ext/config_converter.rb index 14929910..64ed28d7 100644 --- a/jruby/neo4j/driver/ext/config_converter.rb +++ b/jruby/neo4j/driver/ext/config_converter.rb @@ -67,22 +67,15 @@ def trust_strategy(**config) end def notification_config(minimum_severity: nil, disabled_categories: nil) - config = org.neo4j.driver.NotificationConfig.defaultConfig - - if minimum_severity - config = config.enableMinimumSeverity( - org.neo4j.driver.NotificationSeverity.java_class.field(minimum_severity.upcase).value(nil) - ) - end - - if disabled_categories&.any? - config = config.disableCategories( - disabled_categories - .map { |value| org.neo4j.driver.NotificationClassification.value_of(value.upcase) } - .then(&java.util.HashSet.method(:new))) - end + org.neo4j.driver.internal.InternalNotificationConfig.new( + value_of(org.neo4j.driver.internal.InternalNotificationSeverity, minimum_severity).or_else(nil), + disabled_categories + &.map { |value| value_of(org.neo4j.driver.NotificationClassification, value) } + &.then(&java.util.HashSet.method(:new))) + end - config + def value_of(klass, value) + klass.value_of(value&.to_s&.upcase) end end end