Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 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.

* New types for MessagePack extensions compatible with go-option (#459).
* Added `box.MustNew` wrapper for `box.New` without an error (#448).
* Added missing IPROTO feature flags to greeting negotiation
(iproto.IPROTO_FEATURE_IS_SYNC, iproto.IPROTO_FEATURE_INSERT_ARROW) (#466).
Comment on lines +15 to +16
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, move the changelog entry in a separate commit.


### Changed

Expand All @@ -24,6 +26,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
and Future.GetIterator() methods, ResponseIterator and TimeoutResponseIterator types,
Future.pushes[] (#480).
* `LogAppendPushFailed` replaced with `LogBoxSessionPushUnsupported` (#480)
* Replaced the use of optional types in crud with go-option library (#492).

### Fixed

Expand All @@ -45,8 +48,7 @@ flag handling, and fixes watcher panic.
Now you can check this error with `errors.Is(err, tarantool.ErrConcurrentSchemaUpdate)`.
- Implemented support for `IPROTO_IS_SYNC` flag in stream transactions,
added `IsSync(bool)` method for `BeginRequest`/`CommitRequest` (#447).
- Added missing IPROTO feature flags to greeting negotiation
(iproto.IPROTO_FEATURE_IS_SYNC, iproto.IPROTO_FEATURE_INSERT_ARROW) (#466).


### Fixed

Expand Down
106 changes: 106 additions & 0 deletions crud/compile_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// crud/compile_test.go
package crud

import (
"testing"

"github.com/tarantool/go-option"
)

// TestOptionTypesCompilation verifies that all option types are compiled correctly.
func TestOptionTypesCompilation(t *testing.T) {
// Test BaseOpts
baseOpts := BaseOpts{
Timeout: option.SomeFloat64(1.5),
VshardRouter: option.SomeString("router"),
}

// Check that Get() is working.
if timeout, exists := baseOpts.Timeout.Get(); !exists || timeout != 1.5 {
t.Errorf("BaseOpts.Timeout.Get() failed")
}

// Test SimpleOperationOpts.
simpleOpts := SimpleOperationOpts{
Timeout: option.SomeFloat64(2.0),
VshardRouter: option.SomeString("router2"),
Fields: MakeOptAny([]interface{}{"field1", "field2"}),
BucketId: option.SomeUint(456),
FetchLatestMetadata: option.SomeBool(true),
Noreturn: option.SomeBool(false),
}

if bucket, exists := simpleOpts.BucketId.Get(); !exists || bucket != 456 {
t.Errorf("BucketId.Get() failed: got %v, %v", bucket, exists)
}

if fields, exists := simpleOpts.Fields.Get(); !exists {
t.Errorf("Fields.Get() failed")
} else {
t.Logf("Fields: %v", fields)
}

// Test OperationManyOpts.
manyOpts := OperationManyOpts{
Timeout: option.SomeFloat64(3.0),
StopOnError: option.SomeBool(true),
}

if stop, exists := manyOpts.StopOnError.Get(); !exists || !stop {
t.Errorf("StopOnError.Get() failed")
}
}

// TestMakeOptAny checks the operation of MakeOptAny (replacing MakeOptTuple).
func TestMakeOptAny(t *testing.T) {
// Test with simple data types.
testCases := []struct {
name string
value interface{}
expected interface{}
}{
{"string", "test", "test"},
{"number", 42, 42},
{"nil", nil, nil},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
opt := MakeOptAny(tc.value)
val, exists := opt.Get()

if tc.value == nil {
if exists {
t.Errorf("Expected no value for nil input, but got %v", val)
}
} else {
if !exists {
t.Errorf("Expected value for %v, but got none", tc.value)
}
if val != tc.expected {
t.Errorf("Expected %v, got %v", tc.expected, val)
}
}
})
}

// Test with a slice - we check without comparing the values.
t.Run("slice", func(t *testing.T) {
sliceValue := []interface{}{"id", "name"}
opt := MakeOptAny(sliceValue)
val, exists := opt.Get()

if !exists {
t.Errorf("Expected value for slice, but got none")
}

// We check the type and length instead of direct comparison.
if valSlice, ok := val.([]interface{}); !ok {
t.Errorf("Expected slice type, got %T", val)
} else if len(valSlice) != 2 {
t.Errorf("Expected slice length 2, got %d", len(valSlice))
} else {
t.Logf("Slice test passed: %v", valSlice)
}
})
}
19 changes: 10 additions & 9 deletions crud/count.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/vmihailenco/msgpack/v5"

"github.com/tarantool/go-option"
"github.com/tarantool/go-tarantool/v3"
)

Expand All @@ -15,30 +16,30 @@ type CountResult = NumberResult
type CountOpts struct {
// Timeout is a `vshard.call` timeout and vshard
// master discovery timeout (in seconds).
Timeout OptFloat64
Timeout option.Float64
// VshardRouter is cartridge vshard group name or
// vshard router instance.
VshardRouter OptString
VshardRouter option.String
// Mode is a parameter with `write`/`read` possible values,
// if `write` is specified then operation is performed on master.
Mode OptString
Mode option.String
// PreferReplica is a parameter to specify preferred target
// as one of the replicas.
PreferReplica OptBool
PreferReplica option.Bool
// Balance is a parameter to use replica according to vshard
// load balancing policy.
Balance OptBool
Balance option.Bool
// YieldEvery describes number of tuples processed to yield after.
// Should be positive.
YieldEvery OptUint
YieldEvery option.Uint
// BucketId is a bucket ID.
BucketId OptUint
BucketId option.Uint
// ForceMapCall describes the map call is performed without any
// optimizations even if full primary key equal condition is specified.
ForceMapCall OptBool
ForceMapCall option.Bool
// Fullscan describes if a critical log entry will be skipped on
// potentially long count.
Fullscan OptBool
Fullscan option.Bool
}

// EncodeMsgpack provides custom msgpack encoder.
Expand Down
7 changes: 4 additions & 3 deletions crud/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"reflect"
"time"

"github.com/tarantool/go-option"
"github.com/tarantool/go-tarantool/v3"
"github.com/tarantool/go-tarantool/v3/crud"
)
Expand Down Expand Up @@ -288,7 +289,7 @@ func ExampleResult_noreturn() {
[]interface{}{uint(2011), nil, "bla"},
}).
Opts(crud.ReplaceManyOpts{
Noreturn: crud.MakeOptBool(true),
Noreturn: option.SomeBool(true),
})

ret := crud.Result{}
Expand Down Expand Up @@ -375,8 +376,8 @@ func ExampleSelectRequest_pagination() {

req := crud.MakeSelectRequest(exampleSpace).
Opts(crud.SelectOpts{
First: crud.MakeOptInt(2),
After: crud.MakeOptTuple(tuple),
First: option.SomeInt64(2),
After: crud.MakeOptAny(tuple),
})
ret := crud.Result{}
if err := conn.Do(req).GetTyped(&ret); err != nil {
Expand Down
17 changes: 9 additions & 8 deletions crud/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,36 @@ import (

"github.com/vmihailenco/msgpack/v5"

"github.com/tarantool/go-option"
"github.com/tarantool/go-tarantool/v3"
)

// GetOpts describes options for `crud.get` method.
type GetOpts struct {
// Timeout is a `vshard.call` timeout and vshard
// master discovery timeout (in seconds).
Timeout OptFloat64
Timeout option.Float64
// VshardRouter is cartridge vshard group name or
// vshard router instance.
VshardRouter OptString
VshardRouter option.String
// Fields is field names for getting only a subset of fields.
Fields OptTuple
Fields OptAny // Type Any is instead of a local type Tuple.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add the option.Any type into the go-option library. Users won't be confused then with the own type.

// BucketId is a bucket ID.
BucketId OptUint
BucketId option.Uint
// Mode is a parameter with `write`/`read` possible values,
// if `write` is specified then operation is performed on master.
Mode OptString
Mode option.String
// PreferReplica is a parameter to specify preferred target
// as one of the replicas.
PreferReplica OptBool
PreferReplica option.Bool
// Balance is a parameter to use replica according to vshard
// load balancing policy.
Balance OptBool
Balance option.Bool
// FetchLatestMetadata guarantees the up-to-date metadata (space format)
// in first return value, otherwise it may not take into account
// the latest migration of the data format. Performance overhead is up to 15%.
// Disabled by default.
FetchLatestMetadata OptBool
FetchLatestMetadata option.Bool
}

// EncodeMsgpack provides custom msgpack encoder.
Expand Down
3 changes: 1 addition & 2 deletions crud/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package crud
import (
"context"

"github.com/vmihailenco/msgpack/v5"

"github.com/tarantool/go-tarantool/v3"
"github.com/vmihailenco/msgpack/v5"
)

// InsertOpts describes options for `crud.insert` method.
Expand Down
Loading
Loading