test code push

This commit is contained in:
geek 2017-04-26 15:58:38 +09:00
parent 515b618aba
commit 3958a77ba3
2 changed files with 42 additions and 12 deletions

View File

@ -2,8 +2,8 @@ package queue
import (
"container/heap"
"github.com/prometheus/common/log"
"loafle.com/overflow/agent_api/observer"
"log"
"time"
)
@ -78,6 +78,20 @@ func (lq *LoafleQueue) notifyEventHandler(c chan interface{}) {
}
}
func (lq *LoafleQueue) StringType(tp EventType) string {
var tempType string
if tp == DATA_TYPE {
tempType = "DATA_TYPE"
} else if tp == EVENT_TYPE {
tempType = "EVENT_TYPE"
} else {
log.Fatal("Event Type Error")
}
return tempType
}
func (lq *LoafleQueue) Close() {
if lq.eventChanel != nil {
observer.Remove(lq.queueType, lq.eventChanel)
@ -86,23 +100,18 @@ func (lq *LoafleQueue) Close() {
func NewLoafleQueue(eventType EventType, interval time.Duration) *LoafleQueue {
items := make([]*item, 0)
event := make(chan interface{}, 0)
var tempType string
if eventType == DATA_TYPE {
tempType = "DATA_TYPE"
} else if eventType == EVENT_TYPE {
tempType = "EVENT_TYPE"
} else {
log.Fatal("Event Type Error")
}
lq := &LoafleQueue{
items: items,
queueType: tempType,
//queueType: tempType,
interval: interval,
eventChanel: event,
}
lq.queueType = lq.StringType(eventType)
heap.Init(lq)
observer.Add(lq.queueType, lq.eventChanel)
go lq.notifyEventHandler(event)

21
queue_test.go Normal file
View File

@ -0,0 +1,21 @@
package queue
import (
"fmt"
"loafle.com/overflow/agent_api/observer"
"testing"
)
func TestNewLoafleQueue(t *testing.T) {
lq := NewLoafleQueue(EVENT_TYPE, 5)
typeEvent := lq.StringType(EVENT_TYPE)
observer.Notify(typeEvent, "data")
re := lq.GetItems()
for it, val := range re {
fmt.Println(val)
fmt.Println(it)
}
}