const added
This commit is contained in:
parent
0afdad9d81
commit
6aeb8743ca
8
messages/agent.go
Normal file
8
messages/agent.go
Normal file
|
@ -0,0 +1,8 @@
|
|||
package messages
|
||||
|
||||
const (
|
||||
AGT_STARTING = "AGT_STARTING"
|
||||
AGT_WILL_STOP = "AGENT_WILL_STOP"
|
||||
AGT_STOPPED = "AGENT_STOPPED"
|
||||
AGT_INITIALIZED = "AGT_INITIALIZED"
|
||||
)
|
|
@ -7,9 +7,9 @@ const (
|
|||
|
||||
CFG_LOADED = "CONFIG_LOADED"
|
||||
|
||||
SCF_READY = "SENSOR_CONFIG_READY"
|
||||
SCF_STOPPED = "SENSOR_CONFIG_STOPPED"
|
||||
SCF_READY = "SENSOR_CONFIG_READY"
|
||||
SCF_STOPPED = "SENSOR_CONFIG_STOPPED"
|
||||
SCF_SENSOR_ADD_DONE = "SENSOR_CONFIG_SENSOR_ADD_DONE"
|
||||
|
||||
SCF_SENSOR_UPDATE_DONE = "SENSOR_CONFIG_SENSOR_UPDATE_DONE"
|
||||
)
|
||||
)
|
|
@ -1,6 +1,6 @@
|
|||
package messages
|
||||
|
||||
const (
|
||||
CRAWLER_ADD = "CRAWLER_ADD"
|
||||
CRAWLER_ADD = "CRAWLER_ADD"
|
||||
CRAWLER_REMOVE = "CRAWLER_REMOVE"
|
||||
)
|
||||
)
|
10
messages/crawler_manager.go
Normal file
10
messages/crawler_manager.go
Normal file
|
@ -0,0 +1,10 @@
|
|||
package messages
|
||||
|
||||
const (
|
||||
CRM_READY = "CRAWLER_READY"
|
||||
CRM_STOPPED = "CRAWLER_STOPPED"
|
||||
CRM_SENSOR_ADD_DONE = "CRAWLER_SENSOR_ADD_DONE"
|
||||
CRM_SENSOR_REMOVE_DONE = "CRAWLER_SENSOR_REMOVE_DONE"
|
||||
CRM_SENSOR_UPDATE_DONE = "CRAWLER_SENSOR_UPDATE_DONE"
|
||||
CRM_UPDATE_DONE = "CRAWLER_UPDATE_DONE"
|
||||
)
|
|
@ -2,4 +2,4 @@ package messages
|
|||
|
||||
const (
|
||||
EVENT_ERROR = "EVENT_ERROR"
|
||||
)
|
||||
)
|
14
messages/poller.go
Normal file
14
messages/poller.go
Normal file
|
@ -0,0 +1,14 @@
|
|||
package messages
|
||||
|
||||
const (
|
||||
TASK_SENSOR_START = "TASK_SENSOR_START"
|
||||
TASK_SENSOR_STOP = "TASK_SENSOR_STOP"
|
||||
TASK_SENSOR_ADD = "TASK_SENSOR_ADD"
|
||||
TASK_SENSOR_REMOVE = "TASK_SENSOR_REMOVE"
|
||||
TASK_SENSOR_UPDATE = "TASK_SENSOR_UPDATE"
|
||||
TASK_CRAWLER_UPDATE = "TASK_CRAWLER_UPDATE"
|
||||
TASK_AGENT_UPDATE = "TASK_AGENT_UPDATE"
|
||||
TASK_LOG_SEND = "TASK_LOG_SEND"
|
||||
TASK_DONE = "TASK_DONE"
|
||||
TASK_POLLER_INTERVAL_UPDATE = "TASK_POLLER_INTERVAL_UPDATE"
|
||||
)
|
|
@ -1,7 +1,6 @@
|
|||
package messages
|
||||
|
||||
const (
|
||||
QUEUE_DATA = "QUEUE_DATA"
|
||||
QUEUE_DATA = "QUEUE_DATA"
|
||||
QUEUE_EVENT = "QUEUE_EVENT"
|
||||
)
|
||||
|
6
messages/task.go
Normal file
6
messages/task.go
Normal file
|
@ -0,0 +1,6 @@
|
|||
package messages
|
||||
|
||||
type AgentTask struct {
|
||||
Command string
|
||||
Params map[string]string
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package messages
|
||||
|
||||
const (
|
||||
AGT_STARTING = "AGT_STARTING"
|
||||
AGT_WILL_STOP = "AGENT_WILL_STOP"
|
||||
AGT_STOPPED = "AGENT_STOPPED"
|
||||
AGT_INITIALIZED = "AGT_INITIALIZED"
|
||||
)
|
|
@ -1,12 +0,0 @@
|
|||
package messages
|
||||
|
||||
|
||||
const (
|
||||
CRM_READY = "CRAWLER_READY"
|
||||
CRM_STOPPED = "CRAWLER_STOPPED"
|
||||
CRM_SENSOR_ADD_DONE = "CRAWLER_SENSOR_ADD_DONE"
|
||||
CRM_SENSOR_REMOVE_DONE = "CRAWLER_SENSOR_REMOVE_DONE"
|
||||
CRM_SENSOR_UPDATE_DONE = "CRAWLER_SENSOR_UPDATE_DONE"
|
||||
CRM_UPDATE_DONE = "CRAWLER_UPDATE_DONE"
|
||||
|
||||
)
|
|
@ -1,14 +0,0 @@
|
|||
package messages
|
||||
|
||||
const (
|
||||
TASK_SENSOR_START = "TASK_SENSOR_START"
|
||||
TASK_SENSOR_STOP = "TASK_SENSOR_STOP"
|
||||
TASK_SENSOR_ADD = "TASK_SENSOR_ADD"
|
||||
TASK_SENSOR_REMOVE = "TASK_SENSOR_REMOVE"
|
||||
TASK_SENSOR_UPDATE = "TASK_SENSOR_UPDATE"
|
||||
TASK_CRAWLER_UPDATE = "TASK_CRAWLER_UPDATE"
|
||||
TASK_AGENT_UPDATE = "TASK_AGENT_UPDATE"
|
||||
TASK_LOG_SEND = "TASK_LOG_SEND"
|
||||
TASK_DONE = "TASK_DONE"
|
||||
TASK_POLLER_INTERVAL_UPDATE = "TASK_POLLER_INTERVAL_UPDATE"
|
||||
)
|
|
@ -1,11 +1,11 @@
|
|||
package observer
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"loafle.com/overflow/agent_api/messages"
|
||||
"testing"
|
||||
"time"
|
||||
"loafle.com/overflow/agent_api/observer/messages"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Test struct {
|
||||
|
@ -20,7 +20,7 @@ func TestAddNotifyObserver(t *testing.T) {
|
|||
Notify("test", Test{Id: "test"})
|
||||
}()
|
||||
|
||||
ch := make(chan interface{},0)
|
||||
ch := make(chan interface{}, 0)
|
||||
Add("test", ch)
|
||||
|
||||
dd := <-ch
|
||||
|
@ -30,7 +30,7 @@ func TestAddNotifyObserver(t *testing.T) {
|
|||
|
||||
func TestRemoveObserver(t *testing.T) {
|
||||
|
||||
ch := make(chan interface{},0)
|
||||
ch := make(chan interface{}, 0)
|
||||
Add("test", ch)
|
||||
|
||||
err := Remove("test", ch)
|
||||
|
@ -39,48 +39,48 @@ func TestRemoveObserver(t *testing.T) {
|
|||
|
||||
// +build ignore
|
||||
func TestMultiAddObserver(t *testing.T) {
|
||||
ch1 := make(chan interface{},0)
|
||||
ch2 := make(chan interface{},0)
|
||||
ch3 := make(chan interface{},0)
|
||||
ch4 := make(chan interface{},0)
|
||||
ch5 := make(chan interface{},0)
|
||||
|
||||
ch1 := make(chan interface{}, 0)
|
||||
ch2 := make(chan interface{}, 0)
|
||||
ch3 := make(chan interface{}, 0)
|
||||
ch4 := make(chan interface{}, 0)
|
||||
ch5 := make(chan interface{}, 0)
|
||||
|
||||
go func() {
|
||||
d:=<-ch1
|
||||
d := <-ch1
|
||||
dd := d.(Test)
|
||||
assert.Equal(t, dd.Id,"test")
|
||||
assert.Equal(t, dd.Id, "test")
|
||||
}()
|
||||
|
||||
|
||||
go func() {
|
||||
d:=<-ch2
|
||||
d := <-ch2
|
||||
dd := d.(Test)
|
||||
assert.Equal(t, dd.Id,"test")
|
||||
assert.Equal(t, dd.Id, "test")
|
||||
}()
|
||||
|
||||
|
||||
go func() {
|
||||
d:=<-ch3
|
||||
d := <-ch3
|
||||
dd := d.(Test)
|
||||
assert.Equal(t, dd.Id,"test")
|
||||
assert.Equal(t, dd.Id, "test")
|
||||
}()
|
||||
|
||||
|
||||
go func() {
|
||||
d:=<-ch4
|
||||
d := <-ch4
|
||||
dd := d.(Test)
|
||||
assert.Equal(t, dd.Id,"test")
|
||||
assert.Equal(t, dd.Id, "test")
|
||||
}()
|
||||
|
||||
|
||||
go func() {
|
||||
d:=<-ch4
|
||||
d := <-ch4
|
||||
dd := d.(Test)
|
||||
assert.Equal(t, dd.Id,"test")
|
||||
assert.Equal(t, dd.Id, "test")
|
||||
}()
|
||||
|
||||
|
||||
Add("test", ch1)
|
||||
Add("test", ch2)
|
||||
Add("test", ch3)
|
||||
Add("test", ch4)
|
||||
Add("test", ch5)
|
||||
|
||||
|
||||
// others package notify call
|
||||
go func() {
|
||||
time.Sleep(1 * time.Second)
|
||||
|
@ -93,22 +93,21 @@ func TestMultiAddObserver(t *testing.T) {
|
|||
Remove("test", ch4)
|
||||
Remove("test", ch5)
|
||||
}()
|
||||
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
func TestStringNotify(t *testing.T) {
|
||||
ch := make(chan interface{},0)
|
||||
Add("test",ch)
|
||||
|
||||
ch := make(chan interface{}, 0)
|
||||
Add("test", ch)
|
||||
|
||||
go func() {
|
||||
data :=<-ch
|
||||
data := <-ch
|
||||
str := data.(string)
|
||||
fmt.Println(str)
|
||||
}()
|
||||
|
||||
Notify("test","testsetasetaset")
|
||||
|
||||
Notify("test", "testsetasetaset")
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user