diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 20dfa43c..21419bd9 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -36,10 +36,12 @@ jobs: - name: Test SSL connection with CA run: | make up-ssl + sleep 10 make ssl-test - name: Test SSL connection self-signed run: | make up-ssl + sleep 10 make ssl-test-self-signed - name: down if: always() diff --git a/Makefile b/Makefile index 98feae01..d1a8ffeb 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ up: cd ./nebula-docker-compose && docker-compose up -d up-ssl: - cd ./nebula-docker-compose && enable_ssl=true docker-compose up -d + cd ./nebula-docker-compose && enable_ssl=true docker-compose -f docker-compose-ssl.yaml up -d down: cd ./nebula-docker-compose && docker-compose down -v @@ -25,9 +25,6 @@ ssl-test: ssl_test=true go test -v -run TestSslConnection; ssl-test-self-signed: - cd ./nebula-docker-compose && enable_ssl=true docker-compose up -d && \ - sleep 10 && \ - cd .. && \ self_signed=true go test -v -run TestSslConnection; run-examples: diff --git a/client_test.go b/client_test.go index be38745a..60146324 100644 --- a/client_test.go +++ b/client_test.go @@ -193,7 +193,7 @@ func TestAuthentication(t *testing.T) { defer conn.close() _, authErr := conn.authenticate(username, password) - assert.EqualError(t, authErr, "fail to authenticate, error: Bad username/password") + assert.EqualError(t, authErr, "fail to authenticate, error: User not exist") } func TestInvalidHostTimeout(t *testing.T) { @@ -369,7 +369,7 @@ func TestServiceDataIO(t *testing.T) { return } assert.Equal(t, - "(\"Bob\" :student{interval: P12M0DT0S, name: \"Bob\"} "+ + "(\"Bob\" :student{interval: P1MT100.000020000S, name: \"Bob\"} "+ ":person{age: 10, birthday: 2010-09-10T10:08:02.000000, book_num: 100, "+ "child_name: \"Hello Worl\", expend: 100.0, "+ "first_out_city: 1111, friends: 10, grade: 3, "+ @@ -929,7 +929,7 @@ func TestExecuteJson(t *testing.T) { "person.property": float64(1000), "person.start_school": `2017-09-10`, "student.name": "Bob", - "student.interval": `P12M0DT0S`, + "student.interval": `P1MT100.000020000S`, }, } @@ -1066,7 +1066,7 @@ func TestExecuteWithParameter(t *testing.T) { } // Complex result { - resp, err := tryToExecuteWithParameter(session, "MATCH (v:person {name: $p4.b}) WHERE v.age>$p2-3 and $p1==true RETURN v ORDER BY $p3[0] LIMIT $p2", params) + resp, err := tryToExecuteWithParameter(session, "MATCH (v:person {name: $p4.b}) WHERE v.person.age>$p2-3 and $p1==true RETURN v ORDER BY $p3[0] LIMIT $p2", params) if err != nil { t.Fatalf(err.Error()) return @@ -1088,7 +1088,7 @@ func TestExecuteWithParameter(t *testing.T) { return } assert.Equal(t, - "(\"Bob\" :student{interval: P12M0DT0S, name: \"Bob\"} "+ + "(\"Bob\" :student{interval: P1MT100.000020000S, name: \"Bob\"} "+ ":person{age: 10, birthday: 2010-09-10T10:08:02.000000, book_num: 100, "+ "child_name: \"Hello Worl\", expend: 100.0, "+ "first_out_city: 1111, friends: 10, grade: 3, "+ @@ -1275,7 +1275,7 @@ func loadTestData(t *testing.T, session *Session) { query = "INSERT VERTEX student(name, interval) VALUES " + - "'Bob':('Bob', duration({years: 1, seconds: 0})), 'Lily':('Lily', duration({years: 1, seconds: 0})), " + + "'Bob':('Bob', duration({months:1, seconds:100, microseconds:20})), 'Lily':('Lily', duration({years: 1, seconds: 0})), " + "'Tom':('Tom', duration({years: 1, seconds: 0})), 'Jerry':('Jerry', duration({years: 1, seconds: 0})), 'John':('John', duration({years: 1, seconds: 0}))" resultSet, err = tryToExecute(session, query) if err != nil { diff --git a/nebula-docker-compose/docker-compose-ssl.yaml b/nebula-docker-compose/docker-compose-ssl.yaml new file mode 100644 index 00000000..1b5682ae --- /dev/null +++ b/nebula-docker-compose/docker-compose-ssl.yaml @@ -0,0 +1,438 @@ +version: '3.4' +services: + metad0: + image: vesoft/nebula-metad:nightly + environment: + USER: root + TZ: "${TZ}" + command: + - --meta_server_addrs=metad0:45500,metad1:45500,metad2:45500 + - --local_ip=metad0 + - --ws_ip=metad0 + - --port=45500 + - --ws_http_port=11000 + - --data_path=/data/meta + - --log_dir=/logs + - --v=0 + - --minloglevel=0 + - --timezone_name=+08:00 + - --heartbeat_interval_secs=1 + # ssl + - --ca_path=${ca_path} + - --cert_path=${cert_path} + - --key_path=${key_path} + - --enable_ssl=${enable_ssl} + - --password_path=${password_path} + healthcheck: + test: ["CMD", "curl", "-sf", "http://metad0:11000/status"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 20s + ports: + - 45500 + - 11000 + - 11002 + volumes: + - ./secrets:/secrets + - ./data/meta0:/data/meta + - ./logs/meta0:/logs + networks: + - nebula-net + restart: on-failure + cap_add: + - SYS_PTRACE + + metad1: + image: vesoft/nebula-metad:nightly + environment: + USER: root + TZ: "${TZ}" + command: + - --meta_server_addrs=metad0:45500,metad1:45500,metad2:45500 + - --local_ip=metad1 + - --ws_ip=metad1 + - --port=45500 + - --ws_http_port=11000 + - --data_path=/data/meta + - --log_dir=/logs + - --v=0 + - --minloglevel=0 + - --timezone_name=+08:00 + - --heartbeat_interval_secs=1 + # ssl + - --ca_path=${ca_path} + - --cert_path=${cert_path} + - --key_path=${key_path} + - --enable_ssl=${enable_ssl} + - --password_path=${password_path} + healthcheck: + test: ["CMD", "curl", "-sf", "http://metad1:11000/status"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 20s + ports: + - 45500 + - 11000 + - 11002 + volumes: + - ./secrets:/secrets + - ./data/meta1:/data/meta + - ./logs/meta1:/logs + networks: + - nebula-net + restart: on-failure + cap_add: + - SYS_PTRACE + + metad2: + image: vesoft/nebula-metad:nightly + environment: + USER: root + TZ: "${TZ}" + command: + - --meta_server_addrs=metad0:45500,metad1:45500,metad2:45500 + - --local_ip=metad2 + - --ws_ip=metad2 + - --port=45500 + - --ws_http_port=11000 + - --data_path=/data/meta + - --log_dir=/logs + - --v=0 + - --minloglevel=0 + - --timezone_name=+08:00 + - --heartbeat_interval_secs=1 + # ssl + - --ca_path=${ca_path} + - --cert_path=${cert_path} + - --key_path=${key_path} + - --enable_ssl=${enable_ssl} + - --password_path=${password_path} + healthcheck: + test: ["CMD", "curl", "-sf", "http://metad2:11000/status"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 20s + ports: + - 45500 + - 11000 + - 11002 + volumes: + - ./secrets:/secrets + - ./data/meta2:/data/meta + - ./logs/meta2:/logs + networks: + - nebula-net + restart: on-failure + cap_add: + - SYS_PTRACE + + storaged0: + image: vesoft/nebula-storaged:nightly + environment: + USER: root + TZ: "${TZ}" + command: + - --meta_server_addrs=metad0:45500,metad1:45500,metad2:45500 + - --local_ip=storaged0 + - --ws_ip=storaged0 + - --port=44500 + - --ws_http_port=12000 + - --data_path=/data/storage + - --log_dir=/logs + - --v=0 + - --minloglevel=0 + - --timezone_name=+08:00 + - --heartbeat_interval_secs=1 + # ssl + - --ca_path=${ca_path} + - --cert_path=${cert_path} + - --key_path=${key_path} + - --enable_ssl=${enable_ssl} + - --password_path=${password_path} + depends_on: + - metad0 + - metad1 + - metad2 + healthcheck: + test: ["CMD", "curl", "-sf", "http://storaged0:12000/status"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 20s + ports: + - 44500 + - 12000 + - 12002 + volumes: + - ./secrets:/secrets + - ./data/storage0:/data/storage + - ./logs/storage0:/logs + networks: + - nebula-net + restart: on-failure + cap_add: + - SYS_PTRACE + + storaged1: + image: vesoft/nebula-storaged:nightly + environment: + USER: root + TZ: "${TZ}" + command: + - --meta_server_addrs=metad0:45500,metad1:45500,metad2:45500 + - --local_ip=storaged1 + - --ws_ip=storaged1 + - --port=44500 + - --ws_http_port=12000 + - --data_path=/data/storage + - --log_dir=/logs + - --v=0 + - --minloglevel=0 + - --timezone_name=+08:00 + - --heartbeat_interval_secs=1 + # ssl + - --ca_path=${ca_path} + - --cert_path=${cert_path} + - --key_path=${key_path} + - --enable_ssl=${enable_ssl} + - --password_path=${password_path} + depends_on: + - metad0 + - metad1 + - metad2 + healthcheck: + test: ["CMD", "curl", "-sf", "http://storaged1:12000/status"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 20s + ports: + - 44500 + - 12000 + - 12002 + volumes: + - ./secrets:/secrets + - ./data/storage1:/data/storage + - ./logs/storage1:/logs + networks: + - nebula-net + restart: on-failure + cap_add: + - SYS_PTRACE + + storaged2: + image: vesoft/nebula-storaged:nightly + environment: + USER: root + TZ: "${TZ}" + command: + - --meta_server_addrs=metad0:45500,metad1:45500,metad2:45500 + - --local_ip=storaged2 + - --ws_ip=storaged2 + - --port=44500 + - --ws_http_port=12000 + - --data_path=/data/storage + - --log_dir=/logs + - --v=0 + - --minloglevel=0 + - --timezone_name=+08:00 + - --heartbeat_interval_secs=1 + # ssl + - --ca_path=${ca_path} + - --cert_path=${cert_path} + - --key_path=${key_path} + - --enable_ssl=${enable_ssl} + - --password_path=${password_path} + depends_on: + - metad0 + - metad1 + - metad2 + healthcheck: + test: ["CMD", "curl", "-sf", "http://storaged2:12000/status"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 20s + ports: + - 44500 + - 12000 + - 12002 + volumes: + - ./secrets:/secrets + - ./data/storage2:/data/storage + - ./logs/storage2:/logs + networks: + - nebula-net + restart: on-failure + cap_add: + - SYS_PTRACE + + graphd: + image: vesoft/nebula-graphd:nightly + environment: + USER: root + TZ: "${TZ}" + command: + - --meta_server_addrs=metad0:45500,metad1:45500,metad2:45500 + - --port=3699 + - --ws_ip=graphd + - --ws_http_port=13000 + - --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 + # ssl + - --ca_path=${ca_path} + - --cert_path=${cert_path} + - --key_path=${key_path} + - --enable_ssl=${enable_ssl} + - --password_path=${password_path} + depends_on: + - metad0 + - metad1 + - metad2 + healthcheck: + test: ["CMD", "curl", "-sf", "http://graphd:13000/status"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 20s + ports: + - "3699:3699" + - 13000 + - 13002 + volumes: + - ./secrets:/secrets + - ./logs/graph:/logs + networks: + - nebula-net + restart: on-failure + cap_add: + - SYS_PTRACE + + graphd1: + image: vesoft/nebula-graphd:nightly + environment: + USER: root + TZ: "${TZ}" + command: + - --meta_server_addrs=metad0:45500,metad1:45500,metad2:45500 + - --port=3699 + - --ws_ip=graphd1 + - --ws_http_port=13000 + - --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 + # ssl + - --ca_path=${ca_path} + - --cert_path=${cert_path} + - --key_path=${key_path} + - --enable_ssl=${enable_ssl} + - --password_path=${password_path} + depends_on: + - metad0 + - metad1 + - metad2 + healthcheck: + test: ["CMD", "curl", "-sf", "http://graphd1:13000/status"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 20s + ports: + - "3700:3699" + - 13000 + - 13002 + volumes: + - ./secrets:/secrets + - ./logs/graph1:/logs + networks: + - nebula-net + restart: on-failure + cap_add: + - SYS_PTRACE + + graphd2: + image: vesoft/nebula-graphd:nightly + environment: + USER: root + TZ: "${TZ}" + command: + - --meta_server_addrs=metad0:45500,metad1:45500,metad2:45500 + - --port=3699 + - --ws_ip=graphd2 + - --ws_http_port=13000 + - --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 + # ssl + - --ca_path=${ca_path} + - --cert_path=${cert_path} + - --key_path=${key_path} + - --enable_ssl=${enable_ssl} + - --password_path=${password_path} + + + depends_on: + - metad0 + - metad1 + - metad2 + healthcheck: + test: ["CMD", "curl", "-sf", "http://graphd2:13000/status"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 20s + ports: + - "3701:3699" + - 13000 + - 13002 + volumes: + - ./secrets:/secrets + - ./logs/graph2:/logs + networks: + - nebula-net + restart: on-failure + cap_add: + - SYS_PTRACE + + console: + image: vesoft/nebula-console:nightly + entrypoint: "" + command: + - sh + - -c + - | + for i in `seq 1 60`;do + echo "Adding hosts..." + var=`nebula-console -addr graphd -port 3699 -u root -p nebula -enable_ssl=true -ssl_root_ca_path /secrets/test.ca.pem -ssl_cert_path /secrets/test.client.crt -ssl_private_key_path /secrets/test.client.key --ssl_insecure_skip_verify=true -e 'ADD HOSTS "storaged0":44500,"storaged1":44500,"storaged2":44500'`; + if [[ $$? == 0 ]];then + echo "Hosts added successfully" + break; + fi; + sleep 1; + echo "retry to add hosts."; + done && tail -f /dev/null; + volumes: + - ./secrets:/secrets + depends_on: + - graphd + networks: + - nebula-net + +networks: + nebula-net: diff --git a/nebula-docker-compose/docker-compose.yaml b/nebula-docker-compose/docker-compose.yaml index 8429d68d..790758d5 100644 --- a/nebula-docker-compose/docker-compose.yaml +++ b/nebula-docker-compose/docker-compose.yaml @@ -417,9 +417,14 @@ services: - sh - -c - | - sleep 3 && - nebula-console -addr graphd -port 3699 -u root -p nebula -e 'ADD HOSTS "storaged0":44500,"storaged1":44500,"storaged2":44500' && - sleep 36000 + for i in `seq 1 60`;do + var=`nebula-console -addr graphd -port 3699 -u root -p nebula -e 'ADD HOSTS "storaged0":44500,"storaged1":44500,"storaged2":44500'`; + if [[ $$? == 0 ]];then + break; + fi; + sleep 1; + echo "retry to add hosts."; + done && tail -f /dev/null; depends_on: - graphd networks: diff --git a/result_set_test.go b/result_set_test.go index 25358ccb..5616e99b 100644 --- a/result_set_test.go +++ b/result_set_test.go @@ -423,7 +423,7 @@ func TestAsDuration(t *testing.T) { value := nebula.Value{DuVal: &nebula.Duration{86400, 3000, 12}} valWrap := ValueWrapper{&value, testTimezone} assert.Equal(t, true, valWrap.IsDuration()) - assert.Equal(t, "P12M1DT86400S", valWrap.String()) + assert.Equal(t, "P12MT86400.003000000S", valWrap.String()) } func TestNode(t *testing.T) { vertex := getVertex("Tom", 3, 5) diff --git a/value_wrapper.go b/value_wrapper.go index c128b23e..e63c2227 100644 --- a/value_wrapper.go +++ b/value_wrapper.go @@ -404,8 +404,10 @@ func (valWrap ValueWrapper) String() string { return toWKT(ggval) } else if value.IsSetDuVal() { duval := value.GetDuVal() - days := duval.GetSeconds() / (24 * 60 * 60) - return fmt.Sprintf("P%vM%vDT%vS", duval.GetMonths(), days, duval.GetSeconds()) + totalSeconds := duval.GetSeconds() + int64(duval.GetMicroseconds())/1000000 + remainMicroSeconds := duval.GetMicroseconds() % 1000000 + s := fmt.Sprintf("P%vMT%v.%06d000S", duval.GetMonths(), totalSeconds, remainMicroSeconds) + return s } else { // is empty return "" }