You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@slider.apache.org by st...@apache.org on 2015/11/23 18:19:33 UTC
[3/7] incubator-slider git commit: SLIDER-128 Support graceful stop
of component instances (separate terminate and stop cmd test)
SLIDER-128 Support graceful stop of component instances (separate terminate and stop cmd test)
Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/c2ae8e69
Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/c2ae8e69
Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/c2ae8e69
Branch: refs/heads/feature/SLIDER-82-pass-3.1
Commit: c2ae8e69745ceb8db174b4ee64643bdddeb55b50
Parents: d850dd2
Author: Gour Saha <go...@apache.org>
Authored: Thu Nov 12 10:22:39 2015 -0800
Committer: Gour Saha <go...@apache.org>
Committed: Thu Nov 12 10:22:39 2015 -0800
----------------------------------------------------------------------
.../src/test/python/agent/TestController.py | 105 ++++++++++++++++++-
1 file changed, 103 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c2ae8e69/slider-agent/src/test/python/agent/TestController.py
----------------------------------------------------------------------
diff --git a/slider-agent/src/test/python/agent/TestController.py b/slider-agent/src/test/python/agent/TestController.py
index 69ed8cc..7eeecb9 100644
--- a/slider-agent/src/test/python/agent/TestController.py
+++ b/slider-agent/src/test/python/agent/TestController.py
@@ -527,7 +527,7 @@ class TestController(unittest.TestCase):
@patch("time.sleep")
@patch("json.loads")
@patch("json.dumps")
- def test_heartbeatWithServerTerminateAgent(self, dumpsMock, loadsMock, sleepMock, event_mock):
+ def test_heartbeatWithServerStopAgent(self, dumpsMock, loadsMock, sleepMock, event_mock):
original_value = self.controller.config
self.controller.config = AgentConfig("", "")
out = StringIO.StringIO()
@@ -626,7 +626,108 @@ class TestController(unittest.TestCase):
self.assertFalse(self.controller.terminateAgent)
assert not self.controller.stopCommand == None
- # now no need to have STOP command in response, just send terminateAgent
+ # Now STOP execution command stops the agent completely so terminateAgent
+ # flag test is moved to test_heartbeatWithServerTerminateAgent
+
+ sleepMock.assert_called_with(
+ self.controller.netutil.MINIMUM_INTERVAL_BETWEEN_HEARTBEATS)
+
+ sys.stdout = sys.__stdout__
+ self.controller.sendRequest = Controller.Controller.sendRequest
+ self.controller.addToQueue = Controller.Controller.addToQueue
+
+ self.controller.config = original_value
+ pass
+
+ @patch.object(threading._Event, "wait")
+ @patch("time.sleep")
+ @patch("json.loads")
+ @patch("json.dumps")
+ def test_heartbeatWithServerTerminateAgent(self, dumpsMock, loadsMock, sleepMock, event_mock):
+ original_value = self.controller.config
+ self.controller.config = AgentConfig("", "")
+ out = StringIO.StringIO()
+ sys.stdout = out
+
+ hearbeat = MagicMock()
+ self.controller.heartbeat = hearbeat
+
+ dumpsMock.return_value = "data"
+
+ sendRequest = MagicMock(name="sendRequest")
+ self.controller.sendRequest = sendRequest
+
+ self.controller.responseId = 1
+ response = {"responseId":"2", "restartAgent": False}
+ loadsMock.return_value = response
+
+ def one_heartbeat(*args, **kwargs):
+ self.controller.DEBUG_STOP_HEARTBEATING = True
+ return "data"
+
+ sendRequest.side_effect = one_heartbeat
+
+ actionQueue = MagicMock()
+ actionQueue.isIdle.return_value = True
+
+ # one successful request, after stop
+ self.controller.actionQueue = actionQueue
+ self.controller.heartbeatWithServer()
+ self.assertTrue(sendRequest.called)
+
+ calls = []
+ def retry(*args, **kwargs):
+ if len(calls) == 0:
+ calls.append(1)
+ response["responseId"] = "3"
+ raise Exception()
+ if len(calls) > 0:
+ self.controller.DEBUG_STOP_HEARTBEATING = True
+ return "data"
+
+ # exception, retry, successful and stop
+ sendRequest.side_effect = retry
+ self.controller.DEBUG_STOP_HEARTBEATING = False
+ self.controller.heartbeatWithServer()
+
+ self.assertEqual(1, self.controller.DEBUG_SUCCESSFULL_HEARTBEATS)
+
+ original_stopApp = self.controller.stopApp
+
+ # terminateAgent command - test 1
+ self.controller.responseId = 1
+ self.controller.DEBUG_STOP_HEARTBEATING = False
+ response = {"responseId":"2", "terminateAgent": True}
+ loadsMock.return_value = response
+ stopApp = MagicMock(name="stopApp")
+ self.controller.stopApp = stopApp
+ self.controller.heartbeatWithServer()
+ stopApp.assert_called_once_with()
+
+ # reset for next test
+ self.controller.terminateAgent = False
+
+ # terminateAgent command - test 2
+ self.controller.responseId = 1
+ self.controller.DEBUG_STOP_HEARTBEATING = False
+ response = {"responseId":"2", "terminateAgent": True}
+ loadsMock.return_value = response
+ self.controller.stopApp = original_stopApp
+ stopCommand = {"roleCommand": "STOP"}
+ self.controller.stopCommand = stopCommand
+ addToQueue = MagicMock(name="addToQueue")
+ self.controller.addToQueue = addToQueue
+ self.controller.componentActualState = State.STARTED
+ self.controller.heartbeatWithServer()
+ self.assertTrue(self.controller.terminateAgent)
+ self.assertTrue(self.controller.appGracefulStopQueued)
+ addToQueue.assert_has_calls([call([stopCommand])])
+
+ # reset for next test
+ self.controller.terminateAgent = False
+ self.controller.appGracefulStopQueued = False
+
+ # terminateAgent command - test 3
self.controller.responseId = 2
self.controller.DEBUG_STOP_HEARTBEATING = False
response = {"responseId":"3", "terminateAgent": True}