Пример #1
0
    def test_automaton_phase_0_actions(self):
        view_est_mod = ViewEstablishmentModule(0, self.resolver, 2, 0)
        pred_module = PredicatesAndAction(view_est_mod, 0, self.resolver, 2, 0)

        # Case 0 should call adopt and next_view in view Establishment module
        view_est_mod.next_phs = Mock()
        pred_module.adopt = Mock()
        pred_module.reset_v_change = Mock()
        pred_module.view_pair_to_adopt = pred_module.RST_PAIR
        self.assertEqual(
            pred_module.automation(ViewEstablishmentEnums.ACTION, 0, 0),
            ViewEstablishmentEnums.NO_RETURN_VALUE)
        view_est_mod.next_phs.assert_any_call()
        #pred_module.reset_v_change.assert_any_call()
        pred_module.adopt.assert_called_once_with(pred_module.RST_PAIR)

        # Case 1a should call next_view and next_phs in view Establishment module
        pred_module.next_view = Mock()
        view_est_mod.next_phs = Mock()
        pred_module.vChange = [True for i in range(2)]
        self.assertEqual(
            pred_module.automation(ViewEstablishmentEnums.ACTION, 0, 1),
            ViewEstablishmentEnums.NO_RETURN_VALUE)
        pred_module.next_view.assert_any_call()
        view_est_mod.next_phs.assert_any_call()

        # Case 1b should call next_phs in View Establishment module
        pred_module.vChange = [False for i in range(2)]
        view_est_mod.next_phs = Mock()
        pred_module.views[pred_module.id] = pred_module.RST_PAIR
        self.assertEqual(
            pred_module.automation(ViewEstablishmentEnums.ACTION, 0, 1),
            ViewEstablishmentEnums.NO_RETURN_VALUE)
        view_est_mod.next_phs.assert_any_call()

        # Case 2 should return "No action" and call reset_v_change
        pred_module.reset_v_change = Mock()
        self.assertEqual(
            pred_module.automation(ViewEstablishmentEnums.ACTION, 0, 2),
            ViewEstablishmentEnums.NO_ACTION)
        # pred_module.reset_v_change.assert_any_call()

        # Case 3 should return "Reset"
        pred_module.reset_all = MagicMock(
            return_value=ViewEstablishmentEnums.RESET)
        #pred_module.reset_v_change = Mock()
        self.assertEqual(
            pred_module.automation(ViewEstablishmentEnums.ACTION, 0, 3),
            ViewEstablishmentEnums.RESET)
Пример #2
0
 def test_added_logic_phase_0_case_1_b(self):
     # No mocking needed, establishable should return true
     view_est_mod = ViewEstablishmentModule(0, self.resolver, 2, 0)
     pred_module = PredicatesAndAction(view_est_mod, 0, self.resolver, 2, 0)
     pred_module.vChange = [False for i in range(2)]
     pred_module.views = [pred_module.RST_PAIR, pred_module.RST_PAIR]
     view_est_mod.phs = [0, 0]
     self.assertTrue(
         pred_module.automation(ViewEstablishmentEnums.PREDICATE, 0, 1))
Пример #3
0
    def test_automaton_phase_1_actions(self):
        view_est_mod = ViewEstablishmentModule(0, self.resolver, 2, 0)
        pred_module = PredicatesAndAction(view_est_mod, 0, self.resolver, 2, 0)

        # Case 0 should call adopt and next_view in view Establishment module
        pred_module.adopt = Mock()
        pred_module.reset_v_change = Mock()
        pred_module.view_pair_to_adopt = pred_module.RST_PAIR

        self.assertEqual(
            pred_module.automation(ViewEstablishmentEnums.ACTION, 1, 0),
            ViewEstablishmentEnums.NO_RETURN_VALUE)
        pred_module.adopt.assert_called_once_with(pred_module.RST_PAIR)
        pred_module.reset_v_change.assert_any_call()

        # Case 1 should call next_view and next_phs in view Establishment module
        view_est_mod.next_phs = Mock()
        pred_module.reset_v_change = Mock()
        pred_module.establish = Mock()
        self.resolver.execute = Mock()
        pred_module.views[pred_module.id] = pred_module.RST_PAIR

        self.assertEqual(
            pred_module.automation(ViewEstablishmentEnums.ACTION, 1, 1),
            ViewEstablishmentEnums.NO_RETURN_VALUE)
        view_est_mod.next_phs.assert_any_call()
        pred_module.reset_v_change.assert_any_call()
        pred_module.establish.assert_any_call()
        # self.resolver.execute.assert_called_once_with(module=Module.REPLICATION_MODULE,
        #                 func=Function.REPLICA_FLUSH)

        # Case 2 should return "No action" and call reset_v_change
        pred_module.reset_v_change = Mock()
        self.assertEqual(
            pred_module.automation(ViewEstablishmentEnums.ACTION, 1, 2),
            ViewEstablishmentEnums.NO_ACTION)
        pred_module.reset_v_change.assert_any_call()

        # Case 3 should return "Reset"
        pred_module.reset_all = MagicMock(
            return_value=ViewEstablishmentEnums.RESET)
        self.assertEqual(
            pred_module.automation(ViewEstablishmentEnums.ACTION, 1, 3),
            ViewEstablishmentEnums.RESET)
Пример #4
0
    def test_automaton_phase_1_predicates(self):
        view_est_mod = ViewEstablishmentModule(0, self.resolver, 2, 0)
        pred_module = PredicatesAndAction(view_est_mod, 0, self.resolver, 2, 0)

        # Case 0
        pred_module.views = [{CURRENT: 0, NEXT: 4}, {CURRENT: 1, NEXT: 1}]
        pred_module.transit_adopble = MagicMock(return_value=True)
        self.assertTrue(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 1, 0))

        # Not a adoptable view in transit
        pred_module.transit_adopble = MagicMock(return_value=False)
        self.assertFalse(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 1, 0))
        # The adoptable view is the same as processor i
        pred_module.views = [{CURRENT: 0, NEXT: 0}, {CURRENT: 0, NEXT: 0}]
        pred_module.transit_adopble = MagicMock(return_value=True)
        self.assertFalse(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 1, 0))

        # Case 1
        pred_module.establishable = MagicMock(return_value=True)
        self.assertTrue(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 1, 1))
        # The threshold to move to a view change is not fulfilled
        pred_module.establishable = MagicMock(return_value=False)
        self.assertFalse(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 1, 1))

        # Case 2
        # There is not an adoptable view in transit
        self.assertTrue(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 1, 2))
        # There is not an adoptable view in transit
        pred_module.transit_adopble = MagicMock(return_value=False)
        self.assertFalse(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 1, 2))

        # Case 3 should return True
        self.assertTrue(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 1, 3))
Пример #5
0
    def test_automaton_phase_0_predicates(self):
        view_est_mod = ViewEstablishmentModule(0, self.resolver, 2, 0)
        pred_module = PredicatesAndAction(view_est_mod, 0, self.resolver, 2, 0)

        # Case 0
        pred_module.views = [{CURRENT: 0, NEXT: 0}, {CURRENT: 1, NEXT: 1}]
        pred_module.transit_adopble = MagicMock(return_value=True)
        self.assertTrue(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 0, 0))
        # Not a adoptable view in transit
        pred_module.transit_adopble = MagicMock(return_value=False)
        self.assertFalse(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 0, 0))
        # The adoptable view is the same as processor i
        pred_module.views = [{CURRENT: 0, NEXT: 0}, {CURRENT: 0, NEXT: 0}]
        pred_module.transit_adopble = MagicMock(return_value=True)
        self.assertFalse(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 0, 0))

        # Case 1b
        pred_module.vChange = [False for i in range(2)]
        pred_module.establishable = MagicMock(return_value=True)
        pred_module.views[pred_module.id] = pred_module.RST_PAIR
        self.assertTrue(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 0, 1))

        # Case 1a
        pred_module.views[pred_module.id] = {
            "current": 1,
            "next": 1
        }  # NOT the RST_PAIR
        pred_module.establishable = MagicMock(return_value=True)
        pred_module.vChange = [True for i in range(2)]
        self.assertTrue(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 0, 1))
        # View change is not required
        pred_module.vChange = [False for i in range(2)]
        pred_module.views[1] = {"current": 1, "next": 1}
        self.assertFalse(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 0, 1))
        # The threshold to move to a view change is not fulfilled
        pred_module.establishable = MagicMock(return_value=False)
        pred_module.vChange = [True for i in range(2)]
        self.assertFalse(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 0, 1))

        # Case 2
        # There is a adoptable view in transit
        self.assertTrue(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 0, 2))
        # None of the condition is fulfilled
        pred_module.transit_adopble = MagicMock(return_value=False)
        self.assertFalse(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 0, 2))
        # Processor i view_pair is the default pair
        pred_module.views[pred_module.id] = pred_module.RST_PAIR
        self.assertTrue(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 0, 2))

        # Case 3 should return True
        self.assertTrue(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 0, 3))