package queue import ( "git.loafle.net/overflow/agent_api/observer" "git.loafle.net/overflow/agent_api/observer/messages" "log" "reflect" "testing" "time" ) func TestNewQueue(t *testing.T) { senderChanel := make(chan interface{}, 0) lq := NewQueue(messages.QUEUE_DATA, 3, 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") go GetItemTest(senderChanel) time.Sleep(time.Second * 3) 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") 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).Elem().Interface() dd := d.(Item) log.Printf("data: %s , periorty: %d", dd.Value, dd.Priority) } //fmt.Println(sc) } }