本文整理匯總了Golang中github.com/dgraph-io/dgraph/x.DirectedEdge.Source方法的典型用法代碼示例。如果您正苦於以下問題:Golang DirectedEdge.Source方法的具體用法?Golang DirectedEdge.Source怎麽用?Golang DirectedEdge.Source使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/dgraph-io/dgraph/x.DirectedEdge
的用法示例。
在下文中一共展示了DirectedEdge.Source方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestAddMutation
func TestAddMutation(t *testing.T) {
// logrus.SetLevel(logrus.DebugLevel)
l := NewList()
key := Key(1, "name")
dir, err := ioutil.TempDir("", "storetest_")
if err != nil {
t.Error(err)
return
}
defer os.RemoveAll(dir)
ps := new(store.Store)
ps.Init(dir)
clog := commit.NewLogger(dir, "mutations", 50<<20)
clog.Init()
defer clog.Close()
l.init(key, ps, clog)
edge := x.DirectedEdge{
ValueId: 9,
Source: "testing",
Timestamp: time.Now(),
}
if err := l.AddMutation(edge, Set); err != nil {
t.Error(err)
}
/*
if err := l.CommitIfDirty(); err != nil {
t.Error(err)
}
*/
if l.Length() != 1 {
t.Error("Unable to find added elements in posting list")
}
var p types.Posting
if ok := l.Get(&p, 0); !ok {
t.Error("Unable to retrieve posting at 1st iter")
t.Fail()
}
if p.Uid() != 9 {
t.Errorf("Expected 9. Got: %v", p.Uid)
}
if string(p.Source()) != "testing" {
t.Errorf("Expected testing. Got: %v", string(p.Source()))
}
// return // Test 1.
// Add another edge now.
edge.ValueId = 81
l.AddMutation(edge, Set)
// l.CommitIfDirty()
if l.Length() != 2 {
t.Errorf("Length: %d", l.Length())
t.Fail()
}
var uid uint64
uid = 1
for i := 0; i < l.Length(); i++ {
if ok := l.Get(&p, i); !ok {
t.Error("Unable to retrieve posting at 2nd iter")
}
uid *= 9
if p.Uid() != uid {
t.Logf("Expected: %v. Got: %v", uid, p.Uid())
}
}
// return // Test 2.
// Add another edge, in between the two above.
uids := []uint64{
9, 49, 81,
}
edge.ValueId = 49
if err := l.AddMutation(edge, Set); err != nil {
t.Error(err)
}
/*
if err := l.CommitIfDirty(); err != nil {
t.Error(err)
}
*/
if err := checkUids(t, l, uids...); err != nil {
t.Error(err)
}
// return // Test 3.
// Delete an edge, add an edge, replace an edge
edge.ValueId = 49
if err := l.AddMutation(edge, Del); err != nil {
t.Error(err)
}
edge.ValueId = 69
if err := l.AddMutation(edge, Set); err != nil {
t.Error(err)
}
//.........這裏部分代碼省略.........