Beispiel #1
0
func TestIncrementalPool(t *testing.T) {

	assert := assert.New(t)
	pool := idpool.NewIncrementalPool()

	assert.Equal(uint64(1), pool.GetId(), "Id should start by 1")
	assert.Equal(uint64(2), pool.GetId(), "IdPool should give incremental ids")
	assert.Equal(uint64(3), pool.GetId(), "IdPool should give incremental ids")
	assert.Equal(uint64(4), pool.GetId(), "IdPool should give incremental ids")

}
Beispiel #2
0
package idpool_test

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

var p1 = idpool.NewIncrementalPool()
var p2 = idpool.NewReusableIdPool()

func BenchmarkIncrementalPool(b *testing.B) {
	for n := 0; n < b.N; n++ {
		i := p1.GetId()
		p1.ReleaseId(i)
	}
}

func BenchmarkReusablePool(b *testing.B) {
	for n := 0; n < b.N; n++ {
		i := p2.GetId()
		p2.ReleaseId(i)
	}
}

func TestIncrementalPool(t *testing.T) {

	assert := assert.New(t)
	pool := idpool.NewIncrementalPool()

	assert.Equal(uint64(1), pool.GetId(), "Id should start by 1")