-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
api: remove RouterMapCallRWImpl method (resolve #26)
- Loading branch information
1 parent
a284589
commit a38d1e7
Showing
5 changed files
with
115 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package tnt | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
vshardrouter "github.com/tarantool/go-vshard-router" | ||
"github.com/tarantool/go-vshard-router/providers/static" | ||
) | ||
|
||
func TestRouterMapCall(t *testing.T) { | ||
skipOnInvalidRun(t) | ||
|
||
t.Parallel() | ||
|
||
ctx := context.Background() | ||
|
||
cfg := getCfg() | ||
|
||
router, err := vshardrouter.NewRouter(ctx, vshardrouter.Config{ | ||
TopologyProvider: static.NewProvider(cfg), | ||
DiscoveryTimeout: 5 * time.Second, | ||
DiscoveryMode: vshardrouter.DiscoveryModeOn, | ||
TotalBucketCount: totalBucketCount, | ||
User: defaultTntUser, | ||
Password: defaultTntPassword, | ||
}) | ||
|
||
require.Nil(t, err, "NewRouter finished successfully") | ||
|
||
callOpts := vshardrouter.RouterMapCallRWOptions{} | ||
|
||
const arg = "arg1" | ||
|
||
// Enusre that RouterMapCallRWImpl works at all | ||
echoArgs := []interface{}{arg} | ||
respStr, err := vshardrouter.RouterMapCallRW[string](router, ctx, "echo", echoArgs, callOpts) | ||
require.NoError(t, err, "RouterMapCallRWImpl echo finished with no err") | ||
|
||
for k, v := range respStr { | ||
require.Equalf(t, arg, v, "RouterMapCallRWImpl value ok for %v", k) | ||
} | ||
|
||
echoArgs = []interface{}{1} | ||
respInt, err := vshardrouter.RouterMapCallRW[int](router, ctx, "echo", echoArgs, vshardrouter.RouterMapCallRWOptions{}) | ||
require.NoError(t, err, "RouterMapCallRW[int] echo finished with no err") | ||
for k, v := range respInt { | ||
require.Equalf(t, 1, v, "RouterMapCallRW[int] value ok for %v", k) | ||
} | ||
|
||
// RouterMapCallRWImpl returns only one value | ||
echoArgs = []interface{}{arg, "arg2"} | ||
respStr, err = vshardrouter.RouterMapCallRW[string](router, ctx, "echo", echoArgs, callOpts) | ||
require.NoError(t, err, "RouterMapCallRWImpl echo finished with no err") | ||
|
||
for k, v := range respStr { | ||
require.Equalf(t, arg, v, "RouterMapCallRWImpl value ok for %v", k) | ||
} | ||
|
||
// RouterMapCallRWImpl returns nil when no return value | ||
noArgs := []interface{}{} | ||
resp, err := vshardrouter.RouterMapCallRW[interface{}](router, ctx, "echo", noArgs, callOpts) | ||
require.NoError(t, err, "RouterMapCallRWImpl echo finished with no err") | ||
|
||
for k, v := range resp { | ||
require.Equalf(t, nil, v, "RouterMapCallRWImpl value ok for %v", k) | ||
} | ||
|
||
// Ensure that RouterMapCallRWImpl sends requests concurrently | ||
const sleepToSec int = 1 | ||
sleepArgs := []interface{}{sleepToSec} | ||
|
||
start := time.Now() | ||
_, err = vshardrouter.RouterMapCallRW[interface{}](router, ctx, "sleep", sleepArgs, vshardrouter.RouterMapCallRWOptions{ | ||
Timeout: 2 * time.Second, // because default timeout is 0.5 sec | ||
}) | ||
duration := time.Since(start) | ||
|
||
require.NoError(t, err, "RouterMapCallRWImpl sleep finished with no err") | ||
require.Greater(t, len(cfg), 1, "There are more than one replicasets") | ||
require.Less(t, duration, 1200*time.Millisecond, "Requests were send concurrently") | ||
|
||
// RouterMapCallRWImpl returns err on raise_luajit_error | ||
_, err = vshardrouter.RouterMapCallRW[interface{}](router, ctx, "raise_luajit_error", noArgs, callOpts) | ||
require.NotNil(t, err, "RouterMapCallRWImpl raise_luajit_error finished with error") | ||
|
||
// RouterMapCallRWImpl invalid usage | ||
_, err = vshardrouter.RouterMapCallRW[interface{}](router, ctx, "echo", nil, callOpts) | ||
require.NotNil(t, err, "RouterMapCallRWImpl with nil args finished with error") | ||
|
||
// Ensure that RouterMapCallRWImpl doesn't work when it mean't to | ||
for k := range cfg { | ||
errs := router.RemoveReplicaset(ctx, k.UUID) | ||
Check failure on line 95 in tests/tnt/routermap_call_test.go GitHub Actions / all-tests (1.22, 2.8)
Check failure on line 95 in tests/tnt/routermap_call_test.go GitHub Actions / all-tests (1.22, 2.10)
Check failure on line 95 in tests/tnt/routermap_call_test.go GitHub Actions / golangci-lint
Check failure on line 95 in tests/tnt/routermap_call_test.go GitHub Actions / all-tests (1.22, master)
Check failure on line 95 in tests/tnt/routermap_call_test.go GitHub Actions / all-tests (stable, 2.8)
Check failure on line 95 in tests/tnt/routermap_call_test.go GitHub Actions / all-tests (stable, 2.10)
|
||
require.Emptyf(t, errs, "%s successfully removed from router", k.UUID) | ||
break | ||
} | ||
|
||
_, err = vshardrouter.RouterMapCallRW[interface{}](router, ctx, "echo", echoArgs, callOpts) | ||
require.NotNilf(t, err, "RouterMapCallRWImpl failed on not full cluster") | ||
} |