2024-04-14 00:16:55 +03:00
|
|
|
package pool
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2024-09-29 22:58:53 +03:00
|
|
|
func TestByte(t *testing.T) {
|
|
|
|
p := NewBytePool(1024)
|
|
|
|
b := p.Get()
|
|
|
|
copy(*b, []byte(`test`))
|
|
|
|
if bytes.Equal(*b, []byte("test")) {
|
|
|
|
t.Fatal("pool not works")
|
|
|
|
}
|
|
|
|
p.Put(b)
|
|
|
|
b = p.Get()
|
|
|
|
for i := 0; i < 1500; i++ {
|
|
|
|
*b = append(*b, []byte(`test`)...)
|
|
|
|
}
|
|
|
|
p.Put(b)
|
|
|
|
st := p.Stats()
|
|
|
|
if st.Get != 2 && st.Put != 2 && st.Mis != 1 && st.Ret != 1 {
|
|
|
|
t.Fatalf("pool stats error %#+v", st)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-14 00:16:55 +03:00
|
|
|
func TestBytes(t *testing.T) {
|
2024-09-29 22:58:53 +03:00
|
|
|
p := NewBytesPool(1024)
|
2024-04-14 00:16:55 +03:00
|
|
|
b := p.Get()
|
|
|
|
b.Write([]byte(`test`))
|
|
|
|
if b.String() != "test" {
|
|
|
|
t.Fatal("pool not works")
|
|
|
|
}
|
|
|
|
p.Put(b)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStrings(t *testing.T) {
|
2024-09-29 22:58:53 +03:00
|
|
|
p := NewStringsPool(20)
|
2024-04-14 00:16:55 +03:00
|
|
|
b := p.Get()
|
|
|
|
b.Write([]byte(`test`))
|
|
|
|
if b.String() != "test" {
|
|
|
|
t.Fatal("pool not works")
|
|
|
|
}
|
|
|
|
p.Put(b)
|
|
|
|
}
|