func new() *parse.TextProtocolParse {
	c := config.New()
	c.Servers = []string{"127.0.0.1:11211"}

	p, _ := pool.New(c)

	return parse.NewTextProtocolParse(p, c)
}
示例#2
0
func TestNewConfig(t *testing.T) {
	c := config.New()

	t.Logf("%+v\n", c)

	c.Servers = []string{"127.0.0.1:8080", "192.168.2.156:8080"}
	c.InitConns = 25

	t.Logf("%+v\n", c)
}
func BenchmarkConsistentAdd(b *testing.B) {
	conf := config.New()
	conf.Servers = servers

	consistent := selector.NewConsistent(conf)

	for i := 0; i < 300; i++ {
		key := fmt.Sprintf("127.0.0.1_%d", i)
		consistent.Add(key)
	}
}
func TestAdd(t *testing.T) {
	conf := config.New()
	conf.Servers = servers

	consistent := selector.NewConsistent(conf)

	for _, server := range servers {
		consistent.Add(server)
	}

	consistent.Print()
}
func BenchmarkConsistentGet(b *testing.B) {
	conf := config.New()
	conf.Servers = servers

	consistent := selector.NewConsistent(conf)

	for _, v := range servers {
		consistent.Add(v)
	}

	for i := 0; i < b.N; i++ {
		key := fmt.Sprintf("127.0.0.1_%d", i)
		b.Log(consistent.Get(key))
	}
}
func TestGet(t *testing.T) {
	conf := config.New()
	conf.Servers = servers

	consistent := selector.NewConsistent(conf)

	for _, server := range servers {
		consistent.Add(server)
	}

	for i := 0; i < 30; i++ {
		key := servers[i%len(servers)]
		t.Log(consistent.Get(fmt.Sprintf("%s-oef%d", key, i)))
	}
}
示例#7
0
func createPool(t *testing.T) *pool.ConnectionPool {
	c := config.New()
	if c == nil {
		t.Error("new config error.")
	}

	c.Servers = servers

	p, err := pool.New(c)
	if err != nil {
		t.Error("new pool error.")
	}

	t.Logf("%+v\n", p)

	return p.(*pool.ConnectionPool)
}