Skip to content

Commit

Permalink
api: rename connection_pool to pool
Browse files Browse the repository at this point in the history
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
  • Loading branch information
oleg-jukovec committed May 23, 2023
1 parent eac17f0 commit 0bc4366
Show file tree
Hide file tree
Showing 21 changed files with 320 additions and 310 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
14 changes: 7 additions & 7 deletions connection_pool/call_16_test.go → pool/call_16_test.go
Original file line number Diff line number Diff line change
@@ -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"
)

Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down
14 changes: 7 additions & 7 deletions connection_pool/call_17_test.go → pool/call_17_test.go
Original file line number Diff line number Diff line change
@@ -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"
)

Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down
File renamed without changes.
14 changes: 7 additions & 7 deletions connection_pool/connection_pool.go → pool/connection_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// - Automatic master discovery by mode parameter.
//
// Since: 1.6.0
package connection_pool
package pool

import (
"errors"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -89,7 +89,7 @@ Main features:
type ConnectionPool struct {
addrs []string
connOpts tarantool.Opts
opts OptsPool
opts Opts

state state
done chan struct{}
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 0bc4366

Please sign in to comment.