Created
April 9, 2018 15:56
-
-
Save claudio-benfatto/a925d48573302e585052e9a2e68a5671 to your computer and use it in GitHub Desktop.
metron_throughput.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main_test | |
import ( | |
"time" | |
. "github.com/onsi/ginkgo" | |
. "github.com/onsi/gomega" | |
. "github.com/jriguera/metron-throughput/receiver" | |
"github.com/cloudfoundry/sonde-go/events" | |
"github.com/gogo/protobuf/proto" | |
) | |
var _ = Describe("Dispatcher", func() { | |
It("Can process a single log message", func() { | |
jobQueue := make(chan Job, 10) | |
go func() { | |
for i := 0; i < 100000; i++ { | |
envelope, _ := buildLogMessage() | |
job := Job{ | |
PayloadV1: envelope, | |
PayloadV2: nil, | |
Version: 1, | |
} | |
jobQueue <- job | |
} | |
}() | |
dispatcher := NewDispatcher(jobQueue, 10) | |
dispatcher.Run("metron-throughput/zz", 10) | |
dispatcher.WaitStop() | |
dispatcher.Print(1) | |
}) | |
}) | |
func buildLogMessage() (*events.Envelope, []byte) { | |
envelope := &events.Envelope{ | |
Origin: proto.String("metron-throughput/zz"), | |
EventType: events.Envelope_LogMessage.Enum(), | |
Timestamp: proto.Int64(time.Now().UnixNano()), | |
LogMessage: &events.LogMessage{ | |
Message: []byte("some-log-message"), | |
MessageType: events.LogMessage_OUT.Enum(), | |
Timestamp: proto.Int64(time.Now().UnixNano()), | |
}, | |
} | |
data, err := proto.Marshal(envelope) | |
Expect(err).ToNot(HaveOccurred()) | |
return envelope, data | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment