Skip to content

Commit

Permalink
draft implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentyn Kahamlyk authored and Valentyn Kahamlyk committed Dec 22, 2023
1 parent c28aa2e commit 1ce1ba2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 39 deletions.
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)
})
}
8 changes: 8 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,9 @@ type connectionSettings struct {
}

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

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

Expand All @@ -65,6 +69,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 +113,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

0 comments on commit 1ce1ba2

Please sign in to comment.