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

draft implementation #96

Draft
wants to merge 4 commits into
base: 3.7-dev
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
50 changes: 24 additions & 26 deletions gremlin-go/driver/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,30 +378,28 @@ func TestClientAgainstSocketServer(t *testing.T) {
* purposes. See https://issues.apache.org/jira/browse/TINKERPOP-2845.
* This test should be uncommented with the resolution of TINKERPOP-2845
*/
/*
t.Run("Should try create new connection if closed by server", func(t *testing.T) {
skipTestsIfNotEnabled(t, integrationTestSuiteName, testNoAuthEnable)
client, err := NewClient(testSocketServerUrl)
defer client.Close()
assert.Nil(t, err)
assert.NotNil(t, client)
resultSet, err := client.SubmitWithOptions("1", new(RequestOptionsBuilder).
SetRequestId(settings.CLOSE_CONNECTION_REQUEST_ID).Create())
assert.Nil(t, err)
assert.NotNil(t, resultSet)

result, ok, err := resultSet.One()

assert.EqualError(t, err, "websocket: close 1005 (no status)")

resultSet, err = client.SubmitWithOptions("1", new(RequestOptionsBuilder).
SetRequestId(settings.SINGLE_VERTEX_REQUEST_ID).Create())
assert.Nil(t, err)
assert.NotNil(t, resultSet)
result, ok, err = resultSet.One()
assert.Nil(t, err)
assert.True(t, ok)
assert.NotNil(t, result)
})
*/
t.Run("Should try create new connection if closed by server", func(t *testing.T) {
skipTestsIfNotEnabled(t, integrationTestSuiteName, testNoAuthEnable)
client, err := NewClient(testSocketServerUrl)
defer client.Close()
assert.Nil(t, err)
assert.NotNil(t, client)
resultSet, err := client.SubmitWithOptions("1", new(RequestOptionsBuilder).
SetRequestId(settings.CLOSE_CONNECTION_REQUEST_ID).Create())
assert.Nil(t, err)
assert.NotNil(t, resultSet)

result, ok, err := resultSet.One()

assert.EqualError(t, err, "websocket: close 1005 (no status)")

resultSet, err = client.SubmitWithOptions("1", new(RequestOptionsBuilder).
SetRequestId(settings.SINGLE_VERTEX_REQUEST_ID).Create())
assert.Nil(t, err)
assert.NotNil(t, resultSet)
result, ok, err = resultSet.One()
assert.Nil(t, err)
assert.True(t, ok)
assert.NotNil(t, result)
})
}
12 changes: 12 additions & 0 deletions gremlin-go/driver/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type connection struct {
protocol protocol
results *synchronizedMap
state connectionState
syncLock sync.Mutex
}

type connectionSettings struct {
Expand All @@ -54,6 +55,13 @@ type connectionSettings struct {
}

func (connection *connection) errorCallback() {
connection.syncLock.Lock()
defer connection.syncLock.Unlock()

if connection.state == closed || connection.state == closedDueToError {
return
}

connection.logHandler.log(Error, errorCallback)
connection.state = closedDueToError

Expand All @@ -65,6 +73,9 @@ func (connection *connection) errorCallback() {
}

func (connection *connection) close() error {
connection.syncLock.Lock()
defer connection.syncLock.Unlock()

if connection.state != established {
return newError(err0101ConnectionCloseError)
}
Expand Down Expand Up @@ -106,6 +117,7 @@ func createConnection(url string, logHandler *logHandler, connSettings *connecti
nil,
&synchronizedMap{map[string]ResultSet{}, sync.Mutex{}},
initialized,
sync.Mutex{},
}
logHandler.log(Info, connectConnection)
protocol, err := newGremlinServerWSProtocol(logHandler, Gorilla, url, connSettings, conn.results, conn.errorCallback)
Expand Down
Loading
Loading