本文整理匯總了Golang中github.com/nytlabs/streamtools/test_utils.NewBlock函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewBlock函數的具體用法?Golang NewBlock怎麽用?Golang NewBlock使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewBlock函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestFilter
func (s *FilterSuite) TestFilter(c *C) {
log.Println("testing Filter")
b, ch := test_utils.NewBlock("testingFilter", "filter")
go blocks.BlockRoutine(b)
ruleMsg := map[string]interface{}{"Filter": ".device == 'iPhone'"}
toRule := &blocks.Msg{Msg: ruleMsg, Route: "rule"}
ch.InChan <- toRule
outChan := make(chan *blocks.Msg)
ch.AddChan <- &blocks.AddChanMsg{Route: "1", Channel: outChan}
queryOutChan := make(blocks.MsgChan)
ch.QueryChan <- &blocks.QueryMsg{MsgChan: queryOutChan, Route: "rule"}
time.AfterFunc(time.Duration(5)*time.Second, func() {
ch.QuitChan <- true
})
for {
select {
case messageI := <-queryOutChan:
c.Assert(messageI, DeepEquals, ruleMsg)
case message := <-outChan:
log.Println(message)
case err := <-ch.ErrChan:
if err != nil {
c.Errorf(err.Error())
} else {
return
}
}
}
}
示例2: TestMovingAverage
func (s *MovingAverageSuite) TestMovingAverage(c *C) {
loghub.Start()
log.Println("testing moving average")
b, ch := test_utils.NewBlock("testing movingaverave", "movingaverage")
go blocks.BlockRoutine(b)
outChan := make(chan *blocks.Msg)
ch.AddChan <- &blocks.AddChanMsg{
Route: "out",
Channel: outChan,
}
time.AfterFunc(time.Duration(5)*time.Second, func() {
ch.QuitChan <- true
})
ruleMsg := map[string]interface{}{"Path": ".a", "Window": "4s"}
rule := &blocks.Msg{Msg: ruleMsg, Route: "rule"}
ch.InChan <- rule
/*
m := map[string]string{"b": "test"}
arr := []interface{}{m}
inMsg := map[string]interface{}{"a": arr}
ch.InChan <- &blocks.Msg{Msg: inMsg, Route: "in"}
*/
for {
select {
case err := <-ch.ErrChan:
if err != nil {
c.Errorf(err.Error())
} else {
return
}
case <-outChan:
}
}
}
示例3: TestParseXML
func (s *ParseXMLSuite) TestParseXML(c *C) {
log.Println("testing ParseXML")
b, ch := test_utils.NewBlock("testingParseXML", "parsexml")
go blocks.BlockRoutine(b)
outChan := make(chan *blocks.Msg)
ch.AddChan <- &blocks.AddChanMsg{
Route: "out",
Channel: outChan,
}
// where to find the xml in input
ruleMsg := map[string]interface{}{"Path": ".data"}
toRule := &blocks.Msg{Msg: ruleMsg, Route: "rule"}
ch.InChan <- toRule
queryOutChan := make(blocks.MsgChan)
time.AfterFunc(time.Duration(1)*time.Second, func() {
ch.QueryChan <- &blocks.QueryMsg{MsgChan: queryOutChan, Route: "rule"}
})
var xmldata = string(`
<?xml version="1.0" encoding="utf-8"?>
<OdfBody DocumentType="DT_GM" Date="20130131" Time="140807885" LogicalDate="20130131" Venue="ACV" Language="ENG" FeedFlag="P" DocumentCode="AS0ACV000" Version="3" Serial="1">
<Competition Code="OG2014">
<Config SDelay="60" />
</Competition>
</OdfBody>
`)
time.AfterFunc(time.Duration(2)*time.Second, func() {
xmlMsg := map[string]interface{}{"data": xmldata}
postData := &blocks.Msg{Msg: xmlMsg, Route: "in"}
ch.InChan <- postData
})
time.AfterFunc(time.Duration(5)*time.Second, func() {
ch.QuitChan <- true
})
for {
select {
case err := <-ch.ErrChan:
if err != nil {
c.Errorf(err.Error())
} else {
return
}
case messageI := <-queryOutChan:
if !reflect.DeepEqual(messageI, ruleMsg) {
log.Println("Rule mismatch:", messageI, ruleMsg)
c.Fail()
}
case messageI := <-outChan:
message := messageI.Msg.(map[string]interface{})
odfbody := message["OdfBody"].(map[string]interface{})
competition := odfbody["Competition"].(map[string]interface{})
c.Assert(odfbody["DocumentType"], Equals, "DT_GM")
c.Assert(competition["Code"], Equals, "OG2014")
}
}
}
示例4: TestFromPost
func (s *FromPostSuite) TestFromPost(c *C) {
log.Println("testing FromPost")
b, ch := test_utils.NewBlock("testingPost", "frompost")
go blocks.BlockRoutine(b)
outChan := make(chan *blocks.Msg)
ch.AddChan <- &blocks.AddChanMsg{
Route: "out",
Channel: outChan,
}
inputMsg := map[string]interface{}{"Foo": "BAR"}
inputBlock := &blocks.Msg{Msg: inputMsg, Route: "in"}
ch.InChan <- inputBlock
time.AfterFunc(time.Duration(5)*time.Second, func() {
ch.QuitChan <- true
})
for {
select {
case err := <-ch.ErrChan:
if err != nil {
c.Errorf(err.Error())
} else {
return
}
case <-outChan:
}
}
}
示例5: TestSet
func (s *SetSuite) TestSet(c *C) {
loghub.Start()
log.Println("testing set")
b, ch := test_utils.NewBlock("testing set", "set")
go blocks.BlockRoutine(b)
outChan := make(chan *blocks.Msg)
ch.AddChan <- &blocks.AddChanMsg{
Route: "out",
Channel: outChan,
}
ruleMsg := map[string]interface{}{"Path": ".a"}
rule := &blocks.Msg{Msg: ruleMsg, Route: "rule"}
ch.InChan <- rule
time.AfterFunc(time.Duration(5)*time.Second, func() {
ch.QuitChan <- true
})
for {
select {
case err := <-ch.ErrChan:
if err != nil {
c.Errorf(err.Error())
} else {
return
}
case <-outChan:
}
}
}
示例6: TestPoisson
func (s *PoissonSuite) TestPoisson(c *C) {
loghub.Start()
log.Println("testing Poisson")
b, ch := test_utils.NewBlock("testingPoisson", "poisson")
go blocks.BlockRoutine(b)
outChan := make(chan *blocks.Msg)
ch.AddChan <- &blocks.AddChanMsg{
Route: "out",
Channel: outChan,
}
time.AfterFunc(time.Duration(5)*time.Second, func() {
ch.QuitChan <- true
})
for {
select {
case err := <-ch.ErrChan:
if err != nil {
c.Errorf(err.Error())
} else {
return
}
case <-outChan:
}
}
}
示例7: TestDeDupe
func (s *DeDupeSuite) TestDeDupe(c *C) {
loghub.Start()
log.Println("testing dedupe")
b, ch := test_utils.NewBlock("testing dedupe", "dedupe")
emittedValues := make(map[string]bool)
go blocks.BlockRoutine(b)
outChan := make(chan *blocks.Msg)
ch.AddChan <- &blocks.AddChanMsg{
Route: "out",
Channel: outChan,
}
ruleMsg := map[string]interface{}{"Path": ".a"}
rule := &blocks.Msg{Msg: ruleMsg, Route: "rule"}
ch.InChan <- rule
var sampleInput = map[string]interface{}{
"a": "foobar",
}
time.AfterFunc(time.Duration(2)*time.Second, func() {
postData := &blocks.Msg{Msg: sampleInput, Route: "in"}
ch.InChan <- postData
})
time.AfterFunc(time.Duration(1)*time.Second, func() {
postData := &blocks.Msg{Msg: sampleInput, Route: "in"}
ch.InChan <- postData
})
time.AfterFunc(time.Duration(1)*time.Second, func() {
postData := &blocks.Msg{Msg: map[string]interface{}{"a": "baz"}, Route: "in"}
ch.InChan <- postData
})
time.AfterFunc(time.Duration(5)*time.Second, func() {
ch.QuitChan <- true
})
for {
select {
case err := <-ch.ErrChan:
if err != nil {
c.Errorf(err.Error())
} else {
return
}
case messageI := <-outChan:
message := messageI.Msg.(map[string]interface{})
value := message["a"].(string)
_, ok := emittedValues[value]
if ok {
c.Errorf("block emitted a dupe message", value)
} else {
emittedValues[value] = true
}
}
}
}
示例8: TestGetHTTPXML
func (s *GetHTTPSuite) TestGetHTTPXML(c *C) {
log.Println("testing GetHTTP with XML")
b, ch := test_utils.NewBlock("testingGetHTTPXML", "gethttp")
go blocks.BlockRoutine(b)
outChan := make(chan *blocks.Msg)
ch.AddChan <- &blocks.AddChanMsg{
Route: "out",
Channel: outChan,
}
ruleMsg := map[string]interface{}{"Path": ".url"}
toRule := &blocks.Msg{Msg: ruleMsg, Route: "rule"}
ch.InChan <- toRule
queryOutChan := make(blocks.MsgChan)
time.AfterFunc(time.Duration(1)*time.Second, func() {
ch.QueryChan <- &blocks.QueryMsg{MsgChan: queryOutChan, Route: "rule"}
})
time.AfterFunc(time.Duration(2)*time.Second, func() {
xmlMsg := map[string]interface{}{"url": "https://raw.github.com/nytlabs/streamtools/master/examples/odf.xml"}
postData := &blocks.Msg{Msg: xmlMsg, Route: "in"}
ch.InChan <- postData
})
time.AfterFunc(time.Duration(5)*time.Second, func() {
ch.QuitChan <- true
})
for {
select {
case err := <-ch.ErrChan:
if err != nil {
c.Errorf(err.Error())
} else {
return
}
case messageI := <-queryOutChan:
if !reflect.DeepEqual(messageI, ruleMsg) {
log.Println("Rule mismatch:", messageI, ruleMsg)
c.Fail()
}
case messageI := <-outChan:
message := messageI.Msg.(map[string]interface{})
messageData := message["data"].(string)
var xmldata = string(`<?xml version="1.0" encoding="utf-8"?>
<OdfBody DocumentType="DT_GM" Date="20130131" Time="140807885" LogicalDate="20130131" Venue="ACV" Language="ENG" FeedFlag="P" DocumentCode="AS0ACV000" Version="3" Serial="1">
<Competition Code="OG2014">
<Config SDelay="60" />
</Competition>
</OdfBody>
`)
c.Assert(messageData, Equals, xmldata)
}
}
}
示例9: TestSync
func (s *SyncSuite) TestSync(c *C) {
loghub.Start()
log.Println("testing Sync")
b, ch := test_utils.NewBlock("testingSync", "sync")
go blocks.BlockRoutine(b)
time.AfterFunc(time.Duration(5)*time.Second, func() {
ch.QuitChan <- true
})
err := <-ch.ErrChan
if err != nil {
c.Errorf(err.Error())
}
}
示例10: TestRedisSMEMBERS
func (s *RedisSuite) TestRedisSMEMBERS(c *C) {
loghub.Start()
log.Println("testing Redis: SMEMBERS")
b, ch := test_utils.NewBlock("testingRedisSMEM", "redis")
go blocks.BlockRoutine(b)
m := []string{"'foobar'"}
ruleMsg := map[string]interface{}{"Server": "localhost:6379", "Password": "", "Command": "SMEMBERS", "Arguments": m}
toRule := &blocks.Msg{Msg: ruleMsg, Route: "rule"}
ch.InChan <- toRule
outChan := make(chan *blocks.Msg)
ch.AddChan <- &blocks.AddChanMsg{Route: "1", Channel: outChan}
ch.InChan <- &blocks.Msg{Msg: map[string]interface{}{"tick": "123"}, Route: "in"}
queryOutChan := make(blocks.MsgChan)
ch.QueryChan <- &blocks.QueryMsg{MsgChan: queryOutChan, Route: "rule"}
time.AfterFunc(time.Duration(5)*time.Second, func() {
ch.QuitChan <- true
})
for {
select {
case messageI := <-queryOutChan:
if !reflect.DeepEqual(messageI, ruleMsg) {
log.Println("Rule mismatch:", messageI, ruleMsg)
c.Fail()
}
case messageI := <-outChan:
message := messageI.Msg.(map[string]interface{})
expectedValue := []interface{}{"baz"}
c.Assert(message["response"], DeepEquals, expectedValue)
case err := <-ch.ErrChan:
if err != nil {
c.Errorf(err.Error())
} else {
return
}
}
}
}
示例11: TestFromPostXML
func (s *FromPostSuite) TestFromPostXML(c *C) {
log.Println("testing fromPost with XML")
b, ch := test_utils.NewBlock("testingFromPostXML", "frompost")
go blocks.BlockRoutine(b)
outChan := make(chan *blocks.Msg)
ch.AddChan <- &blocks.AddChanMsg{
Route: "out",
Channel: outChan,
}
var xmlstring = string(`
<?xml version="1.0" encoding="utf-8"?>
<OdfBody DocumentType="DT_GM" Date="20130131" Time="140807885" LogicalDate="20130131" Venue="ACV" Language="ENG" FeedFlag="P" DocumentCode="AS0ACV000" Version="3" Serial="1">
<Competition Code="OG2014">
<Config SDelay="60" />
</Competition>
</OdfBody>
`)
var xmldata = map[string]interface{}{
"data": xmlstring,
}
time.AfterFunc(time.Duration(2)*time.Second, func() {
postData := &blocks.Msg{Msg: xmldata, Route: "in"}
ch.InChan <- postData
})
time.AfterFunc(time.Duration(5)*time.Second, func() {
ch.QuitChan <- true
})
for {
select {
case err := <-ch.ErrChan:
if err != nil {
c.Errorf(err.Error())
} else {
return
}
case messageI := <-outChan:
message := messageI.Msg.(map[string]interface{})
messageXML := message["data"].(string)
c.Assert(messageXML, Equals, xmlstring)
}
}
}
示例12: TestGetHTTP
func (s *GetHTTPSuite) TestGetHTTP(c *C) {
log.Println("testing GetHTTP")
b, ch := test_utils.NewBlock("testingGetHTTP", "gethttp")
go blocks.BlockRoutine(b)
outChan := make(chan *blocks.Msg)
ch.AddChan <- &blocks.AddChanMsg{
Route: "out",
Channel: outChan,
}
ruleMsg := map[string]interface{}{"Path": ".url"}
toRule := &blocks.Msg{Msg: ruleMsg, Route: "rule"}
ch.InChan <- toRule
queryOutChan := make(blocks.MsgChan)
time.AfterFunc(time.Duration(1)*time.Second, func() {
ch.QueryChan <- &blocks.QueryMsg{MsgChan: queryOutChan, Route: "rule"}
})
time.AfterFunc(time.Duration(2)*time.Second, func() {
nsqMsg := map[string]interface{}{"url": "https://raw.github.com/nytlabs/streamtools/master/examples/citibike.json"}
postData := &blocks.Msg{Msg: nsqMsg, Route: "in"}
ch.InChan <- postData
})
time.AfterFunc(time.Duration(5)*time.Second, func() {
ch.QuitChan <- true
})
for {
select {
case err := <-ch.ErrChan:
if err != nil {
c.Errorf(err.Error())
} else {
return
}
case messageI := <-queryOutChan:
if !reflect.DeepEqual(messageI, ruleMsg) {
log.Println("Rule mismatch:", messageI, ruleMsg)
c.Fail()
}
case msg := <-outChan:
log.Println(msg)
}
}
}
示例13: TestToNSQ
func (s *NSQSuite) TestToNSQ(c *C) {
log.Println("testing toNSQ")
toB, toC := test_utils.NewBlock("testingToNSQ", "tonsq")
go blocks.BlockRoutine(toB)
ruleMsg := map[string]interface{}{"Topic": "librarytest", "NsqdTCPAddrs": "127.0.0.1:4150"}
toRule := &blocks.Msg{Msg: ruleMsg, Route: "rule"}
toC.InChan <- toRule
toQueryChan := make(blocks.MsgChan)
time.AfterFunc(time.Duration(1)*time.Second, func() {
toC.QueryChan <- &blocks.QueryMsg{MsgChan: toQueryChan, Route: "rule"}
})
outChan := make(chan *blocks.Msg)
toC.AddChan <- &blocks.AddChanMsg{Route: "1", Channel: outChan}
time.AfterFunc(time.Duration(2)*time.Second, func() {
nsqMsg := map[string]interface{}{"Foo": "Bar"}
postData := &blocks.Msg{Msg: nsqMsg, Route: "in"}
toC.InChan <- postData
})
time.AfterFunc(time.Duration(5)*time.Second, func() {
toC.QuitChan <- true
})
for {
select {
case messageI := <-toQueryChan:
c.Assert(messageI, DeepEquals, ruleMsg)
case message := <-outChan:
log.Println("printing message from outChan:", message)
case err := <-toC.ErrChan:
if err != nil {
c.Errorf(err.Error())
} else {
return
}
}
}
}
示例14: TestMask
func (s *MaskSuite) TestMask(c *C) {
log.Println("testing Mask")
b, ch := test_utils.NewBlock("testingMask", "mask")
go blocks.BlockRoutine(b)
ruleMsg := map[string]interface{}{
"Mask": map[string]interface{}{
".foo": "{}",
},
}
toRule := &blocks.Msg{Msg: ruleMsg, Route: "rule"}
ch.InChan <- toRule
outChan := make(chan *blocks.Msg)
ch.AddChan <- &blocks.AddChanMsg{Route: "1", Channel: outChan}
queryOutChan := make(blocks.MsgChan)
ch.QueryChan <- &blocks.QueryMsg{MsgChan: queryOutChan, Route: "rule"}
time.AfterFunc(time.Duration(5)*time.Second, func() {
ch.QuitChan <- true
})
for {
select {
case messageI := <-queryOutChan:
if !reflect.DeepEqual(messageI, ruleMsg) {
log.Println("Rule mismatch:", messageI, ruleMsg)
c.Fail()
}
case message := <-outChan:
log.Println(message)
case err := <-ch.ErrChan:
if err != nil {
c.Errorf(err.Error())
} else {
return
}
}
}
}
示例15: TestToFile
func (s *ToFileSuite) TestToFile(c *C) {
loghub.Start()
log.Println("testing toFile")
b, ch := test_utils.NewBlock("testingToFile", "tofile")
go blocks.BlockRoutine(b)
ruleMsg := map[string]interface{}{"Filename": "foobar.log"}
toRule := &blocks.Msg{Msg: ruleMsg, Route: "rule"}
ch.InChan <- toRule
outChan := make(chan *blocks.Msg)
ch.AddChan <- &blocks.AddChanMsg{Route: "1", Channel: outChan}
queryOutChan := make(blocks.MsgChan)
ch.QueryChan <- &blocks.QueryMsg{MsgChan: queryOutChan, Route: "rule"}
time.AfterFunc(time.Duration(5)*time.Second, func() {
err := os.Remove("foobar.log")
if err != nil {
c.Errorf(err.Error())
}
ch.QuitChan <- true
})
for {
select {
case messageI := <-queryOutChan:
if !reflect.DeepEqual(messageI, ruleMsg) {
c.Fail()
}
case message := <-outChan:
log.Println(message)
case err := <-ch.ErrChan:
if err != nil {
c.Errorf(err.Error())
} else {
return
}
}
}
}