Skip to content

Fix notification config #254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 15 commits into
base: 5.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions jruby/neo4j/driver/ext/config_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ def trust_strategy(**config)

def notification_config(minimum_severity: nil, disabled_categories: nil)
org.neo4j.driver.internal.InternalNotificationConfig.new(
value_of(org.neo4j.driver.internal.InternalNotificationSeverity, minimum_severity),
value_of(org.neo4j.driver.internal.InternalNotificationSeverity, minimum_severity).or_else(nil),
disabled_categories
&.map { |value| value_of(org.neo4j.driver.internal.InternalNotificationCategory, value) }
Copy link
Member

Choose a reason for hiding this comment

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

@nsauk could you check. It appears to me that the only change needed was this line:

&.map { |value| value_of(org.neo4j.driver.NotificationClassification, value) }

Copy link
Member

Choose a reason for hiding this comment

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

Maybe, additionally move the .or_else(nil) from value_of method to the line 71 as the value_of of java enum, which NotificationClassification now is, does not return Optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I rewrote the rest of this method using the Java driver's public API so we rely less on internals.

InternalNotificationSeverity works with value_of, but NotificationSeverity fails because it's an interface. As far as I can understand, we can't use the same approach for both (unless it's const_get).

&.map { |value| value_of(org.neo4j.driver.NotificationClassification, value) }
&.then(&java.util.HashSet.method(:new)))
end

def value_of(klass, value)
klass.value_of(value&.to_s&.upcase).or_else(nil)
klass.value_of(value&.to_s&.upcase)
end
end
end
Expand Down
17 changes: 17 additions & 0 deletions ruby/neo4j/driver/notification_classification.rb
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions ruby/neo4j/driver/notification_severity.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module Neo4j
module Driver
module NotificationSeverity
INFORMATION = :information
OFF = :off
WARNING = :warning
end
end
end
39 changes: 38 additions & 1 deletion spec/neo4j/driver/dev_manual_examples_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.execute_write { |tx| tx.run('CREATE (a:Item)') }
Expand Down Expand Up @@ -293,4 +299,35 @@ def match_person_nodes(tx)
expect(add_employees('abc')).to eq(2)
end
end

context '5. Notification config', version: '>=5', concurrency: true 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.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
let(:config) { {} }

it { is_expected.not_to be_empty }
end

context 'Example 5.2. Custom severity and categories' do
let(:config) { { notification_config: { minimum_severity: :warning, disabled_categories: [:hint, :generic] } } }

it { is_expected.to be_empty }
end
end
end
Loading