当前位置: 首页>>代码示例>>Golang>>正文


Golang fakeyagnats.New函数代码示例

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


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

示例1: TestRouterClientGreeting

func (s *RCSuite) TestRouterClientGreeting(c *C) {
	mbus := fakeyagnats.New()

	routerClient := NewCFRouterClient("1.2.3.4", mbus)

	routerClient.Register(123, "abc")

	err := routerClient.Greet()
	c.Assert(err, IsNil)

	greetMsg := mbus.PublishedMessages("router.greet")[0]

	greetCallback := mbus.Subscriptions(greetMsg.ReplyTo)[0]
	greetCallback.Callback(&yagnats.Message{
		Payload: []byte(`{"minimumRegisterIntervalInSeconds":1}`),
	})

	c.Assert(len(mbus.PublishedMessages("router.register")), Equals, 1)

	time.Sleep(600 * time.Millisecond)

	c.Assert(len(mbus.PublishedMessages("router.register")), Equals, 1)

	time.Sleep(600 * time.Millisecond)

	c.Assert(len(mbus.PublishedMessages("router.register")), Equals, 2)

	time.Sleep(600 * time.Millisecond)

	c.Assert(len(mbus.PublishedMessages("router.register")), Equals, 2)

	time.Sleep(600 * time.Millisecond)

	c.Assert(len(mbus.PublishedMessages("router.register")), Equals, 3)
}
开发者ID:MatthiasWinzeler,项目名称:gibson,代码行数:35,代码来源:router_client_test.go

示例2: TestRouterClientRouterStartHandling

func (s *RCSuite) TestRouterClientRouterStartHandling(c *C) {
	mbus := fakeyagnats.New()

	routerClient := NewCFRouterClient("1.2.3.4", mbus)

	err := routerClient.Greet()
	c.Assert(err, IsNil)

	startCallback := mbus.Subscriptions["router.start"][0]
	startCallback.Callback(&yagnats.Message{
		Payload: []byte(`{"minimumRegisterIntervalInSeconds":1}`),
	})

	routerClient.Register(123, "abc")

	c.Assert(len(mbus.PublishedMessages["router.register"]), Equals, 1)

	time.Sleep(600 * time.Millisecond)

	c.Assert(len(mbus.PublishedMessages["router.register"]), Equals, 1)

	time.Sleep(600 * time.Millisecond)

	c.Assert(len(mbus.PublishedMessages["router.register"]), Equals, 2)

	time.Sleep(600 * time.Millisecond)

	c.Assert(len(mbus.PublishedMessages["router.register"]), Equals, 2)

	time.Sleep(600 * time.Millisecond)

	c.Assert(len(mbus.PublishedMessages["router.register"]), Equals, 3)
}
开发者ID:MatthiasWinzeler,项目名称:route-registrar,代码行数:33,代码来源:router_client_test.go

示例3: SetUpTest

func (s *ProxySuite) SetUpTest(c *C) {
	s.conf = config.DefaultConfig()
	s.conf.TraceKey = "my_trace_key"
	s.conf.EndpointTimeout = 500 * time.Millisecond

	mbus := fakeyagnats.New()

	s.r = registry.NewCFRegistry(s.conf, mbus)
	fmt.Printf("Config: %#v", s.conf)

	s.accessLogFile = new(test_util.FakeFile)
	accessLog := access_log.NewFileAndLoggregatorAccessLogger(s.accessLogFile, "localhost:9843", "secret", 42)
	go accessLog.Run()

	s.p = NewProxy(ProxyArgs{
		EndpointTimeout: s.conf.EndpointTimeout,
		Ip:              s.conf.Ip,
		TraceKey:        s.conf.TraceKey,
		Registry:        s.r,
		Reporter:        nullVarz{},
		Logger:          accessLog,
	})

	ln, err := net.Listen("tcp", "127.0.0.1:0")
	if err != nil {
		panic(err)
	}

	server := server.Server{Handler: s.p}
	go server.Serve(ln)

	s.proxyServer = ln
}
开发者ID:nimbus-cloud,项目名称:gorouter,代码行数:33,代码来源:proxy_test.go

示例4: BenchmarkRegister

func BenchmarkRegister(b *testing.B) {
	c := config.DefaultConfig()
	mbus := fakeyagnats.New()
	r := registry.NewCFRegistry(c, mbus)

	proxy.NewProxy(proxy.ProxyArgs{
		EndpointTimeout: c.EndpointTimeout,
		Ip:              c.Ip,
		TraceKey:        c.TraceKey,
		Registry:        r,
		Reporter:        varz.NewVarz(r),
		Logger:          access_log.CreateRunningAccessLogger(c),
	})

	for i := 0; i < b.N; i++ {
		str := strconv.Itoa(i)

		r.Register(
			route.Uri("bench.vcap.me."+str),
			&route.Endpoint{
				Host: "localhost",
				Port: uint16(i),
			},
		)
	}
}
开发者ID:jackfengibm,项目名称:gorouter,代码行数:26,代码来源:perf_test.go

示例5: createNatsClientAndHandler

func createNatsClientAndHandler() (client *fakeyagnats.FakeYagnats, handler natsHandler) {
	settings := boshsettings.Settings{
		AgentId: "my-agent-id",
		Mbus:    "nats://foo:[email protected]:1234",
	}

	client = fakeyagnats.New()
	handler = newNatsHandler(client, settings)
	return
}
开发者ID:sbb,项目名称:bosh,代码行数:10,代码来源:nats_handler_test.go

示例6: TestRouterClientUnregistering

func (s *RCSuite) TestRouterClientUnregistering(c *C) {
	mbus := fakeyagnats.New()

	routerClient := NewCFRouterClient("1.2.3.4", mbus)

	routerClient.Unregister(123, "abc")

	unregistrations := mbus.PublishedMessages["router.unregister"]

	c.Assert(len(unregistrations), Not(Equals), 0)
	c.Assert(string(unregistrations[0].Payload), Equals, `{"uris":["abc"],"host":"1.2.3.4","port":123}`)
}
开发者ID:MatthiasWinzeler,项目名称:route-registrar,代码行数:12,代码来源:router_client_test.go

示例7: TestRouterClientRegistering

func (s *RCSuite) TestRouterClientRegistering(c *C) {
	mbus := fakeyagnats.New()

	routerClient := NewCFRouterClient("1.2.3.4", mbus)

	routerClient.Register(123, "abc")

	registrations := mbus.PublishedMessages("router.register")

	c.Assert(len(registrations), Not(Equals), 0)
	c.Assert(string(registrations[0].Payload), Equals,
		`{"uris":["abc"],"host":"1.2.3.4","port":123,"private_instance_id":"`+routerClient.PrivateInstanceId+`"}`)
}
开发者ID:MatthiasWinzeler,项目名称:gibson,代码行数:13,代码来源:router_client_test.go

示例8: BenchmarkRegister

func BenchmarkRegister(b *testing.B) {
	c := config.DefaultConfig()
	mbus := fakeyagnats.New()
	r := registry.NewRegistry(c, mbus)
	p := proxy.NewProxy(c, r, varz.NewVarz(r))

	for i := 0; i < b.N; i++ {
		str := strconv.Itoa(i)

		p.Register(
			route.Uri("bench.vcap.me."+str),
			&route.Endpoint{
				Host: "localhost",
				Port: uint16(i),
			},
		)
	}
}
开发者ID:nakaji-s,项目名称:gorouter,代码行数:18,代码来源:perf_test.go

示例9: SetUpTest

func (s *ProxySuite) SetUpTest(c *C) {
	config := config.DefaultConfig()
	config.TraceKey = "my_trace_key"
	config.EndpointTimeout = 500 * time.Millisecond

	mbus := fakeyagnats.New()
	s.r = registry.NewRegistry(config, mbus)
	s.p = NewProxy(config, s.r, nullVarz{})

	ln, err := net.Listen("tcp", "127.0.0.1:0")
	if err != nil {
		panic(err)
	}

	server := server.Server{Handler: s.p}
	go server.Serve(ln)

	s.proxyServer = ln
}
开发者ID:karlpilkington,项目名称:golang-devops-stuff,代码行数:19,代码来源:proxy_test.go

示例10: SetUpTest

func (s *RegistrySuite) SetUpTest(c *C) {
	var configObj *config.Config

	configObj = config.DefaultConfig()
	configObj.DropletStaleThreshold = 10 * time.Millisecond

	s.messageBus = fakeyagnats.New()
	s.Registry = NewRegistry(configObj, s.messageBus)

	fooEndpoint = &route.Endpoint{
		Host: "192.168.1.1",
		Port: 1234,

		ApplicationId: "12345",
		Tags: map[string]string{
			"runtime":   "ruby18",
			"framework": "sinatra",
		},
	}

	barEndpoint = &route.Endpoint{
		Host: "192.168.1.2",
		Port: 4321,

		ApplicationId: "54321",
		Tags: map[string]string{
			"runtime":   "javascript",
			"framework": "node",
		},
	}

	bar2Endpoint = &route.Endpoint{
		Host: "192.168.1.3",
		Port: 1234,

		ApplicationId: "54321",
		Tags: map[string]string{
			"runtime":   "javascript",
			"framework": "node",
		},
	}
}
开发者ID:nakaji-s,项目名称:gorouter,代码行数:42,代码来源:registry_test.go

示例11: buildNatsClientAndHandler

func buildNatsClientAndHandler(settings boshsettings.Service) (client *fakeyagnats.FakeYagnats, handler natsHandler) {
	logger := boshlog.NewLogger(boshlog.LEVEL_NONE)
	client = fakeyagnats.New()
	handler = newNatsHandler(settings, logger, client)
	return
}
开发者ID:ian-plosker,项目名称:bosh,代码行数:6,代码来源:nats_handler_test.go

示例12:

	"time"
)

var _ = Describe("RouteRegistry", func() {
	var r *RouteRegistry
	var messageBus *fakeyagnats.FakeYagnats

	var fooEndpoint, barEndpoint, bar2Endpoint *route.Endpoint
	var configObj *config.Config

	BeforeEach(func() {
		configObj = config.DefaultConfig()
		configObj.PruneStaleDropletsInterval = 50 * time.Millisecond
		configObj.DropletStaleThreshold = 10 * time.Millisecond

		messageBus = fakeyagnats.New()
		r = NewRouteRegistry(configObj, messageBus)
		fooEndpoint = route.NewEndpoint("12345", "192.168.1.1", 1234,
			"id1", map[string]string{
				"runtime":   "ruby18",
				"framework": "sinatra",
			})

		barEndpoint = route.NewEndpoint("54321", "192.168.1.2", 4321,
			"id2", map[string]string{
				"runtime":   "javascript",
				"framework": "node",
			})

		bar2Endpoint = route.NewEndpoint("54321", "192.168.1.3", 1234,
			"id3", map[string]string{
开发者ID:tomzhang,项目名称:golang-devops-stuff,代码行数:31,代码来源:registry_test.go

示例13: init

func init() {
	Describe("natsHandler", func() {
		var (
			settingsService *fakesettings.FakeSettingsService
			client          *fakeyagnats.FakeYagnats
			logger          boshlog.Logger
			handler         boshhandler.Handler
		)

		BeforeEach(func() {
			settingsService = &fakesettings.FakeSettingsService{
				Settings: boshsettings.Settings{
					AgentID: "my-agent-id",
					Mbus:    "nats://fake-username:[email protected]:1234",
				},
			}
			logger = boshlog.NewLogger(boshlog.LevelNone)
			client = fakeyagnats.New()
			handler = NewNatsHandler(settingsService, client, logger)
		})

		Describe("Start", func() {
			It("starts", func() {
				var receivedRequest boshhandler.Request

				handler.Start(func(req boshhandler.Request) (resp boshhandler.Response) {
					receivedRequest = req
					return boshhandler.NewValueResponse("expected value")
				})
				defer handler.Stop()

				Expect(client.ConnectedConnectionProvider()).ToNot(BeNil())

				Expect(client.SubscriptionCount()).To(Equal(1))
				subscriptions := client.Subscriptions("agent.my-agent-id")
				Expect(len(subscriptions)).To(Equal(1))

				expectedPayload := []byte(`{"method":"ping","arguments":["foo","bar"], "reply_to": "reply to me!"}`)
				subscription := subscriptions[0]
				subscription.Callback(&yagnats.Message{
					Subject: "agent.my-agent-id",
					Payload: expectedPayload,
				})

				Expect(receivedRequest).To(Equal(boshhandler.Request{
					ReplyTo: "reply to me!",
					Method:  "ping",
					Payload: expectedPayload,
				}))

				Expect(client.PublishedMessageCount()).To(Equal(1))
				messages := client.PublishedMessages("reply to me!")
				Expect(len(messages)).To(Equal(1))
				Expect(messages[0].Payload).To(Equal([]byte(`{"value":"expected value"}`)))
			})

			It("does not respond if the response is nil", func() {
				err := handler.Start(func(req boshhandler.Request) (resp boshhandler.Response) {
					return nil
				})
				Expect(err).ToNot(HaveOccurred())
				defer handler.Stop()

				subscription := client.Subscriptions("agent.my-agent-id")[0]
				subscription.Callback(&yagnats.Message{
					Subject: "agent.my-agent-id",
					Payload: []byte(`{"method":"ping","arguments":["foo","bar"], "reply_to": "reply to me!"}`),
				})

				Expect(client.PublishedMessageCount()).To(Equal(0))
			})

			It("responds with an error if the response is bigger than 1MB", func() {
				err := handler.Start(func(req boshhandler.Request) (resp boshhandler.Response) {
					// gets inflated by json.Marshal when enveloping
					size := 0

					switch req.Method {
					case "small":
						size = 1024*1024 - 12
					case "big":
						size = 1024 * 1024
					default:
						panic("unknown request size")
					}

					chars := make([]byte, size)
					for i := range chars {
						chars[i] = 'A'
					}
					return boshhandler.NewValueResponse(string(chars))
				})
				Expect(err).ToNot(HaveOccurred())
				defer handler.Stop()

				subscription := client.Subscriptions("agent.my-agent-id")[0]
				subscription.Callback(&yagnats.Message{
					Subject: "agent.my-agent-id",
					Payload: []byte(`{"method":"small","arguments":[], "reply_to": "fake-reply-to"}`),
				})
//.........这里部分代码省略.........
开发者ID:nimbus-cloud,项目名称:bosh-agent,代码行数:101,代码来源:nats_handler_test.go

示例14: init

func init() {
	Describe("natsHandler", func() {
		var (
			client  *fakeyagnats.FakeYagnats
			logger  boshlog.Logger
			handler boshhandler.Handler
		)

		BeforeEach(func() {
			settings := &fakesettings.FakeSettingsService{
				AgentID: "my-agent-id",
				MbusURL: "nats://fake-username:[email protected]:1234",
			}
			logger = boshlog.NewLogger(boshlog.LevelNone)
			client = fakeyagnats.New()
			handler = NewNatsHandler(settings, logger, client)
		})

		Describe("Start", func() {
			It("starts", func() {
				var receivedRequest boshhandler.Request

				handler.Start(func(req boshhandler.Request) (resp boshhandler.Response) {
					receivedRequest = req
					return boshhandler.NewValueResponse("expected value")
				})
				defer handler.Stop()

				Expect(client.ConnectedConnectionProvider).ToNot(BeNil())

				Expect(len(client.Subscriptions)).To(Equal(1))
				subscriptions := client.Subscriptions["agent.my-agent-id"]
				Expect(len(subscriptions)).To(Equal(1))

				expectedPayload := []byte(`{"method":"ping","arguments":["foo","bar"], "reply_to": "reply to me!"}`)
				subscription := client.Subscriptions["agent.my-agent-id"][0]
				subscription.Callback(&yagnats.Message{
					Subject: "agent.my-agent-id",
					Payload: expectedPayload,
				})

				Expect(receivedRequest).To(Equal(boshhandler.Request{
					ReplyTo: "reply to me!",
					Method:  "ping",
					Payload: expectedPayload,
				}))

				Expect(len(client.PublishedMessages)).To(Equal(1))
				messages := client.PublishedMessages["reply to me!"]
				Expect(len(messages)).To(Equal(1))
				Expect(messages[0].Payload).To(Equal([]byte(`{"value":"expected value"}`)))
			})

			It("does not respond if the response is nil", func() {
				err := handler.Start(func(req boshhandler.Request) (resp boshhandler.Response) {
					return nil
				})
				Expect(err).ToNot(HaveOccurred())
				defer handler.Stop()

				subscription := client.Subscriptions["agent.my-agent-id"][0]
				subscription.Callback(&yagnats.Message{
					Subject: "agent.my-agent-id",
					Payload: []byte(`{"method":"ping","arguments":["foo","bar"], "reply_to": "reply to me!"}`),
				})

				Expect(len(client.PublishedMessages)).To(Equal(0))
			})

			It("responds with an error if the response is bigger than 1MB", func() {
				err := handler.Start(func(req boshhandler.Request) (resp boshhandler.Response) {
					// gets inflated by json.Marshal when enveloping
					size := 0

					switch req.Method {
					case "small":
						size = 1024*1024 - 12
					case "big":
						size = 1024 * 1024
					default:
						panic("unknown request size")
					}

					chars := make([]byte, size)
					for i := range chars {
						chars[i] = 'A'
					}
					return boshhandler.NewValueResponse(string(chars))
				})
				Expect(err).ToNot(HaveOccurred())
				defer handler.Stop()

				subscription := client.Subscriptions["agent.my-agent-id"][0]
				subscription.Callback(&yagnats.Message{
					Subject: "agent.my-agent-id",
					Payload: []byte(`{"method":"small","arguments":[], "reply_to": "fake-reply-to"}`),
				})

				subscription.Callback(&yagnats.Message{
					Subject: "agent.my-agent-id",
//.........这里部分代码省略.........
开发者ID:Jane4PKU,项目名称:bosh,代码行数:101,代码来源:nats_handler_test.go

示例15:

}

var _ = Describe("Proxy", func() {
	var r *registry.RouteRegistry
	var p Proxy
	var conf *config.Config
	var proxyServer net.Listener
	var accessLog access_log.AccessLogger
	var accessLogFile *test_util.FakeFile

	BeforeEach(func() {
		conf = config.DefaultConfig()
		conf.TraceKey = "my_trace_key"
		conf.EndpointTimeout = 500 * time.Millisecond

		mbus := fakeyagnats.New()

		r = registry.NewRouteRegistry(conf, mbus)

		accessLogFile = new(test_util.FakeFile)
		accessLog = access_log.NewFileAndLoggregatorAccessLogger(accessLogFile, nil)
		go accessLog.Run()

		p = NewProxy(ProxyArgs{
			EndpointTimeout: conf.EndpointTimeout,
			Ip:              conf.Ip,
			TraceKey:        conf.TraceKey,
			Registry:        r,
			Reporter:        nullVarz{},
			AccessLogger:    accessLog,
		})
开发者ID:tomzhang,项目名称:golang-devops-stuff,代码行数:31,代码来源:proxy_test.go


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