refactor names

master
kevin 4 years ago
parent 4bdf5e4c90
commit 4b636cd293

@ -9,24 +9,24 @@ import (
var ErrNoAvailablePusher = errors.New("no available pusher") var ErrNoAvailablePusher = errors.New("no available pusher")
type BalancedQueuePusher struct { type BalancedPusher struct {
name string name string
pushers []Pusher pushers []Pusher
index uint64 index uint64
} }
func NewBalancedQueuePusher(pushers []Pusher) Pusher { func NewBalancedPusher(pushers []Pusher) Pusher {
return &BalancedQueuePusher{ return &BalancedPusher{
name: generateName(pushers), name: generateName(pushers),
pushers: pushers, pushers: pushers,
} }
} }
func (pusher *BalancedQueuePusher) Name() string { func (pusher *BalancedPusher) Name() string {
return pusher.name return pusher.name
} }
func (pusher *BalancedQueuePusher) Push(message string) error { func (pusher *BalancedPusher) Push(message string) error {
size := len(pusher.pushers) size := len(pusher.pushers)
for i := 0; i < size; i++ { for i := 0; i < size; i++ {

@ -20,7 +20,7 @@ func TestBalancedQueuePusher(t *testing.T) {
mockedPushers = append(mockedPushers, p) mockedPushers = append(mockedPushers, p)
} }
pusher := NewBalancedQueuePusher(pushers) pusher := NewBalancedPusher(pushers)
assert.True(t, len(pusher.Name()) > 0) assert.True(t, len(pusher.Name()) > 0)
for i := 0; i < numPushers*1000; i++ { for i := 0; i < numPushers*1000; i++ {
@ -37,7 +37,7 @@ func TestBalancedQueuePusher(t *testing.T) {
} }
func TestBalancedQueuePusher_NoAvailable(t *testing.T) { func TestBalancedQueuePusher_NoAvailable(t *testing.T) {
pusher := NewBalancedQueuePusher(nil) pusher := NewBalancedPusher(nil)
assert.True(t, len(pusher.Name()) == 0) assert.True(t, len(pusher.Name()) == 0)
assert.Equal(t, ErrNoAvailablePusher, pusher.Push("item")) assert.Equal(t, ErrNoAvailablePusher, pusher.Push("item"))
} }

@ -2,23 +2,23 @@ package queue
import "github.com/tal-tech/go-zero/core/errorx" import "github.com/tal-tech/go-zero/core/errorx"
type MultiQueuePusher struct { type MultiPusher struct {
name string name string
pushers []Pusher pushers []Pusher
} }
func NewMultiQueuePusher(pushers []Pusher) Pusher { func NewMultiPusher(pushers []Pusher) Pusher {
return &MultiQueuePusher{ return &MultiPusher{
name: generateName(pushers), name: generateName(pushers),
pushers: pushers, pushers: pushers,
} }
} }
func (pusher *MultiQueuePusher) Name() string { func (pusher *MultiPusher) Name() string {
return pusher.name return pusher.name
} }
func (pusher *MultiQueuePusher) Push(message string) error { func (pusher *MultiPusher) Push(message string) error {
var batchError errorx.BatchError var batchError errorx.BatchError
for _, each := range pusher.pushers { for _, each := range pusher.pushers {

@ -21,7 +21,7 @@ func TestMultiQueuePusher(t *testing.T) {
mockedPushers = append(mockedPushers, p) mockedPushers = append(mockedPushers, p)
} }
pusher := NewMultiQueuePusher(pushers) pusher := NewMultiPusher(pushers)
assert.True(t, len(pusher.Name()) > 0) assert.True(t, len(pusher.Name()) > 0)
for i := 0; i < 1000; i++ { for i := 0; i < 1000; i++ {
Loading…
Cancel
Save