Skip to content

Commit

Permalink
Merge pull request #10 from amsokol/v0.10
Browse files Browse the repository at this point in the history
Thin client protocol v1.1.0 support (Apache Ignite v2.5)
  • Loading branch information
Aleksandr Sokolovskii authored Jun 3, 2018
2 parents c40dfff + 90f287a commit 317cae8
Show file tree
Hide file tree
Showing 13 changed files with 264 additions and 125 deletions.
61 changes: 41 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,16 @@ c, err := ignite.Connect(ctx, ignite.ConnInfo{
Host: "localhost",
Port: 10800,
Major: 1,
Minor: 0,
Minor: 1,
Patch: 0,
Username: "ignite",
Password: "ignite",
Dialer: net.Dialer{
Timeout: 10 * time.Second,
},
TLSConfig: &tls.Config{
InsecureSkipVerify: true,
},
})
if err != nil {
t.Fatalf("failed connect to server: %v", err)
Expand All @@ -69,9 +74,9 @@ defer c.Close()

```

See [example of Key-Value Queries](https://github.com/amsokol/ignite-go-client/blob/master/examples_test.go#L98) for more.
See [example of Key-Value Queries](https://github.com/amsokol/ignite-go-client/blob/master/examples_test.go#L106) for more.

See [example of SQL Queries](https://github.com/amsokol/ignite-go-client/blob/master/examples_test.go#L162) for more.
See [example of SQL Queries](https://github.com/amsokol/ignite-go-client/blob/master/examples_test.go#L181) for more.

See ["_test.go" files](https://github.com/amsokol/ignite-go-client/tree/master/binary/v1) for other examples.

Expand All @@ -93,15 +98,16 @@ Connect to server:
ctx := context.Background()

// open connection
db, err := sql.Open("ignite", "tcp://localhost:10800/ExampleDB?version=1.0.0&&page-size=10000&timeout=5000")
db, err := sql.Open("ignite", "tcp://localhost:10800/ExampleDB?version=1.1.0&username=ignite&password=ignite"+
"&tls=yes&tls-insecure-skip-verify=yes&page-size=10000&timeout=5000")
if err != nil {
t.Fatalf("failed to open connection: %v", err)
}
defer db.Close()

```

See [example](https://github.com/amsokol/ignite-go-client/blob/master/examples_test.go#L15) for more.
See [example](https://github.com/amsokol/ignite-go-client/blob/master/examples_test.go#L16) for more.

Connection URL format:

Expand All @@ -120,24 +126,29 @@ protocol://host:port/cache?param1=value1&param2=value2&paramN=valueN

**URL parameters (param1,...paramN):**

| Name | Mandatory | Description | Default value |
|--------------------|-----------|---------------------------------------------------------------|-----------------------------------|
| schema | no | Database schema | "" (PUBLIC schema is used) |
| version | no | Binary protocol version in Semantic Version format | 1.0.0 |
| page-size | no | Query cursor page size | 10000 |
| max-rows | no | Max rows to return by query | 0 (looks like it means unlimited) |
| timeout | no | Timeout in milliseconds to execute query | 0 (disable timeout) |
| distributed-joins | no | Distributed joins (yes/no) | no |
| local-query | no | Local query (yes/no) | no |
| replicated-only | no | Whether query contains only replicated tables or not (yes/no) | no |
| enforce-join-order | no | Enforce join order (yes/no) | no |
| collocated | no | Whether your data is co-located or not (yes/no) | no |
| lazy-query | no | Lazy query execution (yes/no) | no |
| Name | Mandatory | Description | Default value |
|--------------------------|-----------|---------------------------------------------------------------------------------|-----------------------------------|
| schema | no | Database schema | "" (PUBLIC schema is used) |
| version | no | Binary protocol version in Semantic Version format | 1.0.0 |
| username | no | Username | no |
| password | no | Password | no |
| tls | no | Connect using TLS | no |
| tls-insecure-skip-verify | no | Controls whether a client verifies the server's certificate chain and host name | no |
| page-size | no | Query cursor page size | 10000 |
| max-rows | no | Max rows to return by query | 0 (looks like it means unlimited) |
| timeout | no | Timeout in milliseconds to execute query | 0 (disable timeout) |
| distributed-joins | no | Distributed joins (yes/no) | no |
| local-query | no | Local query (yes/no) | no |
| replicated-only | no | Whether query contains only replicated tables or not (yes/no) | no |
| enforce-join-order | no | Enforce join order (yes/no) | no |
| collocated | no | Whether your data is co-located or not (yes/no) | no |
| lazy-query | no | Lazy query execution (yes/no) | no |

### How to run tests

1. Download `Apache Ignite 2.4+` from [official site](https://ignite.apache.org/download.cgi#binaries)
1. Download `Apache Ignite 2.5` from [official site](https://ignite.apache.org/download.cgi#binaries)
1. Extract distributive to any folder
1. Persistance mode is enabled to run test. So you need to remove `<path_with_ignite>\work` folder each time to clean test data before run tests.
1. `cd` to `testdata` folder with `configuration-for-tests.xml` file
1. Start Ignite server with `configuration-for-tests.xml` configuration file:

Expand All @@ -149,7 +160,17 @@ protocol://host:port/cache?param1=value1&param2=value2&paramN=valueN
<path_with_ignite>/bin/ignite.sh ./configuration-for-tests.xml
```

1. Run tests into the root folder of this project:
6. Activate cluster:

```bash
# For Windows:
<path_with_ignite>\bin\control.bat --activate --user ignite --password ignite

# For Linux:
<path_with_ignite>/bin/control.bat --activate --user ignite --password ignite
```

7. Run tests into the root folder of this project:

```bash
go test ./...
Expand Down
18 changes: 12 additions & 6 deletions binary/v1/client-cache-configuration_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package ignite

import (
"crypto/tls"
"reflect"
"testing"
)

var testConnInfo = ConnInfo{
Network: "tcp",
Host: "localhost",
Port: 10800,
Major: 1,
Minor: 0,
Patch: 0,
Network: "tcp",
Host: "localhost",
Port: 10800,
Major: 1,
Minor: 1,
Patch: 0,
Username: "ignite",
Password: "ignite",
TLSConfig: &tls.Config{
InsecureSkipVerify: true,
},
}

func Test_client_CacheCreateWithName(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion binary/v1/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type ConnInfo struct {
Network, Host string
Port int
Major, Minor, Patch int
Username, Password string
Dialer net.Dialer
TLSConfig *tls.Config
}
Expand Down Expand Up @@ -268,7 +269,7 @@ func Connect(ci ConnInfo) (Client, error) {
runtime.SetFinalizer(c, clientFinalizer)

// request and response
req := NewRequestHandshake(ci.Major, ci.Minor, ci.Patch)
req := NewRequestHandshake(ci.Major, ci.Minor, ci.Patch, ci.Username, ci.Password)
res := &ResponseHandshake{}

// make handshake
Expand Down
35 changes: 23 additions & 12 deletions binary/v1/client_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ignite

import (
"crypto/tls"
"testing"
)

Expand All @@ -18,25 +19,35 @@ func TestConnect(t *testing.T) {
name: "1",
args: args{
ci: ConnInfo{
Network: "tcp",
Host: "localhost",
Port: 10800,
Major: 1,
Minor: 0,
Patch: 0,
Network: "tcp",
Host: "localhost",
Port: 10800,
Major: 1,
Minor: 1,
Patch: 0,
Username: "ignite",
Password: "ignite",
TLSConfig: &tls.Config{
InsecureSkipVerify: true,
},
},
},
},
{
name: "2",
args: args{
ci: ConnInfo{
Network: "tcp",
Host: "localhost",
Port: 10800,
Major: 999,
Minor: 0,
Patch: 0,
Network: "tcp",
Host: "localhost",
Port: 10800,
Major: 999,
Minor: 0,
Patch: 0,
Username: "ignite",
Password: "ignite",
TLSConfig: &tls.Config{
InsecureSkipVerify: true,
},
},
},
wantErr: true,
Expand Down
13 changes: 11 additions & 2 deletions binary/v1/request-handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
// RequestHandshake is struct handshake request
type RequestHandshake struct {
major, minor, patch int
username, password string

request
}
Expand All @@ -32,6 +33,14 @@ func (r *RequestHandshake) WriteTo(w io.Writer) (int64, error) {
if err := WriteByte(r, 2); err != nil {
return 0, errors.Wrapf(err, "failed to write handshake client code")
}
if len(r.username) > 0 {
if err := WriteOString(r, r.username); err != nil {
return 0, errors.Wrapf(err, "failed to write handshake username")
}
if err := WriteOString(r, r.password); err != nil {
return 0, errors.Wrapf(err, "failed to write handshake password")
}
}

// write payload length
l := int32(r.payload.Len())
Expand All @@ -44,7 +53,7 @@ func (r *RequestHandshake) WriteTo(w io.Writer) (int64, error) {
}

// NewRequestHandshake creates new handshake request object
func NewRequestHandshake(major, minor, patch int) *RequestHandshake {
func NewRequestHandshake(major, minor, patch int, username, password string) *RequestHandshake {
return &RequestHandshake{request: newRequest(),
major: major, minor: minor, patch: patch}
major: major, minor: minor, patch: patch, username: username, password: password}
}
10 changes: 6 additions & 4 deletions binary/v1/request-handshake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ func TestRequestHandshake_WriteTo(t *testing.T) {
wantErr bool
}{
{
name: "1",
r: NewRequestHandshake(1, 0, 0),
want: 4 + 8,
wantW: []byte{0x8, 0x0, 0x0, 0x0, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2},
name: "1",
r: NewRequestHandshake(1, 0, 0, "ignite", "ignite"),
want: 4 + 8 + 22,
wantW: []byte{0x1e, 0x0, 0x0, 0x0, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2,
0x9, 0x6, 0x0, 0x0, 0x0, 0x69, 0x67, 0x6e, 0x69, 0x74, 0x65, 0x9, 0x6,
0x0, 0x0, 0x0, 0x69, 0x67, 0x6e, 0x69, 0x74, 0x65},
},
}
for _, tt := range tests {
Expand Down
44 changes: 31 additions & 13 deletions examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package examples

import (
"context"
"crypto/tls"
"database/sql"
"log"
"net"
Expand All @@ -16,7 +17,14 @@ func Test_SQL_Driver(t *testing.T) {
ctx := context.Background()

// open connection
db, err := sql.Open("ignite", "tcp://localhost:10800/ExampleDB?version=1.0.0&&page-size=10000&timeout=5000")
db, err := sql.Open("ignite", "tcp://localhost:10800/ExampleDB?"+
"version=1.1.0"+
"&username=ignite"+
"&password=ignite"+
"&tls=yes"+
"&tls-insecure-skip-verify=yes"+
"&page-size=10000"+
"&timeout=5000")
if err != nil {
t.Fatalf("failed to open connection: %v", err)
}
Expand Down Expand Up @@ -98,15 +106,20 @@ func Test_SQL_Driver(t *testing.T) {
func Test_Key_Value(t *testing.T) {
// connect
c, err := ignite.Connect(ignite.ConnInfo{
Network: "tcp",
Host: "localhost",
Port: 10800,
Major: 1,
Minor: 0,
Patch: 0,
Network: "tcp",
Host: "localhost",
Port: 10800,
Major: 1,
Minor: 1,
Patch: 0,
Username: "ignite",
Password: "ignite",
Dialer: net.Dialer{
Timeout: 10 * time.Second,
},
TLSConfig: &tls.Config{
InsecureSkipVerify: true,
},
})
if err != nil {
t.Fatalf("failed connect to server: %v", err)
Expand Down Expand Up @@ -168,15 +181,20 @@ func Test_Key_Value(t *testing.T) {
func Test_SQL_Queries(t *testing.T) {
// connect
c, err := ignite.Connect(ignite.ConnInfo{
Network: "tcp",
Host: "localhost",
Port: 10800,
Major: 1,
Minor: 0,
Patch: 0,
Network: "tcp",
Host: "localhost",
Port: 10800,
Major: 1,
Minor: 1,
Patch: 0,
Username: "ignite",
Password: "ignite",
Dialer: net.Dialer{
Timeout: 10 * time.Second,
},
TLSConfig: &tls.Config{
InsecureSkipVerify: true,
},
})
if err != nil {
t.Fatalf("failed connect to server: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion sql/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func Test_connector_Connect(t *testing.T) {
d := &Driver{}
ci, err := d.OpenConnector("tcp://localhost:10800/DriverOpen")
ci, err := d.OpenConnector("tcp://localhost:10800/DriverOpen?version=1.1.0&username=ignite&password=ignite&tls=yes&tls-insecure-skip-verify=yes")
if err != nil {
t.Errorf("failed to open connector: %v", err)
return
Expand Down
2 changes: 1 addition & 1 deletion sql/driver-go1.10_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestDriver_OpenConnector(t *testing.T) {
name: "success test 1",
d: &Driver{},
args: args{
name: "tcp://localhost:10800/OpenConnector",
name: "tcp://localhost:10800/OpenConnector?version=1.1.0&username=ignite&password=ignite&tls=yes&tls-insecure-skip-verify=yes",
},
},
{
Expand Down
Loading

0 comments on commit 317cae8

Please sign in to comment.