Fix imports.

This commit is contained in:
Vladimir Mihailenco 2012-07-27 14:43:30 +03:00
parent 557a0f8403
commit 9c5def7f1f
4 changed files with 123 additions and 8 deletions

View File

@ -5,7 +5,7 @@ import (
"io" "io"
"sync" "sync"
"github.com/togoio/redisgoproxy/bufreader" "github.com/vmihailenco/bufreader"
) )
type connectFunc func() (io.ReadWriter, error) type connectFunc func() (io.ReadWriter, error)
@ -27,7 +27,7 @@ type Client struct {
func NewClient(connect connectFunc, disconnect disconnectFunc) *Client { func NewClient(connect connectFunc, disconnect disconnectFunc) *Client {
return &Client{ return &Client{
readerPool: bufreader.NewReaderPool(10, createReader), readerPool: bufreader.NewReaderPool(100, createReader),
connect: connect, connect: connect,
disconnect: disconnect, disconnect: disconnect,
} }
@ -35,7 +35,7 @@ func NewClient(connect connectFunc, disconnect disconnectFunc) *Client {
func NewMultiClient(connect connectFunc, disconnect disconnectFunc) *Client { func NewMultiClient(connect connectFunc, disconnect disconnectFunc) *Client {
return &Client{ return &Client{
readerPool: bufreader.NewReaderPool(10, createReader), readerPool: bufreader.NewReaderPool(100, createReader),
connect: connect, connect: connect,
disconnect: disconnect, disconnect: disconnect,

View File

@ -3,12 +3,14 @@ package redis_test
import ( import (
"io" "io"
"net" "net"
"strconv"
"testing" "testing"
"time" "time"
. "launchpad.net/gocheck" . "launchpad.net/gocheck"
"github.com/togoio/redisgoproxy/redis" "github.com/vmihailenco/bufreader"
"github.com/vmihailenco/redis"
) )
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -1166,20 +1168,82 @@ func (t *RedisTest) TestMultiExec(c *C) {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
func (t *RedisTest) BenchmarkPing(c *C) { func (t *RedisTest) TestConcAccess(c *C) {
for i := int64(0); i < 99; i++ {
go func() {
msg := "echo" + strconv.FormatInt(i, 10)
echo, err := t.redisC.Echo(msg).Reply()
c.Check(err, IsNil)
c.Check(echo, Equals, msg)
}()
}
}
//------------------------------------------------------------------------------
func (t *RedisTest) BenchmarkRedisPing(c *C) {
c.StopTimer()
for i := 0; i < 10; i++ {
pong, err := t.redisC.Ping().Reply()
c.Check(err, IsNil)
c.Check(pong, Equals, "PONG")
}
c.StartTimer()
for i := 0; i < c.N; i++ { for i := 0; i < c.N; i++ {
t.redisC.Ping().Reply() t.redisC.Ping().Reply()
} }
} }
func (t *RedisTest) BenchmarkSet(c *C) { func (t *RedisTest) BenchmarkRedisSet(c *C) {
c.StopTimer()
for i := 0; i < 10; i++ {
ok, err := t.redisC.Set("foo", "bar").Reply()
c.Check(err, IsNil)
c.Check(ok, Equals, "OK")
}
c.StartTimer()
for i := 0; i < c.N; i++ { for i := 0; i < c.N; i++ {
t.redisC.Set("foo", "bar").Reply() t.redisC.Set("foo", "bar").Reply()
} }
} }
func (t *RedisTest) BenchmarkGet(c *C) { func (t *RedisTest) BenchmarkRedisGet(c *C) {
c.StopTimer()
for i := 0; i < 10; i++ {
v, err := t.redisC.Get("foo").Reply()
c.Check(err, Equals, redis.Nil)
c.Check(v, Equals, "")
}
c.StartTimer()
for i := 0; i < c.N; i++ { for i := 0; i < c.N; i++ {
t.redisC.Get("foo").Reply() t.redisC.Get("foo").Reply()
} }
} }
func (t *RedisTest) BenchmarkRedisWriteRead(c *C) {
c.StopTimer()
req := []byte("PING\r\n")
rd := bufreader.NewSizedReader(1024)
for i := 0; i < 10; i++ {
err := t.redisC.WriteRead(req, rd)
c.Check(err, IsNil)
c.Check(rd.Bytes(), DeepEquals, []byte("+PONG\r\n"))
}
c.StartTimer()
for i := 0; i < c.N; i++ {
t.redisC.WriteRead(req, rd)
}
}

View File

@ -6,7 +6,7 @@ import (
"io" "io"
"strconv" "strconv"
"github.com/togoio/redisgoproxy/bufreader" "github.com/vmihailenco/bufreader"
) )
var Nil = errors.New("(nil)") var Nil = errors.New("(nil)")

51
request_test.go Normal file
View File

@ -0,0 +1,51 @@
package redis_test
import (
"github.com/vmihailenco/bufreader"
. "launchpad.net/gocheck"
"github.com/vmihailenco/redis"
)
//------------------------------------------------------------------------------
type RequestTest struct{}
var _ = Suite(&RequestTest{})
//------------------------------------------------------------------------------
func (t *RequestTest) SetUpTest(c *C) {}
func (t *RequestTest) TearDownTest(c *C) {}
//------------------------------------------------------------------------------
func (t *RequestTest) BenchmarkStatusReq(c *C) {
c.StopTimer()
rd := bufreader.NewSizedReader(1024)
rd.Set([]byte("+OK\r\n"))
req := redis.NewStatusReq()
for i := 0; i < 10; i++ {
rd.ResetPos()
vI, err := req.ParseReply(rd)
c.Check(err, IsNil)
c.Check(vI, Equals, "OK")
req.SetVal(vI)
v, err := req.Reply()
c.Check(err, IsNil)
c.Check(v, Equals, "OK")
}
c.StartTimer()
for i := 0; i < c.N; i++ {
rd.ResetPos()
v, _ := req.ParseReply(rd)
req.SetVal(v)
req.Reply()
}
}