Beispiel #1
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
Beispiel #2
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
Beispiel #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
Beispiel #4
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()
Beispiel #5
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)
Beispiel #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
Beispiel #7
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)
Beispiel #8
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)
Beispiel #9
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"
Beispiel #10
0
    def test_get_all_delayed_write_cuboid_keys(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)

        keys = csdb.get_delayed_writes(delayed_write_key)
        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}")
        csdb.add_to_delayed_write(write_cuboid_key3, lookup_key, resolution, morton, time_sample, "{dummy resource str}")

        keys = csdb.get_delayed_writes(delayed_write_key)
        assert len(keys) == 3
        assert keys[0] == write_cuboid_key1
        assert keys[1] == write_cuboid_key2
        assert keys[2] == write_cuboid_key3

        keys = csdb.get_delayed_writes(delayed_write_key)
        assert not keys
Beispiel #11
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)
Beispiel #12
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"