Example #1
0
func TestRequestConversion(t *testing.T) {

	assert := assert.New(t)

	m1 := message.NewRequest(message.Identity)
	m2 := message.NewRequest(message.List)
	m3 := message.NewRelayRequest(testList, testBody)
	m4 := message.NewRelayRequest(testutils.GenList(message.MAX_RECEIVERS+1), testBody)
	m5 := message.NewRelayRequest(testList, testutils.GenPayload(message.MAX_PAYLOAD+1))

	assert.Nil(m4, "Messages with too many receivers not allowed")
	assert.Nil(m5, "Messages with payload too big not allowed")

	b1 := m1.ToByteArray()
	b2 := m2.ToByteArray()
	b3 := m3.ToByteArray()

	c1 := new(message.Request)
	c2 := new(message.Request)
	c3 := new(message.Request)
	c4 := new(message.Request)

	e1 := c1.FromByteArray(b1)
	e2 := c2.FromByteArray(b2)
	e3 := c3.FromByteArray(b3)
	e4 := c4.FromByteArray(nil)
	e5 := c4.FromByteArray(make([]byte, 0))

	assert.Nil(e1, "No error in conversion (1)")
	assert.Nil(e2, "No error in conversion (2)")
	assert.Nil(e3, "No error in conversion (3)")
	assert.NotNil(e4, "Conversion from nil throws an error (4)")
	assert.NotNil(e5, "Conversion from empty throws an error (4)")

	assert.Nil(testutils.CompareRequests(m1, c1), "Identity request conversion wrong")
	assert.Nil(testutils.CompareRequests(m2, c2), "List request conversion wrong")
	assert.Nil(testutils.CompareRequests(m3, c3), "Relay request conversion wrong")
}
Example #2
0
package message_test

import (
	"github.com/sech90/go-message-hub/message"
	"github.com/sech90/go-message-hub/testutils"
	"github.com/stretchr/testify/assert"
	"testing"
)

var testId = uint64(12345)
var testNum = uint32(12345)
var testList = testutils.GenList(255)
var testBody = testutils.GenPayload(1024 * 1000)
var testListByte = message.Uint64ArrayToByteArray(testList)

var tAns = new(message.Answer)
var tAnsList = message.NewAnswerList(testList)
var tAnsBody = message.NewAnswerRelay(testBody)
var tAnsListBytes = tAnsList.ToByteArray()
var tAnsBodyBytes = tAnsBody.ToByteArray()

var tReq = new(message.Request)
var tReqList = message.NewRequest(message.List)
var tReqBody = message.NewRelayRequest(testList, testBody)
var tReqListBytes = tReqList.ToByteArray()
var tReqBodyBytes = tReqBody.ToByteArray()

var mockRW = testutils.NewMockRW(nil, true)

/* Benchmark List Conversions */
func BenchmarkByteArrayToUint64Array(b *testing.B) {
Example #3
0
	"testing"
	"time"
)

const (
	addr = "localhost"
	port = 9999

	ListLength    = 255
	delayTime     = time.Millisecond * 0
	PayloadLength = 1024 * 1000
	SizeTestList  = 1
)

var testId = uint64(12345)
var testList = testutils.GenList(ListLength)
var testBody = testutils.GenPayload(PayloadLength)

var tAnsId = message.NewAnswerIdentity(testId)
var tAnsList = message.NewAnswerList(testList)
var tAnsBody = message.NewAnswerRelay(testBody)
var emptyAns = new(message.Answer)

var tReqId = message.NewRequest(message.Identity)
var tReqList = message.NewRequest(message.List)
var tReqBody = message.NewRelayRequest(testList, testBody)
var emptyReq = new(message.Request)

var listener net.Listener
var newConn = make(chan net.Conn)