transx/cache/queue_test.go

29 lines
466 B
Go

package cache
import (
"fmt"
"testing"
)
func GetAndPut(name string, get *BlockingQueueCache, put *BlockingQueueCache) {
r, _ := get.Get()
fmt.Printf("%s Get\n", name)
put.Put(r, 1)
fmt.Printf("%s Put\n", name)
}
func TestAsynchronousCache(t *testing.T) {
a := NewBlockingQueueCache(1)
b := NewBlockingQueueCache(1)
a.Put(make([]byte, 1), 1)
go func() {
for {
GetAndPut("A", a, b)
}
}()
for i := 0; i < 1000; i++ {
GetAndPut("B", b, a)
}
}