コード例 #1
0
func Init() {
	payload = testutils.GenPayload(pSize)
	messagesToRead = (cliNum - 1) * mexNum
	allStats = new(statbucket.StatBucket)

	outMex = cliNum * mexNum
	inMex = (cliNum - 1) * mexNum * cliNum

	//HACK: for convenience and semplicity, we can calculate what will be the dimension of a message from here
	inByte = inMex * (5 + pSize)
	outByte = outMex * (5 + 1 + (cliNum * 8) + pSize)

	//Needed if the application is forced close by the user
	CatchExit()
}
コード例 #2
0
ファイル: message_test.go プロジェクト: sech90/go-message-hub
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")
}
コード例 #3
0
ファイル: message_test.go プロジェクト: sech90/go-message-hub
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) {
コード例 #4
0
	"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)

//for testing
コード例 #5
0
ファイル: general_test.go プロジェクト: sech90/go-message-hub
	"time"
)

const (
	Port = 9999
	Addr = "localhost"

	TimeoutTime       = 5 * time.Second
	ClientsNum        = 25
	PayloadBytes      = 1024 * 10
	MessagesPerCLient = 10
)

var climap = syncmap.NewSyncMap()
var server = hub.NewHub(Port)
var testBody = testutils.GenPayload(PayloadBytes)
var allCliId []uint64

func TestInit(t *testing.T) {
	go server.Run()
}

func TestIdentity(t *testing.T) {

	assert := assert.New(t)
	var wg sync.WaitGroup

	wg.Add(ClientsNum)
	for i := 0; i < ClientsNum; i++ {
		go func() {
			c := client.NewClient()