2017-04-26 06:58:38 +00:00
|
|
|
package queue
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"loafle.com/overflow/agent_api/observer"
|
2017-04-27 06:23:04 +00:00
|
|
|
"loafle.com/overflow/agent_api/observer/messages"
|
|
|
|
"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 06:23:04 +00:00
|
|
|
lq := NewQueue(messages.QUEUE_DATA, 5, senderChanel)
|
2017-04-26 06:58:38 +00:00
|
|
|
|
2017-04-27 06:23:04 +00:00
|
|
|
fmt.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")
|
|
|
|
|
|
|
|
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 {
|
|
|
|
fmt.Println("ddddd")
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < items.Len(); i++ {
|
|
|
|
d := items.Index(i)
|
|
|
|
fmt.Println(d)
|
|
|
|
}
|
2017-04-26 06:58:38 +00:00
|
|
|
}
|
|
|
|
}
|