本文整理汇总了Golang中github.com/cloudfoundry/yagnats/fakeyagnats.FakeYagnats.PublishedMessageCount方法的典型用法代码示例。如果您正苦于以下问题:Golang FakeYagnats.PublishedMessageCount方法的具体用法?Golang FakeYagnats.PublishedMessageCount怎么用?Golang FakeYagnats.PublishedMessageCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cloudfoundry/yagnats/fakeyagnats.FakeYagnats
的用法示例。
在下文中一共展示了FakeYagnats.PublishedMessageCount方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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"}`),
})
//.........这里部分代码省略.........