當前位置: 首頁>>代碼示例>>Golang>>正文


Golang RequestWrapper.Res方法代碼示例

本文整理匯總了Golang中github.com/eluleci/dock/messages.RequestWrapper.Res方法的典型用法代碼示例。如果您正苦於以下問題:Golang RequestWrapper.Res方法的具體用法?Golang RequestWrapper.Res怎麽用?Golang RequestWrapper.Res使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/eluleci/dock/messages.RequestWrapper的用法示例。


在下文中一共展示了RequestWrapper.Res方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestInbox

func TestInbox(t *testing.T) {

	Convey("Should call actor.handleRequest", t, func() {
		var called bool
		handleRequest = func(a *Actor, requestWrapper messages.RequestWrapper) (response messages.Message) {
			called = true
			return
		}

		var requestWrapper messages.RequestWrapper
		requestWrapper.Res = "/"
		responseChannel := make(chan messages.Message)
		requestWrapper.Listener = responseChannel

		var actor Actor
		actor.class = "someclass"
		actor.res = "/"
		actor.Inbox = make(chan messages.RequestWrapper)
		go actor.Run()
		actor.Inbox <- requestWrapper
		response := <-responseChannel

		So(response, ShouldNotBeNil)
		So(called, ShouldBeTrue)
	})

	Convey("Should forward message to a child actor", t, func() {
		parentRes := "/users"
		childRes := "/users/123"

		var calledOnParent bool
		var calledOnChild bool
		handleRequest = func(a *Actor, requestWrapper messages.RequestWrapper) (response messages.Message) {
			if strings.EqualFold(a.res, parentRes) {
				calledOnParent = true
			}
			if strings.EqualFold(a.res, childRes) {
				calledOnChild = true
			}
			return
		}

		var requestWrapper messages.RequestWrapper
		requestWrapper.Res = childRes
		responseChannel := make(chan messages.Message)
		requestWrapper.Listener = responseChannel

		CreateActor = func(res string, level int, parentInbox chan messages.RequestWrapper) (a Actor) {
			a.res = childRes
			a.level = 2
			a.Inbox = make(chan messages.RequestWrapper)
			return
		}

		var actor Actor
		actor.res = parentRes
		actor.level = 1
		actor.children = make(map[string]Actor)
		actor.Inbox = make(chan messages.RequestWrapper)
		go actor.Run()
		actor.Inbox <- requestWrapper
		response := <-responseChannel

		So(response, ShouldNotBeNil)
		So(calledOnParent, ShouldBeFalse)
		So(calledOnChild, ShouldBeTrue)
	})
}
開發者ID:eluleci,項目名稱:dock,代碼行數:68,代碼來源:actor_test.go


注:本文中的github.com/eluleci/dock/messages.RequestWrapper.Res方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。