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

Golang events.NewLogger函数代码示例

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

本文整理汇总了Golang中github.com/syncthing/syncthing/lib/events.NewLogger函数的典型用法代码示例。如果您正苦于以下问题:Golang NewLogger函数的具体用法?Golang NewLogger怎么用?Golang NewLogger使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: TestBufferedSub

func TestBufferedSub(t *testing.T) {
	l := events.NewLogger()

	s := l.Subscribe(events.AllEvents)
	defer l.Unsubscribe(s)
	bs := events.NewBufferedSubscription(s, 10*events.BufferSize)

	go func() {
		for i := 0; i < 10*events.BufferSize; i++ {
			l.Log(events.DeviceConnected, fmt.Sprintf("event-%d", i))
			if i%30 == 0 {
				// Give the buffer routine time to pick up the events
				time.Sleep(20 * time.Millisecond)
			}
		}
	}()

	recv := 0
	for recv < 10*events.BufferSize {
		evs := bs.Since(recv, nil)
		for _, ev := range evs {
			if ev.ID != recv+1 {
				t.Fatalf("Incorrect ID; %d != %d", ev.ID, recv+1)
			}
			recv = ev.ID
		}
	}

}
开发者ID:wmwwmv,项目名称:syncthing,代码行数:29,代码来源:events_test.go


示例2: TestSubscriber

func TestSubscriber(t *testing.T) {
	l := events.NewLogger()
	s := l.Subscribe(0)
	if s == nil {
		t.Fatal("Unexpected nil Subscription")
	}
}
开发者ID:burkemw3,项目名称:syncthing,代码行数:7,代码来源:events_test.go


示例3: TestIDs

func TestIDs(t *testing.T) {
	l := events.NewLogger()

	s := l.Subscribe(events.AllEvents)
	defer l.Unsubscribe(s)
	l.Log(events.DeviceConnected, "foo")
	_ = l.Subscribe(events.AllEvents)
	l.Log(events.DeviceConnected, "bar")

	ev, err := s.Poll(timeout)
	if err != nil {
		t.Fatal("Unexpected error:", err)
	}
	if ev.Data.(string) != "foo" {
		t.Fatal("Incorrect event:", ev)
	}
	id := ev.ID

	ev, err = s.Poll(timeout)
	if err != nil {
		t.Fatal("Unexpected error:", err)
	}
	if ev.Data.(string) != "bar" {
		t.Fatal("Incorrect event:", ev)
	}
	if ev.ID != id+1 {
		t.Fatalf("ID not incremented (%d != %d)", ev.ID, id+1)
	}
}
开发者ID:wmwwmv,项目名称:syncthing,代码行数:29,代码来源:events_test.go


示例4: TestSinceUsesSubscriptionId

func TestSinceUsesSubscriptionId(t *testing.T) {
	l := events.NewLogger()

	s := l.Subscribe(events.DeviceConnected)
	defer l.Unsubscribe(s)
	bs := events.NewBufferedSubscription(s, 10*events.BufferSize)

	l.Log(events.DeviceConnected, "a") // SubscriptionID = 1
	l.Log(events.DeviceDisconnected, "b")
	l.Log(events.DeviceDisconnected, "c")
	l.Log(events.DeviceConnected, "d") // SubscriptionID = 2

	// We need to loop for the events, as they may not all have been
	// delivered to the buffered subscription when we get here.
	t0 := time.Now()
	for time.Since(t0) < time.Second {
		events := bs.Since(0, nil)
		if len(events) == 2 {
			break
		}
		if len(events) > 2 {
			t.Fatal("Incorrect number of events:", len(events))
		}
	}

	events := bs.Since(1, nil)
	if len(events) != 1 {
		t.Fatal("Incorrect number of events:", len(events))
	}
}
开发者ID:xduugu,项目名称:syncthing,代码行数:30,代码来源:events_test.go


示例5: TestTimeout

func TestTimeout(t *testing.T) {
	l := events.NewLogger()
	s := l.Subscribe(0)
	_, err := s.Poll(timeout)
	if err != events.ErrTimeout {
		t.Fatal("Unexpected non-Timeout error:", err)
	}
}
开发者ID:burkemw3,项目名称:syncthing,代码行数:8,代码来源:events_test.go


示例6: TestEventAfterSubscribeIgnoreMask

func TestEventAfterSubscribeIgnoreMask(t *testing.T) {
	l := events.NewLogger()

	s := l.Subscribe(events.DeviceDisconnected)
	l.Log(events.DeviceConnected, "foo")

	_, err := s.Poll(timeout)
	if err != events.ErrTimeout {
		t.Fatal("Unexpected non-Timeout error:", err)
	}
}
开发者ID:burkemw3,项目名称:syncthing,代码行数:11,代码来源:events_test.go


示例7: TestEventBeforeSubscribe

func TestEventBeforeSubscribe(t *testing.T) {
	l := events.NewLogger()

	l.Log(events.DeviceConnected, "foo")
	s := l.Subscribe(0)

	_, err := s.Poll(timeout)
	if err != events.ErrTimeout {
		t.Fatal("Unexpected non-Timeout error:", err)
	}
}
开发者ID:burkemw3,项目名称:syncthing,代码行数:11,代码来源:events_test.go


示例8: TestBufferOverflow

func TestBufferOverflow(t *testing.T) {
	l := events.NewLogger()

	_ = l.Subscribe(events.AllEvents)

	t0 := time.Now()
	for i := 0; i < events.BufferSize*2; i++ {
		l.Log(events.DeviceConnected, "foo")
	}
	if time.Since(t0) > timeout {
		t.Fatalf("Logging took too long")
	}
}
开发者ID:burkemw3,项目名称:syncthing,代码行数:13,代码来源:events_test.go


示例9: BenchmarkBufferedSub

func BenchmarkBufferedSub(b *testing.B) {
	l := events.NewLogger()

	s := l.Subscribe(events.AllEvents)
	defer l.Unsubscribe(s)
	bufferSize := events.BufferSize
	bs := events.NewBufferedSubscription(s, bufferSize)

	// The coord channel paces the sender according to the receiver,
	// ensuring that no events are dropped. The benchmark measures sending +
	// receiving + synchronization overhead.

	coord := make(chan struct{}, bufferSize)
	for i := 0; i < bufferSize-1; i++ {
		coord <- struct{}{}
	}

	// Receive the events
	done := make(chan struct{})
	go func() {
		defer close(done)
		recv := 0
		var evs []events.Event
		for i := 0; i < b.N; {
			evs = bs.Since(recv, evs[:0])
			for _, ev := range evs {
				if ev.GlobalID != recv+1 {
					b.Fatal("skipped event", ev.GlobalID, recv)
				}
				recv = ev.GlobalID
				coord <- struct{}{}
			}
			i += len(evs)
		}
	}()

	// Send the events
	eventData := map[string]string{
		"foo":   "bar",
		"other": "data",
		"and":   "something else",
	}
	for i := 0; i < b.N; i++ {
		l.Log(events.DeviceConnected, eventData)
		<-coord
	}

	<-done
	b.ReportAllocs()
}
开发者ID:xduugu,项目名称:syncthing,代码行数:50,代码来源:events_test.go


示例10: TestUnsubscribe

func TestUnsubscribe(t *testing.T) {
	l := events.NewLogger()

	s := l.Subscribe(events.AllEvents)
	l.Log(events.DeviceConnected, "foo")

	_, err := s.Poll(timeout)
	if err != nil {
		t.Fatal("Unexpected error:", err)
	}

	l.Unsubscribe(s)
	l.Log(events.DeviceConnected, "foo")

	_, err = s.Poll(timeout)
	if err != events.ErrClosed {
		t.Fatal("Unexpected non-Closed error:", err)
	}
}
开发者ID:wmwwmv,项目名称:syncthing,代码行数:19,代码来源:events_test.go


示例11: TestSubscriptionIDs

func TestSubscriptionIDs(t *testing.T) {
	l := events.NewLogger()

	s := l.Subscribe(events.DeviceConnected)
	defer l.Unsubscribe(s)

	l.Log(events.DeviceDisconnected, "a")
	l.Log(events.DeviceConnected, "b")
	l.Log(events.DeviceConnected, "c")
	l.Log(events.DeviceDisconnected, "d")

	ev, err := s.Poll(timeout)
	if err != nil {
		t.Fatal("Unexpected error:", err)
	}

	if ev.GlobalID != 2 {
		t.Fatal("Incorrect GlobalID:", ev.GlobalID)
	}
	if ev.SubscriptionID != 1 {
		t.Fatal("Incorrect SubscriptionID:", ev.SubscriptionID)
	}

	ev, err = s.Poll(timeout)
	if err != nil {
		t.Fatal("Unexpected error:", err)
	}
	if ev.GlobalID != 3 {
		t.Fatal("Incorrect GlobalID:", ev.GlobalID)
	}
	if ev.SubscriptionID != 2 {
		t.Fatal("Incorrect SubscriptionID:", ev.SubscriptionID)
	}

	ev, err = s.Poll(timeout)
	if err != events.ErrTimeout {
		t.Fatal("Unexpected error:", err)
	}
}
开发者ID:xduugu,项目名称:syncthing,代码行数:39,代码来源:events_test.go


示例12: TestEventAfterSubscribe

func TestEventAfterSubscribe(t *testing.T) {
	l := events.NewLogger()

	s := l.Subscribe(events.AllEvents)
	l.Log(events.DeviceConnected, "foo")

	ev, err := s.Poll(timeout)

	if err != nil {
		t.Fatal("Unexpected error:", err)
	}
	if ev.Type != events.DeviceConnected {
		t.Error("Incorrect event type", ev.Type)
	}
	switch v := ev.Data.(type) {
	case string:
		if v != "foo" {
			t.Error("Incorrect Data string", v)
		}
	default:
		t.Errorf("Incorrect Data type %#v", v)
	}
}
开发者ID:burkemw3,项目名称:syncthing,代码行数:23,代码来源:events_test.go


示例13: TestNewLogger

func TestNewLogger(t *testing.T) {
	l := events.NewLogger()
	if l == nil {
		t.Fatal("Unexpected nil Logger")
	}
}
开发者ID:wmwwmv,项目名称:syncthing,代码行数:6,代码来源:events_test.go



注:本文中的github.com/syncthing/syncthing/lib/events.NewLogger函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang events.Subscription类代码示例发布时间:2022-05-29
下一篇:
Golang events.NewBufferedSubscription函数代码示例发布时间:2022-05-29
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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