Skip to content

Commit 79c0f60

Browse files
authored
[Feature] [v2] Add HTTP2 connection (#284)
1 parent cbd9012 commit 79c0f60

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1829
-345
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Change Log
22

33
## [master](https://github.com/arangodb/go-driver/tree/master) (N/A)
4+
- Add Driver V2 in Alpha version
5+
- Add HTTP2 support for V1 and V2
46

57
## [1.1.0](https://github.com/arangodb/go-driver/tree/1.1.0) (2020-08-11)
68
- Use internal coordinator communication for cursors if specified coordinator was not found on endpoint list

Makefile

+12-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ TMPDIR := ${SCRIPTDIR}/.tmp
1010

1111
DOCKER_CMD:=docker run
1212

13+
GOBUILDTAGS:=$(TAGS)
14+
GOBUILDTAGSOPT=-tags "$(GOBUILDTAGS)"
15+
1316
ifndef ARANGODB
1417
ARANGODB := arangodb/arangodb:latest
1518
endif
@@ -43,18 +46,17 @@ endif
4346

4447
ifeq ("$(TEST_AUTH)", "none")
4548
ARANGOENV := -e ARANGO_NO_AUTH=1
46-
TEST_AUTHENTICATION :=
47-
TAGS :=
49+
TEST_AUTHENTICATION :=
4850
TESTS := $(REPOPATH) $(REPOPATH)/test
4951
else ifeq ("$(TEST_AUTH)", "rootpw")
5052
ARANGOENV := -e ARANGO_ROOT_PASSWORD=rootpw
5153
TEST_AUTHENTICATION := basic:root:rootpw
52-
TAGS := -tags auth
54+
GOBUILDTAGS += auth
5355
TESTS := $(REPOPATH)/test
5456
else ifeq ("$(TEST_AUTH)", "jwt")
5557
ARANGOENV := -e ARANGO_ROOT_PASSWORD=rootpw
5658
TEST_AUTHENTICATION := jwt:root:rootpw
57-
TAGS := -tags auth
59+
GOBUILDTAGS += auth
5860
TESTS := $(REPOPATH)/test
5961
JWTSECRET := testing
6062
JWTSECRETFILE := "${TMPDIR}/${TESTCONTAINER}-jwtsecret"
@@ -179,6 +181,10 @@ run-tests-single-json-with-auth:
179181
@echo "Single server, HTTP+JSON, with authentication"
180182
@${MAKE} TEST_MODE="single" TEST_AUTH="rootpw" TEST_CONTENT_TYPE="json" __run_tests
181183

184+
run-tests-single-json-http2-with-auth:
185+
@echo "Single server, HTTP+JSON, with authentication"
186+
@${MAKE} TEST_MODE="single" TAGS="http2" TEST_AUTH="rootpw" TEST_CONTENT_TYPE="json" __run_tests
187+
182188
run-tests-single-vpack-with-auth:
183189
@echo "Single server, HTTP+Velocypack, with authentication"
184190
@${MAKE} TEST_MODE="single" TEST_AUTH="rootpw" TEST_CONTENT_TYPE="vpack" __run_tests
@@ -351,7 +357,7 @@ __test_go_test:
351357
-e CGO_ENABLED=0 \
352358
-w /usr/code/ \
353359
golang:$(GOVERSION) \
354-
go test $(TAGS) $(TESTOPTIONS) $(TESTVERBOSEOPTIONS) $(TESTS)
360+
go test $(GOBUILDTAGSOPT) $(TESTOPTIONS) $(TESTVERBOSEOPTIONS) $(TESTS)
355361

356362
# Internal test tasks
357363
__run_v2_tests: __test_prepare __test_v2_go_test __test_cleanup
@@ -371,7 +377,7 @@ __test_v2_go_test:
371377
-e CGO_ENABLED=0 \
372378
-w /usr/code/v2/ \
373379
golang:$(GOV2VERSION) \
374-
go test $(TAGS) $(TESTOPTIONS) $(TESTVERBOSEOPTIONS) ./tests
380+
go test $(GOBUILDTAGSOPT) $(TESTOPTIONS) $(TESTVERBOSEOPTIONS) ./tests
375381

376382

377383
__test_prepare:

client_foxx.go

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
//
2020
// Author Tomasz Mielech
2121
//
22+
2223
package driver
2324

2425
import (

client_foxx_impl.go

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
//
2020
// Author Tomasz Mielech
2121
//
22+
2223
package driver
2324

2425
// Foxx provides access to foxx services specific operations.

foxx.go

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
//
2020
// Author Tomasz Mielech
2121
//
22+
2223
package driver
2324

2425
import (

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ require (
1212
github.com/pkg/errors v0.9.1
1313
github.com/rs/zerolog v1.19.0 // indirect
1414
github.com/stretchr/testify v1.5.1
15+
golang.org/x/net v0.0.0-20200625001655-4c5254603344
1516
golang.org/x/tools v0.0.0-20200818005847-188abfa75333 // indirect
1617
)

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
5050
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
5151
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
5252
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
53+
golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4=
5354
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
5455
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
5556
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -58,6 +59,7 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ
5859
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
5960
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
6061
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
62+
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
6163
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
6264
golang.org/x/tools v0.0.0-20190828213141-aed303cbaa74/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
6365
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=

test/client_connection_http2_test.go

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// +build http2
2+
//
3+
// DISCLAIMER
4+
//
5+
// Copyright 2017 ArangoDB GmbH, Cologne, Germany
6+
//
7+
// Licensed under the Apache License, Version 2.0 (the "License");
8+
// you may not use this file except in compliance with the License.
9+
// You may obtain a copy of the License at
10+
//
11+
// http://www.apache.org/licenses/LICENSE-2.0
12+
//
13+
// Unless required by applicable law or agreed to in writing, software
14+
// distributed under the License is distributed on an "AS IS" BASIS,
15+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
// See the License for the specific language governing permissions and
17+
// limitations under the License.
18+
//
19+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
20+
//
21+
// Author Adam Janikowski
22+
//
23+
24+
package test
25+
26+
import (
27+
"crypto/tls"
28+
"net/http"
29+
30+
"golang.org/x/net/http2"
31+
)
32+
33+
func NewConnectionTransport() http.RoundTripper {
34+
return &http2.Transport{
35+
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
36+
AllowHTTP: true,
37+
}
38+
}

test/client_connection_http_test.go

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// +build !http2
2+
//
3+
// DISCLAIMER
4+
//
5+
// Copyright 2017 ArangoDB GmbH, Cologne, Germany
6+
//
7+
// Licensed under the Apache License, Version 2.0 (the "License");
8+
// you may not use this file except in compliance with the License.
9+
// You may obtain a copy of the License at
10+
//
11+
// http://www.apache.org/licenses/LICENSE-2.0
12+
//
13+
// Unless required by applicable law or agreed to in writing, software
14+
// distributed under the License is distributed on an "AS IS" BASIS,
15+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
// See the License for the specific language governing permissions and
17+
// limitations under the License.
18+
//
19+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
20+
//
21+
// Author Adam Janikowski
22+
//
23+
24+
package test
25+
26+
import (
27+
"crypto/tls"
28+
"net"
29+
"net/http"
30+
"time"
31+
)
32+
33+
func NewConnectionTransport() http.RoundTripper {
34+
return &http.Transport{
35+
// Copy default values from http.DefaultTransport
36+
Proxy: http.ProxyFromEnvironment,
37+
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
38+
DialContext: (&net.Dialer{
39+
Timeout: 30 * time.Second,
40+
KeepAlive: 30 * time.Second,
41+
DualStack: true,
42+
}).DialContext,
43+
MaxIdleConns: 100,
44+
IdleConnTimeout: 90 * time.Second,
45+
TLSHandshakeTimeout: 10 * time.Second,
46+
ExpectContinueTimeout: 1 * time.Second,
47+
}
48+
}

test/client_test.go

+1-32
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ func waitUntilEndpointSynchronized(ctx context.Context, c driver.Client, dbname
339339
func TestCreateClientHttpConnection(t *testing.T) {
340340
conn, err := http.NewConnection(http.ConnectionConfig{
341341
Endpoints: getEndpointsFromEnv(t),
342-
TLSConfig: &tls.Config{InsecureSkipVerify: true},
342+
Transport: NewConnectionTransport(),
343343
})
344344
if err != nil {
345345
t.Fatalf("Failed to create new http connection: %s", describe(err))
@@ -353,37 +353,6 @@ func TestCreateClientHttpConnection(t *testing.T) {
353353
}
354354
}
355355

356-
// TestCreateClientHttpConnectionCustomTransport creates an HTTP connection to the environment specified
357-
// endpoints with a custom HTTP roundtripper and creates a client for that.
358-
func TestCreateClientHttpConnectionCustomTransport(t *testing.T) {
359-
conn, err := http.NewConnection(http.ConnectionConfig{
360-
Endpoints: getEndpointsFromEnv(t),
361-
Transport: &httplib.Transport{},
362-
TLSConfig: &tls.Config{InsecureSkipVerify: true},
363-
})
364-
if err != nil {
365-
t.Fatalf("Failed to create new http connection: %s", describe(err))
366-
}
367-
c, err := driver.NewClient(driver.ClientConfig{
368-
Connection: conn,
369-
Authentication: createAuthenticationFromEnv(t),
370-
})
371-
if err != nil {
372-
t.Fatalf("Failed to create new client: %s", describe(err))
373-
}
374-
timeout := 3 * time.Minute
375-
ctx, cancel := context.WithTimeout(context.Background(), timeout)
376-
defer cancel()
377-
if up := waitUntilServerAvailable(ctx, c, t); up != nil {
378-
t.Fatalf("Connection is not available in %s: %s", timeout, describe(up))
379-
}
380-
if info, err := c.Version(driver.WithDetails(ctx)); err != nil {
381-
t.Errorf("Version failed: %s", describe(err))
382-
} else {
383-
t.Logf("Got server version %s", info)
384-
}
385-
}
386-
387356
// TestResponseHeader checks the Response.Header function.
388357
func TestResponseHeader(t *testing.T) {
389358
c := createClientFromEnv(t, true)

test/database_transaction_test.go

+22
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2020 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
// Author Adam Janikowski
21+
//
22+
123
package test
224

325
import (

test/foxx_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
//
2020
// Author Tomasz Mielech
2121
//
22+
2223
package test
2324

2425
import (

test/revisions_test.go

+22
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2020 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
// Author Adam Janikowski
21+
//
22+
123
package test
224

325
import (

v2/arangodb/client.go

+1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ type Client interface {
2727

2828
ClientAdminBackup
2929
ClientDatabase
30+
ClientServerInfo
3031
}

v2/arangodb/client_impl.go

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func newClient(connection connection.Connection) *client {
3636
}
3737

3838
c.clientDatabase = newClientDatabase(c)
39+
c.clientServerInfo = newClientServerInfo(c)
3940

4041
c.Requests = NewRequests(connection)
4142

@@ -48,6 +49,7 @@ type client struct {
4849
connection connection.Connection
4950

5051
*clientDatabase
52+
*clientServerInfo
5153

5254
Requests
5355
}

0 commit comments

Comments
 (0)