本文整理汇总了Golang中github.com/cloudfoundry/loggregatorlib/logmessage/testhelpers.NewMessage函数的典型用法代码示例。如果您正苦于以下问题:Golang NewMessage函数的具体用法?Golang NewMessage怎么用?Golang NewMessage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewMessage函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestDumpReturnsAllRecentMessagesToMultipleDumpRequests
func TestDumpReturnsAllRecentMessagesToMultipleDumpRequests(t *testing.T) {
var bufferSize uint
bufferSize = 2
dump := NewDumpSink("myApp", bufferSize, loggertesthelper.Logger())
dump.Run()
logMessage := messagetesthelpers.NewMessage(t, "1", "appId")
dump.Channel() <- logMessage
logMessage = messagetesthelpers.NewMessage(t, "2", "appId")
dump.Channel() <- logMessage
logMessage = messagetesthelpers.NewMessage(t, "3", "appId")
dump.Channel() <- logMessage
runtime.Gosched()
logMessages := dumpAllMessages(dump, bufferSize)
assert.Equal(t, len(logMessages), 2)
assert.Equal(t, string(logMessages[0].GetLogMessage().GetMessage()), "2")
assert.Equal(t, string(logMessages[1].GetLogMessage().GetMessage()), "3")
logMessages = dumpAllMessages(dump, bufferSize)
assert.Equal(t, len(logMessages), 2)
assert.Equal(t, string(logMessages[0].GetLogMessage().GetMessage()), "2")
assert.Equal(t, string(logMessages[1].GetLogMessage().GetMessage()), "3")
}
示例2: TestThatItSends
func TestThatItSends(t *testing.T) {
receivedChan := make(chan []byte, 2)
expectedMessageString := "Some data"
message := messagetesthelpers.NewMessage(t, expectedMessageString, "myApp01")
otherMessageString := "Some more stuff"
otherMessage := messagetesthelpers.NewMessage(t, otherMessageString, "myApp01")
_, dontKeepAliveChan, _ := testhelpers.AddWSSink(t, receivedChan, SERVER_PORT, "/tail/?app=myApp01")
WaitForWebsocketRegistration()
dataReadChannel <- message
dataReadChannel <- otherMessage
select {
case <-time.After(1 * time.Second):
t.Errorf("Did not get message 1.")
case message := <-receivedChan:
messagetesthelpers.AssertProtoBufferMessageEquals(t, expectedMessageString, message)
}
select {
case <-time.After(1 * time.Second):
t.Errorf("Did not get message 2.")
case message := <-receivedChan:
messagetesthelpers.AssertProtoBufferMessageEquals(t, otherMessageString, message)
}
dontKeepAliveChan <- true
}
示例3: TestDumpWithLotsOfMessagesAndLargeBuffer
func TestDumpWithLotsOfMessagesAndLargeBuffer(t *testing.T) {
var bufferSize uint
bufferSize = 200
dump := NewDumpSink("myApp", bufferSize, loggertesthelper.Logger())
dump.Run()
for i := 0; i < 1000; i++ {
logMessage := messagetesthelpers.NewMessage(t, strconv.Itoa(i), "appId")
dump.Channel() <- logMessage
}
runtime.Gosched()
logMessages := dumpAllMessages(dump, bufferSize)
assert.Equal(t, len(logMessages), 200)
assert.Equal(t, string(logMessages[0].GetLogMessage().GetMessage()), "800")
assert.Equal(t, string(logMessages[1].GetLogMessage().GetMessage()), "801")
for i := 1000; i < 2000; i++ {
logMessage := messagetesthelpers.NewMessage(t, strconv.Itoa(i), "appId")
dump.Channel() <- logMessage
}
runtime.Gosched()
logMessages = dumpAllMessages(dump, bufferSize)
assert.Equal(t, len(logMessages), 200)
assert.Equal(t, string(logMessages[0].GetLogMessage().GetMessage()), "1800")
assert.Equal(t, string(logMessages[1].GetLogMessage().GetMessage()), "1801")
logMessages = dumpAllMessages(dump, bufferSize)
assert.Equal(t, len(logMessages), 200)
assert.Equal(t, string(logMessages[0].GetLogMessage().GetMessage()), "1800")
assert.Equal(t, string(logMessages[1].GetLogMessage().GetMessage()), "1801")
}
示例4: TestSendingToErrorChannelDoesNotBlock
func TestSendingToErrorChannelDoesNotBlock(t *testing.T) {
testMessageRouter := NewMessageRouter(1024, false, nil, loggertesthelper.Logger())
testMessageRouter.errorChannel = make(chan *logmessage.Message, 1)
go testMessageRouter.Start()
sinkChannel := make(chan *logmessage.Message, 10)
ourSink := testSink{sinkChannel, false}
testMessageRouter.sinkOpenChan <- ourSink
<-time.After(1 * time.Millisecond)
for i := 0; i < 10; i++ {
badMessage := messagetesthelpers.NewMessage(t, "error msg", "appIdWeDontCareAbout")
badMessage.GetLogMessage().DrainUrls = []string{fmt.Sprintf("<nil%d>", i)}
testMessageRouter.parsedMessageChan <- badMessage
}
goodMessage := messagetesthelpers.NewMessage(t, "error msg", "appId")
testMessageRouter.parsedMessageChan <- goodMessage
select {
case _ = <-ourSink.Channel():
case <-time.After(1000 * time.Millisecond):
t.Error("Should have received a message")
}
}
示例5: TestDumpReturnsAllRecentMessagesToMultipleDumpRequestsWithMessagesCloningInInTheMeantime
func TestDumpReturnsAllRecentMessagesToMultipleDumpRequestsWithMessagesCloningInInTheMeantime(t *testing.T) {
dump := NewDumpSink("myApp", 2, loggertesthelper.Logger(), make(chan Sink, 1), time.Second)
go dump.Run()
logMessage := messagetesthelpers.NewMessage(t, "1", "appId")
dump.Channel() <- logMessage
logMessage = messagetesthelpers.NewMessage(t, "2", "appId")
dump.Channel() <- logMessage
logMessage = messagetesthelpers.NewMessage(t, "3", "appId")
dump.Channel() <- logMessage
runtime.Gosched()
logMessages := dump.Dump()
assert.Equal(t, len(logMessages), 2)
assert.Equal(t, string(logMessages[0].GetLogMessage().GetMessage()), "2")
assert.Equal(t, string(logMessages[1].GetLogMessage().GetMessage()), "3")
logMessage = messagetesthelpers.NewMessage(t, "4", "appId")
dump.Channel() <- logMessage
runtime.Gosched()
logMessages = dump.Dump()
assert.Equal(t, len(logMessages), 2)
assert.Equal(t, string(logMessages[0].GetLogMessage().GetMessage()), "3")
assert.Equal(t, string(logMessages[1].GetLogMessage().GetMessage()), "4")
}
示例6: TestDumpsMostRecentMessagesWithSmallerOutputChan
func TestDumpsMostRecentMessagesWithSmallerOutputChan(t *testing.T) {
var bufferSize uint
bufferSize = 4
dump := NewDumpSink("myApp", bufferSize, loggertesthelper.Logger())
dump.Run()
logMessage := messagetesthelpers.NewMessage(t, "1", "appId")
dump.Channel() <- logMessage
logMessage = messagetesthelpers.NewMessage(t, "2", "appId")
dump.Channel() <- logMessage
logMessage = messagetesthelpers.NewMessage(t, "3", "appId")
dump.Channel() <- logMessage
logMessage = messagetesthelpers.NewMessage(t, "4", "appId")
dump.Channel() <- logMessage
runtime.Gosched()
receivedChan := make(chan *logmessage.Message, 2)
dump.Dump(receivedChan)
firstMessage := <-receivedChan
assert.Equal(t, string(firstMessage.GetLogMessage().GetMessage()), "3")
secondMessage := <-receivedChan
assert.Equal(t, string(secondMessage.GetLogMessage().GetMessage()), "4")
}
示例7: TestDumpWithLotsOfMessages
func TestDumpWithLotsOfMessages(t *testing.T) {
dump := NewDumpSink("myApp", 2, loggertesthelper.Logger())
for i := 0; i < 100; i++ {
logMessage := messagetesthelpers.NewMessage(t, strconv.Itoa(i), "appId")
dump.Channel() <- logMessage
}
runtime.Gosched()
logMessages := dumpAllMessages(dump)
assert.Equal(t, len(logMessages), 2)
assert.Equal(t, string(logMessages[0].GetLogMessage().GetMessage()), "98")
assert.Equal(t, string(logMessages[1].GetLogMessage().GetMessage()), "99")
for i := 100; i < 200; i++ {
logMessage := messagetesthelpers.NewMessage(t, strconv.Itoa(i), "appId")
dump.Channel() <- logMessage
}
runtime.Gosched()
logMessages = dumpAllMessages(dump)
assert.Equal(t, len(logMessages), 2)
assert.Equal(t, string(logMessages[0].GetLogMessage().GetMessage()), "198")
assert.Equal(t, string(logMessages[1].GetLogMessage().GetMessage()), "199")
logMessages = dumpAllMessages(dump)
assert.Equal(t, len(logMessages), 2)
assert.Equal(t, string(logMessages[0].GetLogMessage().GetMessage()), "198")
assert.Equal(t, string(logMessages[1].GetLogMessage().GetMessage()), "199")
}
示例8: TestStopsRetryingWhenSinkIsUnregistered
func TestStopsRetryingWhenSinkIsUnregistered(t *testing.T) {
testMessageRouter := NewMessageRouter(1024, false, []iprange.IPRange{iprange.IPRange{Start: "10.10.123.1", End: "10.10.123.1"}}, loggertesthelper.Logger())
go testMessageRouter.Start()
ourSink := testSink{make(chan *logmessage.Message, 100), true}
testMessageRouter.sinkOpenChan <- ourSink
runtime.Gosched()
go func() {
message := messagetesthelpers.NewMessage(t, "error msg", "appId")
message.GetLogMessage().DrainUrls = []string{"syslog://localhost:41223"}
testMessageRouter.parsedMessageChan <- message
newMessage := messagetesthelpers.NewMessage(t, "RemoveSyslogSink", "appId")
testMessageRouter.parsedMessageChan <- newMessage
}()
for {
readMessage := <-ourSink.Channel()
if string(readMessage.GetLogMessage().GetMessage()) == "RemoveSyslogSink" {
break
}
}
select {
case message := <-ourSink.Channel():
t.Errorf("Should not receive another message after removal; message was %v", string(message.GetLogMessage().GetMessage()))
case <-time.After(2 * time.Second):
}
}
示例9: TestDumpWithLotsOfMessagesAndLargeBuffer
func TestDumpWithLotsOfMessagesAndLargeBuffer(t *testing.T) {
dump := NewDumpSink("myApp", 200, loggertesthelper.Logger(), make(chan Sink, 1), time.Second)
go dump.Run()
for i := 0; i < 1000; i++ {
logMessage := messagetesthelpers.NewMessage(t, strconv.Itoa(i), "appId")
dump.Channel() <- logMessage
}
runtime.Gosched()
logMessages := dump.Dump()
assert.Equal(t, len(logMessages), 200)
assert.Equal(t, string(logMessages[0].GetLogMessage().GetMessage()), "800")
assert.Equal(t, string(logMessages[1].GetLogMessage().GetMessage()), "801")
for i := 1000; i < 2000; i++ {
logMessage := messagetesthelpers.NewMessage(t, strconv.Itoa(i), "appId")
dump.Channel() <- logMessage
}
runtime.Gosched()
logMessages = dump.Dump()
assert.Equal(t, len(logMessages), 200)
assert.Equal(t, string(logMessages[0].GetLogMessage().GetMessage()), "1800")
assert.Equal(t, string(logMessages[1].GetLogMessage().GetMessage()), "1801")
logMessages = dump.Dump()
assert.Equal(t, len(logMessages), 200)
assert.Equal(t, string(logMessages[0].GetLogMessage().GetMessage()), "1800")
assert.Equal(t, string(logMessages[1].GetLogMessage().GetMessage()), "1801")
}
示例10: TestDumpAlwaysReturnsTheNewestMessages
func TestDumpAlwaysReturnsTheNewestMessages(t *testing.T) {
dump := NewDumpSink("myApp", 2, loggertesthelper.Logger(), time.Second, fakeTimeProvider)
dumpRunnerDone := make(chan struct{})
inputChan := make(chan *logmessage.Message)
go func() {
dump.Run(inputChan)
close(dumpRunnerDone)
}()
logMessage := messagetesthelpers.NewMessage(t, "1", "appId")
inputChan <- logMessage
logMessage = messagetesthelpers.NewMessage(t, "2", "appId")
inputChan <- logMessage
logMessage = messagetesthelpers.NewMessage(t, "3", "appId")
inputChan <- logMessage
close(inputChan)
<-dumpRunnerDone
logMessages := dump.Dump()
assert.Equal(t, len(logMessages), 2)
assert.Equal(t, string(logMessages[0].GetLogMessage().GetMessage()), "2")
assert.Equal(t, string(logMessages[1].GetLogMessage().GetMessage()), "3")
}
示例11: TestSimpleBlacklistRule
func TestSimpleBlacklistRule(t *testing.T) {
logger := loggertesthelper.Logger()
sinkManager := NewSinkManager(1024, false, []iprange.IPRange{iprange.IPRange{Start: "10.10.123.1", End: "10.10.123.1"}}, logger)
oldActiveSyslogSinksCounter := sinkManager.Metrics.SyslogSinks
go sinkManager.Start()
incomingLogChan := make(chan []byte, 10)
testMessageRouter := NewMessageRouter(incomingLogChan, testhelpers.UnmarshallerMaker("secret"), sinkManager, 2048, logger)
go testMessageRouter.Start()
ourSink := testSink{make(chan *logmessage.Message, 100), true}
sinkManager.sinkOpenChan <- ourSink
<-time.After(1 * time.Millisecond)
message := messagetesthelpers.NewMessage(t, "error msg", "appId")
message.GetLogMessage().DrainUrls = []string{"http://10.10.123.1"}
testMessageRouter.outgoingLogChan <- message
select {
case _ = <-ourSink.Channel():
case <-time.After(100 * time.Millisecond):
t.Error("Did not receive real message")
}
select {
case _ = <-ourSink.Channel():
case <-time.After(100 * time.Millisecond):
t.Error("Did not message about blacklisted syslog drain")
}
testMessageRouter.outgoingLogChan <- message
select {
case _ = <-ourSink.Channel():
case <-time.After(100 * time.Millisecond):
t.Error("Did not receive real message")
}
select {
case _ = <-ourSink.Channel():
t.Error("Should not receive another message about the blacklisted url since we cache blacklisted urls")
case <-time.After(100 * time.Millisecond):
}
assert.Equal(t, sinkManager.Metrics.SyslogSinks, oldActiveSyslogSinksCounter)
message = messagetesthelpers.NewMessage(t, "error msg", "appId")
message.GetLogMessage().DrainUrls = []string{"http://10.10.123.2"}
testMessageRouter.outgoingLogChan <- message
waitForMessageGettingProcessed(t, ourSink, 10*time.Millisecond)
assert.Equal(t, sinkManager.Metrics.SyslogSinks, oldActiveSyslogSinksCounter+1)
}
示例12: TestSysLoggerDiesAndComesBack
func TestSysLoggerDiesAndComesBack(t *testing.T) {
sysLogger := NewSyslogWriterRecorder()
sink := NewSyslogSink("appId", "url_not_used", loggertesthelper.Logger(), sysLogger, make(chan *logmessage.Message))
sysLogger.SetUp(true)
done := make(chan bool)
go func() {
sink.Run()
done <- true
}()
msg := fmt.Sprintf("first message")
logMessage := messagetesthelpers.NewMessage(t, msg, "appId")
sink.Channel() <- logMessage
select {
case <-sysLogger.receivedChannel:
break
case <-time.After(10 * time.Millisecond):
t.Error("Should have received a message by now")
}
sysLogger.SetUp(false)
assert.Equal(t, len(sysLogger.ReceivedMessages()), 1)
for i := 0; i < 11; i++ {
msg := fmt.Sprintf("message no %v", i)
logMessage := messagetesthelpers.NewMessage(t, msg, "appId")
sink.Channel() <- logMessage
}
sysLogger.SetUp(true)
close(sink.Channel())
<-done
assert.Equal(t, len(sysLogger.ReceivedMessages()), 11)
stringOfMessages := fmt.Sprintf("%v", sysLogger.ReceivedMessages())
assert.Contains(t, stringOfMessages, "first message", "This message should have been there, since the server was up")
assert.NotContains(t, stringOfMessages, "out: message no 0", "This message should have been lost because the connection problem was detected while trying to send it.")
assert.Contains(t, stringOfMessages, "out: message no 1", "This message should have been there, since it was in the ringbuffer while the server was down")
assert.Contains(t, stringOfMessages, "out: message no 2", "This message should have been there, since it was in the ringbuffer while the server was down")
assert.Contains(t, stringOfMessages, "out: message no 3", "This message should have been there, since it was in the ringbuffer while the server was down")
assert.Contains(t, stringOfMessages, "out: message no 4", "This message should have been there, since it was in the ringbuffer while the server was down")
assert.Contains(t, stringOfMessages, "out: message no 5", "This message should have been there, since it was in the ringbuffer while the server was down")
assert.Contains(t, stringOfMessages, "out: message no 6", "This message should have been there, since it was in the ringbuffer while the server was down")
assert.Contains(t, stringOfMessages, "out: message no 7", "This message should have been there, since it was in the ringbuffer while the server was down")
assert.Contains(t, stringOfMessages, "out: message no 8", "This message should have been there, since it was in the ringbuffer while the server was down")
assert.Contains(t, stringOfMessages, "out: message no 9", "This message should have been there, since it was in the ringbuffer while the server was down")
assert.Contains(t, stringOfMessages, "out: message no 10", "This message should have been there, since it was in the ringbuffer while the server was down")
}
示例13: TestBufferDropsOldMessages
func TestBufferDropsOldMessages(t *testing.T) {
channel, buffer := setup(1)
message1 := messagetesthelpers.NewMessage(t, "message 1", "appId")
channel <- message1
message2 := messagetesthelpers.NewMessage(t, "message 2", "appId")
channel <- message2
close(channel)
buffer.waitForClose()
dump := buffer.Dump()
assert.Equal(t, 1, len(dump))
assert.Equal(t, message2, dump[0])
}
示例14: TestDumpWithLotsOfMessagesAndLargeBuffer
func TestDumpWithLotsOfMessagesAndLargeBuffer(t *testing.T) {
dump := NewDumpSink("myApp", 200, loggertesthelper.Logger(), time.Second, fakeTimeProvider)
dumpRunnerDone := make(chan struct{})
inputChan := make(chan *logmessage.Message)
go func() {
dump.Run(inputChan)
close(dumpRunnerDone)
}()
for i := 0; i < 1000; i++ {
logMessage := messagetesthelpers.NewMessage(t, strconv.Itoa(i), "appId")
inputChan <- logMessage
}
close(inputChan)
<-dumpRunnerDone
logMessages := dump.Dump()
assert.Equal(t, len(logMessages), 200)
assert.Equal(t, string(logMessages[0].GetLogMessage().GetMessage()), "800")
assert.Equal(t, string(logMessages[1].GetLogMessage().GetMessage()), "801")
dumpRunnerDone = make(chan struct{})
inputChan = make(chan *logmessage.Message)
go func() {
dump.Run(inputChan)
close(dumpRunnerDone)
}()
for i := 1000; i < 2000; i++ {
logMessage := messagetesthelpers.NewMessage(t, strconv.Itoa(i), "appId")
inputChan <- logMessage
}
close(inputChan)
<-dumpRunnerDone
logMessages = dump.Dump()
assert.Equal(t, len(logMessages), 200)
assert.Equal(t, string(logMessages[0].GetLogMessage().GetMessage()), "1800")
assert.Equal(t, string(logMessages[1].GetLogMessage().GetMessage()), "1801")
logMessages = dump.Dump()
assert.Equal(t, len(logMessages), 200)
assert.Equal(t, string(logMessages[0].GetLogMessage().GetMessage()), "1800")
assert.Equal(t, string(logMessages[1].GetLogMessage().GetMessage()), "1801")
}
示例15: TestThatItWorksLikeAChannel
func TestThatItWorksLikeAChannel(t *testing.T) {
inMessageChan := make(chan *logmessage.Message)
buffer := NewTruncatingBuffer(inMessageChan, 2, nil)
go buffer.Run()
logMessage1 := messagetesthelpers.NewMessage(t, "message 1", "appId")
inMessageChan <- logMessage1
readMessage := <-buffer.GetOutputChannel()
assert.Contains(t, string(readMessage.GetRawMessage()), "message 1")
logMessage2 := messagetesthelpers.NewMessage(t, "message 2", "appId")
inMessageChan <- logMessage2
readMessage2 := <-buffer.GetOutputChannel()
assert.Contains(t, string(readMessage2.GetRawMessage()), "message 2")
}