Skip to content

Commit

Permalink
Update third party (#78)
Browse files Browse the repository at this point in the history
* Update third party and replace thrift files

* Modify client interface

* Add data i/o test

* Fix test
  • Loading branch information
Aiee authored Apr 16, 2021
1 parent 7e94e09 commit 052593c
Show file tree
Hide file tree
Showing 23 changed files with 12,760 additions and 18,991 deletions.
102 changes: 102 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,108 @@ func TestInvalidHostTimeout(t *testing.T) {
}
}

func TestDataIO(t *testing.T) {
hostAdress := HostAddress{Host: address, Port: port}
hostList := []HostAddress{}
hostList = append(hostList, hostAdress)

testPoolConfig = PoolConfig{
TimeOut: 0 * time.Millisecond,
IdleTime: 0 * time.Millisecond,
MaxConnPoolSize: 10,
MinConnPoolSize: 1,
}

// Initialize connectin pool
pool, err := NewConnectionPool(hostList, testPoolConfig, nebulaLog)
if err != nil {
t.Fatalf("Fail to initialize the connection pool, host: %s, port: %d, %s", address, port, err.Error())
}
// close all connections in the pool
defer pool.Close()

// Create session
session, err := pool.GetSession(username, password)
if err != nil {
t.Fatalf("Fail to create a new session from connection pool, username: %s, password: %s, %s",
username, password, err.Error())
}
defer session.Release()

// Method used to check execution response
checkResultSet := func(prefix string, res *ResultSet) {
if !res.IsSucceed() {
t.Fatalf("%s, ErrorCode: %v, ErrorMsg: %s", prefix, res.GetErrorCode(), res.GetErrorMsg())
}
}
// Do some data read/write
{
createSchema := "CREATE SPACE IF NOT EXISTS test_space; " +
"USE test_space;" +
"CREATE TAG IF NOT EXISTS person(name string, age int);" +
"CREATE EDGE IF NOT EXISTS like(likeness double)"

// Excute a query
resultSet, err := session.Execute(createSchema)
if err != nil {
t.Fatalf(err.Error())
return
}
checkResultSet(createSchema, resultSet)
}
time.Sleep(5 * time.Second)
{
insertVertexes := "INSERT VERTEX person(name, age) VALUES " +
"'Bob':('Bob', 10), " +
"'Lily':('Lily', 9), " +
"'Tom':('Tom', 10), " +
"'Jerry':('Jerry', 13), " +
"'John':('John', 11);"

// Insert multiple vertexes
resultSet, err := session.Execute(insertVertexes)
if err != nil {
t.Fatalf(err.Error())
return
}
checkResultSet(insertVertexes, resultSet)
}
{
insertEdges := "INSERT EDGE like(likeness) VALUES " +
"'Bob'->'Lily':(80.0), " +
"'Bob'->'Tom':(70.0), " +
"'Lily'->'Jerry':(84.0), " +
"'Tom'->'Jerry':(68.3), " +
"'Bob'->'John':(97.2);"

resultSet, err := session.Execute(insertEdges)
if err != nil {
t.Fatalf(err.Error())
return
}
checkResultSet(insertEdges, resultSet)
}
{
query := "GO FROM 'Bob' OVER like YIELD $^.person.name, $^.person.age, like.likeness"
// Send query
resultSet, err := session.Execute(query)
if err != nil {
t.Fatalf(err.Error())
return
}
checkResultSet(query, resultSet)
}
// Drop space
{
query := "DROP SPACE test_space;"
_, err := session.Execute(query)
if err != nil {
t.Fatalf(err.Error())
return
}
}
}

func TestPool_SingleHost(t *testing.T) {
hostAdress := HostAddress{Host: address, Port: port}
hostList := []HostAddress{}
Expand Down
9 changes: 5 additions & 4 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ func (cn *connection) open(hostAddress HostAddress, timeout time.Duration) error
if err != nil {
return fmt.Errorf("Failed to create a net.Conn-backed Transport,: %s", err.Error())
}

transport := thrift.NewBufferedTransport(sock, bufferSize)
// Set transport buffer
bufferedTranFactory := thrift.NewBufferedTransportFactory(bufferSize)
transport := thrift.NewFramedTransport(bufferedTranFactory.GetTransport(sock))
pf := thrift.NewBinaryProtocolFactoryDefault()
cn.graph = graph.NewGraphServiceClientFactory(transport, pf)
if err = cn.graph.Transport.Open(); err != nil {
if err = cn.graph.Open(); err != nil {
return fmt.Errorf("Failed to open transport, error: %s", err.Error())
}
if !cn.graph.Transport.IsOpen() {
if !cn.graph.IsOpen() {
return fmt.Errorf("Transport is off")
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ go 1.13

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/facebook/fbthrift v0.0.0-20190922225929-2f9839604e25
github.com/facebook/fbthrift v0.31.1-0.20210223140454-614a73a42488
github.com/stretchr/testify v1.6.1
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/facebook/fbthrift v0.0.0-20190922225929-2f9839604e25 h1:dezRDs9oGYxeavyvcNg/Js+dK6kIvfzERoJ7K8Xkv14=
github.com/facebook/fbthrift v0.0.0-20190922225929-2f9839604e25/go.mod h1:2tncLx5rmw69e5kMBv/yJneERbzrr1yr5fdlnTbu8lU=
github.com/facebook/fbthrift v0.31.1-0.20210223140454-614a73a42488 h1:A4KCT0mvTBkvb93gGN+efLPkrgTqmqMeaLDG51KVhMM=
github.com/facebook/fbthrift v0.31.1-0.20210223140454-614a73a42488/go.mod h1:2tncLx5rmw69e5kMBv/yJneERbzrr1yr5fdlnTbu8lU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
Expand Down
7 changes: 3 additions & 4 deletions gorountines_example/graph_client_goroutines_example.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func main() {
}
}
{
createSchema := "CREATE SPACE IF NOT EXISTS test; " +
"USE test;" +
createSchema := "CREATE SPACE IF NOT EXISTS example_space; " +
"USE example_space;" +
"CREATE TAG IF NOT EXISTS person(name string, age int);" +
"CREATE EDGE IF NOT EXISTS like(likeness double)"

Expand Down Expand Up @@ -88,7 +88,6 @@ func main() {
}
checkResultSet(insertVertexes, resultSet)
}

{
// Insert multiple edges
insertEdges := "INSERT EDGE like(likeness) VALUES " +
Expand All @@ -105,7 +104,7 @@ func main() {
}
checkResultSet(insertEdges, resultSet)
}

// Extract data from the resultSet
{
query := "GO FROM 'Bob' OVER like YIELD $^.person.name, $^.person.age, like.likeness"
// Send query
Expand Down
2 changes: 2 additions & 0 deletions nebula/constants.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions nebula/graph/constants.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions nebula/graph/graph_service-remote/graph_service-remote.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 052593c

Please sign in to comment.