Skip to content
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

Package tidy up #549

Open
wants to merge 7 commits into
base: 5.0
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,12 @@ boltLogger := neo4j.ConsoleBoltLogger()
result, err := neo4j.ExecuteQuery(ctx, driver, query, params, transformer, neo4j.ExecuteQueryWithBoltLogger(boltLogger))

# for the regular session APIs (session.Run, session.BeginTransaction, session.ExecuteRead, session.ExecuteWrite)
session := driver.NewSession(neo4j.SessionConfig{BoltLogger: boltLogger})
session := driver.NewSession(config.SessionConfig{BoltLogger: boltLogger})
```

### Custom Bolt Logger

The `BoltLogger` field of the `neo4j.SessionConfig` struct is defined to be of interface `neo4j/log.BoltLogger` which has the following definition:
The `BoltLogger` field of the `config.SessionConfig` struct is defined to be of interface `neo4j/log.BoltLogger` which has the following definition:

```go
type BoltLogger interface {
Expand Down
11 changes: 6 additions & 5 deletions benchmark/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ import (

neo4j18 "github.com/neo4j/neo4j-go-driver/neo4j"
neo4j "github.com/neo4j/neo4j-go-driver/v5/neo4j"
"github.com/neo4j/neo4j-go-driver/v5/neo4j/config"
)

func getSetup(driver neo4j.Driver) *neo4j.Node {
// Check if setup already built
sess := driver.NewSession(neo4j.SessionConfig{})
sess := driver.NewSession(config.SessionConfig{})
defer sess.Close()

result, err := sess.Run("MATCH (s:Setup) RETURN s", nil)
Expand Down Expand Up @@ -71,7 +72,7 @@ func getBoolProp(node *neo4j.Node, name string, dflt bool) bool {

func buildSetup(driver neo4j.Driver, setup *neo4j.Node) {

sess := driver.NewSession(neo4j.SessionConfig{})
sess := driver.NewSession(config.SessionConfig{})
defer sess.Close()

if !getBoolProp(setup, "iterMxL", false) {
Expand All @@ -95,7 +96,7 @@ func buildSetup(driver neo4j.Driver, setup *neo4j.Node) {
}

func iterMxL(driver neo4j.Driver) {
sess := driver.NewSession(neo4j.SessionConfig{})
sess := driver.NewSession(config.SessionConfig{})
defer sess.Close()

result, err := sess.Run("MATCH (n:IterMxL) RETURN n", nil)
Expand Down Expand Up @@ -153,7 +154,7 @@ func buildParamsLMap() map[string]any {

func params(driver neo4j.Driver, m map[string]any, n int) {
// Use same session for all of n, not part of measurement
session := driver.NewSession(neo4j.SessionConfig{})
session := driver.NewSession(config.SessionConfig{})
for i := 0; i < n; i++ {
_, err := session.Run("RETURN 0", m)
if err != nil {
Expand All @@ -179,7 +180,7 @@ func params18(driver neo4j18.Driver, m map[string]any, n int) {
// Include session creation in measurement
func getS(driver neo4j.Driver, n int) {
for i := 0; i < n; i++ {
session := driver.NewSession(neo4j.SessionConfig{})
session := driver.NewSession(config.SessionConfig{})
x, _ := session.ReadTransaction(func(tx neo4j.Transaction) (any, error) {
res, err := tx.Run("RETURN $i", map[string]any{"i": i})
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions neo4j/auth/auth_examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ package auth_test
import (
"context"
"fmt"
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
"github.com/neo4j/neo4j-go-driver/v5/neo4j/auth"
"os"
"time"

"github.com/neo4j/neo4j-go-driver/v5/neo4j"
"github.com/neo4j/neo4j-go-driver/v5/neo4j/auth"
)

func ExampleBasicTokenManager() {
Expand Down
15 changes: 8 additions & 7 deletions neo4j/bookmarks.go → neo4j/bookmarks/bookmarks.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
* limitations under the License.
*/

package neo4j
package bookmarks

import (
"context"
"github.com/neo4j/neo4j-go-driver/v5/neo4j/internal/collections"
"sync"

"github.com/neo4j/neo4j-go-driver/v5/neo4j/internal/collections"
)

// Bookmarks is a holder for server-side bookmarks which are used for causally-chained sessions.
Expand Down Expand Up @@ -54,14 +55,14 @@ type BookmarkManagerConfig struct {
BookmarkConsumer func(ctx context.Context, bookmarks Bookmarks) error
}

type bookmarkManager struct {
type DefaultBookmarkManager struct {
bookmarks collections.Set[string]
supplyBookmarks func(context.Context) (Bookmarks, error)
consumeBookmarks func(context.Context, Bookmarks) error
mutex sync.RWMutex
}

func (b *bookmarkManager) UpdateBookmarks(ctx context.Context, previousBookmarks, newBookmarks Bookmarks) error {
func (b *DefaultBookmarkManager) UpdateBookmarks(ctx context.Context, previousBookmarks, newBookmarks Bookmarks) error {
if len(newBookmarks) == 0 {
return nil
}
Expand All @@ -77,7 +78,7 @@ func (b *bookmarkManager) UpdateBookmarks(ctx context.Context, previousBookmarks
return nil
}

func (b *bookmarkManager) GetBookmarks(ctx context.Context) (Bookmarks, error) {
func (b *DefaultBookmarkManager) GetBookmarks(ctx context.Context) (Bookmarks, error) {
var extraBookmarks Bookmarks
if b.supplyBookmarks != nil {
bookmarks, err := b.supplyBookmarks(ctx)
Expand All @@ -100,7 +101,7 @@ func (b *bookmarkManager) GetBookmarks(ctx context.Context) (Bookmarks, error) {
}

func NewBookmarkManager(config BookmarkManagerConfig) BookmarkManager {
return &bookmarkManager{
return &DefaultBookmarkManager{
bookmarks: collections.NewSet(config.InitialBookmarks),
supplyBookmarks: config.BookmarkSupplier,
consumeBookmarks: config.BookmarkConsumer,
Expand All @@ -111,7 +112,7 @@ func NewBookmarkManager(config BookmarkManagerConfig) BookmarkManager {
// Let s1, s2, s3 be Session interfaces. You can easily causally chain the sessions like so:
// ```go
//
// s4 := driver.NewSession(neo4j.SessionConfig{
// s4 := driver.NewSession(config.SessionConfig{
// Bookmarks: neo4j.CombineBookmarks(s1.LastBookmarks(), s2.LastBookmarks(), s3.LastBookmarks()),
// })
//
Expand Down
78 changes: 31 additions & 47 deletions neo4j/bookmarks_test.go → neo4j/bookmarks/bookmarks_test.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,17 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [https://neo4j.com]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package neo4j_test
package bookmarks_test

import (
"context"
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
. "github.com/neo4j/neo4j-go-driver/v5/neo4j/internal/testutil"
"testing"
"testing/quick"

bm "github.com/neo4j/neo4j-go-driver/v5/neo4j/bookmarks"
. "github.com/neo4j/neo4j-go-driver/v5/neo4j/internal/testutil"
)

func TestCombineBookmarks(t *testing.T) {
f := func(slices []neo4j.Bookmarks) bool {
concatenation := neo4j.CombineBookmarks(slices...)
f := func(slices []bm.Bookmarks) bool {
concatenation := bm.CombineBookmarks(slices...)
totalLen := 0
for _, s := range slices {
totalLen += len(s)
Expand Down Expand Up @@ -57,8 +41,8 @@ func TestBookmarkManager(outer *testing.T) {
outer.Parallel()

outer.Run("deduplicates initial bookmarks", func(t *testing.T) {
bookmarkManager := neo4j.NewBookmarkManager(neo4j.BookmarkManagerConfig{
InitialBookmarks: neo4j.Bookmarks{"a", "a", "b"},
bookmarkManager := bm.NewBookmarkManager(bm.BookmarkManagerConfig{
InitialBookmarks: bm.Bookmarks{"a", "a", "b"},
})

bookmarks, err := bookmarkManager.GetBookmarks(ctx)
Expand All @@ -68,7 +52,7 @@ func TestBookmarkManager(outer *testing.T) {
})

outer.Run("gets no bookmarks by default", func(t *testing.T) {
bookmarkManager := neo4j.NewBookmarkManager(neo4j.BookmarkManagerConfig{})
bookmarkManager := bm.NewBookmarkManager(bm.BookmarkManagerConfig{})
getBookmarks := func(db string) bool {
bookmarks, err := bookmarkManager.GetBookmarks(ctx)
AssertNoError(t, err)
Expand All @@ -81,11 +65,11 @@ func TestBookmarkManager(outer *testing.T) {
})

outer.Run("gets bookmarks along with user-supplied bookmarks", func(t *testing.T) {
expectedBookmarks := neo4j.Bookmarks{"a", "b", "c"}
bookmarkManager := neo4j.NewBookmarkManager(neo4j.BookmarkManagerConfig{
InitialBookmarks: neo4j.Bookmarks{"a", "b"},
BookmarkSupplier: func(context.Context) (neo4j.Bookmarks, error) {
return neo4j.Bookmarks{"b", "c"}, nil
expectedBookmarks := bm.Bookmarks{"a", "b", "c"}
bookmarkManager := bm.NewBookmarkManager(bm.BookmarkManagerConfig{
InitialBookmarks: bm.Bookmarks{"a", "b"},
BookmarkSupplier: func(context.Context) (bm.Bookmarks, error) {
return bm.Bookmarks{"b", "c"}, nil
},
})

Expand All @@ -97,14 +81,14 @@ func TestBookmarkManager(outer *testing.T) {
outer.Run("user-supplied bookmarks do not alter internal bookmarks", func(t *testing.T) {
calls := 0
expectedBookmarks := []string{"a"}
bookmarkManager := neo4j.NewBookmarkManager(neo4j.BookmarkManagerConfig{
InitialBookmarks: neo4j.Bookmarks{"a"},
BookmarkSupplier: func(ctx2 context.Context) (neo4j.Bookmarks, error) {
bookmarkManager := bm.NewBookmarkManager(bm.BookmarkManagerConfig{
InitialBookmarks: bm.Bookmarks{"a"},
BookmarkSupplier: func(ctx2 context.Context) (bm.Bookmarks, error) {
defer func() {
calls++
}()
if calls == 0 {
return neo4j.Bookmarks{"b"}, nil
return bm.Bookmarks{"b"}, nil
}
return nil, nil
},
Expand All @@ -119,8 +103,8 @@ func TestBookmarkManager(outer *testing.T) {

outer.Run("returned bookmarks are copies", func(t *testing.T) {
expectedBookmarks := []string{"a"}
bookmarkManager := neo4j.NewBookmarkManager(neo4j.BookmarkManagerConfig{
InitialBookmarks: neo4j.Bookmarks{"a"},
bookmarkManager := bm.NewBookmarkManager(bm.BookmarkManagerConfig{
InitialBookmarks: bm.Bookmarks{"a"},
})
bookmarks, err := bookmarkManager.GetBookmarks(ctx)
AssertNoError(t, err)
Expand All @@ -133,8 +117,8 @@ func TestBookmarkManager(outer *testing.T) {
})

outer.Run("updates bookmarks", func(t *testing.T) {
bookmarkManager := neo4j.NewBookmarkManager(neo4j.BookmarkManagerConfig{
InitialBookmarks: neo4j.Bookmarks{"a", "b", "c"},
bookmarkManager := bm.NewBookmarkManager(bm.BookmarkManagerConfig{
InitialBookmarks: bm.Bookmarks{"a", "b", "c"},
})

err := bookmarkManager.UpdateBookmarks(ctx, []string{"b", "c"}, []string{"d", "a"})
Expand All @@ -149,8 +133,8 @@ func TestBookmarkManager(outer *testing.T) {
outer.Run("notifies updated bookmarks for new DB", func(t *testing.T) {
notifyHookCalled := false
expectedBookmarks := []string{"a", "d"}
bookmarkManager := neo4j.NewBookmarkManager(neo4j.BookmarkManagerConfig{
BookmarkConsumer: func(_ context.Context, bookmarks neo4j.Bookmarks) error {
bookmarkManager := bm.NewBookmarkManager(bm.BookmarkManagerConfig{
BookmarkConsumer: func(_ context.Context, bookmarks bm.Bookmarks) error {
notifyHookCalled = true
AssertEqualsInAnyOrder(t, bookmarks, expectedBookmarks)
return nil
Expand All @@ -170,9 +154,9 @@ func TestBookmarkManager(outer *testing.T) {

outer.Run("does not notify updated bookmarks when empty", func(t *testing.T) {
initialBookmarks := []string{"a", "b"}
bookmarkManager := neo4j.NewBookmarkManager(neo4j.BookmarkManagerConfig{
bookmarkManager := bm.NewBookmarkManager(bm.BookmarkManagerConfig{
InitialBookmarks: initialBookmarks,
BookmarkConsumer: func(_ context.Context, bookmarks neo4j.Bookmarks) error {
BookmarkConsumer: func(_ context.Context, bookmarks bm.Bookmarks) error {
t.Error("I must not be called")
return nil
},
Expand All @@ -189,9 +173,9 @@ func TestBookmarkManager(outer *testing.T) {
outer.Run("notifies updated bookmarks for existing DB without bookmarks", func(t *testing.T) {
notifyHookCalled := false
expectedBookmarks := []string{"a", "d"}
bookmarkManager := neo4j.NewBookmarkManager(neo4j.BookmarkManagerConfig{
bookmarkManager := bm.NewBookmarkManager(bm.BookmarkManagerConfig{
InitialBookmarks: nil,
BookmarkConsumer: func(_ context.Context, bookmarks neo4j.Bookmarks) error {
BookmarkConsumer: func(_ context.Context, bookmarks bm.Bookmarks) error {
notifyHookCalled = true
AssertEqualsInAnyOrder(t, bookmarks, expectedBookmarks)
return nil
Expand All @@ -212,9 +196,9 @@ func TestBookmarkManager(outer *testing.T) {
outer.Run("notifies updated bookmarks for existing DB with previous bookmarks", func(t *testing.T) {
notifyHookCalled := false
expectedBookmarks := []string{"a", "d"}
bookmarkManager := neo4j.NewBookmarkManager(neo4j.BookmarkManagerConfig{
InitialBookmarks: neo4j.Bookmarks{"a", "b", "c"},
BookmarkConsumer: func(_ context.Context, bookmarks neo4j.Bookmarks) error {
bookmarkManager := bm.NewBookmarkManager(bm.BookmarkManagerConfig{
InitialBookmarks: bm.Bookmarks{"a", "b", "c"},
BookmarkConsumer: func(_ context.Context, bookmarks bm.Bookmarks) error {
notifyHookCalled = true
AssertEqualsInAnyOrder(t, bookmarks, expectedBookmarks)
return nil
Expand Down
18 changes: 16 additions & 2 deletions neo4j/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,30 @@
package neo4j

import (
"github.com/neo4j/neo4j-go-driver/v5/neo4j/config"
"github.com/neo4j/neo4j-go-driver/v5/neo4j/notifications"
"math"
"net/url"
"time"

"github.com/neo4j/neo4j-go-driver/v5/neo4j/bookmarks"
"github.com/neo4j/neo4j-go-driver/v5/neo4j/config"
"github.com/neo4j/neo4j-go-driver/v5/neo4j/notifications"
)

// Deprecated: please use config.Config directly. This alias will be removed in 6.0.
type Config = config.Config

// Deprecated: please use config.SessionConfig directly. This alias will be removed in 6.0.
type SessionConfig = config.SessionConfig

// Deprecated: please use config.AccessMode directly. This alias will be removed in 6.0.
type AccessMode = config.AccessMode

// Deprecated: please use config.TransactionConfig directly. This alias will be removed in 6.0.
type TransactionConfig = config.TransactionConfig

// Deprecated: please use bookmarks.Bookmarks directly. This alias will be removed in 6.0.
type Bookmarks = bookmarks.Bookmarks

// Deprecated: please use config.ServerAddressResolver directly. This alias will be removed in 6.0.
type ServerAddressResolver = config.ServerAddressResolver

Expand Down
3 changes: 2 additions & 1 deletion neo4j/config/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ package config
import (
"crypto/tls"
"crypto/x509"
"time"

"github.com/neo4j/neo4j-go-driver/v5/neo4j/log"
"github.com/neo4j/neo4j-go-driver/v5/neo4j/notifications"
"time"
)

// A Config contains options that can be used to customize certain
Expand Down
Loading