Example #1
0
		udpWrapper = dopplerforwarder.NewUDPWrapper(sharedSecret, logger)

		var err error
		message, err = proto.Marshal(envelope)
		Expect(err).NotTo(HaveOccurred())

	})

	It("counts the number of bytes sent", func() {
		// Make sure the counter counts the sent byte count,
		// instead of len(message)
		sentLength := len(message) - 3
		client.WriteOutput.sentLength <- sentLength
		client.WriteOutput.err <- nil

		err := udpWrapper.Write(client, message)
		Expect(err).NotTo(HaveOccurred())
		Eventually(func() uint64 {
			return sender.GetCounter("udp.sentByteCount")
		}).Should(BeEquivalentTo(sentLength))
	})

	It("counts the number of messages sent", func() {
		client.WriteOutput.sentLength <- len(message)
		client.WriteOutput.err <- nil

		err := udpWrapper.Write(client, message)
		Expect(err).NotTo(HaveOccurred())
		Eventually(func() uint64 {
			return sender.GetCounter("udp.sentMessageCount")
		}).Should(BeEquivalentTo(1))
		udpWrapper = dopplerforwarder.NewUDPWrapper(sharedSecret, logger)

		var err error
		message, err = proto.Marshal(envelope)
		Expect(err).NotTo(HaveOccurred())

	})

	It("counts the number of bytes sent", func() {
		// Make sure the counter counts the sent byte count,
		// instead of len(message)
		sentLength := len(message) - 3
		client.WriteOutput.SentLength <- sentLength
		client.WriteOutput.Err <- nil

		err := udpWrapper.Write(client, message)
		Expect(err).NotTo(HaveOccurred())
		Eventually(mockBatcher.BatchAddCounterInput).Should(BeCalled(
			With("udp.sentByteCount", uint64(sentLength)),
		))
	})

	It("counts the number of messages sent", func() {
		client.WriteOutput.SentLength <- len(message)
		client.WriteOutput.Err <- nil
		mockChainer := newMockBatchCounterChainer()
		testhelpers.AlwaysReturn(mockChainer.SetTagOutput, mockChainer)

		err := udpWrapper.Write(client, message, mockChainer)
		Expect(err).NotTo(HaveOccurred())
		Eventually(mockBatcher.BatchIncrementCounterInput).Should(BeCalled(