Beispiel #1
0
func checkTestRole(addr string, checkRoles []interface{}) error {
	conn, _ := goredis.Connect(addr)
	defer conn.Close()
	roles, err := goredis.MultiBulk(conn.Do("ROLE"))
	if err != nil {
		return err
	} else if !reflect.DeepEqual(roles, checkRoles) {
		return fmt.Errorf("%v != %v", roles, checkRoles)
	}
	return nil
}
Beispiel #2
0
func (m *master) checkConn() error {
	m.connLock.Lock()
	defer m.connLock.Unlock()

	var err error
	if m.conn == nil {
		m.conn, err = goredis.Connect(m.addr)
	} else {
		if _, err = m.conn.Do("PING"); err != nil {
			m.conn.Close()
			m.conn = nil
		}
	}
	return err
}
Beispiel #3
0
func TestMigrate(t *testing.T) {
	data_dir := "/tmp/test_migrate"
	os.RemoveAll(data_dir)

	s1Cfg := config.NewConfigDefault()
	s1Cfg.DataDir = fmt.Sprintf("%s/s1", data_dir)
	s1Cfg.Addr = "127.0.0.1:11185"

	s2Cfg := config.NewConfigDefault()
	s2Cfg.DataDir = fmt.Sprintf("%s/s2", data_dir)
	s2Cfg.Addr = "127.0.0.1:11186"

	s1, err := NewApp(s1Cfg)
	if err != nil {
		t.Fatal(err)
	}
	defer s1.Close()

	s2, err := NewApp(s2Cfg)
	if err != nil {
		t.Fatal(err)
	}
	defer s2.Close()

	go s1.Run()

	go s2.Run()

	time.Sleep(1 * time.Second)

	c1, _ := goredis.Connect(s1Cfg.Addr)
	defer c1.Close()

	c2, _ := goredis.Connect(s2Cfg.Addr)
	defer c2.Close()

	if _, err = c1.Do("set", "a", "1"); err != nil {
		t.Fatal(err)
	}

	timeout := 30000
	if _, err = c1.Do("xmigrate", "127.0.0.1", 11186, "KV", "a", 0, timeout); err != nil {
		t.Fatal(err)
	}

	if s, err := goredis.String(c2.Do("get", "a")); err != nil {
		t.Fatal(err)
	} else if s != "1" {
		t.Fatal(s, "must 1")
	}

	if s, err := goredis.String(c1.Do("get", "a")); err != nil && err != goredis.ErrNil {
		t.Fatal(err)
	} else if s != "" {
		t.Fatal(s, "must empty")
	}

	if num, err := goredis.Int(c2.Do("xmigratedb", "127.0.0.1", 11185, "KV", 10, 0, timeout)); err != nil {
		t.Fatal(err)
	} else if num != 1 {
		t.Fatal(num, "must number 1")
	}

	if s, err := goredis.String(c1.Do("get", "a")); err != nil {
		t.Fatal(err)
	} else if s != "1" {
		t.Fatal(s, "must 1")
	}

	if s, err := goredis.String(c2.Do("get", "a")); err != nil && err != goredis.ErrNil {
		t.Fatal(err)
	} else if s != "" {
		t.Fatal(s, "must empty")
	}

	if _, err = c1.Do("xmigrate", "127.0.0.1", 11186, "ALL", "a", 0, timeout); err != nil {
		t.Fatal(err)
	}

	if s, err := goredis.String(c2.Do("get", "a")); err != nil {
		t.Fatal(err)
	} else if s != "1" {
		t.Fatal(s, "must 1")
	}

	if s, err := goredis.String(c1.Do("get", "a")); err != nil && err != goredis.ErrNil {
		t.Fatal(err)
	} else if s != "" {
		t.Fatal(s, "must empty")
	}
}