def setUp(self): super(TestRestarter, self).setUp() self.mock_instance_watcher = self.mox.CreateMock(InstanceWatcher) self.mock_scheduler_proxy = self.mox.CreateMock(SchedulerProxyApiSpec) self.restarter = Restarter(JOB, RESTART_SETTINGS, self.mock_scheduler_proxy, self.mock_instance_watcher)
def setUp(self): super(TestRestarter, self).setUp() self.mock_scheduler = self.mox.CreateMock(scheduler_client) self.mock_instance_watcher = self.mox.CreateMock(InstanceWatcher) self.lock = None self.restarter = Restarter( JOB, UPDATER_CONFIG, HEALTH_CHECK_INTERVAL_SECONDS, FakeSchedulerProxy(CLUSTER, self.mock_scheduler, SESSION_KEY), self.mock_instance_watcher)
def setUp(self): super(TestRestarter, self).setUp() self.mock_scheduler = self.mox.CreateMock(scheduler_client) self.mock_instance_watcher = self.mox.CreateMock(InstanceWatcher) self.restarter = Restarter( JOB, RESTART_SETTINGS, FakeSchedulerProxy(Cluster(name=CLUSTER), self.mock_scheduler), self.mock_instance_watcher)
def setUp(self): super(TestRestarter, self).setUp() self.mock_instance_watcher = self.mox.CreateMock(InstanceWatcher) self.mock_scheduler_proxy = self.mox.CreateMock(SchedulerProxyApiSpec) self.restarter = Restarter( JOB, RESTART_SETTINGS, self.mock_scheduler_proxy, self.mock_instance_watcher)
class TestRestarter(MoxTestBase): def setUp(self): super(TestRestarter, self).setUp() self.mock_scheduler = self.mox.CreateMock(scheduler_client) self.mock_instance_watcher = self.mox.CreateMock(InstanceWatcher) self.lock = None self.restarter = Restarter( JOB, UPDATER_CONFIG, HEALTH_CHECK_INTERVAL_SECONDS, FakeSchedulerProxy(CLUSTER, self.mock_scheduler, SESSION_KEY), self.mock_instance_watcher) def mock_restart_instances(self, instances, lock=None): response = Response(responseCode=ResponseCode.OK, messageDEPRECATED='test') self.mock_scheduler.restartShards( JOB.to_thrift(), instances, lock, SESSION_KEY).AndReturn(response) self.mock_instance_watcher.watch(instances).AndReturn([]) def test_restart_one_iteration(self): self.mock_status_active_tasks([0, 1, 3, 4, 5]) self.mock_restart_instances([0, 1]) self.mox.ReplayAll() self.restarter.restart([0, 1]) def mock_three_iterations(self): self.mock_restart_instances([0, 1]) self.mock_restart_instances([3, 4]) self.mock_restart_instances([5]) def test_rolling_restart(self): self.mock_status_active_tasks([0, 1, 3, 4, 5]) self.mock_three_iterations() self.mox.ReplayAll() self.restarter.restart([0, 1, 3, 4, 5]) def mock_status_active_tasks(self, instance_ids): tasks = [] for i in instance_ids: tasks.append(ScheduledTask( status=ScheduleStatus.RUNNING, assignedTask=AssignedTask(task=TaskConfig(), instanceId=i) )) response = Response(responseCode=ResponseCode.OK, messageDEPRECATED='test') response.result = Result() response.result.scheduleStatusResult = ScheduleStatusResult(tasks=tasks) self.mock_scheduler.getTasksWithoutConfigs(IgnoreArg()).AndReturn(response) def test_restart_all_instances(self): self.mock_status_active_tasks([0, 1, 3, 4, 5]) self.mock_three_iterations() self.mox.ReplayAll() self.restarter.restart(None) def mock_status_no_active_task(self): response = Response(responseCode=ResponseCode.INVALID_REQUEST, messageDEPRECATED='test') self.mock_scheduler.getTasksWithoutConfigs(IgnoreArg()).AndReturn(response) def test_restart_no_instance_active(self): self.mock_status_no_active_task() self.mox.ReplayAll() self.restarter.restart(None) def mock_restart_fails(self): response = Response(responseCode=ResponseCode.ERROR, messageDEPRECATED='test error') self.mock_scheduler.restartShards( JOB.to_thrift(), IgnoreArg(), self.lock, SESSION_KEY).AndReturn(response) def test_restart_instance_fails(self): self.mock_status_active_tasks([0, 1]) self.mock_restart_fails() self.mox.ReplayAll() assert self.restarter.restart(None).responseCode == ResponseCode.ERROR def mock_restart_watch_fails(self, instances): response = Response(responseCode=ResponseCode.OK, messageDEPRECATED='test') self.mock_scheduler.restartShards( JOB.to_thrift(), instances, self.lock, SESSION_KEY).AndReturn(response) self.mock_instance_watcher.watch(instances).AndReturn(instances) def test_restart_instances_watch_fails(self): instances = [0, 1] self.mock_status_active_tasks(instances) self.mock_restart_watch_fails(instances) self.mox.ReplayAll() self.restarter.restart(None)
class TestRestarter(MoxTestBase): def setUp(self): super(TestRestarter, self).setUp() self.mock_scheduler = self.mox.CreateMock(scheduler_client) self.mock_instance_watcher = self.mox.CreateMock(InstanceWatcher) self.lock = None self.restarter = Restarter( JOB, UPDATER_CONFIG, HEALTH_CHECK_INTERVAL_SECONDS, FakeSchedulerProxy(CLUSTER, self.mock_scheduler, SESSION_KEY), self.mock_instance_watcher) def mock_restart_instances(self, instances, lock=None): response = Response(responseCode=ResponseCode.OK, messageDEPRECATED='test') self.mock_scheduler.restartShards(JOB.to_thrift(), instances, lock, SESSION_KEY).AndReturn(response) self.mock_instance_watcher.watch(instances).AndReturn([]) def test_restart_one_iteration(self): self.mock_status_active_tasks([0, 1, 3, 4, 5]) self.mock_restart_instances([0, 1]) self.mox.ReplayAll() self.restarter.restart([0, 1]) def mock_three_iterations(self): self.mock_restart_instances([0, 1]) self.mock_restart_instances([3, 4]) self.mock_restart_instances([5]) def test_rolling_restart(self): self.mock_status_active_tasks([0, 1, 3, 4, 5]) self.mock_three_iterations() self.mox.ReplayAll() self.restarter.restart([0, 1, 3, 4, 5]) def mock_status_active_tasks(self, instance_ids): tasks = [] for i in instance_ids: tasks.append( ScheduledTask(status=ScheduleStatus.RUNNING, assignedTask=AssignedTask(task=TaskConfig(), instanceId=i))) response = Response(responseCode=ResponseCode.OK, messageDEPRECATED='test') response.result = Result() response.result.scheduleStatusResult = ScheduleStatusResult( tasks=tasks) self.mock_scheduler.getTasksWithoutConfigs( IgnoreArg()).AndReturn(response) def test_restart_all_instances(self): self.mock_status_active_tasks([0, 1, 3, 4, 5]) self.mock_three_iterations() self.mox.ReplayAll() self.restarter.restart(None) def mock_status_no_active_task(self): response = Response(responseCode=ResponseCode.INVALID_REQUEST, messageDEPRECATED='test') self.mock_scheduler.getTasksWithoutConfigs( IgnoreArg()).AndReturn(response) def test_restart_no_instance_active(self): self.mock_status_no_active_task() self.mox.ReplayAll() self.restarter.restart(None) def mock_restart_fails(self): response = Response(responseCode=ResponseCode.ERROR, messageDEPRECATED='test error') self.mock_scheduler.restartShards(JOB.to_thrift(), IgnoreArg(), self.lock, SESSION_KEY).AndReturn(response) def test_restart_instance_fails(self): self.mock_status_active_tasks([0, 1]) self.mock_restart_fails() self.mox.ReplayAll() assert self.restarter.restart(None).responseCode == ResponseCode.ERROR def mock_restart_watch_fails(self, instances): response = Response(responseCode=ResponseCode.OK, messageDEPRECATED='test') self.mock_scheduler.restartShards(JOB.to_thrift(), instances, self.lock, SESSION_KEY).AndReturn(response) self.mock_instance_watcher.watch(instances).AndReturn(instances) def test_restart_instances_watch_fails(self): instances = [0, 1] self.mock_status_active_tasks(instances) self.mock_restart_watch_fails(instances) self.mox.ReplayAll() self.restarter.restart(None)
class TestRestarter(MoxTestBase): def setUp(self): super(TestRestarter, self).setUp() self.mock_scheduler = self.mox.CreateMock(scheduler_client) self.mock_instance_watcher = self.mox.CreateMock(InstanceWatcher) self.restarter = Restarter( JOB, RESTART_SETTINGS, FakeSchedulerProxy(Cluster(name=CLUSTER), self.mock_scheduler), self.mock_instance_watcher) def mock_restart_instances(self, instances): self.mock_scheduler.restartShards(JOB.to_thrift(), instances).AndReturn(make_response()) self.mock_instance_watcher.watch(instances).AndReturn([]) def test_restart_one_iteration(self): self.mock_status_active_tasks([0, 1, 3, 4, 5]) self.mock_restart_instances([0, 1]) self.mox.ReplayAll() self.restarter.restart([0, 1]) def mock_three_iterations(self): self.mock_restart_instances([0, 1]) self.mock_restart_instances([3, 4]) self.mock_restart_instances([5]) def test_rolling_restart(self): self.mock_status_active_tasks([0, 1, 3, 4, 5]) self.mock_three_iterations() self.mox.ReplayAll() self.restarter.restart([0, 1, 3, 4, 5]) def mock_status_active_tasks(self, instance_ids): tasks = [] for i in instance_ids: tasks.append(ScheduledTask( status=ScheduleStatus.RUNNING, assignedTask=AssignedTask(task=TaskConfig(), instanceId=i) )) response = make_response(result=Result(scheduleStatusResult=ScheduleStatusResult(tasks=tasks))) self.mock_scheduler.getTasksWithoutConfigs(IgnoreArg()).AndReturn(response) def test_restart_all_instances(self): self.mock_status_active_tasks([0, 1, 3, 4, 5]) self.mock_three_iterations() self.mox.ReplayAll() self.restarter.restart(None) def mock_status_no_active_task(self): response = make_response(code=ResponseCode.INVALID_REQUEST) self.mock_scheduler.getTasksWithoutConfigs(IgnoreArg()).AndReturn(response) def test_restart_no_instance_active(self): self.mock_status_no_active_task() self.mox.ReplayAll() self.restarter.restart(None) def mock_restart_fails(self): response = make_response(code=ResponseCode.ERROR, message='test error') self.mock_scheduler.restartShards(JOB.to_thrift(), IgnoreArg()).AndReturn(response) def test_restart_instance_fails(self): self.mock_status_active_tasks([0, 1]) self.mock_restart_fails() self.mox.ReplayAll() assert self.restarter.restart(None).responseCode == ResponseCode.ERROR def mock_restart_watch_fails(self, instances): self.mock_scheduler.restartShards(JOB.to_thrift(), instances).AndReturn(make_response()) self.mock_instance_watcher.watch(instances).AndReturn(instances) def test_restart_instances_watch_fails(self): instances = [0, 1] self.mock_status_active_tasks(instances) self.mock_restart_watch_fails(instances) self.mox.ReplayAll() self.restarter.restart(None)