1. 把tunnelid函数放到其他地方
2.在创建tunnel的时候显示每个tunnel属于哪个model 3.增加了queuecache的测试
This commit is contained in:
10
cache/queue.go
vendored
10
cache/queue.go
vendored
@@ -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
25
cache/queue_test.go
vendored
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user