Skip to content

Commit

Permalink
Merge branch 'master' into test-timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
Aiee authored Jul 8, 2021
2 parents 1cd1749 + 05a674d commit 6e95bb0
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 22 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ jobs:
sleep 10
popd
go test -v -race
- name: Run examples
run: |
go run basic_example/graph_client_basic_example.go
go run gorountines_example/graph_client_goroutines_example.go
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: build test test-dev fmt ci
.PHONY: build test fmt ci run-examples

default: build

Expand All @@ -19,3 +19,7 @@ ci:
cd .. && \
go test -v -race; \
cd ./nebula-docker-compose && docker-compose down -v

run-examples:
go run basic_example/graph_client_basic_example.go
go run gorountines_example/graph_client_goroutines_example.go
27 changes: 20 additions & 7 deletions basic_example/graph_client_basic_example.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import (
)

const (
address = "127.0.0.1"
port = 9669
username = "user"
password = "password"
address = "127.0.0.1"
// The default port of Nebula Graph 2.x is 9669.
// 3699 is only for testing.
port = 3699
username = "root"
password = "nebula"
)

// Initialize logger
Expand Down Expand Up @@ -47,14 +49,14 @@ func main() {

checkResultSet := func(prefix string, res *nebula.ResultSet) {
if !res.IsSucceed() {
fmt.Printf("%s, ErrorCode: %v, ErrorMsg: %s", prefix, res.GetErrorCode(), res.GetErrorMsg())
log.Fatal(fmt.Sprintf("%s, ErrorCode: %v, ErrorMsg: %s", prefix, res.GetErrorCode(), res.GetErrorMsg()))
}
}

{
// Prepare the query
createSchema := "CREATE SPACE IF NOT EXISTS test; " +
"USE test;" +
createSchema := "CREATE SPACE IF NOT EXISTS basic_example_space(vid_type=FIXED_STRING(20)); " +
"USE basic_example_space;" +
"CREATE TAG IF NOT EXISTS person(name string, age int);" +
"CREATE EDGE IF NOT EXISTS like(likeness double)"

Expand All @@ -66,6 +68,17 @@ func main() {
}
checkResultSet(createSchema, resultSet)
}
// Drop space
{
query := "DROP SPACE IF EXISTS basic_example_space"
// Send query
resultSet, err := session.Execute(query)
if err != nil {
fmt.Print(err.Error())
return
}
checkResultSet(query, resultSet)
}

fmt.Print("\n")
log.Info("Nebula Go Client Basic Example Finished")
Expand Down
11 changes: 5 additions & 6 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func TestServiceDataIO(t *testing.T) {
}
checkResultSet(createSchema, resultSet)
}
time.Sleep(5 * time.Second)
time.Sleep(3 * time.Second)

// Load data
{
Expand Down Expand Up @@ -950,14 +950,13 @@ func startContainer(t *testing.T, containerName string) {
}
}

func tryToExecute(session *Session, query string) (*ResultSet, error) {
var err error
func tryToExecute(session *Session, query string) (resp *ResultSet, err error) {
for i := 3; i > 0; i-- {
resp, err := session.Execute(query)
resp, err = session.Execute(query)
if err == nil && resp.IsSucceed() {
return resp, nil
return
}
time.Sleep(2 * time.Second)
}
return nil, err
return
}
25 changes: 19 additions & 6 deletions gorountines_example/graph_client_goroutines_example.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ import (
)

const (
address = "127.0.0.1"
port = 9669
username = "user"
password = "password"
address = "127.0.0.1"
// The default port of Nebula Graph 2.x is 9669.
// 3699 is only for testing.
port = 3699
username = "root"
password = "nebula"
)

// Initialize logger
Expand Down Expand Up @@ -54,11 +56,11 @@ func main() {
// Method used to check execution response
checkResultSet := func(prefix string, res *nebula.ResultSet) {
if !res.IsSucceed() {
fmt.Printf("%s, ErrorCode: %v, ErrorMsg: %s", prefix, res.GetErrorCode(), res.GetErrorMsg())
log.Fatal(fmt.Sprintf("%s, ErrorCode: %v, ErrorMsg: %s", prefix, res.GetErrorCode(), res.GetErrorMsg()))
}
}
{
createSchema := "CREATE SPACE IF NOT EXISTS example_space; " +
createSchema := "CREATE SPACE IF NOT EXISTS example_space(vid_type=FIXED_STRING(20)); " +
"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 @@ -145,6 +147,17 @@ func main() {
// Print ValueWrapper using String()
fmt.Printf("Print using ValueWrapper.String(): %s", valueWrapper.String())
}
// Drop space
{
query := "DROP SPACE IF EXISTS example_space"
// Send query
resultSet, err := session.Execute(query)
if err != nil {
fmt.Print(err.Error())
return
}
checkResultSet(query, resultSet)
}
}(&wg)
wg.Wait()

Expand Down
13 changes: 12 additions & 1 deletion nebula-docker-compose/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ services:
- --v=0
- --minloglevel=0
- --timezone_name=+08:00
- --heartbeat_interval_secs=1
healthcheck:
test: ["CMD", "curl", "-sf", "http://metad0:11000/status"]
interval: 30s
Expand Down Expand Up @@ -51,6 +52,7 @@ services:
- --v=0
- --minloglevel=0
- --timezone_name=+08:00
- --heartbeat_interval_secs=1
healthcheck:
test: ["CMD", "curl", "-sf", "http://metad1:11000/status"]
interval: 30s
Expand Down Expand Up @@ -86,6 +88,7 @@ services:
- --v=0
- --minloglevel=0
- --timezone_name=+08:00
- --heartbeat_interval_secs=1
healthcheck:
test: ["CMD", "curl", "-sf", "http://metad2:11000/status"]
interval: 30s
Expand Down Expand Up @@ -121,6 +124,7 @@ services:
- --v=0
- --minloglevel=0
- --timezone_name=+08:00
- --heartbeat_interval_secs=1
depends_on:
- metad0
- metad1
Expand Down Expand Up @@ -160,6 +164,7 @@ services:
- --v=0
- --minloglevel=0
- --timezone_name=+08:00
- --heartbeat_interval_secs=1
depends_on:
- metad0
- metad1
Expand Down Expand Up @@ -199,6 +204,7 @@ services:
- --v=0
- --minloglevel=0
- --timezone_name=+08:00
- --heartbeat_interval_secs=1
depends_on:
- metad0
- metad1
Expand Down Expand Up @@ -235,9 +241,10 @@ services:
- --log_dir=/logs
- --v=0
- --minloglevel=0
- --enable_authorize
- --enable_authorize=true
- --timezone_name=+08:00
- --system_memory_high_watermark_ratio=0.99
- --heartbeat_interval_secs=1
depends_on:
- metad0
- metad1
Expand Down Expand Up @@ -273,8 +280,10 @@ services:
- --log_dir=/logs
- --v=0
- --minloglevel=0
- --enable_authorize=true
- --timezone_name=+08:00
- --system_memory_high_watermark_ratio=0.99
- --heartbeat_interval_secs=1
depends_on:
- metad0
- metad1
Expand Down Expand Up @@ -310,8 +319,10 @@ services:
- --log_dir=/logs
- --v=0
- --minloglevel=0
- --enable_authorize=true
- --timezone_name=+08:00
- --system_memory_high_watermark_ratio=0.99
- --heartbeat_interval_secs=1
depends_on:
- metad0
- metad1
Expand Down

0 comments on commit 6e95bb0

Please sign in to comment.