本文整理匯總了Golang中github.com/mesos/mesos-go/messenger.NewMockedMessenger函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewMockedMessenger函數的具體用法?Golang NewMockedMessenger怎麽用?Golang NewMockedMessenger使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewMockedMessenger函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestSchdulerDriverAbort
func (suite *SchedulerTestSuite) TestSchdulerDriverAbort() {
// Set expections and return values.
messenger := messenger.NewMockedMessenger()
messenger.On("Start").Return(nil)
messenger.On("UPID").Return(&upid.UPID{})
messenger.On("Send").Return(nil)
messenger.On("Stop").Return(nil)
messenger.On("Route").Return(nil)
driver := newTestSchedulerDriver(suite.T(), NewMockScheduler(), suite.framework, suite.master, nil)
driver.messenger = messenger
suite.True(driver.Stopped())
go func() {
stat, err := driver.Run()
suite.NoError(err)
suite.Equal(mesos.Status_DRIVER_ABORTED, stat)
}()
time.Sleep(time.Millisecond * 1)
driver.setConnected(true) // simulated
suite.False(driver.Stopped())
suite.Equal(mesos.Status_DRIVER_RUNNING, driver.Status())
stat, err := driver.Abort()
time.Sleep(time.Millisecond * 1)
suite.NoError(err)
suite.True(driver.Stopped())
suite.Equal(mesos.Status_DRIVER_ABORTED, stat)
suite.Equal(mesos.Status_DRIVER_ABORTED, driver.Status())
}
示例2: TestSchedulerDriverJoinOK
func (suite *SchedulerTestSuite) TestSchedulerDriverJoinOK() {
// Set expections and return values.
messenger := messenger.NewMockedMessenger()
messenger.On("Start").Return(nil)
messenger.On("UPID").Return(&upid.UPID{})
messenger.On("Send").Return(nil)
messenger.On("Stop").Return(nil)
driver := newTestSchedulerDriver(suite.T(), NewMockScheduler(), suite.framework, suite.master, nil)
driver.messenger = messenger
suite.True(driver.Stopped())
stat, err := driver.Start()
suite.NoError(err)
suite.Equal(mesos.Status_DRIVER_RUNNING, stat)
suite.False(driver.Stopped())
testCh := make(chan mesos.Status)
go func() {
stat, _ := driver.Join()
testCh <- stat
}()
close(driver.stopCh) // manually stopping
stat = <-testCh // when Stop() is called, stat will be DRIVER_STOPPED.
}
示例3: TestExecutorDriverJoin
func TestExecutorDriverJoin(t *testing.T) {
setEnvironments(t, "", false)
// Set expections and return values.
messenger := messenger.NewMockedMessenger()
messenger.On("Start").Return(nil)
messenger.On("UPID").Return(upid.UPID{})
messenger.On("Send").Return(nil)
messenger.On("Stop").Return(nil)
exec := NewMockedExecutor()
exec.On("Error").Return(nil)
driver := newTestExecutorDriver(t, exec)
driver.messenger = messenger
assert.False(t, driver.Running())
stat, err := driver.Start()
assert.NoError(t, err)
assert.True(t, driver.Running())
assert.Equal(t, mesosproto.Status_DRIVER_RUNNING, stat)
testCh := make(chan mesosproto.Status)
go func() {
stat, _ := driver.Join()
testCh <- stat
}()
driver.Stop()
stat = <-testCh // when Stop() is called, stat will be DRIVER_STOPPED.
assert.Equal(t, mesosproto.Status_DRIVER_STOPPED, stat)
}
示例4: TestExecutorDriverStartSucceed
func TestExecutorDriverStartSucceed(t *testing.T) {
setEnvironments(t, "", false)
exec := NewMockedExecutor()
exec.On("Error").Return(nil)
driver := newTestExecutorDriver(t, exec)
messenger := messenger.NewMockedMessenger()
driver.messenger = messenger
messenger.On("Start").Return(nil)
messenger.On("UPID").Return(upid.UPID{})
messenger.On("Send").Return(nil)
messenger.On("Stop").Return(nil)
assert.False(t, driver.Running())
status, err := driver.Start()
assert.True(t, driver.Running())
assert.NoError(t, err)
assert.Equal(t, mesosproto.Status_DRIVER_RUNNING, status)
messenger.AssertNumberOfCalls(t, "Start", 1)
messenger.AssertNumberOfCalls(t, "UPID", 1)
messenger.AssertNumberOfCalls(t, "Send", 1)
}
示例5: TestSchedulerDriverStartWithRegistrationFailure
func (suite *SchedulerTestSuite) TestSchedulerDriverStartWithRegistrationFailure() {
sched := NewMockScheduler()
sched.On("Error").Return()
// Set expections and return values.
messenger := messenger.NewMockedMessenger()
messenger.On("Start").Return(nil)
messenger.On("UPID").Return(&upid.UPID{})
messenger.On("Stop").Return(nil)
driver := newTestSchedulerDriver(suite.T(), sched, suite.framework, suite.master, nil)
driver.messenger = messenger
suite.True(driver.Stopped())
// reliable registration loops until the driver is stopped, connected, etc..
stat, err := driver.Start()
suite.NoError(err)
suite.Equal(mesos.Status_DRIVER_RUNNING, stat)
time.Sleep(5 * time.Second) // wait a bit, registration should be looping...
suite.False(driver.Stopped())
suite.Equal(mesos.Status_DRIVER_RUNNING, driver.Status())
// stop the driver, should not panic!
driver.Stop(false) // not failing over
suite.True(driver.Stopped())
suite.Equal(mesos.Status_DRIVER_STOPPED, driver.Status())
messenger.AssertExpectations(suite.T())
}
示例6: TestExecutorDriverRun
func TestExecutorDriverRun(t *testing.T) {
setEnvironments(t, "", false)
// Set expections and return values.
messenger := messenger.NewMockedMessenger()
messenger.On("Start").Return(nil)
messenger.On("UPID").Return(upid.UPID{})
messenger.On("Send").Return(nil)
messenger.On("Stop").Return(nil)
exec := NewMockedExecutor()
exec.On("Error").Return(nil)
driver := newTestExecutorDriver(t, exec)
driver.messenger = messenger
assert.False(t, driver.Running())
ch := make(chan struct{})
go func() {
defer close(ch)
stat, err := driver.Run()
assert.NoError(t, err)
assert.Equal(t, mesosproto.Status_DRIVER_STOPPED, stat)
}()
<-driver.started
assert.True(t, driver.Running())
driver.Stop()
<-ch
}
示例7: TestSchedulerDriverRun
func (suite *SchedulerTestSuite) TestSchedulerDriverRun() {
// Set expections and return values.
messenger := messenger.NewMockedMessenger()
messenger.On("Start").Return(nil)
messenger.On("UPID").Return(&upid.UPID{})
messenger.On("Send").Return(nil)
messenger.On("Stop").Return(nil)
driver := newTestSchedulerDriver(suite.T(), NewMockScheduler(), suite.framework, suite.master, nil)
driver.messenger = messenger
suite.True(driver.Stopped())
go func() {
stat, err := driver.Run()
suite.NoError(err)
suite.Equal(mesos.Status_DRIVER_STOPPED, stat)
}()
time.Sleep(time.Millisecond * 1)
suite.False(driver.Stopped())
suite.Equal(mesos.Status_DRIVER_RUNNING, driver.Status())
// close it all.
driver.setStatus(mesos.Status_DRIVER_STOPPED)
close(driver.stopCh)
time.Sleep(time.Millisecond * 1)
}
示例8: TestSchdulerDriverStop_WithoutFailover
func (suite *SchedulerTestSuite) TestSchdulerDriverStop_WithoutFailover() {
// Set expections and return values.
messenger := &msgTracker{MockedMessenger: messenger.NewMockedMessenger()}
messenger.On("Start").Return(nil)
messenger.On("UPID").Return(&upid.UPID{})
messenger.On("Send").Return(nil)
messenger.On("Stop").Return(nil)
messenger.On("Route").Return(nil)
driver := newTestSchedulerDriver(suite.T(), NewMockScheduler(), suite.framework, suite.master, nil)
driver.messenger = messenger
suite.True(driver.Stopped())
go func() {
stat, err := driver.Run()
suite.NoError(err)
suite.Equal(mesos.Status_DRIVER_STOPPED, stat)
}()
time.Sleep(time.Millisecond * 1)
suite.False(driver.Stopped())
suite.Equal(mesos.Status_DRIVER_RUNNING, driver.Status())
driver.connected = true // pretend that we're already registered
driver.Stop(false)
msg := messenger.lastMessage
suite.NotNil(msg)
_, isUnregMsg := msg.(proto.Message)
suite.True(isUnregMsg, "expected UnregisterFrameworkMessage instead of %+v", msg)
suite.True(driver.Stopped())
suite.Equal(mesos.Status_DRIVER_STOPPED, driver.Status())
}
示例9: TestSchdulerDriverReconcileTasks
func (suite *SchedulerTestSuite) TestSchdulerDriverReconcileTasks() {
messenger := messenger.NewMockedMessenger()
messenger.On("Start").Return(nil)
messenger.On("UPID").Return(&upid.UPID{})
messenger.On("Send").Return(nil)
messenger.On("Stop").Return(nil)
messenger.On("Route").Return(nil)
driver, err := newTestSchedulerDriver(NewMockScheduler(), suite.framework, suite.master, nil)
driver.messenger = messenger
suite.NoError(err)
suite.True(driver.Stopped())
driver.Start()
driver.setConnected(true) // simulated
suite.Equal(mesos.Status_DRIVER_RUNNING, driver.Status())
stat, err := driver.ReconcileTasks(
[]*mesos.TaskStatus{
util.NewTaskStatus(util.NewTaskID("test-task-001"), mesos.TaskState_TASK_FINISHED),
},
)
suite.NoError(err)
suite.Equal(mesos.Status_DRIVER_RUNNING, stat)
}
示例10: TestExecutorDriverRun
func TestExecutorDriverRun(t *testing.T) {
setEnvironments(t, "", false)
// Set expections and return values.
messenger := messenger.NewMockedMessenger()
messenger.On("Start").Return(nil)
messenger.On("UPID").Return(&upid.UPID{})
messenger.On("Send").Return(nil)
messenger.On("Stop").Return(nil)
exec := NewMockedExecutor()
exec.On("Error").Return(nil)
driver := newTestExecutorDriver(t, exec)
driver.messenger = messenger
assert.True(t, driver.stopped)
checker := healthchecker.NewMockedHealthChecker()
checker.On("Start").Return()
checker.On("Stop").Return()
go func() {
stat, err := driver.Run()
assert.NoError(t, err)
assert.Equal(t, mesosproto.Status_DRIVER_STOPPED, stat)
}()
time.Sleep(time.Millisecond * 1) // allow for things to settle
assert.False(t, driver.Stopped())
assert.Equal(t, mesosproto.Status_DRIVER_RUNNING, driver.Status())
// mannually close it all
driver.setStatus(mesosproto.Status_DRIVER_STOPPED)
close(driver.stopCh)
time.Sleep(time.Millisecond * 1)
}
示例11: TestSchdulerDriverSendFrameworkMessage
func (suite *SchedulerTestSuite) TestSchdulerDriverSendFrameworkMessage() {
messenger := messenger.NewMockedMessenger()
messenger.On("Start").Return(nil)
messenger.On("UPID").Return(&upid.UPID{})
messenger.On("Send").Return(nil)
messenger.On("Stop").Return(nil)
messenger.On("Route").Return(nil)
driver, err := newTestSchedulerDriver(NewMockScheduler(), suite.framework, suite.master, nil)
driver.messenger = messenger
suite.NoError(err)
suite.True(driver.Stopped())
driver.Start()
driver.setConnected(true) // simulated
suite.Equal(mesos.Status_DRIVER_RUNNING, driver.Status())
stat, err := driver.SendFrameworkMessage(
util.NewExecutorID("test-exec-001"),
util.NewSlaveID("test-slave-001"),
"Hello!",
)
suite.NoError(err)
suite.Equal(mesos.Status_DRIVER_RUNNING, stat)
}
示例12: TestSchdulerDriverKillTask
func (suite *SchedulerTestSuite) TestSchdulerDriverKillTask() {
messenger := messenger.NewMockedMessenger()
messenger.On("Start").Return(nil)
messenger.On("UPID").Return(&upid.UPID{})
messenger.On("Send").Return(nil)
messenger.On("Stop").Return(nil)
messenger.On("Route").Return(nil)
driver, err := newTestSchedulerDriver(NewMockScheduler(), suite.framework, suite.master, nil)
driver.messenger = messenger
suite.NoError(err)
suite.True(driver.Stopped())
go func() {
driver.Run()
}()
time.Sleep(time.Millisecond * 1)
driver.setConnected(true) // simulated
suite.False(driver.Stopped())
suite.Equal(mesos.Status_DRIVER_RUNNING, driver.Status())
stat, err := driver.KillTask(util.NewTaskID("test-task-1"))
suite.NoError(err)
suite.Equal(mesos.Status_DRIVER_RUNNING, stat)
}
示例13: TestSchdulerDriverRequestResources
func (suite *SchedulerTestSuite) TestSchdulerDriverRequestResources() {
messenger := messenger.NewMockedMessenger()
messenger.On("Start").Return(nil)
messenger.On("UPID").Return(&upid.UPID{})
messenger.On("Send").Return(nil)
messenger.On("Stop").Return(nil)
messenger.On("Route").Return(nil)
driver := newTestSchedulerDriver(suite.T(), NewMockScheduler(), suite.framework, suite.master, nil)
driver.messenger = messenger
suite.True(driver.Stopped())
driver.Start()
driver.setConnected(true) // simulated
suite.Equal(mesos.Status_DRIVER_RUNNING, driver.Status())
stat, err := driver.RequestResources(
[]*mesos.Request{
{
SlaveId: util.NewSlaveID("test-slave-001"),
Resources: []*mesos.Resource{
util.NewScalarResource("test-res-001", 33.00),
},
},
},
)
suite.NoError(err)
suite.Equal(mesos.Status_DRIVER_RUNNING, stat)
}
示例14: TestSchdulerDriverStopOK
func (suite *SchedulerTestSuite) TestSchdulerDriverStopOK() {
// Set expections and return values.
messenger := messenger.NewMockedMessenger()
messenger.On("Start").Return(nil)
messenger.On("UPID").Return(&upid.UPID{})
messenger.On("Send").Return(nil)
messenger.On("Stop").Return(nil)
messenger.On("Route").Return(nil)
driver, err := newTestSchedulerDriver(NewMockScheduler(), suite.framework, suite.master, nil)
suite.NotNil(driver, "expected valid driver")
suite.NoError(err)
driver.messenger = messenger
suite.NoError(err)
suite.True(driver.Stopped())
go func() {
stat, err := driver.Run()
suite.NoError(err)
suite.Equal(mesos.Status_DRIVER_STOPPED, stat)
}()
time.Sleep(time.Millisecond * 1)
suite.False(driver.Stopped())
suite.Equal(mesos.Status_DRIVER_RUNNING, driver.Status())
driver.Stop(false)
time.Sleep(time.Millisecond * 1)
suite.True(driver.Stopped())
suite.Equal(mesos.Status_DRIVER_STOPPED, driver.Status())
}
示例15: mockedMessenger
func mockedMessenger() *messenger.MockedMessenger {
m := messenger.NewMockedMessenger()
m.On("Start").Return(nil)
m.On("UPID").Return(upid.UPID{})
m.On("Send").Return(nil)
m.On("Stop").Return(nil)
m.On("Route").Return(nil)
m.On("Install").Return(nil)
return m
}