-
Notifications
You must be signed in to change notification settings - Fork 131
/
buffer_pool_test.go
43 lines (33 loc) · 1.04 KB
/
buffer_pool_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package statsd
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestBufferPoolSize(t *testing.T) {
bufferPool := newBufferPool(10, 1024, 20)
assert.Equal(t, 10, cap(bufferPool.pool))
assert.Equal(t, 10, len(bufferPool.pool))
}
func TestBufferPoolBufferCreation(t *testing.T) {
bufferPool := newBufferPool(10, 1024, 20)
buffer := bufferPool.borrowBuffer()
assert.Equal(t, 1024, buffer.maxSize)
assert.Equal(t, 20, buffer.maxElements)
}
func TestBufferPoolEmpty(t *testing.T) {
bufferPool := newBufferPool(1, 1024, 20)
bufferPool.borrowBuffer()
assert.Equal(t, 0, len(bufferPool.pool))
buffer := bufferPool.borrowBuffer()
assert.NotNil(t, buffer.bytes())
}
func TestBufferReturn(t *testing.T) {
bufferPool := newBufferPool(1, 1024, 20)
buffer := bufferPool.borrowBuffer()
buffer.writeCount("", nil, "", 1, nil, 1, noTimestamp)
assert.Equal(t, 0, len(bufferPool.pool))
bufferPool.returnBuffer(buffer)
assert.Equal(t, 1, len(bufferPool.pool))
buffer = bufferPool.borrowBuffer()
assert.Equal(t, 0, len(buffer.bytes()))
}