Exemplo n.º 1
0
func RunTruncatingBuffer(inputChan <-chan *events.Envelope, bufferSize uint, logger *gosteno.Logger, dropsondeOrigin string) *truncatingbuffer.TruncatingBuffer {
	b := truncatingbuffer.NewTruncatingBuffer(inputChan, bufferSize, logger, dropsondeOrigin)
	go b.Run()
	return b
}
)

var _ = Describe("Truncating Buffer", func() {
	var inMessageChan chan *events.Envelope
	var stopChannel chan struct{}
	var filter func(eventType events.Envelope_EventType) bool
	var buffer *truncatingbuffer.TruncatingBuffer

	BeforeEach(func() {
		filter = nil
		inMessageChan = make(chan *events.Envelope)
		stopChannel = make(chan struct{})
	})

	JustBeforeEach(func() {
		buffer = truncatingbuffer.NewTruncatingBuffer(inMessageChan, filter, 3, loggertesthelper.Logger(), "dropsonde-origin", "test-sink-name", stopChannel)
	})

	AfterEach(func() {
		if inMessageChan != nil {
			close(inMessageChan)
		}
	})

	It("panics if buffer size is less than 3", func() {
		Expect(func() {
			truncatingbuffer.NewTruncatingBuffer(inMessageChan, nil, 2, loggertesthelper.Logger(), "dropsonde-origin", "test-sync-name", nil)
		}).To(Panic())
	})

	Describe("Run", func() {
Exemplo n.º 3
0
	"doppler/truncatingbuffer"
	"time"

	"github.com/cloudfoundry/dropsonde/factories"
	"github.com/cloudfoundry/sonde-go/events"

	"github.com/cloudfoundry/dropsonde/emitter"
	"github.com/cloudfoundry/loggregatorlib/loggertesthelper"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Truncating Buffer", func() {
	It("works like a channel", func() {
		inMessageChan := make(chan *events.Envelope)
		buffer := truncatingbuffer.NewTruncatingBuffer(inMessageChan, 2, loggertesthelper.Logger(), "dropsonde-origin")
		go buffer.Run()

		logMessage1, _ := emitter.Wrap(factories.NewLogMessage(events.LogMessage_OUT, "message 1", "appId", "App"), "origin")
		inMessageChan <- logMessage1
		readMessage := <-buffer.GetOutputChannel()
		Expect(readMessage.GetLogMessage().GetMessage()).To(ContainSubstring("message 1"))

		logMessage2, _ := emitter.Wrap(factories.NewLogMessage(events.LogMessage_OUT, "message 2", "appId", "App"), "origin")

		inMessageChan <- logMessage2
		readMessage2 := <-buffer.GetOutputChannel()
		Expect(readMessage2.GetLogMessage().GetMessage()).To(ContainSubstring("message 2"))

	})
Exemplo n.º 4
0
func RunTruncatingBuffer(inputChan <-chan *events.Envelope, filterEvent func(events.Envelope_EventType) bool, bufferSize uint, logger *gosteno.Logger, dropsondeOrigin, sinkIdentifier string, stopChannel chan struct{}) *truncatingbuffer.TruncatingBuffer {
	b := truncatingbuffer.NewTruncatingBuffer(inputChan, filterEvent, bufferSize, logger, dropsondeOrigin, sinkIdentifier, stopChannel)
	go b.Run()
	return b
}
	"github.com/cloudfoundry/dropsonde/emitter/fake"
	"github.com/cloudfoundry/dropsonde/metric_sender"
	"github.com/cloudfoundry/dropsonde/metricbatcher"
	"github.com/cloudfoundry/dropsonde/metrics"
	"github.com/cloudfoundry/loggregatorlib/loggertesthelper"
	"github.com/gogo/protobuf/proto"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Truncating Buffer", func() {

	It("panics if buffer size is less than 3", func() {
		inMessageChan := make(chan *events.Envelope)
		Expect(func() {
			truncatingbuffer.NewTruncatingBuffer(inMessageChan, 2, loggertesthelper.Logger(), "dropsonde-origin", "test-sync-name")
		}).To(Panic())
	})

	It("works like a channel", func() {
		inMessageChan := make(chan *events.Envelope)
		buffer := truncatingbuffer.NewTruncatingBuffer(inMessageChan, 3, loggertesthelper.Logger(), "dropsonde-origin", "test-sink-name")
		go buffer.Run()

		sendLogMessages("message 1", inMessageChan)

		readMessage := <-buffer.GetOutputChannel()
		Expect(readMessage.GetLogMessage().GetMessage()).To(ContainSubstring("message 1"))

		sendLogMessages("message 2", inMessageChan)