Пример #1
0
    def test_wait_for_page_in(self):
        """Test to make sure waiting for all the keys to be paged in works properly"""
        # Create test instance
        csdb1 = CacheStateDB(self.config_data)
        csdb2 = CacheStateDB(self.config_data)

        # Create page in channel in the first instance
        ch = csdb1.create_page_in_channel()

        # Publish a message
        csdb2.notify_page_in_complete(ch, "MY_TEST_KEY1")
        csdb2.notify_page_in_complete(ch, "MY_TEST_KEY2")

        # Wait for page in
        csdb1.wait_for_page_in(["MY_TEST_KEY1", "MY_TEST_KEY2"], ch, 5)
Пример #2
0
    def test_remove_from_page_out(self):
        """Test removing a cube from the page out list"""
        csdb = CacheStateDB(self.config_data)

        temp_page_out_key = "temp"
        lookup_key = "1&2&3"
        resolution = 4
        morton = 1000
        time_sample = 5

        page_out_key = "PAGE-OUT&{}&{}".format(lookup_key, resolution)
        assert not self.state_client.get(page_out_key)

        assert not csdb.in_page_out(temp_page_out_key, lookup_key, resolution,
                                    morton, time_sample)

        in_page_out = csdb.add_to_page_out(temp_page_out_key, lookup_key,
                                           resolution, morton, time_sample)
        assert not in_page_out

        assert csdb.in_page_out(temp_page_out_key, lookup_key, resolution,
                                morton, time_sample)

        # Fake the write-cuboid key
        csdb.remove_from_page_out(
            "WRITE-CUBOID&{}&{}&{}&{}&adsf34adsf49sdfj".format(
                lookup_key, resolution, time_sample, morton))
        assert not csdb.in_page_out(temp_page_out_key, lookup_key, resolution,
                                    morton, time_sample)
Пример #3
0
    def test_add_to_delayed_write(self):
        """Test if a cube is in delayed write"""
        csdb = CacheStateDB(self.config_data)

        lookup_key = "1&2&3"
        resolution = 4
        time_sample = 5
        morton = 66
        write_cuboid_key1 = "WRITE-CUBOID&{}&{}&{}&{}&daadsfjk".format(
            lookup_key, resolution, time_sample, morton)
        write_cuboid_key2 = "WRITE-CUBOID&{}&{}&{}&{}&fghfghjg".format(
            lookup_key, resolution, time_sample, morton)

        keys = csdb.get_all_delayed_write_keys()
        assert not keys

        csdb.add_to_delayed_write(write_cuboid_key1, lookup_key, resolution,
                                  morton, time_sample, "{dummy resource str}")
        csdb.add_to_delayed_write(write_cuboid_key2, lookup_key, resolution,
                                  morton, time_sample, "{dummy resource str}")

        keys = csdb.get_all_delayed_write_keys()
        assert len(keys) == 1
        assert keys[0] == "DELAYED-WRITE&{}&{}&{}&{}".format(
            lookup_key, resolution, time_sample, morton)

        write_keys = csdb.get_delayed_writes(keys[0])
        assert len(write_keys) == 2
        assert write_keys[0] == write_cuboid_key1
        assert write_keys[1] == write_cuboid_key2
Пример #4
0
    def test_wait_for_page_in_timeout(self):
        """Test to make sure page in timeout works properly"""
        start_time = datetime.now()
        with self.assertRaises(SpdbError):
            csdb = CacheStateDB(self.config_data)
            ch = csdb.create_page_in_channel()

            csdb.wait_for_page_in(["MY_TEST_KEY1", "MY_TEST_KEY2"], ch, 1)

        assert (datetime.now() - start_time).seconds < 3
Пример #5
0
    def test_add_cache_misses(self):
        """Test if cache cuboid keys are formatted properly"""
        csdb = CacheStateDB(self.config_data)
        assert not self.state_client.get("CACHE-MISS")

        keys = ['key1', 'key2', 'key3']

        csdb.add_cache_misses(keys)

        for k in keys:
            assert k == self.state_client.lpop("CACHE-MISS").decode()
Пример #6
0
    def test_project_locked(self):
        """Test if a channel/layer is locked"""
        csdb = CacheStateDB(self.config_data)

        assert csdb.project_locked("1&1&1") == False

        csdb.set_project_lock("1&1&1", True)

        assert csdb.project_locked("1&1&1") == True

        csdb.set_project_lock("1&1&1", False)

        assert csdb.project_locked("1&1&1") == False
Пример #7
0
    def test_get_single_delayed_write_cuboid_key(self):
        """Test getting all delayed write cuboid keys"""
        csdb = CacheStateDB(self.config_data)

        lookup_key = "1&2&3"
        resolution = 4
        time_sample = 5
        morton = 234
        write_cuboid_key1 = "WRITE-CUBOID&{}&{}&{}{}&&daadsfjk".format(lookup_key,
                                                                       resolution,
                                                                       time_sample,
                                                                       morton)
        write_cuboid_key2 = "WRITE-CUBOID&{}&{}&{}&{}&fghfghjg".format(lookup_key,
                                                                       resolution,
                                                                       time_sample,
                                                                       morton)
        write_cuboid_key3 = "WRITE-CUBOID&{}&{}&{}&{}&aaauihjg".format(lookup_key,
                                                                       resolution,
                                                                       time_sample,
                                                                       morton)

        delayed_write_key = "DELAYED-WRITE&{}&{}&{}&{}".format(lookup_key,
                                                              resolution,
                                                              time_sample,
                                                              morton)

        key = csdb.check_single_delayed_write(delayed_write_key)
        assert not key

        csdb.add_to_delayed_write(write_cuboid_key1, lookup_key, resolution, morton, time_sample, "{dummy resource str}")
        csdb.add_to_delayed_write(write_cuboid_key2, lookup_key, resolution, morton, time_sample, "{dummy resource str}")
        csdb.add_to_delayed_write(write_cuboid_key3, lookup_key, resolution, morton, time_sample, "{dummy resource str}")
        csdb.add_to_delayed_write(write_cuboid_key3, lookup_key, resolution, morton, 67, "{dummy resource str4}")

        key = csdb.check_single_delayed_write(delayed_write_key)
        assert key == write_cuboid_key1

        key = csdb.check_single_delayed_write(delayed_write_key)
        assert key == write_cuboid_key1

        key, resource = csdb.get_single_delayed_write(delayed_write_key)
        assert key == write_cuboid_key1
        assert resource == "{dummy resource str}"

        key, resource = csdb.get_single_delayed_write(delayed_write_key)
        assert key == write_cuboid_key2
        assert resource == "{dummy resource str}"

        key, resource = csdb.get_single_delayed_write(delayed_write_key)
        assert key == write_cuboid_key3
        assert resource == "{dummy resource str}"
Пример #8
0
    def test_page_in_channel(self):
        """Test Page in channel creation and basic message passing"""
        # Create test instance
        csdb1 = CacheStateDB(self.config_data)
        csdb2 = CacheStateDB(self.config_data)

        # Create page in channel in the first instance
        ch = csdb1.create_page_in_channel()
        time.sleep(1.5)

        # Publish a message
        csdb2.notify_page_in_complete(ch, "MY_TEST_KEY")

        # Get message (ignore first message which is the subscribe)
        while True:
            msg = csdb1.status_client_listener.get_message()
            if not msg:
                continue
            if msg['type'] == "message":
                break

        assert msg['channel'].decode() == ch
        assert msg['data'].decode() == "MY_TEST_KEY"
Пример #9
0
    def test_add_to_page_out(self):
        """Test if a cube is in page out"""
        csdb = CacheStateDB(self.config_data)

        temp_page_out_key = "temp"
        lookup_key = "1&1&1"
        resolution = 1
        morton = 234
        time_sample = 1

        page_out_key = "PAGE-OUT&{}&{}".format(lookup_key, resolution)
        assert not self.state_client.get(page_out_key)

        assert not csdb.in_page_out(temp_page_out_key, lookup_key, resolution, morton, time_sample)

        in_page_out = csdb.add_to_page_out(temp_page_out_key, lookup_key, resolution, morton, time_sample)
        assert not in_page_out

        assert csdb.in_page_out(temp_page_out_key, lookup_key, resolution, morton, time_sample)