"github.com/cloudfoundry-incubator/dropsonde/emitter/fake"
	"github.com/cloudfoundry-incubator/dropsonde/events"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

func getHeartbeatEvent(ie emitter.InstrumentedEmitter) *events.Heartbeat {
	return ie.GetHeartbeatEvent().(*events.Heartbeat)
}

var _ = Describe("InstrumentedEmitter", func() {
	var fakeEmitter *fake.FakeByteEmitter
	var instrumentedEmitter emitter.InstrumentedEmitter

	BeforeEach(func() {
		fakeEmitter = fake.NewFakeByteEmitter()
		instrumentedEmitter, _ = emitter.NewInstrumentedEmitter(fakeEmitter)
	})

	Describe("Delegators", func() {

		It("delegates Close() to the concreteEmitter", func() {
			instrumentedEmitter.Close()
			Eventually(fakeEmitter.IsClosed).Should(BeTrue())
		})
	})

	Describe("Emit()", func() {
		var testData = []byte("hello")

		It("calls the concrete emitter", func() {
	"github.com/cloudfoundry-incubator/dropsonde/events"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"log"
	"time"
)

var _ = Describe("HeartbeatEmitter", func() {
	var (
		wrappedEmitter *fake.FakeByteEmitter
		origin         = "testHeartbeatEmitter/0"
	)

	BeforeEach(func() {
		emitter.HeartbeatInterval = 10 * time.Millisecond
		wrappedEmitter = fake.NewFakeByteEmitter()
	})

	Describe("NewHeartbeatEmitter", func() {
		It("requires non-nil args", func() {
			hbEmitter, err := emitter.NewHeartbeatEmitter(nil, origin)
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(Equal("wrappedEmitter is nil"))
			Expect(hbEmitter).To(BeNil())
		})

		It("starts periodic heartbeat emission", func() {
			hbEmitter, err := emitter.NewHeartbeatEmitter(wrappedEmitter, origin)
			Expect(err).NotTo(HaveOccurred())
			Expect(hbEmitter).NotTo(BeNil())
Exemplo n.º 3
0
import (
	"code.google.com/p/gogoprotobuf/proto"
	"github.com/cloudfoundry-incubator/dropsonde/emitter"
	"github.com/cloudfoundry-incubator/dropsonde/emitter/fake"
	"github.com/cloudfoundry-incubator/dropsonde/events"

	"github.com/cloudfoundry-incubator/dropsonde/factories"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("EventEmitter", func() {
	Describe("Emit", func() {
		Context("without an origin", func() {
			It("returns an error", func() {
				innerEmitter := fake.NewFakeByteEmitter()
				eventEmitter := emitter.NewEventEmitter(innerEmitter, "")

				testEvent := factories.NewHeartbeat(1, 2, 3)
				err := eventEmitter.Emit(testEvent)

				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(ContainSubstring("Wrap: "))
			})
		})

		It("marshals events and delegates to the inner emitter", func() {
			innerEmitter := fake.NewFakeByteEmitter()
			origin := "fake-origin"
			eventEmitter := emitter.NewEventEmitter(innerEmitter, origin)