test code push
This commit is contained in:
parent
515b618aba
commit
3958a77ba3
31
queue.go
31
queue.go
|
@ -2,8 +2,8 @@ package queue
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"container/heap"
|
"container/heap"
|
||||||
"github.com/prometheus/common/log"
|
|
||||||
"loafle.com/overflow/agent_api/observer"
|
"loafle.com/overflow/agent_api/observer"
|
||||||
|
"log"
|
||||||
"time"
|
"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() {
|
func (lq *LoafleQueue) Close() {
|
||||||
if lq.eventChanel != nil {
|
if lq.eventChanel != nil {
|
||||||
observer.Remove(lq.queueType, lq.eventChanel)
|
observer.Remove(lq.queueType, lq.eventChanel)
|
||||||
|
@ -86,23 +100,18 @@ func (lq *LoafleQueue) Close() {
|
||||||
func NewLoafleQueue(eventType EventType, interval time.Duration) *LoafleQueue {
|
func NewLoafleQueue(eventType EventType, interval time.Duration) *LoafleQueue {
|
||||||
items := make([]*item, 0)
|
items := make([]*item, 0)
|
||||||
event := make(chan interface{}, 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{
|
lq := &LoafleQueue{
|
||||||
items: items,
|
items: items,
|
||||||
queueType: tempType,
|
//queueType: tempType,
|
||||||
interval: interval,
|
interval: interval,
|
||||||
eventChanel: event,
|
eventChanel: event,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lq.queueType = lq.StringType(eventType)
|
||||||
|
|
||||||
|
heap.Init(lq)
|
||||||
|
|
||||||
observer.Add(lq.queueType, lq.eventChanel)
|
observer.Add(lq.queueType, lq.eventChanel)
|
||||||
go lq.notifyEventHandler(event)
|
go lq.notifyEventHandler(event)
|
||||||
|
|
||||||
|
|
21
queue_test.go
Normal file
21
queue_test.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user