pools_test.go 959 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Public Domain Software
  3. *
  4. * I (Matthias Ladkau) am the author of the source code in this file.
  5. * I have placed the source code in this file in the public domain.
  6. *
  7. * For further information see: http://creativecommons.org/publicdomain/zero/1.0/
  8. */
  9. package pools
  10. import (
  11. "bytes"
  12. "testing"
  13. )
  14. func TestByteBufferPool(t *testing.T) {
  15. pool := NewByteBufferPool()
  16. buf1 := pool.Get().(*bytes.Buffer)
  17. buf2 := pool.Get()
  18. buf3 := pool.Get()
  19. if buf1 == nil || buf2 == nil || buf3 == nil {
  20. t.Error("Initialisation didn't work")
  21. return
  22. }
  23. buf1.Write(make([]byte, 10, 10))
  24. buf1.Reset()
  25. pool.Put(buf1)
  26. }
  27. func TestByteSlicePool(t *testing.T) {
  28. pool := NewByteSlicePool(5)
  29. buf1 := pool.Get().([]byte)
  30. buf2 := pool.Get()
  31. buf3 := pool.Get()
  32. if buf1 == nil || buf2 == nil || buf3 == nil {
  33. t.Error("Initialisation didn't work")
  34. return
  35. }
  36. if s := len(buf1); s != 5 {
  37. t.Error("Unexpected size:", s)
  38. return
  39. }
  40. pool.Put(buf1)
  41. }