예제 #1
0
    def test_get_chunkname_list_from_chunk_table(self):
        """Test if the helper to get a list of chunknames works"""
        self.chunkLayer.start_process()

        n1 = Name("/test/data")
        n2 = Name("/data/test")
        rte1 = RequestTableEntry(n1)
        rte2 = RequestTableEntry(n2)

        rte1.requested_chunks = [
            Name("/test/data/c0"),
            Name("/test/data/c1"),
            Name("/test/data/c2")
        ]
        rte2.requested_chunks = [
            Name("/data/test/c0"),
            Name("/data/test/c1"),
            Name("/data/test/c2")
        ]

        self.chunkLayer._request_table.append(rte1)
        self.chunkLayer._request_table.append(rte2)

        c1 = Content("/test/data/c0", "tdc0")
        c2 = Content("/test/data/c1", "tdc1")
        c3 = Content("/test/data/c2", "tdc2")

        c4 = Content("/data/test/c0", "dtc0")
        c5 = Content("/data/test/c1", "dtc1")
        c6 = Content("/data/test/c2", "dtc2")

        self.chunkLayer._chunk_table[c1.name] = (c1, time.time())
        self.chunkLayer._chunk_table[c2.name] = (c2, time.time())
        self.chunkLayer._chunk_table[c3.name] = (c3, time.time())

        self.chunkLayer._chunk_table[c4.name] = (c4, time.time())
        self.chunkLayer._chunk_table[c5.name] = (c5, time.time())
        self.chunkLayer._chunk_table[c6.name] = (c6, time.time())

        chunks1 = self.chunkLayer.get_chunk_list_from_chunk_table(
            rte1.requested_chunks)
        chunks2 = self.chunkLayer.get_chunk_list_from_chunk_table(
            rte2.requested_chunks)

        compdata1 = [c1, c2, c3]
        compdata2 = [c4, c5, c6]

        for i in range(0, 3):
            self.assertEqual(chunks1[i], compdata1[i])
            self.assertEqual(chunks2[i], compdata2[i])
예제 #2
0
    def test_chunk_name_in_chunk_table(self):
        """Test the chunk requeted and remove"""
        self.chunkLayer.start_process()

        n1 = Name("/test/data")
        n2 = Name("/data/test")

        rte1 = RequestTableEntry(n1)
        rte2 = RequestTableEntry(n2)

        rte1.requested_chunks = [
            Name("/test/data/c0"),
            Name("/test/data/c1"),
            Name("/test/data/c2")
        ]
        rte2.requested_chunks = [
            Name("/data/test/c0"),
            Name("/data/test/c1"),
            Name("/data/test/c2")
        ]

        self.chunkLayer._request_table.append(rte1)
        self.chunkLayer._request_table.append(rte2)

        entry1 = self.chunkLayer.chunk_name_in_request_table(
            Name("/test/data/c1"))
        entry2 = self.chunkLayer.chunk_name_in_request_table(
            Name("/test/data/c4"))
        entry3 = self.chunkLayer.chunk_name_in_request_table(
            Name("/data/test/c2"))

        self.assertTrue(entry1)
        self.assertFalse(entry2)
        self.assertTrue(entry3)
        rt_entry = self.chunkLayer.get_request_table_entry(
            Name("/test/data/c1"))
        self.chunkLayer._request_table.remove(rt_entry)
        rt_entry = self.chunkLayer.remove_chunk_name_from_request_table_entry(
            rt_entry, Name("/test/data/c1"))
        self.chunkLayer._request_table.append(rt_entry)

        entry4 = self.chunkLayer.chunk_name_in_request_table(
            Name("/test/data/c1"))
        self.assertFalse(entry4)