From 0bc43663c5c6f84463880f56fda15a8b86d271c6 Mon Sep 17 00:00:00 2001 From: Oleg Jukovec Date: Thu, 22 Dec 2022 09:16:10 +0300 Subject: [PATCH] api: rename connection_pool to pool By convention, packages are given lower case, single-word names; there should be no need for underscores or mixedCaps [1]. 1. https://go.dev/doc/effective_go#package-names Closes #239 --- CHANGELOG.md | 2 + Makefile | 8 +- README.md | 10 +- {connection_pool => pool}/call_16_test.go | 14 +- {connection_pool => pool}/call_17_test.go | 14 +- {connection_pool => pool}/config.lua | 0 {connection_pool => pool}/connection_pool.go | 14 +- .../connection_pool_test.go | 334 +++++++++--------- {connection_pool => pool}/connector.go | 2 +- {connection_pool => pool}/connector_test.go | 4 +- {connection_pool => pool}/const.go | 2 +- {connection_pool => pool}/example_test.go | 178 +++++----- .../msgpack_helper_test.go | 2 +- .../msgpack_v5_helper_test.go | 2 +- {connection_pool => pool}/pooler.go | 2 +- {connection_pool => pool}/round_robin.go | 2 +- {connection_pool => pool}/round_robin_test.go | 4 +- {connection_pool => pool}/state.go | 2 +- {connection_pool => pool}/watcher.go | 2 +- queue/example_connection_pool_test.go | 22 +- test_helpers/pool_helper.go | 10 +- 21 files changed, 320 insertions(+), 310 deletions(-) rename {connection_pool => pool}/call_16_test.go (82%) rename {connection_pool => pool}/call_17_test.go (81%) rename {connection_pool => pool}/config.lua (100%) rename {connection_pool => pool}/connection_pool.go (99%) rename {connection_pool => pool}/connection_pool_test.go (89%) rename {connection_pool => pool}/connector.go (99%) rename {connection_pool => pool}/connector_test.go (99%) rename {connection_pool => pool}/const.go (97%) rename {connection_pool => pool}/example_test.go (83%) rename {connection_pool => pool}/msgpack_helper_test.go (83%) rename {connection_pool => pool}/msgpack_v5_helper_test.go (83%) rename {connection_pool => pool}/pooler.go (99%) rename {connection_pool => pool}/round_robin.go (98%) rename {connection_pool => pool}/round_robin_test.go (95%) rename {connection_pool => pool}/state.go (94%) rename {connection_pool => pool}/watcher.go (99%) diff --git a/CHANGELOG.md b/CHANGELOG.md index d9b8053c0..173d97595 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release. ### Changed +- connection_pool renamed to pool (#239) + ### Removed - multi subpackage (#240) diff --git a/Makefile b/Makefile index b1d808cda..f48b789cc 100644 --- a/Makefile +++ b/Makefile @@ -57,11 +57,11 @@ testrace: go clean -testcache go test -race -tags "$(TAGS)" ./... -v -p 1 -.PHONY: test-connection-pool -test-connection-pool: - @echo "Running tests in connection_pool package" +.PHONY: test-pool +test-pool: + @echo "Running tests in pool package" go clean -testcache - go test -tags "$(TAGS)" ./connection_pool/ -v -p 1 + go test -tags "$(TAGS)" ./pool/ -v -p 1 .PHONY: test-datetime test-datetime: diff --git a/README.md b/README.md index 8b7b2fbb4..8151f71e2 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ faster than other packages according to public benchmarks. * [Walking\-through example](#walking-through-example) * [Migration to v2](#migration-to-v2) * [multi package](#multi-package) + * [pool package](#pool-package) * [msgpack.v5](#msgpackv5) * [Contributing](#contributing) * [Alternative connectors](#alternative-connectors) @@ -161,7 +162,14 @@ The article describes migration from go-tarantool to go-tarantool/v2. #### multi package -The subpackage has been deleted. You could use `connection_pool` instead. +The subpackage has been deleted. You could use `pool` instead. + +#### pool package + +The logic has not changed, but there are a few renames: + +* The `connection_pool` subpackage has been renamed to `pool`. +* The type `PoolOpts` has been renamed to `Opts`. #### msgpack.v5 diff --git a/connection_pool/call_16_test.go b/pool/call_16_test.go similarity index 82% rename from connection_pool/call_16_test.go rename to pool/call_16_test.go index 806c67ba0..04b8898bc 100644 --- a/connection_pool/call_16_test.go +++ b/pool/call_16_test.go @@ -1,13 +1,13 @@ //go:build !go_tarantool_call_17 // +build !go_tarantool_call_17 -package connection_pool_test +package pool_test import ( "testing" "github.com/stretchr/testify/require" - "github.com/tarantool/go-tarantool/v2/connection_pool" + "github.com/tarantool/go-tarantool/v2/pool" "github.com/tarantool/go-tarantool/v2/test_helpers" ) @@ -17,14 +17,14 @@ func TestCall(t *testing.T) { err := test_helpers.SetClusterRO(servers, connOpts, roles) require.Nilf(t, err, "fail to set roles for cluster") - connPool, err := connection_pool.Connect(servers, connOpts) + connPool, err := pool.Connect(servers, connOpts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, connPool, "conn is nil after Connect") defer connPool.Close() // PreferRO - resp, err := connPool.Call("box.info", []interface{}{}, connection_pool.PreferRO) + resp, err := connPool.Call("box.info", []interface{}{}, pool.PreferRO) require.Nilf(t, err, "failed to Call") require.NotNilf(t, resp, "response is nil after Call") require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Call") @@ -35,7 +35,7 @@ func TestCall(t *testing.T) { require.Truef(t, ro, "expected `true` with mode `PreferRO`") // PreferRW - resp, err = connPool.Call("box.info", []interface{}{}, connection_pool.PreferRW) + resp, err = connPool.Call("box.info", []interface{}{}, pool.PreferRW) require.Nilf(t, err, "failed to Call") require.NotNilf(t, resp, "response is nil after Call") require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Call") @@ -46,7 +46,7 @@ func TestCall(t *testing.T) { require.Falsef(t, ro, "expected `false` with mode `PreferRW`") // RO - resp, err = connPool.Call("box.info", []interface{}{}, connection_pool.RO) + resp, err = connPool.Call("box.info", []interface{}{}, pool.RO) require.Nilf(t, err, "failed to Call") require.NotNilf(t, resp, "response is nil after Call") require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Call") @@ -57,7 +57,7 @@ func TestCall(t *testing.T) { require.Truef(t, ro, "expected `true` with mode `RO`") // RW - resp, err = connPool.Call("box.info", []interface{}{}, connection_pool.RW) + resp, err = connPool.Call("box.info", []interface{}{}, pool.RW) require.Nilf(t, err, "failed to Call") require.NotNilf(t, resp, "response is nil after Call") require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Call") diff --git a/connection_pool/call_17_test.go b/pool/call_17_test.go similarity index 81% rename from connection_pool/call_17_test.go rename to pool/call_17_test.go index 16f1a5e6b..6ca8381ad 100644 --- a/connection_pool/call_17_test.go +++ b/pool/call_17_test.go @@ -1,13 +1,13 @@ //go:build go_tarantool_call_17 // +build go_tarantool_call_17 -package connection_pool_test +package pool_test import ( "testing" "github.com/stretchr/testify/require" - "github.com/tarantool/go-tarantool/v2/connection_pool" + "github.com/tarantool/go-tarantool/v2/pool" "github.com/tarantool/go-tarantool/v2/test_helpers" ) @@ -17,14 +17,14 @@ func TestCall(t *testing.T) { err := test_helpers.SetClusterRO(servers, connOpts, roles) require.Nilf(t, err, "fail to set roles for cluster") - connPool, err := connection_pool.Connect(servers, connOpts) + connPool, err := pool.Connect(servers, connOpts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, connPool, "conn is nil after Connect") defer connPool.Close() // PreferRO - resp, err := connPool.Call("box.info", []interface{}{}, connection_pool.PreferRO) + resp, err := connPool.Call("box.info", []interface{}{}, pool.PreferRO) require.Nilf(t, err, "failed to Call") require.NotNilf(t, resp, "response is nil after Call") require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Call") @@ -35,7 +35,7 @@ func TestCall(t *testing.T) { require.Truef(t, ro, "expected `true` with mode `PreferRO`") // PreferRW - resp, err = connPool.Call("box.info", []interface{}{}, connection_pool.PreferRW) + resp, err = connPool.Call("box.info", []interface{}{}, pool.PreferRW) require.Nilf(t, err, "failed to Call") require.NotNilf(t, resp, "response is nil after Call") require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Call") @@ -46,7 +46,7 @@ func TestCall(t *testing.T) { require.Falsef(t, ro, "expected `false` with mode `PreferRW`") // RO - resp, err = connPool.Call("box.info", []interface{}{}, connection_pool.RO) + resp, err = connPool.Call("box.info", []interface{}{}, pool.RO) require.Nilf(t, err, "failed to Call") require.NotNilf(t, resp, "response is nil after Call") require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Call") @@ -57,7 +57,7 @@ func TestCall(t *testing.T) { require.Truef(t, ro, "expected `true` with mode `RO`") // RW - resp, err = connPool.Call("box.info", []interface{}{}, connection_pool.RW) + resp, err = connPool.Call("box.info", []interface{}{}, pool.RW) require.Nilf(t, err, "failed to Call") require.NotNilf(t, resp, "response is nil after Call") require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Call") diff --git a/connection_pool/config.lua b/pool/config.lua similarity index 100% rename from connection_pool/config.lua rename to pool/config.lua diff --git a/connection_pool/connection_pool.go b/pool/connection_pool.go similarity index 99% rename from connection_pool/connection_pool.go rename to pool/connection_pool.go index 4337514b8..bc8a3541a 100644 --- a/connection_pool/connection_pool.go +++ b/pool/connection_pool.go @@ -8,7 +8,7 @@ // - Automatic master discovery by mode parameter. // // Since: 1.6.0 -package connection_pool +package pool import ( "errors" @@ -57,8 +57,8 @@ type ConnectionHandler interface { Deactivated(conn *tarantool.Connection, role Role) error } -// OptsPool provides additional options (configurable via ConnectWithOpts). -type OptsPool struct { +// Opts provides additional options (configurable via ConnectWithOpts). +type Opts struct { // Timeout for timer to reopen connections that have been closed by some // events and to relocate connection between subpools if ro/rw role has // been updated. @@ -89,7 +89,7 @@ Main features: type ConnectionPool struct { addrs []string connOpts tarantool.Opts - opts OptsPool + opts Opts state state done chan struct{} @@ -111,7 +111,7 @@ type connState struct { // ConnectWithOpts creates pool for instances with addresses addrs // with options opts. -func ConnectWithOpts(addrs []string, connOpts tarantool.Opts, opts OptsPool) (connPool *ConnectionPool, err error) { +func ConnectWithOpts(addrs []string, connOpts tarantool.Opts, opts Opts) (connPool *ConnectionPool, err error) { if len(addrs) == 0 { return nil, ErrEmptyAddrs } @@ -166,9 +166,9 @@ func ConnectWithOpts(addrs []string, connOpts tarantool.Opts, opts OptsPool) (co // // It is useless to set up tarantool.Opts.Reconnect value for a connection. // The connection pool has its own reconnection logic. See -// OptsPool.CheckTimeout description. +// Opts.CheckTimeout description. func Connect(addrs []string, connOpts tarantool.Opts) (connPool *ConnectionPool, err error) { - opts := OptsPool{ + opts := Opts{ CheckTimeout: 1 * time.Second, } return ConnectWithOpts(addrs, connOpts, opts) diff --git a/connection_pool/connection_pool_test.go b/pool/connection_pool_test.go similarity index 89% rename from connection_pool/connection_pool_test.go rename to pool/connection_pool_test.go index 23a8a7e01..18f8d49ae 100644 --- a/connection_pool/connection_pool_test.go +++ b/pool/connection_pool_test.go @@ -1,4 +1,4 @@ -package connection_pool_test +package pool_test import ( "fmt" @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/require" "github.com/tarantool/go-tarantool/v2" - "github.com/tarantool/go-tarantool/v2/connection_pool" + "github.com/tarantool/go-tarantool/v2/pool" "github.com/tarantool/go-tarantool/v2/test_helpers" ) @@ -44,17 +44,17 @@ var defaultTimeoutRetry = 500 * time.Millisecond var instances []test_helpers.TarantoolInstance func TestConnError_IncorrectParams(t *testing.T) { - connPool, err := connection_pool.Connect([]string{}, tarantool.Opts{}) + connPool, err := pool.Connect([]string{}, tarantool.Opts{}) require.Nilf(t, connPool, "conn is not nil with incorrect param") require.NotNilf(t, err, "err is nil with incorrect params") require.Equal(t, "addrs (first argument) should not be empty", err.Error()) - connPool, err = connection_pool.Connect([]string{"err1", "err2"}, connOpts) + connPool, err = pool.Connect([]string{"err1", "err2"}, connOpts) require.Nilf(t, connPool, "conn is not nil with incorrect param") require.NotNilf(t, err, "err is nil with incorrect params") require.Equal(t, "no active connections", err.Error()) - connPool, err = connection_pool.ConnectWithOpts(servers, tarantool.Opts{}, connection_pool.OptsPool{}) + connPool, err = pool.ConnectWithOpts(servers, tarantool.Opts{}, pool.Opts{}) require.Nilf(t, connPool, "conn is not nil with incorrect param") require.NotNilf(t, err, "err is nil with incorrect params") require.Equal(t, "wrong check timeout, must be greater than 0", err.Error()) @@ -62,7 +62,7 @@ func TestConnError_IncorrectParams(t *testing.T) { func TestConnSuccessfully(t *testing.T) { server := servers[0] - connPool, err := connection_pool.Connect([]string{"err", server}, connOpts) + connPool, err := pool.Connect([]string{"err", server}, connOpts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, connPool, "conn is nil after Connect") @@ -70,7 +70,7 @@ func TestConnSuccessfully(t *testing.T) { args := test_helpers.CheckStatusesArgs{ ConnPool: connPool, - Mode: connection_pool.ANY, + Mode: pool.ANY, Servers: []string{server}, ExpectedPoolStatus: true, ExpectedStatuses: map[string]bool{ @@ -84,7 +84,7 @@ func TestConnSuccessfully(t *testing.T) { func TestConnSuccessfullyDuplicates(t *testing.T) { server := servers[0] - connPool, err := connection_pool.Connect([]string{server, server, server, server}, connOpts) + connPool, err := pool.Connect([]string{server, server, server, server}, connOpts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, connPool, "conn is nil after Connect") @@ -92,7 +92,7 @@ func TestConnSuccessfullyDuplicates(t *testing.T) { args := test_helpers.CheckStatusesArgs{ ConnPool: connPool, - Mode: connection_pool.ANY, + Mode: pool.ANY, Servers: []string{server}, ExpectedPoolStatus: true, ExpectedStatuses: map[string]bool{ @@ -110,7 +110,7 @@ func TestConnSuccessfullyDuplicates(t *testing.T) { func TestReconnect(t *testing.T) { server := servers[0] - connPool, err := connection_pool.Connect(servers, connOpts) + connPool, err := pool.Connect(servers, connOpts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, connPool, "conn is nil after Connect") @@ -120,7 +120,7 @@ func TestReconnect(t *testing.T) { args := test_helpers.CheckStatusesArgs{ ConnPool: connPool, - Mode: connection_pool.ANY, + Mode: pool.ANY, Servers: []string{server}, ExpectedPoolStatus: true, ExpectedStatuses: map[string]bool{ @@ -136,7 +136,7 @@ func TestReconnect(t *testing.T) { args = test_helpers.CheckStatusesArgs{ ConnPool: connPool, - Mode: connection_pool.ANY, + Mode: pool.ANY, Servers: []string{server}, ExpectedPoolStatus: true, ExpectedStatuses: map[string]bool{ @@ -154,7 +154,7 @@ func TestDisconnect_withReconnect(t *testing.T) { opts := connOpts opts.Reconnect = 10 * time.Second - connPool, err := connection_pool.Connect([]string{servers[serverId]}, opts) + connPool, err := pool.Connect([]string{servers[serverId]}, opts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, connPool, "conn is nil after Connect") @@ -164,7 +164,7 @@ func TestDisconnect_withReconnect(t *testing.T) { test_helpers.StopTarantoolWithCleanup(instances[serverId]) args := test_helpers.CheckStatusesArgs{ ConnPool: connPool, - Mode: connection_pool.ANY, + Mode: pool.ANY, Servers: []string{servers[serverId]}, ExpectedPoolStatus: false, ExpectedStatuses: map[string]bool{ @@ -181,7 +181,7 @@ func TestDisconnect_withReconnect(t *testing.T) { args = test_helpers.CheckStatusesArgs{ ConnPool: connPool, - Mode: connection_pool.ANY, + Mode: pool.ANY, Servers: []string{servers[serverId]}, ExpectedPoolStatus: true, ExpectedStatuses: map[string]bool{ @@ -198,7 +198,7 @@ func TestDisconnectAll(t *testing.T) { server1 := servers[0] server2 := servers[1] - connPool, err := connection_pool.Connect([]string{server1, server2}, connOpts) + connPool, err := pool.Connect([]string{server1, server2}, connOpts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, connPool, "conn is nil after Connect") @@ -209,7 +209,7 @@ func TestDisconnectAll(t *testing.T) { args := test_helpers.CheckStatusesArgs{ ConnPool: connPool, - Mode: connection_pool.ANY, + Mode: pool.ANY, Servers: []string{server1, server2}, ExpectedPoolStatus: false, ExpectedStatuses: map[string]bool{ @@ -229,7 +229,7 @@ func TestDisconnectAll(t *testing.T) { args = test_helpers.CheckStatusesArgs{ ConnPool: connPool, - Mode: connection_pool.ANY, + Mode: pool.ANY, Servers: []string{server1, server2}, ExpectedPoolStatus: true, ExpectedStatuses: map[string]bool{ @@ -246,13 +246,13 @@ func TestClose(t *testing.T) { server1 := servers[0] server2 := servers[1] - connPool, err := connection_pool.Connect([]string{server1, server2}, connOpts) + connPool, err := pool.Connect([]string{server1, server2}, connOpts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, connPool, "conn is nil after Connect") args := test_helpers.CheckStatusesArgs{ ConnPool: connPool, - Mode: connection_pool.ANY, + Mode: pool.ANY, Servers: []string{server1, server2}, ExpectedPoolStatus: true, ExpectedStatuses: map[string]bool{ @@ -268,7 +268,7 @@ func TestClose(t *testing.T) { args = test_helpers.CheckStatusesArgs{ ConnPool: connPool, - Mode: connection_pool.ANY, + Mode: pool.ANY, Servers: []string{server1, server2}, ExpectedPoolStatus: false, ExpectedStatuses: map[string]bool{ @@ -291,7 +291,7 @@ func (h *testHandler) addErr(err error) { } func (h *testHandler) Discovered(conn *tarantool.Connection, - role connection_pool.Role) error { + role pool.Role) error { discovered := atomic.AddUint32(&h.discovered, 1) if conn == nil { @@ -303,17 +303,17 @@ func (h *testHandler) Discovered(conn *tarantool.Connection, // discovered >= 3 - update a connection after a role update addr := conn.Addr() if addr == servers[0] { - if discovered < 3 && role != connection_pool.MasterRole { + if discovered < 3 && role != pool.MasterRole { h.addErr(fmt.Errorf("unexpected init role %d for addr %s", role, addr)) } - if discovered >= 3 && role != connection_pool.ReplicaRole { + if discovered >= 3 && role != pool.ReplicaRole { h.addErr(fmt.Errorf("unexpected updated role %d for addr %s", role, addr)) } } else if addr == servers[1] { if discovered >= 3 { h.addErr(fmt.Errorf("unexpected discovery for addr %s", addr)) } - if role != connection_pool.ReplicaRole { + if role != pool.ReplicaRole { h.addErr(fmt.Errorf("unexpected role %d for addr %s", role, addr)) } } else { @@ -324,7 +324,7 @@ func (h *testHandler) Discovered(conn *tarantool.Connection, } func (h *testHandler) Deactivated(conn *tarantool.Connection, - role connection_pool.Role) error { + role pool.Role) error { deactivated := atomic.AddUint32(&h.deactivated, 1) if conn == nil { @@ -335,7 +335,7 @@ func (h *testHandler) Deactivated(conn *tarantool.Connection, addr := conn.Addr() if deactivated == 1 && addr == servers[0] { // A first close is a role update. - if role != connection_pool.MasterRole { + if role != pool.MasterRole { h.addErr(fmt.Errorf("unexpected removed role %d for addr %s", role, addr)) } return nil @@ -343,7 +343,7 @@ func (h *testHandler) Deactivated(conn *tarantool.Connection, if addr == servers[0] || addr == servers[1] { // Close. - if role != connection_pool.ReplicaRole { + if role != pool.ReplicaRole { h.addErr(fmt.Errorf("unexpected removed role %d for addr %s", role, addr)) } } else { @@ -361,17 +361,17 @@ func TestConnectionHandlerOpenUpdateClose(t *testing.T) { require.Nilf(t, err, "fail to set roles for cluster") h := &testHandler{} - poolOpts := connection_pool.OptsPool{ + poolOpts := pool.Opts{ CheckTimeout: 100 * time.Microsecond, ConnectionHandler: h, } - pool, err := connection_pool.ConnectWithOpts(poolServers, connOpts, poolOpts) + connPool, err := pool.ConnectWithOpts(poolServers, connOpts, poolOpts) require.Nilf(t, err, "failed to connect") - require.NotNilf(t, pool, "conn is nil after Connect") + require.NotNilf(t, connPool, "conn is nil after Connect") - _, err = pool.Call17("box.cfg", []interface{}{map[string]bool{ + _, err = connPool.Call17("box.cfg", []interface{}{map[string]bool{ "read_only": true, - }}, connection_pool.RW) + }}, pool.RW) require.Nilf(t, err, "failed to make ro") for i := 0; i < 100; i++ { @@ -390,7 +390,7 @@ func TestConnectionHandlerOpenUpdateClose(t *testing.T) { require.Equalf(t, uint32(1), deactivated, "updated not reported as deactivated") - pool.Close() + connPool.Close() for i := 0; i < 100; i++ { // Wait for close of all connections. @@ -403,7 +403,7 @@ func TestConnectionHandlerOpenUpdateClose(t *testing.T) { for _, err := range h.errs { t.Errorf("Unexpected error: %s", err) } - connected, err := pool.ConnectedNow(connection_pool.ANY) + connected, err := connPool.ConnectedNow(pool.ANY) require.Nilf(t, err, "failed to get connected state") require.Falsef(t, connected, "connection pool still be connected") @@ -420,13 +420,13 @@ type testAddErrorHandler struct { } func (h *testAddErrorHandler) Discovered(conn *tarantool.Connection, - role connection_pool.Role) error { + role pool.Role) error { h.discovered++ return fmt.Errorf("any error") } func (h *testAddErrorHandler) Deactivated(conn *tarantool.Connection, - role connection_pool.Role) error { + role pool.Role) error { h.deactivated++ return nil } @@ -435,11 +435,11 @@ func TestConnectionHandlerOpenError(t *testing.T) { poolServers := []string{servers[0], servers[1]} h := &testAddErrorHandler{} - poolOpts := connection_pool.OptsPool{ + poolOpts := pool.Opts{ CheckTimeout: 100 * time.Microsecond, ConnectionHandler: h, } - connPool, err := connection_pool.ConnectWithOpts(poolServers, connOpts, poolOpts) + connPool, err := pool.ConnectWithOpts(poolServers, connOpts, poolOpts) if err == nil { defer connPool.Close() } @@ -453,7 +453,7 @@ type testUpdateErrorHandler struct { } func (h *testUpdateErrorHandler) Discovered(conn *tarantool.Connection, - role connection_pool.Role) error { + role pool.Role) error { atomic.AddUint32(&h.discovered, 1) if atomic.LoadUint32(&h.deactivated) != 0 { @@ -464,7 +464,7 @@ func (h *testUpdateErrorHandler) Discovered(conn *tarantool.Connection, } func (h *testUpdateErrorHandler) Deactivated(conn *tarantool.Connection, - role connection_pool.Role) error { + role pool.Role) error { atomic.AddUint32(&h.deactivated, 1) return nil } @@ -477,42 +477,42 @@ func TestConnectionHandlerUpdateError(t *testing.T) { require.Nilf(t, err, "fail to set roles for cluster") h := &testUpdateErrorHandler{} - poolOpts := connection_pool.OptsPool{ + poolOpts := pool.Opts{ CheckTimeout: 100 * time.Microsecond, ConnectionHandler: h, } - connPool, err := connection_pool.ConnectWithOpts(poolServers, connOpts, poolOpts) + connPool, err := pool.ConnectWithOpts(poolServers, connOpts, poolOpts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, connPool, "conn is nil after Connect") defer connPool.Close() - connected, err := connPool.ConnectedNow(connection_pool.ANY) + connected, err := connPool.ConnectedNow(pool.ANY) require.Nilf(t, err, "failed to get ConnectedNow()") require.Truef(t, connected, "should be connected") for i := 0; i < len(poolServers); i++ { _, err = connPool.Call17("box.cfg", []interface{}{map[string]bool{ "read_only": true, - }}, connection_pool.RW) + }}, pool.RW) require.Nilf(t, err, "failed to make ro") } for i := 0; i < 100; i++ { // Wait for updates done. - connected, err = connPool.ConnectedNow(connection_pool.ANY) + connected, err = connPool.ConnectedNow(pool.ANY) if !connected || err != nil { break } time.Sleep(poolOpts.CheckTimeout) } - connected, err = connPool.ConnectedNow(connection_pool.ANY) + connected, err = connPool.ConnectedNow(pool.ANY) require.Nilf(t, err, "failed to get ConnectedNow()") require.Falsef(t, connected, "should not be any active connection") connPool.Close() - connected, err = connPool.ConnectedNow(connection_pool.ANY) + connected, err = connPool.ConnectedNow(pool.ANY) require.Nilf(t, err, "failed to get ConnectedNow()") require.Falsef(t, connected, "should be deactivated") @@ -526,7 +526,7 @@ func TestRequestOnClosed(t *testing.T) { server1 := servers[0] server2 := servers[1] - connPool, err := connection_pool.Connect([]string{server1, server2}, connOpts) + connPool, err := pool.Connect([]string{server1, server2}, connOpts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, connPool, "conn is nil after Connect") @@ -537,7 +537,7 @@ func TestRequestOnClosed(t *testing.T) { args := test_helpers.CheckStatusesArgs{ ConnPool: connPool, - Mode: connection_pool.ANY, + Mode: pool.ANY, Servers: []string{server1, server2}, ExpectedPoolStatus: false, ExpectedStatuses: map[string]bool{ @@ -548,7 +548,7 @@ func TestRequestOnClosed(t *testing.T) { err = test_helpers.Retry(test_helpers.CheckPoolStatuses, args, defaultCountRetry, defaultTimeoutRetry) require.Nil(t, err) - _, err = connPool.Ping(connection_pool.ANY) + _, err = connPool.Ping(pool.ANY) require.NotNilf(t, err, "err is nil after Ping") err = test_helpers.RestartTarantool(&instances[0]) @@ -564,7 +564,7 @@ func TestGetPoolInfo(t *testing.T) { srvs := []string{server1, server2} expected := []string{server1, server2} - connPool, err := connection_pool.Connect(srvs, connOpts) + connPool, err := pool.Connect(srvs, connOpts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, connPool, "conn is nil after Connect") @@ -583,14 +583,14 @@ func TestCall17(t *testing.T) { err := test_helpers.SetClusterRO(servers, connOpts, roles) require.Nilf(t, err, "fail to set roles for cluster") - connPool, err := connection_pool.Connect(servers, connOpts) + connPool, err := pool.Connect(servers, connOpts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, connPool, "conn is nil after Connect") defer connPool.Close() // PreferRO - resp, err := connPool.Call17("box.info", []interface{}{}, connection_pool.PreferRO) + resp, err := connPool.Call17("box.info", []interface{}{}, pool.PreferRO) require.Nilf(t, err, "failed to Call") require.NotNilf(t, resp, "response is nil after Call") require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Call") @@ -601,7 +601,7 @@ func TestCall17(t *testing.T) { require.Truef(t, ro, "expected `true` with mode `PreferRO`") // PreferRW - resp, err = connPool.Call17("box.info", []interface{}{}, connection_pool.PreferRW) + resp, err = connPool.Call17("box.info", []interface{}{}, pool.PreferRW) require.Nilf(t, err, "failed to Call") require.NotNilf(t, resp, "response is nil after Call") require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Call") @@ -612,7 +612,7 @@ func TestCall17(t *testing.T) { require.Falsef(t, ro, "expected `false` with mode `PreferRW`") // RO - resp, err = connPool.Call17("box.info", []interface{}{}, connection_pool.RO) + resp, err = connPool.Call17("box.info", []interface{}{}, pool.RO) require.Nilf(t, err, "failed to Call") require.NotNilf(t, resp, "response is nil after Call") require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Call") @@ -623,7 +623,7 @@ func TestCall17(t *testing.T) { require.Truef(t, ro, "expected `true` with mode `RO`") // RW - resp, err = connPool.Call17("box.info", []interface{}{}, connection_pool.RW) + resp, err = connPool.Call17("box.info", []interface{}{}, pool.RW) require.Nilf(t, err, "failed to Call") require.NotNilf(t, resp, "response is nil after Call") require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Call") @@ -640,14 +640,14 @@ func TestEval(t *testing.T) { err := test_helpers.SetClusterRO(servers, connOpts, roles) require.Nilf(t, err, "fail to set roles for cluster") - connPool, err := connection_pool.Connect(servers, connOpts) + connPool, err := pool.Connect(servers, connOpts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, connPool, "conn is nil after Connect") defer connPool.Close() // PreferRO - resp, err := connPool.Eval("return box.info().ro", []interface{}{}, connection_pool.PreferRO) + resp, err := connPool.Eval("return box.info().ro", []interface{}{}, pool.PreferRO) require.Nilf(t, err, "failed to Eval") require.NotNilf(t, resp, "response is nil after Eval") require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Eval") @@ -657,7 +657,7 @@ func TestEval(t *testing.T) { require.Truef(t, val, "expected `true` with mode `PreferRO`") // PreferRW - resp, err = connPool.Eval("return box.info().ro", []interface{}{}, connection_pool.PreferRW) + resp, err = connPool.Eval("return box.info().ro", []interface{}{}, pool.PreferRW) require.Nilf(t, err, "failed to Eval") require.NotNilf(t, resp, "response is nil after Eval") require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Eval") @@ -667,7 +667,7 @@ func TestEval(t *testing.T) { require.Falsef(t, val, "expected `false` with mode `PreferRW`") // RO - resp, err = connPool.Eval("return box.info().ro", []interface{}{}, connection_pool.RO) + resp, err = connPool.Eval("return box.info().ro", []interface{}{}, pool.RO) require.Nilf(t, err, "failed to Eval") require.NotNilf(t, resp, "response is nil after Eval") require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Eval") @@ -677,7 +677,7 @@ func TestEval(t *testing.T) { require.Truef(t, val, "expected `true` with mode `RO`") // RW - resp, err = connPool.Eval("return box.info().ro", []interface{}{}, connection_pool.RW) + resp, err = connPool.Eval("return box.info().ro", []interface{}{}, pool.RW) require.Nilf(t, err, "failed to Eval") require.NotNilf(t, resp, "response is nil after Eval") require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Eval") @@ -718,7 +718,7 @@ func TestExecute(t *testing.T) { err := test_helpers.SetClusterRO(servers, connOpts, roles) require.Nilf(t, err, "fail to set roles for cluster") - connPool, err := connection_pool.Connect(servers, connOpts) + connPool, err := pool.Connect(servers, connOpts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, connPool, "conn is nil after Connect") @@ -726,7 +726,7 @@ func TestExecute(t *testing.T) { request := "SELECT NAME0, NAME1 FROM SQL_TEST WHERE NAME0 == 1;" // Execute - resp, err := connPool.Execute(request, []interface{}{}, connection_pool.ANY) + resp, err := connPool.Execute(request, []interface{}{}, pool.ANY) require.Nilf(t, err, "failed to Execute") require.NotNilf(t, resp, "response is nil after Execute") require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Execute") @@ -734,13 +734,13 @@ func TestExecute(t *testing.T) { // ExecuteTyped mem := []Member{} - info, _, err := connPool.ExecuteTyped(request, []interface{}{}, &mem, connection_pool.ANY) + info, _, err := connPool.ExecuteTyped(request, []interface{}{}, &mem, pool.ANY) require.Nilf(t, err, "failed to ExecuteTyped") require.Equalf(t, info.AffectedCount, uint64(0), "unexpected info.AffectedCount") require.Equalf(t, len(mem), 1, "wrong count of results") // ExecuteAsync - fut := connPool.ExecuteAsync(request, []interface{}{}, connection_pool.ANY) + fut := connPool.ExecuteAsync(request, []interface{}{}, pool.ANY) resp, err = fut.Get() require.Nilf(t, err, "failed to ExecuteAsync") require.NotNilf(t, resp, "response is nil after ExecuteAsync") @@ -775,7 +775,7 @@ func TestRoundRobinStrategy(t *testing.T) { err := test_helpers.SetClusterRO(servers, connOpts, roles) require.Nilf(t, err, "fail to set roles for cluster") - connPool, err := connection_pool.Connect(servers, connOpts) + connPool, err := pool.Connect(servers, connOpts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, connPool, "conn is nil after Connect") @@ -786,7 +786,7 @@ func TestRoundRobinStrategy(t *testing.T) { ServersNumber: serversNumber, ExpectedPorts: allPorts, ConnPool: connPool, - Mode: connection_pool.ANY, + Mode: pool.ANY, } err = test_helpers.ProcessListenOnInstance(args) @@ -797,7 +797,7 @@ func TestRoundRobinStrategy(t *testing.T) { ServersNumber: serversNumber, ExpectedPorts: masterPorts, ConnPool: connPool, - Mode: connection_pool.RW, + Mode: pool.RW, } err = test_helpers.ProcessListenOnInstance(args) @@ -808,7 +808,7 @@ func TestRoundRobinStrategy(t *testing.T) { ServersNumber: serversNumber, ExpectedPorts: replicaPorts, ConnPool: connPool, - Mode: connection_pool.RO, + Mode: pool.RO, } err = test_helpers.ProcessListenOnInstance(args) @@ -819,7 +819,7 @@ func TestRoundRobinStrategy(t *testing.T) { ServersNumber: serversNumber, ExpectedPorts: masterPorts, ConnPool: connPool, - Mode: connection_pool.PreferRW, + Mode: pool.PreferRW, } err = test_helpers.ProcessListenOnInstance(args) @@ -830,7 +830,7 @@ func TestRoundRobinStrategy(t *testing.T) { ServersNumber: serversNumber, ExpectedPorts: replicaPorts, ConnPool: connPool, - Mode: connection_pool.PreferRO, + Mode: pool.PreferRO, } err = test_helpers.ProcessListenOnInstance(args) @@ -852,14 +852,14 @@ func TestRoundRobinStrategy_NoReplica(t *testing.T) { err := test_helpers.SetClusterRO(servers, connOpts, roles) require.Nilf(t, err, "fail to set roles for cluster") - connPool, err := connection_pool.Connect(servers, connOpts) + connPool, err := pool.Connect(servers, connOpts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, connPool, "conn is nil after Connect") defer connPool.Close() // RO - _, err = connPool.Eval("return box.cfg.listen", []interface{}{}, connection_pool.RO) + _, err = connPool.Eval("return box.cfg.listen", []interface{}{}, pool.RO) require.NotNilf(t, err, "expected to fail after Eval, but error is nil") require.Equal(t, "can't find ro instance in pool", err.Error()) @@ -868,7 +868,7 @@ func TestRoundRobinStrategy_NoReplica(t *testing.T) { ServersNumber: serversNumber, ExpectedPorts: allPorts, ConnPool: connPool, - Mode: connection_pool.ANY, + Mode: pool.ANY, } err = test_helpers.ProcessListenOnInstance(args) @@ -879,7 +879,7 @@ func TestRoundRobinStrategy_NoReplica(t *testing.T) { ServersNumber: serversNumber, ExpectedPorts: allPorts, ConnPool: connPool, - Mode: connection_pool.RW, + Mode: pool.RW, } err = test_helpers.ProcessListenOnInstance(args) @@ -890,7 +890,7 @@ func TestRoundRobinStrategy_NoReplica(t *testing.T) { ServersNumber: serversNumber, ExpectedPorts: allPorts, ConnPool: connPool, - Mode: connection_pool.PreferRW, + Mode: pool.PreferRW, } err = test_helpers.ProcessListenOnInstance(args) @@ -901,7 +901,7 @@ func TestRoundRobinStrategy_NoReplica(t *testing.T) { ServersNumber: serversNumber, ExpectedPorts: allPorts, ConnPool: connPool, - Mode: connection_pool.PreferRO, + Mode: pool.PreferRO, } err = test_helpers.ProcessListenOnInstance(args) @@ -923,14 +923,14 @@ func TestRoundRobinStrategy_NoMaster(t *testing.T) { err := test_helpers.SetClusterRO(servers, connOpts, roles) require.Nilf(t, err, "fail to set roles for cluster") - connPool, err := connection_pool.Connect(servers, connOpts) + connPool, err := pool.Connect(servers, connOpts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, connPool, "conn is nil after Connect") defer connPool.Close() // RW - _, err = connPool.Eval("return box.cfg.listen", []interface{}{}, connection_pool.RW) + _, err = connPool.Eval("return box.cfg.listen", []interface{}{}, pool.RW) require.NotNilf(t, err, "expected to fail after Eval, but error is nil") require.Equal(t, "can't find rw instance in pool", err.Error()) @@ -939,7 +939,7 @@ func TestRoundRobinStrategy_NoMaster(t *testing.T) { ServersNumber: serversNumber, ExpectedPorts: allPorts, ConnPool: connPool, - Mode: connection_pool.ANY, + Mode: pool.ANY, } err = test_helpers.ProcessListenOnInstance(args) @@ -950,7 +950,7 @@ func TestRoundRobinStrategy_NoMaster(t *testing.T) { ServersNumber: serversNumber, ExpectedPorts: allPorts, ConnPool: connPool, - Mode: connection_pool.RO, + Mode: pool.RO, } err = test_helpers.ProcessListenOnInstance(args) @@ -961,7 +961,7 @@ func TestRoundRobinStrategy_NoMaster(t *testing.T) { ServersNumber: serversNumber, ExpectedPorts: allPorts, ConnPool: connPool, - Mode: connection_pool.PreferRW, + Mode: pool.PreferRW, } err = test_helpers.ProcessListenOnInstance(args) @@ -972,7 +972,7 @@ func TestRoundRobinStrategy_NoMaster(t *testing.T) { ServersNumber: serversNumber, ExpectedPorts: allPorts, ConnPool: connPool, - Mode: connection_pool.PreferRO, + Mode: pool.PreferRO, } err = test_helpers.ProcessListenOnInstance(args) @@ -1006,7 +1006,7 @@ func TestUpdateInstancesRoles(t *testing.T) { err := test_helpers.SetClusterRO(servers, connOpts, roles) require.Nilf(t, err, "fail to set roles for cluster") - connPool, err := connection_pool.Connect(servers, connOpts) + connPool, err := pool.Connect(servers, connOpts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, connPool, "conn is nil after Connect") @@ -1017,7 +1017,7 @@ func TestUpdateInstancesRoles(t *testing.T) { ServersNumber: serversNumber, ExpectedPorts: allPorts, ConnPool: connPool, - Mode: connection_pool.ANY, + Mode: pool.ANY, } err = test_helpers.ProcessListenOnInstance(args) @@ -1028,7 +1028,7 @@ func TestUpdateInstancesRoles(t *testing.T) { ServersNumber: serversNumber, ExpectedPorts: masterPorts, ConnPool: connPool, - Mode: connection_pool.RW, + Mode: pool.RW, } err = test_helpers.ProcessListenOnInstance(args) @@ -1039,7 +1039,7 @@ func TestUpdateInstancesRoles(t *testing.T) { ServersNumber: serversNumber, ExpectedPorts: replicaPorts, ConnPool: connPool, - Mode: connection_pool.RO, + Mode: pool.RO, } err = test_helpers.ProcessListenOnInstance(args) @@ -1050,7 +1050,7 @@ func TestUpdateInstancesRoles(t *testing.T) { ServersNumber: serversNumber, ExpectedPorts: masterPorts, ConnPool: connPool, - Mode: connection_pool.PreferRW, + Mode: pool.PreferRW, } err = test_helpers.ProcessListenOnInstance(args) @@ -1061,7 +1061,7 @@ func TestUpdateInstancesRoles(t *testing.T) { ServersNumber: serversNumber, ExpectedPorts: replicaPorts, ConnPool: connPool, - Mode: connection_pool.PreferRO, + Mode: pool.PreferRO, } err = test_helpers.ProcessListenOnInstance(args) @@ -1088,7 +1088,7 @@ func TestUpdateInstancesRoles(t *testing.T) { ServersNumber: serversNumber, ExpectedPorts: allPorts, ConnPool: connPool, - Mode: connection_pool.ANY, + Mode: pool.ANY, } err = test_helpers.Retry(test_helpers.ProcessListenOnInstance, args, defaultCountRetry, defaultTimeoutRetry) @@ -1099,7 +1099,7 @@ func TestUpdateInstancesRoles(t *testing.T) { ServersNumber: serversNumber, ExpectedPorts: masterPorts, ConnPool: connPool, - Mode: connection_pool.RW, + Mode: pool.RW, } err = test_helpers.Retry(test_helpers.ProcessListenOnInstance, args, defaultCountRetry, defaultTimeoutRetry) @@ -1110,7 +1110,7 @@ func TestUpdateInstancesRoles(t *testing.T) { ServersNumber: serversNumber, ExpectedPorts: replicaPorts, ConnPool: connPool, - Mode: connection_pool.RO, + Mode: pool.RO, } err = test_helpers.Retry(test_helpers.ProcessListenOnInstance, args, defaultCountRetry, defaultTimeoutRetry) @@ -1121,7 +1121,7 @@ func TestUpdateInstancesRoles(t *testing.T) { ServersNumber: serversNumber, ExpectedPorts: masterPorts, ConnPool: connPool, - Mode: connection_pool.PreferRW, + Mode: pool.PreferRW, } err = test_helpers.Retry(test_helpers.ProcessListenOnInstance, args, defaultCountRetry, defaultTimeoutRetry) @@ -1132,7 +1132,7 @@ func TestUpdateInstancesRoles(t *testing.T) { ServersNumber: serversNumber, ExpectedPorts: replicaPorts, ConnPool: connPool, - Mode: connection_pool.PreferRO, + Mode: pool.PreferRO, } err = test_helpers.Retry(test_helpers.ProcessListenOnInstance, args, defaultCountRetry, defaultTimeoutRetry) @@ -1145,7 +1145,7 @@ func TestInsert(t *testing.T) { err := test_helpers.SetClusterRO(servers, connOpts, roles) require.Nilf(t, err, "fail to set roles for cluster") - connPool, err := connection_pool.Connect(servers, connOpts) + connPool, err := pool.Connect(servers, connOpts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, connPool, "conn is nil after Connect") @@ -1233,7 +1233,7 @@ func TestDelete(t *testing.T) { err := test_helpers.SetClusterRO(servers, connOpts, roles) require.Nilf(t, err, "fail to set roles for cluster") - connPool, err := connection_pool.Connect(servers, connOpts) + connPool, err := pool.Connect(servers, connOpts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, connPool, "conn is nil after Connect") @@ -1291,7 +1291,7 @@ func TestUpsert(t *testing.T) { err := test_helpers.SetClusterRO(servers, connOpts, roles) require.Nilf(t, err, "fail to set roles for cluster") - connPool, err := connection_pool.Connect(servers, connOpts) + connPool, err := pool.Connect(servers, connOpts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, connPool, "conn is nil after Connect") @@ -1327,7 +1327,7 @@ func TestUpsert(t *testing.T) { // PreferRW resp, err = connPool.Upsert( spaceName, []interface{}{"upsert_key", "upsert_value"}, - []interface{}{[]interface{}{"=", 1, "new_value"}}, connection_pool.PreferRW) + []interface{}{[]interface{}{"=", 1, "new_value"}}, pool.PreferRW) require.Nilf(t, err, "failed to Upsert") require.NotNilf(t, resp, "response is nil after Upsert") @@ -1356,7 +1356,7 @@ func TestUpdate(t *testing.T) { err := test_helpers.SetClusterRO(servers, connOpts, roles) require.Nilf(t, err, "fail to set roles for cluster") - connPool, err := connection_pool.Connect(servers, connOpts) + connPool, err := pool.Connect(servers, connOpts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, connPool, "conn is nil after Connect") @@ -1409,7 +1409,7 @@ func TestUpdate(t *testing.T) { // PreferRW resp, err = connPool.Update( spaceName, indexNo, []interface{}{"update_key"}, - []interface{}{[]interface{}{"=", 1, "another_value"}}, connection_pool.PreferRW) + []interface{}{[]interface{}{"=", 1, "another_value"}}, pool.PreferRW) require.Nilf(t, err, "failed to Update") require.NotNilf(t, resp, "response is nil after Update") @@ -1438,7 +1438,7 @@ func TestReplace(t *testing.T) { err := test_helpers.SetClusterRO(servers, connOpts, roles) require.Nilf(t, err, "fail to set roles for cluster") - connPool, err := connection_pool.Connect(servers, connOpts) + connPool, err := pool.Connect(servers, connOpts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, connPool, "conn is nil after Connect") @@ -1489,7 +1489,7 @@ func TestReplace(t *testing.T) { require.Equalf(t, "new_value", value, "unexpected body of Select (1)") // PreferRW - resp, err = connPool.Replace(spaceNo, []interface{}{"new_key", "new_value"}, connection_pool.PreferRW) + resp, err = connPool.Replace(spaceNo, []interface{}{"new_key", "new_value"}, pool.PreferRW) require.Nilf(t, err, "failed to Replace") require.NotNilf(t, resp, "response is nil after Replace") @@ -1517,7 +1517,7 @@ func TestSelect(t *testing.T) { err := test_helpers.SetClusterRO(servers, connOpts, roles) require.Nilf(t, err, "fail to set roles for cluster") - connPool, err := connection_pool.Connect(servers, connOpts) + connPool, err := pool.Connect(servers, connOpts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, connPool, "conn is nil after Connect") @@ -1563,7 +1563,7 @@ func TestSelect(t *testing.T) { require.Equalf(t, "any_select_value", value, "unexpected body of Select (1)") // PreferRO - resp, err = connPool.Select(spaceNo, indexNo, 0, 1, tarantool.IterEq, roKey, connection_pool.PreferRO) + resp, err = connPool.Select(spaceNo, indexNo, 0, 1, tarantool.IterEq, roKey, pool.PreferRO) require.Nilf(t, err, "failed to Select") require.NotNilf(t, resp, "response is nil after Select") require.Equalf(t, len(resp.Data), 1, "response Body len != 1 after Select") @@ -1577,7 +1577,7 @@ func TestSelect(t *testing.T) { require.Equalf(t, "ro_select_key", key, "unexpected body of Select (0)") // PreferRW - resp, err = connPool.Select(spaceNo, indexNo, 0, 1, tarantool.IterEq, rwKey, connection_pool.PreferRW) + resp, err = connPool.Select(spaceNo, indexNo, 0, 1, tarantool.IterEq, rwKey, pool.PreferRW) require.Nilf(t, err, "failed to Select") require.NotNilf(t, resp, "response is nil after Select") require.Equalf(t, len(resp.Data), 1, "response Body len != 1 after Select") @@ -1595,7 +1595,7 @@ func TestSelect(t *testing.T) { require.Equalf(t, "rw_select_value", value, "unexpected body of Select (1)") // RO - resp, err = connPool.Select(spaceNo, indexNo, 0, 1, tarantool.IterEq, roKey, connection_pool.RO) + resp, err = connPool.Select(spaceNo, indexNo, 0, 1, tarantool.IterEq, roKey, pool.RO) require.Nilf(t, err, "failed to Select") require.NotNilf(t, resp, "response is nil after Select") require.Equalf(t, len(resp.Data), 1, "response Body len != 1 after Select") @@ -1613,7 +1613,7 @@ func TestSelect(t *testing.T) { require.Equalf(t, "ro_select_value", value, "unexpected body of Select (1)") // RW - resp, err = connPool.Select(spaceNo, indexNo, 0, 1, tarantool.IterEq, rwKey, connection_pool.RW) + resp, err = connPool.Select(spaceNo, indexNo, 0, 1, tarantool.IterEq, rwKey, pool.RW) require.Nilf(t, err, "failed to Select") require.NotNilf(t, resp, "response is nil after Select") require.Equalf(t, len(resp.Data), 1, "response Body len != 1 after Select") @@ -1637,34 +1637,34 @@ func TestPing(t *testing.T) { err := test_helpers.SetClusterRO(servers, connOpts, roles) require.Nilf(t, err, "fail to set roles for cluster") - connPool, err := connection_pool.Connect(servers, connOpts) + connPool, err := pool.Connect(servers, connOpts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, connPool, "conn is nil after Connect") defer connPool.Close() // ANY - resp, err := connPool.Ping(connection_pool.ANY) + resp, err := connPool.Ping(pool.ANY) require.Nilf(t, err, "failed to Ping") require.NotNilf(t, resp, "response is nil after Ping") // RW - resp, err = connPool.Ping(connection_pool.RW) + resp, err = connPool.Ping(pool.RW) require.Nilf(t, err, "failed to Ping") require.NotNilf(t, resp, "response is nil after Ping") // RO - resp, err = connPool.Ping(connection_pool.RO) + resp, err = connPool.Ping(pool.RO) require.Nilf(t, err, "failed to Ping") require.NotNilf(t, resp, "response is nil after Ping") // PreferRW - resp, err = connPool.Ping(connection_pool.PreferRW) + resp, err = connPool.Ping(pool.PreferRW) require.Nilf(t, err, "failed to Ping") require.NotNilf(t, resp, "response is nil after Ping") // PreferRO - resp, err = connPool.Ping(connection_pool.PreferRO) + resp, err = connPool.Ping(pool.PreferRO) require.Nilf(t, err, "failed to Ping") require.NotNilf(t, resp, "response is nil after Ping") } @@ -1675,7 +1675,7 @@ func TestDo(t *testing.T) { err := test_helpers.SetClusterRO(servers, connOpts, roles) require.Nilf(t, err, "fail to set roles for cluster") - connPool, err := connection_pool.Connect(servers, connOpts) + connPool, err := pool.Connect(servers, connOpts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, connPool, "conn is nil after Connect") @@ -1683,27 +1683,27 @@ func TestDo(t *testing.T) { req := tarantool.NewPingRequest() // ANY - resp, err := connPool.Do(req, connection_pool.ANY).Get() + resp, err := connPool.Do(req, pool.ANY).Get() require.Nilf(t, err, "failed to Ping") require.NotNilf(t, resp, "response is nil after Ping") // RW - resp, err = connPool.Do(req, connection_pool.RW).Get() + resp, err = connPool.Do(req, pool.RW).Get() require.Nilf(t, err, "failed to Ping") require.NotNilf(t, resp, "response is nil after Ping") // RO - resp, err = connPool.Do(req, connection_pool.RO).Get() + resp, err = connPool.Do(req, pool.RO).Get() require.Nilf(t, err, "failed to Ping") require.NotNilf(t, resp, "response is nil after Ping") // PreferRW - resp, err = connPool.Do(req, connection_pool.PreferRW).Get() + resp, err = connPool.Do(req, pool.PreferRW).Get() require.Nilf(t, err, "failed to Ping") require.NotNilf(t, resp, "response is nil after Ping") // PreferRO - resp, err = connPool.Do(req, connection_pool.PreferRO).Get() + resp, err = connPool.Do(req, pool.PreferRO).Get() require.Nilf(t, err, "failed to Ping") require.NotNilf(t, resp, "response is nil after Ping") } @@ -1716,23 +1716,23 @@ func TestNewPrepared(t *testing.T) { err := test_helpers.SetClusterRO(servers, connOpts, roles) require.Nilf(t, err, "fail to set roles for cluster") - connPool, err := connection_pool.Connect(servers, connOpts) + connPool, err := pool.Connect(servers, connOpts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, connPool, "conn is nil after Connect") defer connPool.Close() - stmt, err := connPool.NewPrepared("SELECT NAME0, NAME1 FROM SQL_TEST WHERE NAME0=:id AND NAME1=:name;", connection_pool.RO) + stmt, err := connPool.NewPrepared("SELECT NAME0, NAME1 FROM SQL_TEST WHERE NAME0=:id AND NAME1=:name;", pool.RO) require.Nilf(t, err, "fail to prepare statement: %v", err) - if connPool.GetPoolInfo()[stmt.Conn.Addr()].ConnRole != connection_pool.ReplicaRole { + if connPool.GetPoolInfo()[stmt.Conn.Addr()].ConnRole != pool.ReplicaRole { t.Errorf("wrong role for the statement's connection") } executeReq := tarantool.NewExecutePreparedRequest(stmt) unprepareReq := tarantool.NewUnprepareRequest(stmt) - resp, err := connPool.Do(executeReq.Args([]interface{}{1, "test"}), connection_pool.ANY).Get() + resp, err := connPool.Do(executeReq.Args([]interface{}{1, "test"}), pool.ANY).Get() if err != nil { t.Fatalf("failed to execute prepared: %v", err) } @@ -1753,7 +1753,7 @@ func TestNewPrepared(t *testing.T) { } // the second argument for unprepare request is unused - it already belongs to some connection - resp, err = connPool.Do(unprepareReq, connection_pool.ANY).Get() + resp, err = connPool.Do(unprepareReq, pool.ANY).Get() if err != nil { t.Errorf("failed to unprepare prepared statement: %v", err) } @@ -1761,13 +1761,13 @@ func TestNewPrepared(t *testing.T) { t.Errorf("failed to unprepare prepared statement: code %d", resp.Code) } - _, err = connPool.Do(unprepareReq, connection_pool.ANY).Get() + _, err = connPool.Do(unprepareReq, pool.ANY).Get() if err == nil { t.Errorf("the statement must be already unprepared") } require.Contains(t, err.Error(), "Prepared statement with id") - _, err = connPool.Do(executeReq, connection_pool.ANY).Get() + _, err = connPool.Do(executeReq, pool.ANY).Get() if err == nil { t.Errorf("the statement must be already unprepared") } @@ -1782,7 +1782,7 @@ func TestDoWithStrangerConn(t *testing.T) { err := test_helpers.SetClusterRO(servers, connOpts, roles) require.Nilf(t, err, "fail to set roles for cluster") - connPool, err := connection_pool.Connect(servers, connOpts) + connPool, err := pool.Connect(servers, connOpts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, connPool, "conn is nil after Connect") @@ -1790,7 +1790,7 @@ func TestDoWithStrangerConn(t *testing.T) { req := test_helpers.NewStrangerRequest() - _, err = connPool.Do(req, connection_pool.ANY).Get() + _, err = connPool.Do(req, pool.ANY).Get() if err == nil { t.Fatalf("nil error caught") } @@ -1811,12 +1811,12 @@ func TestStream_Commit(t *testing.T) { err = test_helpers.SetClusterRO(servers, connOpts, roles) require.Nilf(t, err, "fail to set roles for cluster") - connPool, err := connection_pool.Connect(servers, connOpts) + connPool, err := pool.Connect(servers, connOpts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, connPool, "conn is nil after Connect") defer connPool.Close() - stream, err := connPool.NewStream(connection_pool.PreferRW) + stream, err := connPool.NewStream(pool.PreferRW) require.Nilf(t, err, "failed to create stream") require.NotNilf(t, connPool, "stream is nil after NewStream") @@ -1910,12 +1910,12 @@ func TestStream_Rollback(t *testing.T) { err = test_helpers.SetClusterRO(servers, connOpts, roles) require.Nilf(t, err, "fail to set roles for cluster") - connPool, err := connection_pool.Connect(servers, connOpts) + connPool, err := pool.Connect(servers, connOpts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, connPool, "conn is nil after Connect") defer connPool.Close() - stream, err := connPool.NewStream(connection_pool.PreferRW) + stream, err := connPool.NewStream(pool.PreferRW) require.Nilf(t, err, "failed to create stream") require.NotNilf(t, connPool, "stream is nil after NewStream") @@ -2009,12 +2009,12 @@ func TestStream_TxnIsolationLevel(t *testing.T) { err = test_helpers.SetClusterRO(servers, connOpts, roles) require.Nilf(t, err, "fail to set roles for cluster") - connPool, err := connection_pool.Connect(servers, connOpts) + connPool, err := pool.Connect(servers, connOpts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, connPool, "conn is nil after Connect") defer connPool.Close() - stream, err := connPool.NewStream(connection_pool.PreferRW) + stream, err := connPool.NewStream(pool.PreferRW) require.Nilf(t, err, "failed to create stream") require.NotNilf(t, connPool, "stream is nil after NewStream") @@ -2103,13 +2103,13 @@ func TestConnectionPool_NewWatcher_noWatchersFeature(t *testing.T) { err := test_helpers.SetClusterRO(servers, opts, roles) require.Nilf(t, err, "fail to set roles for cluster") - pool, err := connection_pool.Connect(servers, opts) + connPool, err := pool.Connect(servers, opts) require.Nilf(t, err, "failed to connect") - require.NotNilf(t, pool, "conn is nil after Connect") - defer pool.Close() + require.NotNilf(t, connPool, "conn is nil after Connect") + defer connPool.Close() - watcher, err := pool.NewWatcher(key, - func(event tarantool.WatchEvent) {}, connection_pool.ANY) + watcher, err := connPool.NewWatcher(key, + func(event tarantool.WatchEvent) {}, pool.ANY) require.Nilf(t, watcher, "watcher must not be created") require.NotNilf(t, err, "an error is expected") expected := "the feature WatchersFeature must be required by connection " + @@ -2131,25 +2131,25 @@ func TestConnectionPool_NewWatcher_modes(t *testing.T) { err := test_helpers.SetClusterRO(servers, opts, roles) require.Nilf(t, err, "fail to set roles for cluster") - pool, err := connection_pool.Connect(servers, opts) + connPool, err := pool.Connect(servers, opts) require.Nilf(t, err, "failed to connect") - require.NotNilf(t, pool, "conn is nil after Connect") - defer pool.Close() + require.NotNilf(t, connPool, "conn is nil after Connect") + defer connPool.Close() - modes := []connection_pool.Mode{ - connection_pool.ANY, - connection_pool.RW, - connection_pool.RO, - connection_pool.PreferRW, - connection_pool.PreferRO, + modes := []pool.Mode{ + pool.ANY, + pool.RW, + pool.RO, + pool.PreferRW, + pool.PreferRO, } for _, mode := range modes { t.Run(fmt.Sprintf("%d", mode), func(t *testing.T) { expectedServers := []string{} for i, server := range servers { - if roles[i] && mode == connection_pool.RW { + if roles[i] && mode == pool.RW { continue - } else if !roles[i] && mode == connection_pool.RO { + } else if !roles[i] && mode == pool.RO { continue } expectedServers = append(expectedServers, server) @@ -2158,7 +2158,7 @@ func TestConnectionPool_NewWatcher_modes(t *testing.T) { events := make(chan tarantool.WatchEvent, 1024) defer close(events) - watcher, err := pool.NewWatcher(key, func(event tarantool.WatchEvent) { + watcher, err := connPool.NewWatcher(key, func(event tarantool.WatchEvent) { require.Equal(t, key, event.Key) require.Equal(t, nil, event.Value) events <- event @@ -2199,7 +2199,7 @@ func TestConnectionPool_NewWatcher_update(t *testing.T) { test_helpers.SkipIfWatchersUnsupported(t) const key = "TestConnectionPool_NewWatcher_update" - const mode = connection_pool.RW + const mode = pool.RW const initCnt = 2 roles := []bool{true, false, false, true, true} @@ -2210,10 +2210,10 @@ func TestConnectionPool_NewWatcher_update(t *testing.T) { err := test_helpers.SetClusterRO(servers, opts, roles) require.Nilf(t, err, "fail to set roles for cluster") - poolOpts := connection_pool.OptsPool{ + poolOpts := pool.Opts{ CheckTimeout: 500 * time.Millisecond, } - pool, err := connection_pool.ConnectWithOpts(servers, opts, poolOpts) + pool, err := pool.ConnectWithOpts(servers, opts, poolOpts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, pool, "conn is nil after Connect") @@ -2286,7 +2286,7 @@ func TestWatcher_Unregister(t *testing.T) { test_helpers.SkipIfWatchersUnsupported(t) const key = "TestWatcher_Unregister" - const mode = connection_pool.RW + const mode = pool.RW const expectedCnt = 2 roles := []bool{true, false, false, true, true} @@ -2297,7 +2297,7 @@ func TestWatcher_Unregister(t *testing.T) { err := test_helpers.SetClusterRO(servers, opts, roles) require.Nilf(t, err, "fail to set roles for cluster") - pool, err := connection_pool.Connect(servers, opts) + pool, err := pool.Connect(servers, opts) require.Nilf(t, err, "failed to connect") require.NotNilf(t, pool, "conn is nil after Connect") defer pool.Close() @@ -2356,21 +2356,21 @@ func TestConnectionPool_NewWatcher_concurrent(t *testing.T) { err := test_helpers.SetClusterRO(servers, opts, roles) require.Nilf(t, err, "fail to set roles for cluster") - pool, err := connection_pool.Connect(servers, opts) + connPool, err := pool.Connect(servers, opts) require.Nilf(t, err, "failed to connect") - require.NotNilf(t, pool, "conn is nil after Connect") - defer pool.Close() + require.NotNilf(t, connPool, "conn is nil after Connect") + defer connPool.Close() var wg sync.WaitGroup wg.Add(testConcurrency) - mode := connection_pool.ANY + mode := pool.ANY callback := func(event tarantool.WatchEvent) {} for i := 0; i < testConcurrency; i++ { go func(i int) { defer wg.Done() - watcher, err := pool.NewWatcher(key, callback, mode) + watcher, err := connPool.NewWatcher(key, callback, mode) if err != nil { t.Errorf("Failed to create a watcher: %s", err) } else { @@ -2396,13 +2396,13 @@ func TestWatcher_Unregister_concurrent(t *testing.T) { err := test_helpers.SetClusterRO(servers, opts, roles) require.Nilf(t, err, "fail to set roles for cluster") - pool, err := connection_pool.Connect(servers, opts) + connPool, err := pool.Connect(servers, opts) require.Nilf(t, err, "failed to connect") - require.NotNilf(t, pool, "conn is nil after Connect") - defer pool.Close() + require.NotNilf(t, connPool, "conn is nil after Connect") + defer connPool.Close() - mode := connection_pool.ANY - watcher, err := pool.NewWatcher(key, func(event tarantool.WatchEvent) { + mode := pool.ANY + watcher, err := connPool.NewWatcher(key, func(event tarantool.WatchEvent) { }, mode) require.Nilf(t, err, "failed to create a watcher") diff --git a/connection_pool/connector.go b/pool/connector.go similarity index 99% rename from connection_pool/connector.go rename to pool/connector.go index 3688b8309..128d80575 100644 --- a/connection_pool/connector.go +++ b/pool/connector.go @@ -1,4 +1,4 @@ -package connection_pool +package pool import ( "errors" diff --git a/connection_pool/connector_test.go b/pool/connector_test.go similarity index 99% rename from connection_pool/connector_test.go rename to pool/connector_test.go index 717fdaec4..d4d197607 100644 --- a/connection_pool/connector_test.go +++ b/pool/connector_test.go @@ -1,4 +1,4 @@ -package connection_pool_test +package pool_test import ( "errors" @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" "github.com/tarantool/go-tarantool/v2" - . "github.com/tarantool/go-tarantool/v2/connection_pool" + . "github.com/tarantool/go-tarantool/v2/pool" ) var testMode Mode = RW diff --git a/connection_pool/const.go b/pool/const.go similarity index 97% rename from connection_pool/const.go rename to pool/const.go index 26b028f5a..7ec239f7d 100644 --- a/connection_pool/const.go +++ b/pool/const.go @@ -1,4 +1,4 @@ -package connection_pool +package pool /* Default mode for each request table: diff --git a/connection_pool/example_test.go b/pool/example_test.go similarity index 83% rename from connection_pool/example_test.go rename to pool/example_test.go index 06134bc35..df37442aa 100644 --- a/connection_pool/example_test.go +++ b/pool/example_test.go @@ -1,11 +1,11 @@ -package connection_pool_test +package pool_test import ( "fmt" "time" "github.com/tarantool/go-tarantool/v2" - "github.com/tarantool/go-tarantool/v2/connection_pool" + "github.com/tarantool/go-tarantool/v2/pool" "github.com/tarantool/go-tarantool/v2/test_helpers" ) @@ -19,12 +19,12 @@ type Tuple struct { var testRoles = []bool{true, true, false, true, true} -func examplePool(roles []bool, connOpts tarantool.Opts) (*connection_pool.ConnectionPool, error) { +func examplePool(roles []bool, connOpts tarantool.Opts) (*pool.ConnectionPool, error) { err := test_helpers.SetClusterRO(servers, connOpts, roles) if err != nil { return nil, fmt.Errorf("ConnectionPool is not established") } - connPool, err := connection_pool.Connect(servers, connOpts) + connPool, err := pool.Connect(servers, connOpts) if err != nil || connPool == nil { return nil, fmt.Errorf("ConnectionPool is not established") } @@ -33,11 +33,11 @@ func examplePool(roles []bool, connOpts tarantool.Opts) (*connection_pool.Connec } func ExampleConnectionPool_Select() { - pool, err := examplePool(testRoles, connOpts) + connPool, err := examplePool(testRoles, connOpts) if err != nil { fmt.Println(err) } - defer pool.Close() + defer connPool.Close() // Connect to servers[2] to check if tuple // was inserted on RW instance @@ -60,17 +60,17 @@ func ExampleConnectionPool_Select() { return } - resp, err := pool.Select( + resp, err := connPool.Select( spaceNo, indexNo, 0, 100, tarantool.IterEq, - []interface{}{"key1"}, connection_pool.PreferRW) + []interface{}{"key1"}, pool.PreferRW) if err != nil { fmt.Printf("error in select is %v", err) return } fmt.Printf("response is %#v\n", resp.Data) - resp, err = pool.Select( + resp, err = connPool.Select( spaceNo, indexNo, 0, 100, tarantool.IterEq, - []interface{}{"key2"}, connection_pool.PreferRW) + []interface{}{"key2"}, pool.PreferRW) if err != nil { fmt.Printf("error in select is %v", err) return @@ -94,11 +94,11 @@ func ExampleConnectionPool_Select() { } func ExampleConnectionPool_SelectTyped() { - pool, err := examplePool(testRoles, connOpts) + connPool, err := examplePool(testRoles, connOpts) if err != nil { fmt.Println(err) } - defer pool.Close() + defer connPool.Close() // Connect to servers[2] to check if tuple // was inserted on RW instance @@ -122,17 +122,17 @@ func ExampleConnectionPool_SelectTyped() { } var res []Tuple - err = pool.SelectTyped( + err = connPool.SelectTyped( spaceNo, indexNo, 0, 100, tarantool.IterEq, - []interface{}{"key1"}, &res, connection_pool.PreferRW) + []interface{}{"key1"}, &res, pool.PreferRW) if err != nil { fmt.Printf("error in select is %v", err) return } fmt.Printf("response is %v\n", res) - err = pool.SelectTyped( + err = connPool.SelectTyped( spaceName, indexName, 0, 100, tarantool.IterEq, - []interface{}{"key2"}, &res, connection_pool.PreferRW) + []interface{}{"key2"}, &res, pool.PreferRW) if err != nil { fmt.Printf("error in select is %v", err) return @@ -156,11 +156,11 @@ func ExampleConnectionPool_SelectTyped() { } func ExampleConnectionPool_SelectAsync() { - pool, err := examplePool(testRoles, connOpts) + connPool, err := examplePool(testRoles, connOpts) if err != nil { fmt.Println(err) } - defer pool.Close() + defer connPool.Close() // Connect to servers[2] to check if tuple // was inserted on RW instance @@ -190,15 +190,15 @@ func ExampleConnectionPool_SelectAsync() { } var futs [3]*tarantool.Future - futs[0] = pool.SelectAsync( + futs[0] = connPool.SelectAsync( spaceName, indexName, 0, 2, tarantool.IterEq, - []interface{}{"key1"}, connection_pool.PreferRW) - futs[1] = pool.SelectAsync( + []interface{}{"key1"}, pool.PreferRW) + futs[1] = connPool.SelectAsync( spaceName, indexName, 0, 1, tarantool.IterEq, - []interface{}{"key2"}, connection_pool.RW) - futs[2] = pool.SelectAsync( + []interface{}{"key2"}, pool.RW) + futs[2] = connPool.SelectAsync( spaceName, indexName, 0, 1, tarantool.IterEq, - []interface{}{"key3"}, connection_pool.RW) + []interface{}{"key3"}, pool.RW) var t []Tuple err = futs[0].GetTyped(&t) fmt.Println("Future", 0, "Error", err) @@ -239,16 +239,16 @@ func ExampleConnectionPool_SelectAsync() { func ExampleConnectionPool_SelectAsync_err() { roles := []bool{true, true, true, true, true} - pool, err := examplePool(roles, connOpts) + connPool, err := examplePool(roles, connOpts) if err != nil { fmt.Println(err) } - defer pool.Close() + defer connPool.Close() var futs [3]*tarantool.Future - futs[0] = pool.SelectAsync( + futs[0] = connPool.SelectAsync( spaceName, indexName, 0, 2, tarantool.IterEq, - []interface{}{"key1"}, connection_pool.RW) + []interface{}{"key1"}, pool.RW) err = futs[0].Err() fmt.Println("Future", 0, "Error", err) @@ -258,14 +258,14 @@ func ExampleConnectionPool_SelectAsync_err() { } func ExampleConnectionPool_Ping() { - pool, err := examplePool(testRoles, connOpts) + connPool, err := examplePool(testRoles, connOpts) if err != nil { fmt.Println(err) } - defer pool.Close() + defer connPool.Close() // Ping a Tarantool instance to check connection. - resp, err := pool.Ping(connection_pool.ANY) + resp, err := connPool.Ping(pool.ANY) fmt.Println("Ping Code", resp.Code) fmt.Println("Ping Data", resp.Data) fmt.Println("Ping Error", err) @@ -276,20 +276,20 @@ func ExampleConnectionPool_Ping() { } func ExampleConnectionPool_Insert() { - pool, err := examplePool(testRoles, connOpts) + connPool, err := examplePool(testRoles, connOpts) if err != nil { fmt.Println(err) } - defer pool.Close() + defer connPool.Close() // Insert a new tuple {"key1", "value1"}. - resp, err := pool.Insert(spaceNo, []interface{}{"key1", "value1"}) + resp, err := connPool.Insert(spaceNo, []interface{}{"key1", "value1"}) fmt.Println("Insert key1") fmt.Println("Error", err) fmt.Println("Code", resp.Code) fmt.Println("Data", resp.Data) // Insert a new tuple {"key2", "value2"}. - resp, err = pool.Insert(spaceName, &Tuple{Key: "key2", Value: "value2"}, connection_pool.PreferRW) + resp, err = connPool.Insert(spaceName, &Tuple{Key: "key2", Value: "value2"}, pool.PreferRW) fmt.Println("Insert key2") fmt.Println("Error", err) fmt.Println("Code", resp.Code) @@ -325,11 +325,11 @@ func ExampleConnectionPool_Insert() { } func ExampleConnectionPool_Delete() { - pool, err := examplePool(testRoles, connOpts) + connPool, err := examplePool(testRoles, connOpts) if err != nil { fmt.Println(err) } - defer pool.Close() + defer connPool.Close() // Connect to servers[2] to check if tuple // was inserted on RW instance @@ -353,14 +353,14 @@ func ExampleConnectionPool_Delete() { } // Delete tuple with primary key {"key1"}. - resp, err := pool.Delete(spaceNo, indexNo, []interface{}{"key1"}) + resp, err := connPool.Delete(spaceNo, indexNo, []interface{}{"key1"}) fmt.Println("Delete key1") fmt.Println("Error", err) fmt.Println("Code", resp.Code) fmt.Println("Data", resp.Data) // Delete tuple with primary key { "key2" }. - resp, err = pool.Delete(spaceName, indexName, []interface{}{"key2"}, connection_pool.PreferRW) + resp, err = connPool.Delete(spaceName, indexName, []interface{}{"key2"}, pool.PreferRW) fmt.Println("Delete key2") fmt.Println("Error", err) fmt.Println("Code", resp.Code) @@ -377,11 +377,11 @@ func ExampleConnectionPool_Delete() { } func ExampleConnectionPool_Replace() { - pool, err := examplePool(testRoles, connOpts) + connPool, err := examplePool(testRoles, connOpts) if err != nil { fmt.Println(err) } - defer pool.Close() + defer connPool.Close() // Connect to servers[2] to check if tuple // was inserted on RW instance @@ -401,22 +401,22 @@ func ExampleConnectionPool_Replace() { // Replace a tuple with primary key ""key1. // Note, Tuple is defined within tests, and has EncdodeMsgpack and // DecodeMsgpack methods. - resp, err := pool.Replace(spaceNo, []interface{}{"key1", "new_value"}) + resp, err := connPool.Replace(spaceNo, []interface{}{"key1", "new_value"}) fmt.Println("Replace key1") fmt.Println("Error", err) fmt.Println("Code", resp.Code) fmt.Println("Data", resp.Data) - resp, err = pool.Replace(spaceName, []interface{}{"key1", "another_value"}) + resp, err = connPool.Replace(spaceName, []interface{}{"key1", "another_value"}) fmt.Println("Replace key1") fmt.Println("Error", err) fmt.Println("Code", resp.Code) fmt.Println("Data", resp.Data) - resp, err = pool.Replace(spaceName, &Tuple{Key: "key1", Value: "value2"}) + resp, err = connPool.Replace(spaceName, &Tuple{Key: "key1", Value: "value2"}) fmt.Println("Replace key1") fmt.Println("Error", err) fmt.Println("Code", resp.Code) fmt.Println("Data", resp.Data) - resp, err = pool.Replace(spaceName, &Tuple{Key: "key1", Value: "new_value2"}, connection_pool.PreferRW) + resp, err = connPool.Replace(spaceName, &Tuple{Key: "key1", Value: "new_value2"}, pool.PreferRW) fmt.Println("Replace key1") fmt.Println("Error", err) fmt.Println("Code", resp.Code) @@ -448,11 +448,11 @@ func ExampleConnectionPool_Replace() { } func ExampleConnectionPool_Update() { - pool, err := examplePool(testRoles, connOpts) + connPool, err := examplePool(testRoles, connOpts) if err != nil { fmt.Println(err) } - defer pool.Close() + defer connPool.Close() // Connect to servers[2] to check if tuple // was inserted on RW instance @@ -470,9 +470,9 @@ func ExampleConnectionPool_Update() { } // Update tuple with primary key { "key1" }. - resp, err := pool.Update( + resp, err := connPool.Update( spaceName, indexName, []interface{}{"key1"}, - []interface{}{[]interface{}{"=", 1, "new_value"}}, connection_pool.PreferRW) + []interface{}{[]interface{}{"=", 1, "new_value"}}, pool.PreferRW) fmt.Println("Update key1") fmt.Println("Error", err) fmt.Println("Code", resp.Code) @@ -492,14 +492,14 @@ func ExampleConnectionPool_Update() { } func ExampleConnectionPool_Call() { - pool, err := examplePool(testRoles, connOpts) + connPool, err := examplePool(testRoles, connOpts) if err != nil { fmt.Println(err) } - defer pool.Close() + defer connPool.Close() // Call a function 'simple_incr' with arguments. - resp, err := pool.Call17("simple_incr", []interface{}{1}, connection_pool.PreferRW) + resp, err := connPool.Call17("simple_incr", []interface{}{1}, pool.PreferRW) fmt.Println("Call simple_incr()") fmt.Println("Error", err) fmt.Println("Code", resp.Code) @@ -512,14 +512,14 @@ func ExampleConnectionPool_Call() { } func ExampleConnectionPool_Eval() { - pool, err := examplePool(testRoles, connOpts) + connPool, err := examplePool(testRoles, connOpts) if err != nil { fmt.Println(err) } - defer pool.Close() + defer connPool.Close() // Run raw Lua code. - resp, err := pool.Eval("return 1 + 2", []interface{}{}, connection_pool.PreferRW) + resp, err := connPool.Eval("return 1 + 2", []interface{}{}, pool.PreferRW) fmt.Println("Eval 'return 1 + 2'") fmt.Println("Error", err) fmt.Println("Code", resp.Code) @@ -532,15 +532,15 @@ func ExampleConnectionPool_Eval() { } func ExampleConnectionPool_Do() { - pool, err := examplePool(testRoles, connOpts) + connPool, err := examplePool(testRoles, connOpts) if err != nil { fmt.Println(err) } - defer pool.Close() + defer connPool.Close() // Ping a Tarantool instance to check connection. req := tarantool.NewPingRequest() - resp, err := pool.Do(req, connection_pool.ANY).Get() + resp, err := connPool.Do(req, pool.ANY).Get() fmt.Println("Ping Code", resp.Code) fmt.Println("Ping Data", resp.Data) fmt.Println("Ping Error", err) @@ -551,13 +551,13 @@ func ExampleConnectionPool_Do() { } func ExampleConnectionPool_NewPrepared() { - pool, err := examplePool(testRoles, connOpts) + connPool, err := examplePool(testRoles, connOpts) if err != nil { fmt.Println(err) } - defer pool.Close() + defer connPool.Close() - stmt, err := pool.NewPrepared("SELECT 1", connection_pool.ANY) + stmt, err := connPool.NewPrepared("SELECT 1", pool.ANY) if err != nil { fmt.Println(err) } @@ -565,11 +565,11 @@ func ExampleConnectionPool_NewPrepared() { executeReq := tarantool.NewExecutePreparedRequest(stmt) unprepareReq := tarantool.NewUnprepareRequest(stmt) - _, err = pool.Do(executeReq, connection_pool.ANY).Get() + _, err = connPool.Do(executeReq, pool.ANY).Get() if err != nil { fmt.Printf("Failed to execute prepared stmt") } - _, err = pool.Do(unprepareReq, connection_pool.ANY).Get() + _, err = connPool.Do(unprepareReq, pool.ANY).Get() if err != nil { fmt.Printf("Failed to prepare") } @@ -584,26 +584,26 @@ func ExampleConnectionPool_NewWatcher() { tarantool.WatchersFeature, } - pool, err := examplePool(testRoles, connOpts) + connPool, err := examplePool(testRoles, connOpts) if err != nil { fmt.Println(err) } - defer pool.Close() + defer connPool.Close() callback := func(event tarantool.WatchEvent) { fmt.Printf("event connection: %s\n", event.Conn.Addr()) fmt.Printf("event key: %s\n", event.Key) fmt.Printf("event value: %v\n", event.Value) } - mode := connection_pool.ANY - watcher, err := pool.NewWatcher(key, callback, mode) + mode := pool.ANY + watcher, err := connPool.NewWatcher(key, callback, mode) if err != nil { fmt.Printf("Unexpected error: %s\n", err) return } defer watcher.Unregister() - pool.Do(tarantool.NewBroadcastRequest(key).Value(value), mode).Get() + connPool.Do(tarantool.NewBroadcastRequest(key).Value(value), mode).Get() time.Sleep(time.Second) } @@ -613,14 +613,14 @@ func ExampleConnectionPool_NewWatcher_noWatchersFeature() { opts := connOpts.Clone() opts.RequiredProtocolInfo.Features = []tarantool.ProtocolFeature{} - pool, err := examplePool(testRoles, connOpts) + connPool, err := examplePool(testRoles, connOpts) if err != nil { fmt.Println(err) } - defer pool.Close() + defer connPool.Close() callback := func(event tarantool.WatchEvent) {} - watcher, err := pool.NewWatcher(key, callback, connection_pool.ANY) + watcher, err := connPool.NewWatcher(key, callback, pool.ANY) fmt.Println(watcher) fmt.Println(err) // Output: @@ -655,15 +655,15 @@ func ExampleCommitRequest() { } txnOpts := getTestTxnOpts() - pool, err := examplePool(testRoles, txnOpts) + connPool, err := examplePool(testRoles, txnOpts) if err != nil { fmt.Println(err) return } - defer pool.Close() + defer connPool.Close() // example pool has only one rw instance - stream, err := pool.NewStream(connection_pool.RW) + stream, err := connPool.NewStream(pool.RW) if err != nil { fmt.Println(err) return @@ -696,7 +696,7 @@ func ExampleCommitRequest() { Limit(1). Iterator(tarantool.IterEq). Key([]interface{}{"example_commit_key"}) - resp, err = pool.Do(selectReq, connection_pool.RW).Get() + resp, err = connPool.Do(selectReq, pool.RW).Get() if err != nil { fmt.Printf("Failed to Select: %s", err.Error()) return @@ -722,7 +722,7 @@ func ExampleCommitRequest() { // Select outside of transaction // example pool has only one rw instance - resp, err = pool.Do(selectReq, connection_pool.RW).Get() + resp, err = connPool.Do(selectReq, pool.RW).Get() if err != nil { fmt.Printf("Failed to Select: %s", err.Error()) return @@ -743,14 +743,14 @@ func ExampleRollbackRequest() { txnOpts := getTestTxnOpts() // example pool has only one rw instance - pool, err := examplePool(testRoles, txnOpts) + connPool, err := examplePool(testRoles, txnOpts) if err != nil { fmt.Println(err) return } - defer pool.Close() + defer connPool.Close() - stream, err := pool.NewStream(connection_pool.RW) + stream, err := connPool.NewStream(pool.RW) if err != nil { fmt.Println(err) return @@ -783,7 +783,7 @@ func ExampleRollbackRequest() { Limit(1). Iterator(tarantool.IterEq). Key([]interface{}{"example_rollback_key"}) - resp, err = pool.Do(selectReq, connection_pool.RW).Get() + resp, err = connPool.Do(selectReq, pool.RW).Get() if err != nil { fmt.Printf("Failed to Select: %s", err.Error()) return @@ -809,7 +809,7 @@ func ExampleRollbackRequest() { // Select outside of transaction // example pool has only one rw instance - resp, err = pool.Do(selectReq, connection_pool.RW).Get() + resp, err = connPool.Do(selectReq, pool.RW).Get() if err != nil { fmt.Printf("Failed to Select: %s", err.Error()) return @@ -830,14 +830,14 @@ func ExampleBeginRequest_TxnIsolation() { txnOpts := getTestTxnOpts() // example pool has only one rw instance - pool, err := examplePool(testRoles, txnOpts) + connPool, err := examplePool(testRoles, txnOpts) if err != nil { fmt.Println(err) return } - defer pool.Close() + defer connPool.Close() - stream, err := pool.NewStream(connection_pool.RW) + stream, err := connPool.NewStream(pool.RW) if err != nil { fmt.Println(err) return @@ -872,7 +872,7 @@ func ExampleBeginRequest_TxnIsolation() { Limit(1). Iterator(tarantool.IterEq). Key([]interface{}{"isolation_level_key"}) - resp, err = pool.Do(selectReq, connection_pool.RW).Get() + resp, err = connPool.Do(selectReq, pool.RW).Get() if err != nil { fmt.Printf("Failed to Select: %s", err.Error()) return @@ -898,7 +898,7 @@ func ExampleBeginRequest_TxnIsolation() { // Select outside of transaction // example pool has only one rw instance - resp, err = pool.Do(selectReq, connection_pool.RW).Get() + resp, err = connPool.Do(selectReq, pool.RW).Get() if err != nil { fmt.Printf("Failed to Select: %s", err.Error()) return @@ -907,13 +907,13 @@ func ExampleBeginRequest_TxnIsolation() { } func ExampleConnectorAdapter() { - pool, err := examplePool(testRoles, connOpts) + connPool, err := examplePool(testRoles, connOpts) if err != nil { fmt.Println(err) } - defer pool.Close() + defer connPool.Close() - adapter := connection_pool.NewConnectorAdapter(pool, connection_pool.RW) + adapter := pool.NewConnectorAdapter(connPool, pool.RW) var connector tarantool.Connector = adapter // Ping an RW instance to check connection. diff --git a/connection_pool/msgpack_helper_test.go b/pool/msgpack_helper_test.go similarity index 83% rename from connection_pool/msgpack_helper_test.go rename to pool/msgpack_helper_test.go index d60c7d84d..f54df2038 100644 --- a/connection_pool/msgpack_helper_test.go +++ b/pool/msgpack_helper_test.go @@ -1,7 +1,7 @@ //go:build !go_tarantool_msgpack_v5 // +build !go_tarantool_msgpack_v5 -package connection_pool_test +package pool_test import ( "gopkg.in/vmihailenco/msgpack.v2" diff --git a/connection_pool/msgpack_v5_helper_test.go b/pool/msgpack_v5_helper_test.go similarity index 83% rename from connection_pool/msgpack_v5_helper_test.go rename to pool/msgpack_v5_helper_test.go index 7c449bec5..a507ffa64 100644 --- a/connection_pool/msgpack_v5_helper_test.go +++ b/pool/msgpack_v5_helper_test.go @@ -1,7 +1,7 @@ //go:build go_tarantool_msgpack_v5 // +build go_tarantool_msgpack_v5 -package connection_pool_test +package pool_test import ( "github.com/vmihailenco/msgpack/v5" diff --git a/connection_pool/pooler.go b/pool/pooler.go similarity index 99% rename from connection_pool/pooler.go rename to pool/pooler.go index 31790620c..626c5af93 100644 --- a/connection_pool/pooler.go +++ b/pool/pooler.go @@ -1,4 +1,4 @@ -package connection_pool +package pool import ( "time" diff --git a/connection_pool/round_robin.go b/pool/round_robin.go similarity index 98% rename from connection_pool/round_robin.go rename to pool/round_robin.go index 0a0988890..6078b136e 100644 --- a/connection_pool/round_robin.go +++ b/pool/round_robin.go @@ -1,4 +1,4 @@ -package connection_pool +package pool import ( "sync" diff --git a/connection_pool/round_robin_test.go b/pool/round_robin_test.go similarity index 95% rename from connection_pool/round_robin_test.go rename to pool/round_robin_test.go index 254217e62..abd7cdfb0 100644 --- a/connection_pool/round_robin_test.go +++ b/pool/round_robin_test.go @@ -1,10 +1,10 @@ -package connection_pool_test +package pool_test import ( "testing" "github.com/tarantool/go-tarantool/v2" - . "github.com/tarantool/go-tarantool/v2/connection_pool" + . "github.com/tarantool/go-tarantool/v2/pool" ) const ( diff --git a/connection_pool/state.go b/pool/state.go similarity index 94% rename from connection_pool/state.go rename to pool/state.go index a9d20392e..24f457bbf 100644 --- a/connection_pool/state.go +++ b/pool/state.go @@ -1,4 +1,4 @@ -package connection_pool +package pool import ( "sync/atomic" diff --git a/connection_pool/watcher.go b/pool/watcher.go similarity index 99% rename from connection_pool/watcher.go rename to pool/watcher.go index f4acc0bdd..2d2b72e17 100644 --- a/connection_pool/watcher.go +++ b/pool/watcher.go @@ -1,4 +1,4 @@ -package connection_pool +package pool import ( "sync" diff --git a/queue/example_connection_pool_test.go b/queue/example_connection_pool_test.go index 11cd3e9b3..51fb967a5 100644 --- a/queue/example_connection_pool_test.go +++ b/queue/example_connection_pool_test.go @@ -8,7 +8,7 @@ import ( "github.com/google/uuid" "github.com/tarantool/go-tarantool/v2" - "github.com/tarantool/go-tarantool/v2/connection_pool" + "github.com/tarantool/go-tarantool/v2/pool" "github.com/tarantool/go-tarantool/v2/queue" "github.com/tarantool/go-tarantool/v2/test_helpers" ) @@ -27,7 +27,7 @@ type QueueConnectionHandler struct { } // QueueConnectionHandler implements the ConnectionHandler interface. -var _ connection_pool.ConnectionHandler = &QueueConnectionHandler{} +var _ pool.ConnectionHandler = &QueueConnectionHandler{} // NewQueueConnectionHandler creates a QueueConnectionHandler object. func NewQueueConnectionHandler(name string, cfg queue.Cfg) *QueueConnectionHandler { @@ -44,7 +44,7 @@ func NewQueueConnectionHandler(name string, cfg queue.Cfg) *QueueConnectionHandl // NOTE: the Queue supports only a master-replica cluster configuration. It // does not support a master-master configuration. func (h *QueueConnectionHandler) Discovered(conn *tarantool.Connection, - role connection_pool.Role) error { + role pool.Role) error { h.mutex.Lock() defer h.mutex.Unlock() @@ -52,7 +52,7 @@ func (h *QueueConnectionHandler) Discovered(conn *tarantool.Connection, return h.err } - master := role == connection_pool.MasterRole + master := role == pool.MasterRole q := queue.New(conn, h.name) @@ -113,8 +113,8 @@ func (h *QueueConnectionHandler) Discovered(conn *tarantool.Connection, // Deactivated doesn't do anything useful for the example. func (h *QueueConnectionHandler) Deactivated(conn *tarantool.Connection, - role connection_pool.Role) error { - if role == connection_pool.MasterRole { + role pool.Role) error { + if role == pool.MasterRole { atomic.AddInt32(&h.masterCnt, -1) } return nil @@ -125,7 +125,7 @@ func (h *QueueConnectionHandler) Close() { close(h.updated) } -// Example demonstrates how to use the queue package with the connection_pool +// Example demonstrates how to use the queue package with the pool // package. First of all, you need to create a ConnectionHandler implementation // for the a ConnectionPool object to process new connections from // RW-instances. @@ -160,11 +160,11 @@ func Example_connectionPool() { User: "test", Pass: "test", } - poolOpts := connection_pool.OptsPool{ + poolOpts := pool.Opts{ CheckTimeout: 5 * time.Second, ConnectionHandler: h, } - connPool, err := connection_pool.ConnectWithOpts(servers, connOpts, poolOpts) + connPool, err := pool.ConnectWithOpts(servers, connOpts, poolOpts) if err != nil { fmt.Printf("Unable to connect to the pool: %s", err) return @@ -182,7 +182,7 @@ func Example_connectionPool() { // Create a Queue object from the ConnectionPool object via // a ConnectorAdapter. - rw := connection_pool.NewConnectorAdapter(connPool, connection_pool.RW) + rw := pool.NewConnectorAdapter(connPool, pool.RW) q := queue.New(rw, "test_queue") fmt.Println("A Queue object is ready to work.") @@ -229,7 +229,7 @@ func Example_connectionPool() { // Take a data from the new master instance. task, err := q.Take() - if err == connection_pool.ErrNoRwInstance { + if err == pool.ErrNoRwInstance { // It may be not registered yet by the pool. continue } else if err != nil { diff --git a/test_helpers/pool_helper.go b/test_helpers/pool_helper.go index 4833d4cc6..a559ef98d 100644 --- a/test_helpers/pool_helper.go +++ b/test_helpers/pool_helper.go @@ -6,20 +6,20 @@ import ( "time" "github.com/tarantool/go-tarantool/v2" - "github.com/tarantool/go-tarantool/v2/connection_pool" + "github.com/tarantool/go-tarantool/v2/pool" ) type ListenOnInstanceArgs struct { - ConnPool *connection_pool.ConnectionPool - Mode connection_pool.Mode + ConnPool *pool.ConnectionPool + Mode pool.Mode ServersNumber int ExpectedPorts map[string]bool } type CheckStatusesArgs struct { - ConnPool *connection_pool.ConnectionPool + ConnPool *pool.ConnectionPool Servers []string - Mode connection_pool.Mode + Mode pool.Mode ExpectedPoolStatus bool ExpectedStatuses map[string]bool }