本文整理汇总了Golang中github.com/youtube/vitess/go/vt/tabletserver.QueryRules.Find方法的典型用法代码示例。如果您正苦于以下问题:Golang QueryRules.Find方法的具体用法?Golang QueryRules.Find怎么用?Golang QueryRules.Find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/youtube/vitess/go/vt/tabletserver.QueryRules
的用法示例。
在下文中一共展示了QueryRules.Find方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestFileCustomRule
func TestFileCustomRule(t *testing.T) {
tqsc := tabletservermock.NewController()
var qrs *tabletserver.QueryRules
rulepath := path.Join(os.TempDir(), ".customrule.json")
// Set r1 and try to get it back
err := ioutil.WriteFile(rulepath, []byte(customRule1), os.FileMode(0644))
if err != nil {
t.Fatalf("Cannot write r1 to rule file %s, err=%v", rulepath, err)
}
fcr := NewFileCustomRule()
// Let FileCustomRule to build rule from the local file
err = fcr.Open(tqsc, rulepath)
if err != nil {
t.Fatalf("Cannot open file custom rule service, err=%v", err)
}
// Fetch query rules we built to verify correctness
qrs, _, err = fcr.GetRules()
if err != nil {
t.Fatalf("GetRules returns error: %v", err)
}
qr := qrs.Find("r1")
if qr == nil {
t.Fatalf("Expect custom rule r1 to be found, but got nothing, qrs=%v", qrs)
}
}
示例2: TestZkCustomRule
func TestZkCustomRule(t *testing.T) {
tqsc := tabletservermock.NewController()
setUpFakeZk(t)
zkcr := NewZkCustomRule(conn)
err := zkcr.Open(tqsc, "/zk/fake/customrules/testrules")
if err != nil {
t.Fatalf("Cannot open zookeeper custom rule service, err=%v", err)
}
var qrs *tabletserver.QueryRules
// Test if we can successfully fetch the original rule (test GetRules)
qrs, _, err = zkcr.GetRules()
if err != nil {
t.Fatalf("GetRules of ZkCustomRule should always return nil error, but we receive %v", err)
}
qr := qrs.Find("r1")
if qr == nil {
t.Fatalf("Expect custom rule r1 to be found, but got nothing, qrs=%v", qrs)
}
// Test updating rules
conn.Set("/zk/fake/customrules/testrules", customRule2, -1)
<-time.After(time.Second) //Wait for the polling thread to respond
qrs, _, err = zkcr.GetRules()
if err != nil {
t.Fatalf("GetRules of ZkCustomRule should always return nil error, but we receive %v", err)
}
qr = qrs.Find("r2")
if qr == nil {
t.Fatalf("Expect custom rule r2 to be found, but got nothing, qrs=%v", qrs)
}
qr = qrs.Find("r1")
if qr != nil {
t.Fatalf("Custom rule r1 should not be found after r2 is set")
}
// Test rule path removal
conn.Delete("/zk/fake/customrules/testrules", -1)
<-time.After(time.Second)
qrs, _, err = zkcr.GetRules()
if err != nil {
t.Fatalf("GetRules of ZkCustomRule should always return nil error, but we receive %v", err)
}
if reflect.DeepEqual(qrs, tabletserver.NewQueryRules()) {
t.Fatalf("Expect empty rule at this point")
}
// Test rule path revival
conn.Create("/zk/fake/customrules/testrules", "customrule2", 0, zookeeper.WorldACL(zookeeper.PERM_ALL))
conn.Set("/zk/fake/customrules/testrules", customRule2, -1)
<-time.After(time.Second) //Wait for the polling thread to respond
qrs, _, err = zkcr.GetRules()
if err != nil {
t.Fatalf("GetRules of ZkCustomRule should always return nil error, but we receive %v", err)
}
qr = qrs.Find("r2")
if qr == nil {
t.Fatalf("Expect custom rule r2 to be found, but got nothing, qrs=%v", qrs)
}
zkcr.Close()
}