const added

This commit is contained in:
insanity@loafle.com 2017-05-15 18:19:37 +09:00
parent 0afdad9d81
commit 6aeb8743ca
14 changed files with 79 additions and 77 deletions

8
messages/agent.go Normal file
View 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"
)

View 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"
)

14
messages/poller.go Normal file
View 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"
)

View File

@ -4,4 +4,3 @@ const (
QUEUE_DATA = "QUEUE_DATA"
QUEUE_EVENT = "QUEUE_EVENT"
)

6
messages/task.go Normal file
View File

@ -0,0 +1,6 @@
package messages
type AgentTask struct {
Command string
Params map[string]string
}

View File

@ -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"
)

View File

@ -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"
)

View File

@ -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"
)

View File

@ -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,40 +39,40 @@ 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)
@ -98,17 +98,16 @@ func TestMultiAddObserver(t *testing.T) {
}
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)
}