本文整理匯總了Golang中bosh/mbus.Request類的典型用法代碼示例。如果您正苦於以下問題:Golang Request類的具體用法?Golang Request怎麽用?Golang Request使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Request類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: assertRequestIsProcessedSynchronously
func assertRequestIsProcessedSynchronously(t *testing.T, req boshmbus.Request) {
settings, handler, platform, taskService, actionFactory := getAgentDependencies()
// when action is successful
actionFactory.CreateAction = &fakeaction.TestAction{
RunValue: "some value",
}
agent := New(settings, handler, platform, taskService, actionFactory)
err := agent.Run()
assert.NoError(t, err)
assert.True(t, handler.ReceivedRun)
resp := handler.Func(req)
assert.Equal(t, req.Method, actionFactory.CreateMethod)
assert.Equal(t, req.GetPayload(), actionFactory.CreateAction.RunPayload)
assert.Equal(t, boshmbus.NewValueResponse("some value"), resp)
// when action returns an error
actionFactory.CreateAction = &fakeaction.TestAction{
RunErr: errors.New("some error"),
}
agent = New(settings, handler, platform, taskService, actionFactory)
agent.Run()
resp = handler.Func(req)
boshassert.MatchesJsonString(t, resp, `{"exception":{"message":"some error"}}`)
}
示例2: Dispatch
func (dispatcher concreteActionDispatcher) Dispatch(req boshmbus.Request) (resp boshmbus.Response) {
action, err := dispatcher.actionFactory.Create(req.Method)
switch {
case err != nil:
resp = boshmbus.NewExceptionResponse("unknown message %s", req.Method)
dispatcher.logger.Error("Action Dispatcher", "Unknown action %s", req.Method)
case action.IsAsynchronous():
task := dispatcher.taskService.StartTask(func() (value interface{}, err error) {
value, err = dispatcher.actionRunner.Run(action, req.GetPayload())
return
})
resp = boshmbus.NewValueResponse(boshtask.TaskStateValue{
AgentTaskId: task.Id,
State: task.State,
})
default:
value, err := dispatcher.actionRunner.Run(action, req.GetPayload())
if err != nil {
err = bosherr.WrapError(err, "Action Failed %s", req.Method)
resp = boshmbus.NewExceptionResponse(err.Error())
dispatcher.logger.Error("Action Dispatcher", err.Error())
return
}
resp = boshmbus.NewValueResponse(value)
}
return
}
示例3: handleGetTask
func (a agent) handleGetTask(req boshmbus.Request) (resp boshmbus.Response) {
taskId, err := parseTaskId(req.GetPayload())
if err != nil {
resp.Exception = fmt.Sprintf("Error finding task, %s", err.Error())
return
}
task, found := a.taskService.FindTask(taskId)
if !found {
resp.Exception = fmt.Sprintf("Task with id %s could not be found", taskId)
return
}
resp.AgentTaskId = task.Id
resp.State = string(task.State)
return
}
示例4: assertRequestIsProcessedAsynchronously
func assertRequestIsProcessedAsynchronously(t *testing.T, req boshmbus.Request) {
settings, handler, platform, taskService, actionFactory := getAgentDependencies()
taskService.StartTaskStartedTask = boshtask.Task{Id: "found-57-id", State: boshtask.TaskStateDone}
actionFactory.CreateAction = new(fakeaction.TestAction)
agent := New(settings, handler, platform, taskService, actionFactory)
err := agent.Run()
assert.NoError(t, err)
assert.True(t, handler.ReceivedRun)
resp := handler.Func(req)
assert.Equal(t, boshmbus.NewValueResponse(TaskValue{AgentTaskId: "found-57-id", State: boshtask.TaskStateDone}), resp)
boshassert.MatchesJsonString(t, resp, `{"value":{"agent_task_id":"found-57-id","state":"done"}}`)
taskService.StartTaskFunc()
assert.Equal(t, req.Method, actionFactory.CreateMethod)
assert.Equal(t, req.GetPayload(), actionFactory.CreateAction.RunPayload)
}