Skip to content

Commit 32e9827

Browse files
committed
add DoTx test with empty transaction operations + changed API of sugar package
1 parent 449a02a commit 32e9827

File tree

7 files changed

+507
-292
lines changed

7 files changed

+507
-292
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Added custom dns-resolver to grpc options for use dns-balancing with round_robin balancing policy
44
* Wrapped with `recover()` system panic on getting system certificates pool
55
* Added linters and fixed issues from them
6+
* Changed API of `sugar` package
67

78
## 3.5.1
89
* Added system certificates for `darwin` system

internal/driver/cluster/cluster_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,17 @@ func TestClusterMergeEndpoints(t *testing.T) {
132132
endpoint.New("bad:23"),
133133
}
134134
t.Run("initial fill", func(t *testing.T) {
135+
// nolint: gocritic
136+
// nolint: nolintlint
135137
ne := append(endpoints, badEndpoints...)
136138
// merge new endpoints into balancer
137139
mergeEndpointIntoCluster(ctx, c, []endpoint.Endpoint{}, ne, WithConnConfig(stub.Config(config.New())))
138140
// try endpoints, filter out bad ones to tracking
139141
assert(t, ne)
140142
})
141143
t.Run("update with another endpoints", func(t *testing.T) {
144+
// nolint: gocritic
145+
// nolint: nolintlint
142146
ne := append(nextEndpoints, nextBadEndpoints...)
143147
// merge new endpoints into balancer
144148
mergeEndpointIntoCluster(ctx, c, append(endpoints, badEndpoints...), ne, WithConnConfig(stub.Config(config.New())))

sugar/sugar.go

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,28 @@ import (
1212
"github.com/ydb-platform/ydb-go-sdk/v3/table"
1313
)
1414

15-
// MakePath creates path inside database
16-
func MakePath(ctx context.Context, db ydb.Connection, path string) error {
17-
for i := len(db.Name()) + 1; i < len(path); i++ {
18-
x := strings.IndexByte(path[i:], '/')
15+
const (
16+
sysTable = ".sys"
17+
)
18+
19+
// MakeRecursive creates path inside database
20+
func MakeRecursive(ctx context.Context, db ydb.Connection, folder string) error {
21+
folder = path.Join(db.Name(), folder)
22+
for i := len(db.Name()) + 1; i < len(folder); i++ {
23+
x := strings.IndexByte(folder[i:], '/')
1924
if x == -1 {
20-
x = len(path[i:]) - 1
25+
x = len(folder[i:]) - 1
2126
}
2227
i += x
23-
sub := path[:i+1]
28+
sub := folder[:i+1]
2429
info, err := db.Scheme().DescribePath(ctx, sub)
2530
var opErr *errors.OpError
2631
if errors.As(err, &opErr) && opErr.Reason == errors.StatusSchemeError {
2732
err = db.Scheme().MakeDirectory(ctx, sub)
33+
if err != nil {
34+
return err
35+
}
36+
info, err = db.Scheme().DescribePath(ctx, sub)
2837
}
2938
if err != nil {
3039
return err
@@ -41,19 +50,15 @@ func MakePath(ctx context.Context, db ydb.Connection, path string) error {
4150
)
4251
}
4352
}
44-
4553
return nil
4654
}
4755

48-
// RmPath remove selected directory or table names in database.
56+
// RemoveRecursive remove selected directory or table names in database.
4957
// All database entities in prefix path will remove if names list is empty.
5058
// Empty prefix means than use root of database.
51-
// RmPath method equal bash command `rm -rf ./pathToRemove/{name1,name2,name3}`
52-
func RmPath(ctx context.Context, db ydb.Connection, pathToRemove string, names ...string) error {
53-
filter := make(map[string]struct{}, len(names))
54-
for _, n := range names {
55-
filter[n] = struct{}{}
56-
}
59+
// RemoveRecursive method equal bash command `rm -rf ./path/to/remove`
60+
func RemoveRecursive(ctx context.Context, db ydb.Connection, pathToRemove string) error {
61+
fullSysTablePath := path.Join(db.Name(), sysTable)
5762
var list func(int, string) error
5863
list = func(i int, p string) error {
5964
dir, err := db.Scheme().ListDirectory(ctx, p)
@@ -65,10 +70,10 @@ func RmPath(ctx context.Context, db ydb.Connection, pathToRemove string, names .
6570
return err
6671
}
6772
for _, child := range dir.Children {
68-
if _, has := filter[child.Name]; !has {
73+
pt := path.Join(p, child.Name)
74+
if pt == fullSysTablePath {
6975
continue
7076
}
71-
pt := path.Join(p, child.Name)
7277
switch child.Type {
7378
case scheme.EntryDirectory:
7479
if err = list(i+1, pt); err != nil {

table/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import (
77
)
88

99
// Operation is the interface that holds an operation for retry.
10-
type Operation func(context.Context, Session) error
10+
type Operation func(ctx context.Context, s Session) error
1111

1212
// TxOperation is the interface that holds an operation for retry.
13-
type TxOperation func(context.Context, Transaction) error
13+
type TxOperation func(ctx context.Context, tx TransactionActor) error
1414

1515
type Option func(o *Options)
1616

table/table.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,13 @@ type DataQuery interface {
117117
YQL() string
118118
}
119119

120-
type Transaction interface {
120+
type TransactionIdentifier interface {
121121
ID() string
122+
}
123+
124+
type TransactionActor interface {
125+
TransactionIdentifier
126+
122127
Execute(
123128
ctx context.Context,
124129
query string,
@@ -131,6 +136,11 @@ type Transaction interface {
131136
params *QueryParameters,
132137
opts ...options.ExecuteDataQueryOption,
133138
) (result.Result, error)
139+
}
140+
141+
type Transaction interface {
142+
TransactionActor
143+
134144
CommitTx(
135145
ctx context.Context,
136146
opts ...options.CommitTransactionOption,

test/ratelimiter_test.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package test
55

66
import (
77
"context"
8-
"log"
98
"os"
109
"testing"
1110
"time"
@@ -17,30 +16,13 @@ import (
1716
"github.com/ydb-platform/ydb-go-sdk/v3/internal/errors"
1817
internal "github.com/ydb-platform/ydb-go-sdk/v3/internal/ratelimiter"
1918
public "github.com/ydb-platform/ydb-go-sdk/v3/ratelimiter"
20-
"github.com/ydb-platform/ydb-go-sdk/v3/trace"
2119
)
2220

2321
const (
2422
testCoordinationNodePath = "/local/test"
2523
testResource = "test_res"
2624
)
2725

28-
func driverTrace() trace.Driver {
29-
var t trace.Driver
30-
trace.Stub(&t, func(name string, args ...interface{}) {
31-
log.Printf("[driver] %s: %+v", name, trace.ClearContext(args))
32-
})
33-
return t
34-
}
35-
36-
func tableTrace() trace.Table {
37-
var t trace.Table
38-
trace.Stub(&t, func(name string, args ...interface{}) {
39-
log.Printf("[table] %s: %+v", name, trace.ClearContext(args))
40-
})
41-
return t
42-
}
43-
4426
func TestRateLimiter(t *testing.T) {
4527
ctx, cancel := context.WithTimeout(context.Background(), time.Second*2)
4628
defer cancel()
@@ -49,8 +31,6 @@ func TestRateLimiter(t *testing.T) {
4931
ctx,
5032
ydb.WithConnectionString(os.Getenv("YDB_CONNECTION_STRING")),
5133
ydb.WithAnonymousCredentials(),
52-
ydb.WithTraceDriver(driverTrace()),
53-
ydb.WithTraceTable(tableTrace()),
5434
ydb.With(
5535
config.WithRequestTimeout(time.Second*5),
5636
config.WithStreamTimeout(time.Second*5),

0 commit comments

Comments
 (0)