Exemple #1
0
    def test_blocking_all_uris(self):
        """
        test that the uris will be blocked and unblocked after delay
        """

        # -------------------------------------------------------------- --

        # setup a local registry for the test

        DictResourceRegistry.registry = {}

        # ------------------------------------------------------------------ --

        # setup the Resource Scheduler

        res_sched = ResourceScheduler(
                            tries=1,
                            resource_registry_class=DictResourceRegistry)

        res_sched.uri_list = string_to_list("uri://1, uri://2, uri://3, ")

        # ------------------------------------------------------------------ --

        # check that all uris are blocked

        with freeze_time("2012-01-14 12:00:00"):

            # -------------------------------------------------------------- --

            # block all uris

            for uri in res_sched.next():
                res_sched.block(uri, delay=30)

            # -------------------------------------------------------------- --

            # verify that all uris are blocked and none is iterated

            uris = []
            for uri in res_sched.next():
                uris.append(uri)

            self.assertTrue(len(uris) == 0)

        # one minute later
        with freeze_time("2012-01-14 12:01:00"):

            # -------------------------------------------------------------- --

            # verify that all uris are un blocked after the delay

            uris = []
            for uri in res_sched.next():
                uris.append(uri)

            self.assertTrue('uri://1' in uris)
            self.assertTrue('uri://2' in uris)
            self.assertTrue('uri://3' in uris)

        return
Exemple #2
0
    def test_blocking_all_uris(self):
        """
        test that the uris will be blocked and unblocked after delay
        """

        # -------------------------------------------------------------- --

        # setup a local registry for the test

        DictResourceRegistry.registry = {}

        # ------------------------------------------------------------------ --

        # setup the Resource Scheduler

        res_sched = ResourceScheduler(
            tries=1, resource_registry_class=DictResourceRegistry)

        res_sched.uri_list = string_to_list("uri://1, uri://2, uri://3, ")

        # ------------------------------------------------------------------ --

        # check that all uris are blocked

        with freeze_time("2012-01-14 12:00:00"):

            # -------------------------------------------------------------- --

            # block all uris

            for uri in next(res_sched):
                res_sched.block(uri, delay=30)

            # -------------------------------------------------------------- --

            # verify that all uris are blocked and none is iterated

            uris = []
            for uri in next(res_sched):
                uris.append(uri)

            assert len(uris) == 0

        # one minute later
        with freeze_time("2012-01-14 12:01:00"):

            # -------------------------------------------------------------- --

            # verify that all uris are un blocked after the delay

            uris = []
            for uri in next(res_sched):
                uris.append(uri)

            assert "uri://1" in uris
            assert "uri://2" in uris
            assert "uri://3" in uris

        return
Exemple #3
0
    def test_uris_retry(self):
        """
        test all uris will be n-times tried
        """

        # -------------------------------------------------------------- --

        # setup a local registry for the test

        DictResourceRegistry.registry = {}

        # -------------------------------------------------------------- --

        # setup the Resource Scheduler

        res_sched = ResourceScheduler(
            tries=3, resource_registry_class=DictResourceRegistry)

        res_sched.uri_list = string_to_list(
            "bluri://1, bluri://2, bluri://3, ")

        # -------------------------------------------------------------- --

        # check that the retry will be run through all uris n-times

        uris = []
        for uri in next(res_sched):
            uris.append(uri)

        assert len(uris) == 9

        # -------------------------------------------------------------- --

        # check that every uri is registered in the global registry

        for _key, val in list(res_sched.resource_registry.registry.items()):
            value, b_ind, b_count = val

            assert value is None
            assert b_ind == 0
            assert b_count == 0

        return
Exemple #4
0
    def test_uris_retry(self):
        """
        test all uris will be n-times tried
        """

        # -------------------------------------------------------------- --

        # setup a local registry for the test

        DictResourceRegistry.registry = {}

        # -------------------------------------------------------------- --

        # setup the Resource Scheduler

        res_sched = ResourceScheduler(
                            tries=3,
                            resource_registry_class=DictResourceRegistry)

        res_sched.uri_list = string_to_list("bluri://1, bluri://2, bluri://3, ")

        # -------------------------------------------------------------- --

        # check that the retry will be run through all uris n-times

        uris = []
        for uri in res_sched.next():
            uris.append(uri)

        self.assertTrue(len(uris) == 9)

        # -------------------------------------------------------------- --

        # check that every uri is registered in the global registry

        for _key, val in res_sched.resource_registry.registry.items():
            value, b_ind, b_count = val

            self.assertTrue(value is None)
            self.assertTrue(b_ind == 0 )
            self.assertTrue(b_count == 0)

        return
Exemple #5
0
    def test_uris_retry(self):
        """
        test all uris will be n-times tried
        """

        # -------------------------------------------------------------- --

        # setup a local registry for the test

        DictResourceRegistry.registry = {}

        # -------------------------------------------------------------- --

        # setup the Resource Scheduler

        res_sched = ResourceScheduler(
            tries=3, resource_registry_class=DictResourceRegistry)

        res_sched.uri_list = string_to_list(
            "bluri://1, bluri://2, bluri://3, ")

        # -------------------------------------------------------------- --

        # check that the retry will be run through all uris n-times

        uris = []
        for uri in res_sched.next():
            uris.append(uri)

        self.assertTrue(len(uris) == 9)

        # -------------------------------------------------------------- --

        # check that every uri is registered in the global registry

        for _key, value in res_sched.resource_registry.registry.items():
            self.assertTrue(value is None)

        return
Exemple #6
0
    def test_blocking_counter(self):
        """
        test that if for one entry the blocking counter increments at max of 8

        run a connection timeout simulation by rising an exception for a
        special uri - we have to run many more times as the blocking url
        is not involved in every run. Thus we count the number when it is
        involved and terminate after 10 calls. THe max though should be t 8.
        """

        # -------------------------------------------------------------- --

        # setup a local registry for the test

        DictResourceRegistry.registry = {}

        # -------------------------------------------------------------- --

        # setup the Resource Scheduler

        res_sched = ResourceScheduler(
            tries=1, resource_registry_class=DictResourceRegistry)

        res_sched.uri_list = string_to_list(
            "bluri://1, bluri://2, bluri://3, ")

        the_blocked_one = res_sched.uri_list[1]

        # -------------------------------------------------------------- --

        # run the loop

        raise_counter = 0
        i = 0

        while raise_counter < 10:
            i += 1
            with freeze_time(datetime.datetime.utcnow() +
                             datetime.timedelta(minutes=i)):

                try:
                    for uri in next(res_sched):

                        if uri == the_blocked_one:
                            raise DummyException()

                except DummyException:
                    raise_counter += 1
                    res_sched.block(the_blocked_one, 30, immediately=True)

        # -------------------------------------------------------------- --

        # check the result

        for key, val in list(res_sched.resource_registry.registry.items()):
            value, b_ind, b_count = val
            if b_ind == 1:
                assert value is not None
                assert key == the_blocked_one
                assert b_count == 8

            else:
                assert value is None
                assert b_count == 0
                assert b_ind == 0

        return
Exemple #7
0
    def test_blocking_one_uri(self):
        """
        test that if one entry is blocked it will not be in the iteration list
        """

        # -------------------------------------------------------------- --

        # setup a local registry for the test

        DictResourceRegistry.registry = {}

        # -------------------------------------------------------------- --

        # setup the Resource Scheduler

        res_sched = ResourceScheduler(
            tries=3, resource_registry_class=DictResourceRegistry)

        res_sched.uri_list = string_to_list(
            "bluri://1, bluri://2, bluri://3, ")

        the_blocked_one = res_sched.uri_list[1]

        with freeze_time("2012-01-14 12:00:00"):

            # -------------------------------------------------------------- --

            # block the second entry

            res_sched.block(the_blocked_one, 30, immediately=True)

            # -------------------------------------------------------------- --

            # verify that the second entry will not be iterated

            uris = []
            for uri in next(res_sched):
                uris.append(uri)

            assert the_blocked_one not in uris

            # -------------------------------------------------------------- --

            # verify that the retry is done 3 times for the other two

            assert len(uris) == 6

            # -------------------------------------------------------------- --

            # verify that the blocked one is marked as blocked in the registry

            for key, val in list(res_sched.resource_registry.registry.items()):
                value, b_ind, b_count = val

                if key == the_blocked_one:
                    assert value is not None
                    assert b_ind == 1
                    assert b_count == 0

                else:
                    assert value is None

        # one minute later

        with freeze_time("2012-01-14 12:01:00"):

            uris = []
            for uri in next(res_sched):
                uris.append(uri)

            # -------------------------------------------------------------- --

            # verify that the former blocked one is now not more blocked

            assert the_blocked_one in uris

            # -------------------------------------------------------------- --

            # verify that the former blocked one is as well unblocked in the
            # registry

            for _key, val in list(
                    res_sched.resource_registry.registry.items()):
                value, _b_ind, _b_count = val
                assert value is None

        return
Exemple #8
0
    def test_blocking_counter(self):
        """
        test that if for one entry the blocking counter increments at max of 8

        run a connection timeout simulation by rising an exception for a
        special uri - we have to run many more times as the blocking url
        is not involved in every run. Thus we count the number when it is
        involved and terminate after 10 calls. THe max though should be t 8.
        """

        # -------------------------------------------------------------- --

        # setup a local registry for the test

        DictResourceRegistry.registry = {}

        # -------------------------------------------------------------- --

        # setup the Resource Scheduler

        res_sched = ResourceScheduler(
            tries=1, resource_registry_class=DictResourceRegistry)

        res_sched.uri_list = string_to_list(
            "bluri://1, bluri://2, bluri://3, ")

        the_blocked_one = res_sched.uri_list[1]

        # -------------------------------------------------------------- --

        # run the loop

        raise_counter = 0
        i = 0

        while raise_counter < 10:
            i += 1
            with freeze_time(
                datetime.datetime.utcnow() + datetime.timedelta(minutes=i)):

                try:
                    for uri in res_sched.next():

                        if uri == the_blocked_one:
                            raise DummyException()

                except DummyException:
                    raise_counter += 1
                    res_sched.block(the_blocked_one, 30, immediately=True)

        # -------------------------------------------------------------- --

        # check the result

        for key, val in res_sched.resource_registry.registry.items():
            value, b_ind, b_count = val
            if b_ind == 1:
                assert value is not None
                assert key == the_blocked_one
                assert b_count == 8

            else:
                assert value is None
                assert b_count == 0
                assert b_ind == 0

        return
Exemple #9
0
    def test_blocking_one_uri(self):
        """
        test that if one entry is blocked it will not be in the iteration list
        """

        # -------------------------------------------------------------- --

        # setup a local registry for the test

        DictResourceRegistry.registry = {}

        # -------------------------------------------------------------- --

        # setup the Resource Scheduler

        res_sched = ResourceScheduler(
                            tries=3,
                            resource_registry_class=DictResourceRegistry)

        res_sched.uri_list = string_to_list("bluri://1, bluri://2, bluri://3, ")

        the_blocked_one = res_sched.uri_list[1]

        with freeze_time("2012-01-14 12:00:00"):

            # -------------------------------------------------------------- --

            # block the second entry

            res_sched.block(the_blocked_one, 30, immediately=True)

            # -------------------------------------------------------------- --

            # verify that the second entry will not be iterated

            uris = []
            for uri in res_sched.next():
                uris.append(uri)

            self.assertTrue(the_blocked_one not in uris)

            # -------------------------------------------------------------- --

            # verify that the retry is done 3 times for the other two

            self.assertTrue(len(uris) == 6)

            # -------------------------------------------------------------- --

            # verify that the blocked one is marked as blocked in the registry

            for key, val in res_sched.resource_registry.registry.items():
                value, b_ind, b_count = val

                if key == the_blocked_one:
                    self.assertTrue(value is not None)
                    self.assertTrue(b_ind == 1)
                    self.assertTrue(b_count == 0)

                else:
                    self.assertTrue(value is None)

        # one minute later

        with freeze_time("2012-01-14 12:01:00"):

            uris = []
            for uri in res_sched.next():
                uris.append(uri)

            # -------------------------------------------------------------- --

            # verify that the former blocked one is now not more blocked

            self.assertTrue(the_blocked_one in uris)

            # -------------------------------------------------------------- --

            # verify that the former blocked one is as well unblocked in the
            # registry

            for _key, val in res_sched.resource_registry.registry.items():
                value, _b_ind, _b_count = val
                self.assertTrue(value is None)

        return