Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit e4905c3b203a4266b22abeaedfe463a9649dc2c9
Author: Chris Bannister <c.bannister@gmail.com>
Date:   Sat May 5 13:22:26 2018 +0100

    idempontent: remove config method, add docs to query

    Add doc to the query methods for idempontency and name the setter to be
    consistent with other query setters, also return the query so it can be
    chained with other settings.

    Expose the default idempotent setting as a value on the strut and remove
    the methods to set/get them.

commit 83d170357e01d984d7d60d25f0d8d3ce6a7a1bd0
Merge: 3a24f01 1ef17f8
Author: Chris Bannister <c.bannister@gmail.com>
Date:   Sat May 5 13:19:36 2018 +0100

    Merge branch 'QueryIdempotence_1087' of https://github.com/alourie/gocql into alourie-QueryIdempotence_1087

commit 1ef17f8
Author: Alex Lourie <alex@instaclustr.com>
Date:   Fri Apr 27 00:10:59 2018 +0930

    Resync with master and cleanup

    Signed-off-by: Alex Lourie <alex@instaclustr.com>

commit 19d8061
Author: Alex Lourie <alex@instaclustr.com>
Date:   Fri Apr 27 00:08:12 2018 +0930

    Update Session.Query() with default idempotence

    Signed-off-by: Alex Lourie <alex@instaclustr.com>

commit b8fd139
Author: Alex Lourie <djay.il@gmail.com>
Date:   Wed Apr 11 14:05:25 2018 +0930

    Initial idempotent work

    Signed-off-by: Alex Lourie <djay.il@gmail.com>
  • Loading branch information
Zariel committed May 5, 2018
1 parent 3a24f01 commit a7b9f75
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cluster.go
Expand Up @@ -125,6 +125,9 @@ type ClusterConfig struct {
// Use it to collect metrics / stats from batche queries by providing an implementation of BatchObserver.
BatchObserver BatchObserver

// Default idempotence for queries
DefaultIdempotence bool

// internal config for testing
disableControlConn bool
}
Expand Down
2 changes: 1 addition & 1 deletion cluster_test.go
Expand Up @@ -2,9 +2,9 @@ package gocql

import (
"net"
"reflect"
"testing"
"time"
"reflect"
)

func TestNewCluster_Defaults(t *testing.T) {
Expand Down
13 changes: 13 additions & 0 deletions session.go
Expand Up @@ -324,6 +324,7 @@ func (s *Session) Query(stmt string, values ...interface{}) *Query {
qry.rt = s.cfg.RetryPolicy
qry.serialCons = s.cfg.SerialConsistency
qry.defaultTimestamp = s.cfg.DefaultTimestamp
qry.idempotent = s.cfg.DefaultIdempotence
s.mu.RUnlock()
return qry
}
Expand Down Expand Up @@ -673,6 +674,7 @@ type Query struct {
defaultTimestampValue int64
disableSkipMetadata bool
context context.Context
idempotent bool

disableAutoPage bool
}
Expand Down Expand Up @@ -912,6 +914,17 @@ func (q *Query) RetryPolicy(r RetryPolicy) *Query {
return q
}

func (q *Query) IsIdempotent() bool {
return q.idempotent
}

// Idempontent marks the query as being idempontent or not depending on
// the value.
func (q *Query) Idempontent(value bool) *Query {
q.idempotent = value
return q
}

// Bind sets query arguments of query. This can also be used to rebind new query arguments
// to an existing query instance.
func (q *Query) Bind(v ...interface{}) *Query {
Expand Down
8 changes: 8 additions & 0 deletions session_test.go
Expand Up @@ -182,23 +182,27 @@ func TestBatchBasicAPI(t *testing.T) {

s.pool = cfg.PoolConfig.buildPool(s)

// Test UnloggedBatch
b := s.NewBatch(UnloggedBatch)
if b.Type != UnloggedBatch {
t.Fatalf("expceted batch.Type to be '%v', got '%v'", UnloggedBatch, b.Type)
} else if b.rt != cfg.RetryPolicy {
t.Fatalf("expceted batch.RetryPolicy to be '%v', got '%v'", cfg.RetryPolicy, b.rt)
}

// Test LoggedBatch
b = NewBatch(LoggedBatch)
if b.Type != LoggedBatch {
t.Fatalf("expected batch.Type to be '%v', got '%v'", LoggedBatch, b.Type)
}

// Test attempts
b.attempts = 1
if b.Attempts() != 1 {
t.Fatalf("expceted batch.Attempts() to return %v, got %v", 1, b.Attempts())
}

// Test latency
if b.Latency() != 0 {
t.Fatalf("expected batch.Latency() to be 0, got %v", b.Latency())
}
Expand All @@ -208,11 +212,13 @@ func TestBatchBasicAPI(t *testing.T) {
t.Fatalf("expected batch.Latency() to return %v, got %v", 4, b.Latency())
}

// Test Consistency
b.Cons = One
if b.GetConsistency() != One {
t.Fatalf("expected batch.GetConsistency() to return 'One', got '%s'", b.GetConsistency())
}

// Test batch.Query()
b.Query("test", 1)
if b.Entries[0].Stmt != "test" {
t.Fatalf("expected batch.Entries[0].Statement to be 'test', got '%v'", b.Entries[0].Stmt)
Expand All @@ -229,6 +235,8 @@ func TestBatchBasicAPI(t *testing.T) {
} else if b.Entries[1].binding == nil {
t.Fatal("expected batch.Entries[1].binding to be defined, got nil")
}

// Test RetryPolicy
r := &SimpleRetryPolicy{NumRetries: 4}

b.RetryPolicy(r)
Expand Down

0 comments on commit a7b9f75

Please sign in to comment.