Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
OleksiienkoMykyta committed Nov 7, 2024
1 parent 92b4056 commit 9ce97bb
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions cassandra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
"errors"
"fmt"
"github.com/stretchr/testify/require"
"io"
"math"
"math/big"
Expand Down Expand Up @@ -1042,6 +1043,55 @@ func matchSliceMap(t *testing.T, sliceMap []map[string]interface{}, testMap map[
}
}

type MyRetryPolicy struct {
}

func (*MyRetryPolicy) Attempt(q RetryableQuery) bool {
if q.Attempts() > 5 {
return false
}
return true
}

func (*MyRetryPolicy) GetRetryType(error) RetryType {
return Retry
}

func Test_RetryPolicyIdempotence(t *testing.T) {
session := createSession(t)
defer session.Close()

testCases := []struct {
name string
idempotency bool
expectedNumberOfTries int
}{
{
name: "with retry",
idempotency: true,
expectedNumberOfTries: 6,
},
{
name: "without retry",
idempotency: false,
expectedNumberOfTries: 1,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
q := session.Query("INSERT INTO gocql_test.not_existing_table(event_id, time, args) VALUES (?,?,?)", 4, UUIDFromTime(time.Now()), "test")

q.Idempotent(tc.idempotency)
q.RetryPolicy(&MyRetryPolicy{})
q.Consistency(All)

_ = q.Exec()
require.Equal(t, tc.expectedNumberOfTries, q.Attempts())
})
}
}

func TestSmallInt(t *testing.T) {
session := createSession(t)
defer session.Close()
Expand Down

0 comments on commit 9ce97bb

Please sign in to comment.