• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang clock.Clock类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中bazil/org/bazil/fs/clock.Clock的典型用法代码示例。如果您正苦于以下问题:Golang Clock类的具体用法?Golang Clock怎么用?Golang Clock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Clock类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestUnmarshalBinarySimple

func TestUnmarshalBinarySimple(t *testing.T) {
	var v clock.Clock
	input := []byte{
		// syncLen
		2,
		// sync
		10, 3,
		11, 2,
		// modLen
		1,
		// mod
		11, 2,
		// createLen
		1,
		// create
		10, 3,
	}
	err := v.UnmarshalBinary(input)
	if g, e := v.String(), `{sync{10:3 11:2} mod{11:2} create{10:3}}`; g != e {
		t.Errorf("bad unmarshal: %v != %v", g, e)
	}
	if err != nil {
		t.Fatalf("got unmarshal error: %v", err)
	}
}
开发者ID:som-snytt,项目名称:bazil,代码行数:25,代码来源:marshal_test.go


示例2: Clock

// Clock returns the clock for this item.
//
// Returned value is valid after the transaction.
func (item *VolumeConflictsItem) Clock() (*clock.Clock, error) {
	var c clock.Clock
	clockBuf := item.key[item.prefixLen:]
	if err := c.UnmarshalBinary(clockBuf); err != nil {
		return nil, fmt.Errorf("error unmarshaling clock: %v", err)
	}
	return &c, nil
}
开发者ID:som-snytt,项目名称:bazil,代码行数:11,代码来源:volumeConflict.go


示例3: Put

func (vc *VolumeClock) Put(parentInode uint64, name string, c *clock.Clock) error {
	key := vc.pathToKey(parentInode, name)
	buf, err := c.MarshalBinary()
	if err != nil {
		return err
	}
	if err := vc.b.Put(key, buf); err != nil {
		return err
	}
	return nil
}
开发者ID:read-later,项目名称:bazil,代码行数:11,代码来源:volumeClock.go


示例4: Get

func (vc *VolumeClock) Get(parentInode uint64, name string) (*clock.Clock, error) {
	key := vc.pathToKey(parentInode, name)
	val := vc.b.Get(key)
	if val == nil {
		return nil, &ClockNotFoundError{ParentInode: parentInode, Name: name}
	}
	var c clock.Clock
	if err := c.UnmarshalBinary(val); err != nil {
		return nil, err
	}
	return &c, nil
}
开发者ID:read-later,项目名称:bazil,代码行数:12,代码来源:volumeClock.go


示例5: Run

func (cmd *decodeCommand) Run() error {
	var buf bytes.Buffer
	const Max = 4096
	n, err := io.CopyN(&buf, os.Stdin, Max)
	if err != nil && err != io.EOF {
		return fmt.Errorf("reading standard input: %v", err)
	}
	if n == Max {
		return errors.New("aborting because clock is unreasonably big")
	}

	var c clock.Clock
	if err := c.UnmarshalBinary(buf.Bytes()); err != nil {
		return err
	}
	fmt.Printf("%v\n", c)
	return nil
}
开发者ID:read-later,项目名称:bazil,代码行数:18,代码来源:decode.go


示例6: Add

func (vc *VolumeConflicts) Add(parentInode uint64, c *clock.Clock, de *wirepeer.Dirent) error {
	clockBuf, err := c.MarshalBinary()
	if err != nil {
		return fmt.Errorf("error marshaling clock: %v", err)
	}
	key := vc.pathToKey(parentInode, de.Name, clockBuf)

	tmp := *de
	tmp.Name = ""
	buf, err := proto.Marshal(&tmp)
	if err != nil {
		return fmt.Errorf("error marshaling dirent: %v", err)
	}

	if err := vc.b.Put(key, buf); err != nil {
		return err
	}
	return nil
}
开发者ID:som-snytt,项目名称:bazil,代码行数:19,代码来源:volumeConflict.go


示例7: TestFigure2C

func TestFigure2C(t *testing.T) {
	var b clock.Clock

	a := clock.Create(10, 1)
	if g, e := clock.Sync(a, &b), clock.Copy; g != e {
		t.Errorf("bad sync decision: %v is to %v -> %v != %v", a, b, g, e)
	}
	b.ResolveTheirs(a)
	a.Update(10, 3)
	b.Update(11, 3)
	if g, e := clock.Sync(&b, a), clock.Conflict; g != e {
		t.Errorf("bad sync decision: %v is to %v -> %v != %v", a, b, g, e)
	}

	if g, e := a.String(), `{sync{10:3} mod{10:3} create{10:1}}`; g != e {
		t.Errorf("bad state A: %v != %v", g, e)
	}
	if g, e := b.String(), `{sync{10:1 11:3} mod{11:3} create{10:1}}`; g != e {
		t.Errorf("bad state B: %v != %v", g, e)
	}

	a.ValidateFile(&clock.Clock{ /* dummy parent */ })
	b.ValidateFile(&clock.Clock{ /* dummy parent */ })
}
开发者ID:read-later,项目名称:bazil,代码行数:24,代码来源:paper_test.go


示例8: UpdateFromChild

func (vc *VolumeClock) UpdateFromChild(parentInode uint64, name string, child *clock.Clock) (changed bool, err error) {
	key := vc.pathToKey(parentInode, name)
	val := vc.b.Get(key)
	if val == nil {
		return false, &ClockNotFoundError{ParentInode: parentInode, Name: name}
	}
	var parentClock clock.Clock
	if err := parentClock.UnmarshalBinary(val); err != nil {
		return false, fmt.Errorf("corrupt clock for %d:%q", parentInode, name)
	}
	if changed := parentClock.UpdateFromChild(child); !changed {
		// no need to persist anything
		return false, nil
	}
	buf, err := parentClock.MarshalBinary()
	if err != nil {
		return false, err
	}
	if err := vc.b.Put(key, buf); err != nil {
		return false, err
	}
	return true, nil
}
开发者ID:read-later,项目名称:bazil,代码行数:23,代码来源:volumeClock.go


示例9: TestFigure3B

func TestFigure3B(t *testing.T) {
	var a clock.Clock
	var b clock.Clock
	var c clock.Clock

	b.Update(11, 1)

	if g, e := clock.Sync(&b, &a), clock.Copy; g != e {
		t.Errorf("bad sync decision: %v is to %v -> %v != %v", a, b, g, e)
	}
	a.ResolveTheirs(&b)

	if g, e := clock.Sync(&b, &c), clock.Copy; g != e {
		t.Errorf("bad sync decision: %v is to %v -> %v != %v", a, b, g, e)
	}
	c.ResolveTheirs(&b)

	a.Update(10, 3)
	b.Update(11, 3)

	if g, e := clock.Sync(&a, &b), clock.Conflict; g != e {
		t.Errorf("bad sync decision: %v is to %v -> %v != %v", a, b, g, e)
	}
	// resolve conflict in favor of a
	b.ResolveTheirs(&a)

	if g, e := clock.Sync(&a, &b), clock.Nothing; g != e {
		t.Errorf("bad sync decision: %v is to %v -> %v != %v", a, b, g, e)
	}

	if g, e := clock.Sync(&c, &b), clock.Nothing; g != e {
		t.Errorf("bad sync decision: %v is to %v -> %v != %v", a, b, g, e)
	}

	a.Update(10, 6)
	if g, e := clock.Sync(&a, &b), clock.Copy; g != e {
		t.Errorf("bad sync decision: %v is to %v -> %v != %v", a, b, g, e)
	}

	a.ValidateFile(&clock.Clock{ /* dummy parent */ })
	b.ValidateFile(&clock.Clock{ /* dummy parent */ })
	c.ValidateFile(&clock.Clock{ /* dummy parent */ })
}
开发者ID:read-later,项目名称:bazil,代码行数:43,代码来源:paper_test.go


示例10: TestSyncPull


//.........这里部分代码省略.........

	const testFileName = "greeting"
	const testFileContent = "hello, world"
	func() {
		mnt := bazfstestutil.Mounted(t, app1, volumeName)
		defer mnt.Close()
		if err := ioutil.WriteFile(path.Join(mnt.Dir, testFileName), []byte(testFileContent), 0644); err != nil {
			t.Fatalf("cannot create file: %v", err)
		}
	}()

	client, err := app2.DialPeer(pub1)
	if err != nil {
		t.Fatalf("dial: %v", err)
	}
	defer client.Close()

	volIDBuf, err := volID.MarshalBinary()
	if err != nil {
		t.Fatalf("marshal volume id: %v", err)
	}
	ctx := context.Background()
	stream, err := client.VolumeSyncPull(ctx, &wire.VolumeSyncPullRequest{
		VolumeID: volIDBuf,
	})
	if err != nil {
		t.Fatalf("sync failed: %v", err)
	}

	item, err := stream.Recv()
	if err != nil {
		t.Fatalf("sync stream failed: %v", err)
	}
	if g, e := item.Error, wire.VolumeSyncPullItem_SUCCESS; g != e {
		t.Errorf("unexpected error: %v != %v", g, e)
	}
	if g, e := item.Peers, map[uint32][]byte{
		0: pub1[:],
		1: pub2[:],
	}; !reflect.DeepEqual(g, e) {
		t.Errorf("bad peers: %v != %v", g, e)
	}

	wantFiles := map[string]func(*wire.Dirent){
		testFileName: func(de *wire.Dirent) {
			if de.File == nil {
				t.Errorf("wrong type for %q, not a file: %v", de.Name, de)
				return
			}

			var c clock.Clock
			if err := c.UnmarshalBinary(de.Clock); err != nil {
				t.Errorf("invalid clock for %q: %v", de.Name, err)
				return
			}
			if g, e := c.String(), `{sync{0:1} mod{0:1} create{0:1}}`; g != e {
				t.Errorf("wrong clock for %q: %v != %v", de.Name, g, e)
				return
			}

			// verify file contents
			manifest, err := de.File.Manifest.ToBlob("file")
			if err != nil {
				t.Errorf("cannot open manifest for %q: %v", de.Name, err)
				return
			}
			blob, err := blobs.Open(chunkStore2, manifest)
			if err != nil {
				t.Errorf("cannot open blob for %q: %v", de.Name, err)
				return
			}
			r := io.NewSectionReader(blob, 0, int64(blob.Size()))
			buf, err := ioutil.ReadAll(r)
			if err != nil {
				t.Errorf("cannot read blob for %q: %v", de.Name, err)
				return
			}
			if g, e := string(buf), testFileContent; g != e {
				t.Errorf("wrong content for %q: %q != %q", de.Name, g, e)
			}
		},
	}
	for _, de := range item.Children {
		fn, ok := wantFiles[de.Name]
		if !ok {
			t.Errorf("unexpected direntry: %q", de.Name)
			continue
		}
		fn(de)
		delete(wantFiles, de.Name)
	}
	for name, _ := range wantFiles {
		t.Errorf("missing direntry: %q", name)
	}

	item, err = stream.Recv()
	if err != io.EOF {
		t.Errorf("expected eof, got error %v, item=%v", err, item)
	}
}
开发者ID:read-later,项目名称:bazil,代码行数:101,代码来源:volumeSyncPull_test.go



注:本文中的bazil/org/bazil/fs/clock.Clock类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang fstestutil.CreateVolume函数代码示例发布时间:2022-05-24
下一篇:
Golang db.Tx类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap