queue_go/queue_test.go

63 lines
1.6 KiB
Go
Raw Normal View History

2017-04-26 06:58:38 +00:00
package queue
import (
"loafle.com/overflow/agent_api/observer"
2017-04-27 06:23:04 +00:00
"loafle.com/overflow/agent_api/observer/messages"
2017-04-27 08:38:35 +00:00
"log"
2017-04-27 06:23:04 +00:00
"reflect"
2017-04-26 06:58:38 +00:00
"testing"
2017-04-27 06:23:04 +00:00
"time"
2017-04-26 06:58:38 +00:00
)
2017-04-26 07:04:28 +00:00
func TestNewQueue(t *testing.T) {
2017-04-27 06:23:04 +00:00
senderChanel := make(chan interface{}, 0)
2017-04-26 06:58:38 +00:00
2017-04-27 08:48:05 +00:00
lq := NewQueue(messages.QUEUE_DATA, 3, senderChanel)
2017-04-26 06:58:38 +00:00
2017-04-27 08:39:14 +00:00
log.Println(lq)
2017-04-26 06:58:38 +00:00
2017-04-27 06:23:04 +00:00
observer.Notify(messages.QUEUE_DATA, "data")
observer.Notify(messages.QUEUE_DATA, "data1111")
2017-04-27 08:38:35 +00:00
observer.Notify(messages.QUEUE_DATA, "data2222")
observer.Notify(messages.QUEUE_DATA, "data3333")
observer.Notify(messages.QUEUE_DATA, "data4444")
observer.Notify(messages.QUEUE_DATA, "data5555")
observer.Notify(messages.QUEUE_DATA, "data6666")
observer.Notify(messages.QUEUE_DATA, "data7777")
observer.Notify(messages.QUEUE_DATA, "data8888")
observer.Notify(messages.QUEUE_DATA, "data9999")
2017-04-27 08:48:05 +00:00
go GetItemTest(senderChanel)
time.Sleep(time.Second * 3)
2017-04-27 08:38:35 +00:00
observer.Notify(messages.QUEUE_DATA, "data1111")
observer.Notify(messages.QUEUE_DATA, "data2222")
observer.Notify(messages.QUEUE_DATA, "data3333")
observer.Notify(messages.QUEUE_DATA, "data4444")
observer.Notify(messages.QUEUE_DATA, "data5555")
observer.Notify(messages.QUEUE_DATA, "data6666")
observer.Notify(messages.QUEUE_DATA, "data7777")
2017-04-27 06:23:04 +00:00
time.Sleep(time.Second * 10)
lq.Close()
close(senderChanel)
}
func GetItemTest(senderChanel chan interface{}) {
for sc := range senderChanel {
items := reflect.ValueOf(sc)
if items.Kind() != reflect.Slice {
2017-04-27 08:39:14 +00:00
log.Println("ddddd")
2017-04-27 06:23:04 +00:00
}
2017-04-27 08:38:35 +00:00
//log.Println(items.Len())
2017-04-27 06:23:04 +00:00
for i := 0; i < items.Len(); i++ {
d := items.Index(i)
2017-04-27 08:38:35 +00:00
log.Println(d)
2017-04-27 06:23:04 +00:00
}
2017-04-27 08:38:35 +00:00
//fmt.Println(sc)
2017-04-26 06:58:38 +00:00
}
}