浏览代码

remove legacy topology (#1037)

Chris Bannister 8 年之前
父节点
当前提交
59441a623b
共有 2 个文件被更改,包括 0 次插入125 次删除
  1. 0 74
      topology.go
  2. 0 51
      topology_test.go

+ 0 - 74
topology.go

@@ -1,74 +0,0 @@
-// Copyright (c) 2012 The gocql Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package gocql
-
-import (
-	"sync"
-	"sync/atomic"
-)
-
-type Node interface {
-	Pick(qry *Query) *Conn
-	Close()
-}
-
-type RoundRobin struct {
-	pool []Node
-	pos  uint32
-	mu   sync.RWMutex
-}
-
-func NewRoundRobin() *RoundRobin {
-	return &RoundRobin{}
-}
-
-func (r *RoundRobin) AddNode(node Node) {
-	r.mu.Lock()
-	r.pool = append(r.pool, node)
-	r.mu.Unlock()
-}
-
-func (r *RoundRobin) RemoveNode(node Node) {
-	r.mu.Lock()
-	n := len(r.pool)
-	for i := 0; i < n; i++ {
-		if r.pool[i] == node {
-			r.pool[i], r.pool[n-1] = r.pool[n-1], r.pool[i]
-			r.pool = r.pool[:n-1]
-			break
-		}
-	}
-	r.mu.Unlock()
-}
-
-func (r *RoundRobin) Size() int {
-	r.mu.RLock()
-	n := len(r.pool)
-	r.mu.RUnlock()
-	return n
-}
-
-func (r *RoundRobin) Pick(qry *Query) *Conn {
-	pos := atomic.AddUint32(&r.pos, 1)
-	var node Node
-	r.mu.RLock()
-	if len(r.pool) > 0 {
-		node = r.pool[pos%uint32(len(r.pool))]
-	}
-	r.mu.RUnlock()
-	if node == nil {
-		return nil
-	}
-	return node.Pick(qry)
-}
-
-func (r *RoundRobin) Close() {
-	r.mu.Lock()
-	for i := 0; i < len(r.pool); i++ {
-		r.pool[i].Close()
-	}
-	r.pool = nil
-	r.mu.Unlock()
-}

+ 0 - 51
topology_test.go

@@ -1,51 +0,0 @@
-// +build all unit
-
-package gocql
-
-import (
-	"testing"
-)
-
-// fakeNode is used as a simple structure to test the RoundRobin API
-type fakeNode struct {
-	conn   *Conn
-	closed bool
-}
-
-// Pick is needed to satisfy the Node interface
-func (n *fakeNode) Pick(qry *Query) *Conn {
-	if n.conn == nil {
-		n.conn = &Conn{}
-	}
-	return n.conn
-}
-
-//Close is needed to satisfy the Node interface
-func (n *fakeNode) Close() {
-	n.closed = true
-}
-
-//TestRoundRobinAPI tests the exported methods of the RoundRobin struct
-//to make sure the API behaves accordingly.
-func TestRoundRobinAPI(t *testing.T) {
-	node := &fakeNode{}
-	rr := NewRoundRobin()
-	rr.AddNode(node)
-
-	if rr.Size() != 1 {
-		t.Fatalf("expected size to be 1, got %v", rr.Size())
-	}
-
-	if c := rr.Pick(nil); c != node.conn {
-		t.Fatalf("expected conn %v, got %v", node.conn, c)
-	}
-
-	rr.Close()
-	if rr.pool != nil {
-		t.Fatalf("expected rr.pool to be nil, got %v", rr.pool)
-	}
-
-	if !node.closed {
-		t.Fatal("expected node.closed to be true, got false")
-	}
-}