6
0
mirror of https://git.mills.io/prologic/msgbus.git synced 2024-06-25 00:09:08 +00:00
prologic-msgbus/msgbus_test.go

79 lines
1.4 KiB
Go
Raw Normal View History

2017-06-03 15:16:17 +00:00
package msgbus
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestMessageBusLen(t *testing.T) {
mb := NewMessageBus()
assert.Equal(t, mb.Len(), 0)
}
func TestMessage(t *testing.T) {
mb := NewMessageBus()
assert.Equal(t, mb.Len(), 0)
topic := "foo"
2017-08-10 07:30:45 +00:00
expected := Message{Topic: topic, Payload: []byte("bar")}
2017-06-03 15:16:17 +00:00
mb.Put(topic, expected)
actual, ok := mb.Get(topic)
assert.True(t, ok)
assert.Equal(t, actual, expected)
}
func TestMessageGetEmpty(t *testing.T) {
mb := NewMessageBus()
assert.Equal(t, mb.Len(), 0)
topic := "foo"
msg, ok := mb.Get(topic)
assert.False(t, ok)
2017-08-10 07:30:45 +00:00
assert.Equal(t, msg, Message{})
2017-06-03 15:16:17 +00:00
}
func BenchmarkMessageBusPut(b *testing.B) {
mb := NewMessageBus()
topic := "foo"
2017-08-10 07:30:45 +00:00
msg := Message{Payload: []byte("foo")}
2017-06-03 15:16:17 +00:00
b.ResetTimer()
for i := 0; i < b.N; i++ {
mb.Put(topic, msg)
}
}
func BenchmarkMessageBusGet(b *testing.B) {
mb := NewMessageBus()
topic := "foo"
2017-08-10 07:30:45 +00:00
msg := Message{Payload: []byte("foo")}
2017-06-03 15:16:17 +00:00
for i := 0; i < b.N; i++ {
mb.Put(topic, msg)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
mb.Get(topic)
}
}
func BenchmarkMessageBusGetEmpty(b *testing.B) {
mb := NewMessageBus()
topic := "foo"
b.ResetTimer()
for i := 0; i < b.N; i++ {
mb.Get(topic)
}
}
func BenchmarkMessageBusPutGet(b *testing.B) {
mb := NewMessageBus()
topic := "foo"
2017-08-10 07:30:45 +00:00
msg := Message{Payload: []byte("foo")}
2017-06-03 15:16:17 +00:00
b.ResetTimer()
for i := 0; i < b.N; i++ {
mb.Put(topic, msg)
mb.Get(topic)
}
}