2012-03-26 13:32:59 +08:00
|
|
|
package client
|
2011-05-19 20:10:53 +08:00
|
|
|
|
|
|
|
import (
|
2012-03-26 13:32:59 +08:00
|
|
|
"bitbucket.org/mikespook/gearman-go/gearman"
|
2011-05-19 20:10:53 +08:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
var client *Client
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
client = NewClient()
|
|
|
|
}
|
|
|
|
|
2011-05-24 13:20:22 +08:00
|
|
|
func TestClientAddServer(t *testing.T) {
|
2011-05-19 20:10:53 +08:00
|
|
|
t.Log("Add local server 127.0.0.1:4730")
|
|
|
|
if err := client.AddServer("127.0.0.1:4730"); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-24 13:20:22 +08:00
|
|
|
func TestClientEcho(t *testing.T) {
|
2011-05-20 17:38:10 +08:00
|
|
|
if echo, err := client.Echo([]byte("Hello world")); err != nil {
|
2011-05-19 20:10:53 +08:00
|
|
|
t.Error(err)
|
2011-05-20 17:38:10 +08:00
|
|
|
} else {
|
|
|
|
t.Log(echo)
|
2011-05-19 20:10:53 +08:00
|
|
|
}
|
|
|
|
}
|
2011-05-22 22:43:14 +08:00
|
|
|
|
2011-05-24 13:20:22 +08:00
|
|
|
func TestClientDo(t *testing.T) {
|
2012-03-26 13:32:59 +08:00
|
|
|
if handle, err := client.Do("ToUpper", []byte("abcdef"), gearman.JOB_LOW|gearman.JOB_BG); err != nil {
|
2011-05-19 23:29:34 +08:00
|
|
|
t.Error(err)
|
2011-05-20 17:38:10 +08:00
|
|
|
} else {
|
|
|
|
t.Log(handle)
|
2011-05-19 23:29:34 +08:00
|
|
|
}
|
|
|
|
}
|
2011-05-19 20:10:53 +08:00
|
|
|
|
2011-05-24 13:20:22 +08:00
|
|
|
func TestClientClose(t *testing.T) {
|
2011-05-19 20:10:53 +08:00
|
|
|
if err := client.Close(); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|