本文整理匯總了Golang中github.com/nytlabs/streamtools/st/blocks.BlockRoutine函數的典型用法代碼示例。如果您正苦於以下問題:Golang BlockRoutine函數的具體用法?Golang BlockRoutine怎麽用?Golang BlockRoutine使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了BlockRoutine函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestPoisson
func (s *StreamSuite) TestPoisson(c *C) {
loghub.Start()
log.Println("testing Poisson")
b, ch := 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:
}
}
}
示例2: TestFromSQS
func (s *StreamSuite) TestFromSQS(c *C) {
log.Println("testing FromSQS")
sampleResponse := string(`
<CreateQueueResponse
xmlns="http://sqs.us-east-1.amazonaws.com/doc/2012-11-05/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="CreateQueueResponse">
<CreateQueueResult>
<QueueUrl>
http://sqs.us-east-1.amazonaws.com/770098461991/queue2
</QueueUrl>
</CreateQueueResult>
<ResponseMetadata>
<RequestId>cb919c0a-9bce-4afe-9b48-9bdf2412bb67</RequestId>
</ResponseMetadata>
</CreateQueueResponse>
`)
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, sampleResponse)
}))
defer ts.Close()
b, ch := newBlock("testingFromSQS", "fromsqs")
go blocks.BlockRoutine(b)
ruleMsg := map[string]interface{}{"SQSEndpoint": ts.URL, "AccessKey": "123access", "AccessSecret": "123secret", "APIVersion": "2012-11-05", "SignatureVersion": "4", "WaitTimeSeconds": "0", "MaxNumberOfMessages": "10"}
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(chan interface{})
ch.QueryChan <- &blocks.QueryMsg{RespChan: 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
}
}
}
}
示例3: 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
}
}
}
}
示例4: TestFromPost
func (s *StreamSuite) TestFromPost(c *C) {
log.Println("testing FromPost")
b, ch := 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: TestPack
func (s *StreamSuite) TestPack(c *C) {
loghub.Start()
log.Println("testing pack")
b, ch := newBlock("testing pack", "pack")
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", "EmitAfter": "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:
}
}
}
示例6: TestParseXML
func (s *StreamSuite) TestParseXML(c *C) {
log.Println("testing ParseXML")
b, ch := 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(chan interface{})
time.AfterFunc(time.Duration(1)*time.Second, func() {
ch.QueryChan <- &blocks.QueryMsg{RespChan: 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")
}
}
}
示例7: TestSet
func (s *StreamSuite) TestSet(c *C) {
loghub.Start()
log.Println("testing set")
b, ch := 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:
}
}
}
示例8: 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
}
}
}
}
示例9: 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)
}
}
}
示例10: TestSync
func (s *StreamSuite) TestSync(c *C) {
log.Println("testing Sync")
b, ch := 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())
}
}
示例11: TestGetHTTPXML
func (s *StreamSuite) TestGetHTTPXML(c *C) {
log.Println("testing GetHTTP with XML")
b, ch := 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(chan interface{})
time.AfterFunc(time.Duration(1)*time.Second, func() {
ch.QueryChan <- &blocks.QueryMsg{RespChan: 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{})
fmt.Printf("%s", message["data"])
}
}
}
示例12: 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
}
}
}
}
示例13: 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)
}
}
}
示例14: TestFromPostXML
func (s *StreamSuite) TestFromPostXML(c *C) {
log.Println("testing fromPost with XML")
b, ch := 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)
}
}
}
示例15: 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
}
}
}
}