コード例 #1
0
			hbEmitter.Close()
		})
	})

	Describe("Emit", func() {
		var (
			hbEmitter emitter.ByteEmitter
			testData  = []byte("hello")
		)

		BeforeEach(func() {
			hbEmitter, _ = emitter.NewHeartbeatEmitter(wrappedEmitter, origin)
		})

		It("delegates to the wrapped emitter", func() {
			hbEmitter.Emit(testData)

			messages := wrappedEmitter.GetMessages()
			Expect(messages).To(HaveLen(1))
			Expect(messages[0]).To(Equal(testData))
		})

		It("increments the heartbeat counter", func() {
			hbEmitter.Emit(testData)

			Eventually(func() bool {
				messages := wrappedEmitter.GetMessages()

				for _, message := range messages {
					hbEnvelope := &events.Envelope{}
					err := proto.Unmarshal(message, hbEnvelope)
コード例 #2
0
			BeforeEach(func() {
				var err error
				agentListener, err = net.ListenPacket("udp4", "")
				Expect(err).ToNot(HaveOccurred())

				udpEmitter, err = emitter.NewUdpEmitter(agentListener.LocalAddr().String())
				Expect(err).ToNot(HaveOccurred())
			})

			AfterEach(func() {
				agentListener.Close()
			})

			It("should send the data", func(done Done) {
				err := udpEmitter.Emit(testData)
				Expect(err).ToNot(HaveOccurred())

				buffer := make([]byte, 4096)
				readCount, _, err := agentListener.ReadFrom(buffer)
				Expect(err).ToNot(HaveOccurred())
				Expect(buffer[:readCount]).To(Equal(testData))

				close(done)
			})
		})

		Context("when the agent is not listening", func() {
			BeforeEach(func() {
				udpEmitter, _ = emitter.NewUdpEmitter("localhost:12345")
			})