Exemplo n.º 1
0
    def test_auto_server_upgrade_auto_role_simple(self):
        debug_log = None #logging.getLogger("upgrade_auto")
        node1 = MultiProcessCounterValueCollector(collecting_address=[("", 5568)], debug_log=debug_log,
            role=CollectingRole.AUTO_ROLE)
        node2 = MultiProcessCounterValueCollector(collecting_address=[("", 5567), ("", 5568)], debug_log=debug_log,
            role=CollectingRole.AUTO_ROLE)

        try:
            self.assertEqual(node1.actual_role, CollectingRole.LEADER_ROLE)
            self.assertEqual(node2.actual_role, CollectingRole.NODE_ROLE)

            if debug_log:
                debug_log.info("Telling the leader it's on a lower level")

            node1.collecting_address = [("", 5567), ("", 5568)]
            node1.leader.leading_level = 1
            node1.node.hosts_and_ports = node1.collecting_address

            node1._auto_upgrade_server_level_target(wait_time=10)

            sleep(0.5)
            self.assertEqual(node1.leader.leading_level, 0)

            with node2.lock: ## wait for node2 to stablize..
                pass

            self.assertEqual(node2.actual_role, CollectingRole.NODE_ROLE)
        finally:
            node2.shutdown()
            node1.shutdown()
Exemplo n.º 2
0
    def test_auto_reelection(self):
        debug_log = None #logging.getLogger("reelection")
        node1 = MultiProcessCounterValueCollector(collecting_address=[("", 4567), ("", 4568)], debug_log=debug_log,
                    role=CollectingRole.AUTO_ROLE)
        node2 = MultiProcessCounterValueCollector(collecting_address=[("", 4567), ("", 4568)], debug_log=debug_log,
                    role=CollectingRole.AUTO_ROLE)
        node3 = MultiProcessCounterValueCollector(collecting_address=[("", 4567), ("", 4568)], debug_log=debug_log,
                    role=CollectingRole.AUTO_ROLE)
        try:
            self.assertEqual(node1.actual_role, CollectingRole.LEADER_ROLE)
            self.assertEqual(node2.actual_role, CollectingRole.NODE_ROLE)
            self.assertEqual(node3.actual_role, CollectingRole.NODE_ROLE)
            if debug_log:
                debug_log.info("Shutting down leader")

            node1.shutdown() # this should cause re-election.
            node1 = None
            sleep(0.5)
            with node2.lock:
                pass ## causes to wait until node2 finished re-electing
            with node3.lock:
                pass ## causes to wait until node2 finished re-electing

            roles = [node2.actual_role, node3.actual_role]
            self.assertEqual(sorted(roles), [0, 1]) # there is a leader again

        finally:
            if node1:
                node1.node.close()
            node2.node.close() # shutting down nodes first to avoid re-election..
            node3.node.close()
            if node1:
                node1.shutdown()
            node2.shutdown()
            node3.shutdown()