1. 把tunnelid函数放到其他地方

2.在创建tunnel的时候显示每个tunnel属于哪个model
3.增加了queuecache的测试
This commit is contained in:
dmy@lab
2016-01-11 00:00:30 +08:00
parent 421c18687e
commit b284b401dc
6 changed files with 90 additions and 48 deletions

10
cache/queue.go vendored
View File

@@ -29,11 +29,11 @@ func (this *UnblockingQueueCache) Put(bits []byte, l int) {
func (this *UnblockingQueueCache) Get() ([]byte, int) {
var t *Cache
select {
case t = <-this.queue:
default:
return make([]byte, 1024*4), 1024 * 4
}
// select {
t = <-this.queue
// default:
// return make([]byte, 1024*4), 1024 * 4
// }
return t.cache, t.l
}

25
cache/queue_test.go vendored Normal file
View File

@@ -0,0 +1,25 @@
package cache
import(
"testing"
"fmt"
)
func GetAndPut(name string,get *BlockingQueueCache,put *BlockingQueueCache){
for{
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 GetAndPut("A",a,b)
GetAndPut("B",b,a)
}