Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit 76c4ae4

Browse files
author
Eric Solender
authored
Merge pull request #1 from mindstand/working_overhaul
Working overhaul
2 parents e4a4016 + ee58e88 commit 76c4ae4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+4609
-3318
lines changed

bolt_mode/consts.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package bolt_mode
2+
3+
type AccessMode int
4+
5+
const (
6+
ReadMode AccessMode = 0
7+
WriteMode AccessMode = 1
8+
)

client.go

Lines changed: 29 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,28 @@ type IClient interface {
1313

1414
// opens a internalDriver pool to neo4j
1515
NewDriverPool(size int) (IDriverPool, error)
16-
17-
// opens a v4 internalDriver
18-
NewDriverV4() (IDriverV4, error)
19-
20-
// opens a v4 internalDriver pool
21-
NewDriverPoolV4(size int) (IDriverPoolV4, error)
2216
}
2317

2418
type Client struct {
2519
// config stuff
26-
connStr string
27-
host string
28-
port int
29-
routing bool
30-
pooled bool
31-
maxConnections int
32-
negotiateVersion bool
33-
user string
34-
password string
35-
serverVersion []byte
36-
timeout time.Duration
37-
chunkSize uint16
38-
useTLS bool
39-
certFile string
40-
caCertFile string
41-
keyFile string
42-
tlsNoVerify bool
43-
readOnly bool
44-
supportsV4 bool
45-
createDbIfNotExists bool
20+
connStr string
21+
host string
22+
port int
23+
routing bool
24+
pooled bool
25+
maxConnections int
26+
negotiateVersion bool
27+
user string
28+
password string
29+
serverVersionBytes []byte
30+
serverVersion int
31+
timeout time.Duration
32+
chunkSize uint16
33+
useTLS bool
34+
certFile string
35+
caCertFile string
36+
keyFile string
37+
tlsNoVerify bool
4638
}
4739

4840
func NewClient(opts ...Opt) (IClient, error) {
@@ -68,12 +60,6 @@ func NewClient(opts ...Opt) (IClient, error) {
6860
client.timeout = time.Second * time.Duration(60)
6961
}
7062

71-
// check version set correctly
72-
if len(client.serverVersion) == 0 {
73-
// set the server version, default to 3
74-
client.serverVersion = make([]byte, 4)
75-
}
76-
7763
// check chunk size
7864
if client.chunkSize == 0 {
7965
// set default chunk size
@@ -104,11 +90,6 @@ func NewClient(opts ...Opt) (IClient, error) {
10490
return nil, errors.Wrap(errors.ErrConfiguration, "user can not be empty")
10591
}
10692

107-
// todo check if neo4j allows passwordless users
108-
if client.password == "" {
109-
return nil, errors.Wrap(errors.ErrConfiguration, "password can not be empty")
110-
}
111-
11293
client.connStr = fmt.Sprintf("%s://%s:%s@%s:%v", protocol, client.user, client.password, client.host, client.port)
11394

11495
// append tls portion if needed
@@ -123,14 +104,12 @@ func NewClient(opts ...Opt) (IClient, error) {
123104
}
124105

125106
func (c *Client) NewDriver() (IDriver, error) {
107+
if c.routing {
108+
return nil, errors.New("can not open non pooled driver with routing enabled")
109+
}
110+
126111
driver := &internalDriver{
127-
createIfNotExists: c.createDbIfNotExists,
128-
connectionFactory: &boltConnectionFactory{
129-
timeout: c.timeout,
130-
chunkSize: c.chunkSize,
131-
serverVersion: c.serverVersion,
132-
connStr: c.connStr,
133-
},
112+
client: c,
134113
}
135114

136115
return &Driver{internalDriver: driver}, nil
@@ -142,42 +121,11 @@ func (c *Client) NewDriverPool(size int) (IDriverPool, error) {
142121
return nil, err
143122
}
144123

145-
return &DriverPool{
146-
internalPool: driverPool,
147-
}, nil
148-
}
149-
150-
func (c *Client) NewDriverV4() (IDriverV4, error) {
151-
if !c.supportsV4 {
152-
return nil, errors.Wrap(errors.ErrInvalidVersion, "attempting to use v4 internalDriver when actual version is [%s]", string(c.serverVersion))
124+
if c.routing {
125+
return newRoutingPool(c, size)
126+
} else {
127+
return &DriverPool{
128+
internalPool: driverPool,
129+
}, nil
153130
}
154-
155-
driver := &internalDriver{
156-
createIfNotExists: c.createDbIfNotExists,
157-
connectionFactory: &boltConnectionFactory{
158-
timeout: c.timeout,
159-
chunkSize: c.chunkSize,
160-
serverVersion: c.serverVersion,
161-
connStr: c.connStr,
162-
},
163-
}
164-
165-
return &DriverV4{
166-
internalDriver: driver,
167-
}, nil
168-
}
169-
170-
func (c *Client) NewDriverPoolV4(size int) (IDriverPoolV4, error) {
171-
if !c.supportsV4 {
172-
return nil, errors.Wrap(errors.ErrInvalidVersion, "attempting to use v4 internalDriver when actual version is [%s]", string(c.serverVersion))
173-
}
174-
175-
driverPool, err := newDriverPool(c.connStr, size)
176-
if err != nil {
177-
return nil, err
178-
}
179-
180-
return &DriverPoolV4{
181-
internalPool: driverPool,
182-
}, nil
183131
}

client_test.go

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,56 @@
11
package goBolt
22

33
import (
4-
ll "github.com/mindstand/go-bolt/log"
5-
"log"
4+
"github.com/mindstand/go-bolt/bolt_mode"
5+
"github.com/mindstand/go-bolt/log"
66
"testing"
77
)
88

99
func TestClient(t *testing.T) {
10-
ll.SetLevel("trace")
11-
client, err := NewClient(WithBasicAuth("neo4j", "changeme"), WithHostPort("0.0.0.0", 7687))
10+
log.SetLevel("trace")
11+
log.Info("opening client")
12+
client, err := NewClient(WithBasicAuth("neo4j", "TZU6xiVZLbe5L5UmZaU5"), WithHostPort("0.0.0.0", 7687))
1213
if err != nil {
1314
t.Log(err)
1415
t.FailNow()
1516
}
1617

18+
log.Infof("opening driver")
1719
driver, err := client.NewDriver()
1820
if err != nil {
1921
t.Log(err)
2022
t.FailNow()
2123
}
2224

23-
conn, err := driver.Open(ReadWriteMode)
25+
log.Info("opening connection")
26+
conn, err := driver.Open(bolt_mode.WriteMode)
2427
if err != nil {
2528
t.Log(err)
2629
t.FailNow()
2730
}
2831

29-
rows, err := conn.QueryNeo("match (n) return n", nil)
32+
log.Infof("executing query")
33+
rows, err := conn.Query("create (:TestNode{uuid:$id})", map[string]interface{}{
34+
"id": "random_id",
35+
})
3036
if err != nil {
3137
t.Log(err)
3238
t.FailNow()
3339
}
3440

35-
log.Println(rows.All())
41+
log.Infof("showing rows")
42+
all, m, err := rows.All()
43+
log.Tracef("rows: %v, %v, %v", all, m, err)
3644

45+
log.Trace("closing rows")
3746
err = rows.Close()
3847
if err != nil {
3948
t.Log(err)
4049
t.FailNow()
4150
}
42-
}
43-
44-
func TestClientV4(t *testing.T) {
45-
ll.SetLevel("trace")
46-
client, err := NewClient(WithBasicAuth("neo4j", "changeme"), WithHostPort("0.0.0.0", 7687), WithVersion("4"))
47-
if err != nil {
48-
t.Log(err)
49-
t.FailNow()
50-
}
5151

52-
driver, err := client.NewDriverV4()
53-
if err != nil {
54-
t.Log(err)
55-
t.FailNow()
56-
}
57-
58-
conn, err := driver.Open("system", ReadWriteMode)
59-
if err != nil {
60-
t.Log(err)
61-
t.FailNow()
62-
}
63-
64-
rows, err := conn.QueryNeo("match (n) return n", nil)
65-
if err != nil {
66-
t.Log(err)
67-
t.FailNow()
68-
}
69-
70-
log.Println(rows.All())
71-
72-
err = rows.Close()
52+
log.Trace("closing connection")
53+
err = conn.Close()
7354
if err != nil {
7455
t.Log(err)
7556
t.FailNow()

compose/docker-compose-3-5-cluster.yaml

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ networks:
66
services:
77

88
core1:
9-
image: neo4j:3.5-enterprise
9+
image: neo4j:3.5.14-enterprise
1010
networks:
1111
- lan
1212
ports:
@@ -31,7 +31,7 @@ services:
3131
- NEO4J_dbms_connector_bolt_listen__address=:7687
3232

3333
core2:
34-
image: neo4j:3.5-enterprise
34+
image: neo4j:3.5.14-enterprise
3535
networks:
3636
- lan
3737
ports:
@@ -55,7 +55,7 @@ services:
5555
- NEO4J_dbms_connector_bolt_listen__address=:7688
5656

5757
core3:
58-
image: neo4j:3.5-enterprise
58+
image: neo4j:3.5.14-enterprise
5959
networks:
6060
- lan
6161
ports:
@@ -79,7 +79,7 @@ services:
7979
- NEO4J_dbms_connector_bolt_listen__address=:7689
8080

8181
read1:
82-
image: neo4j:3.5-enterprise
82+
image: neo4j:3.5.14-enterprise
8383
networks:
8484
- lan
8585
ports:
@@ -101,25 +101,25 @@ services:
101101
- NEO4J_dbms_connector_bolt_listen__address=:7690
102102

103103
# This core demonstrates that additional instances can be added after the initial core is established (ie: this instance is nost listed within "initialDiscoveryMembers")
104-
core4:
105-
image: neo4j:3.5-enterprise
106-
networks:
107-
- lan
108-
ports:
109-
- 7478:7478
110-
- 6481:6481
111-
- 7691:7691
112-
volumes:
113-
- $HOME/neo4j/neo4j-core4/conf:/conf
114-
- $HOME/neo4j/neo4j-core4/data:/data
115-
- $HOME/neo4j/neo4j-core4/logs:/logs
116-
- $HOME/neo4j/neo4j-core1/plugins:/plugins
117-
environment:
118-
- NEO4J_AUTH=neo4j/changeme
119-
- NEO4J_dbms_mode=CORE
120-
- NEO4J_ACCEPT_LICENSE_AGREEMENT=yes
121-
# - NEO4J_causalClustering_expectedCoreClusterSize=3
122-
- NEO4J_causal__clustering_initial__discovery__members=core1:5000,core2:5000,core3:5000
123-
- NEO4J_dbms_connector_http_listen__address=:7478
124-
- NEO4J_dbms_connector_https_listen__address=:6481
125-
- NEO4J_dbms_connector_bolt_listen__address=:7691
104+
# core4:
105+
# image: neo4j:3.5.14-enterprise
106+
# networks:
107+
# - lan
108+
# ports:
109+
# - 7478:7478
110+
# - 6481:6481
111+
# - 7691:7691
112+
# volumes:
113+
# - $HOME/neo4j/neo4j-core4/conf:/conf
114+
# - $HOME/neo4j/neo4j-core4/data:/data
115+
# - $HOME/neo4j/neo4j-core4/logs:/logs
116+
# - $HOME/neo4j/neo4j-core1/plugins:/plugins
117+
# environment:
118+
# - NEO4J_AUTH=neo4j/changeme
119+
# - NEO4J_dbms_mode=CORE
120+
# - NEO4J_ACCEPT_LICENSE_AGREEMENT=yes
121+
# # - NEO4J_causalClustering_expectedCoreClusterSize=3
122+
# - NEO4J_causal__clustering_initial__discovery__members=core1:5000,core2:5000,core3:5000
123+
# - NEO4J_dbms_connector_http_listen__address=:7478
124+
# - NEO4J_dbms_connector_https_listen__address=:6481
125+
# - NEO4J_dbms_connector_bolt_listen__address=:7691

0 commit comments

Comments
 (0)