1package statsd 2 3import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7) 8 9func TestBufferPoolSize(t *testing.T) { 10 bufferPool := newBufferPool(10, 1024, 20) 11 12 assert.Equal(t, 10, cap(bufferPool.pool)) 13 assert.Equal(t, 10, len(bufferPool.pool)) 14} 15 16func TestBufferPoolBufferCreation(t *testing.T) { 17 bufferPool := newBufferPool(10, 1024, 20) 18 buffer := bufferPool.borrowBuffer() 19 20 assert.Equal(t, 1024, buffer.maxSize) 21 assert.Equal(t, 20, buffer.maxElements) 22} 23 24func TestBufferPoolEmpty(t *testing.T) { 25 bufferPool := newBufferPool(1, 1024, 20) 26 bufferPool.borrowBuffer() 27 28 assert.Equal(t, 0, len(bufferPool.pool)) 29 buffer := bufferPool.borrowBuffer() 30 assert.NotNil(t, buffer.bytes()) 31} 32 33func TestBufferReturn(t *testing.T) { 34 bufferPool := newBufferPool(1, 1024, 20) 35 buffer := bufferPool.borrowBuffer() 36 buffer.writeCount("", nil, "", 1, nil, 1) 37 38 assert.Equal(t, 0, len(bufferPool.pool)) 39 bufferPool.returnBuffer(buffer) 40 assert.Equal(t, 1, len(bufferPool.pool)) 41 buffer = bufferPool.borrowBuffer() 42 assert.Equal(t, 0, len(buffer.bytes())) 43} 44