queue_go/queue_test.go
2017-04-27 17:39:14 +09:00

60 lines
1.5 KiB
Go

package queue
import (
"loafle.com/overflow/agent_api/observer"
"loafle.com/overflow/agent_api/observer/messages"
"log"
"reflect"
"testing"
"time"
)
func TestNewQueue(t *testing.T) {
senderChanel := make(chan interface{}, 0)
lq := NewQueue(messages.QUEUE_DATA, 5, senderChanel)
log.Println(lq)
observer.Notify(messages.QUEUE_DATA, "data")
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")
observer.Notify(messages.QUEUE_DATA, "data8888")
observer.Notify(messages.QUEUE_DATA, "data9999")
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")
go GetItemTest(senderChanel)
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 {
log.Println("ddddd")
}
//log.Println(items.Len())
for i := 0; i < items.Len(); i++ {
d := items.Index(i)
log.Println(d)
}
//fmt.Println(sc)
}
}