Browse Source

Squashed commit of the following:

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 1ef17f8a17f47679f2196423631faab5ff2d545b
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 19d8061fc09f2f96aed25dffb7597e652dd440c3
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 b8fd1395ed84ec8d9a864f332c8c0d73e82f1eb4
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>
Chris Bannister 7 năm trước cách đây
mục cha
commit
a7b9f75f10
4 tập tin đã thay đổi với 25 bổ sung1 xóa
  1. 3 0
      cluster.go
  2. 1 1
      cluster_test.go
  3. 13 0
      session.go
  4. 8 0
      session_test.go

+ 3 - 0
cluster.go

@@ -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
 }

+ 1 - 1
cluster_test.go

@@ -2,9 +2,9 @@ package gocql
 
 import (
 	"net"
+	"reflect"
 	"testing"
 	"time"
-	"reflect"
 )
 
 func TestNewCluster_Defaults(t *testing.T) {

+ 13 - 0
session.go

@@ -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
 }
@@ -673,6 +674,7 @@ type Query struct {
 	defaultTimestampValue int64
 	disableSkipMetadata   bool
 	context               context.Context
+	idempotent            bool
 
 	disableAutoPage bool
 }
@@ -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 {

+ 8 - 0
session_test.go

@@ -182,6 +182,7 @@ 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)
@@ -189,16 +190,19 @@ func TestBatchBasicAPI(t *testing.T) {
 		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())
 	}
@@ -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)
@@ -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)