~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_knit.py

  • Committer: Robert Collins
  • Date: 2008-04-08 21:41:15 UTC
  • mto: This revision was merged to the branch mainline in revision 3350.
  • Revision ID: robertc@robertcollins.net-20080408214115-qiz6rr5kyt5mxsyi
 * ``VersionedFile.clear_cache`` and ``enable_cache`` are deprecated.
   These methods added significant complexity to the ``VersionedFile``
   implementation, but were only used for optimising fetches from knits - 
   which can be done from outside the knit layer, or via a caching
   decorator. As knits are not the default format, the complexity is no
   longer worth paying. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1204
1204
        """Store in knit with parents"""
1205
1205
        k = self.make_test_knit(annotate=False)
1206
1206
        self.add_stock_one_and_one_a(k)
1207
 
        k.clear_cache()
1208
1207
        self.assertEqualDiff(''.join(k.get_lines('text-1a')), TEXT_1A)
1209
1208
 
1210
1209
    def test_add_delta_knit_graph_index(self):
1214
1213
            deltas=True)
1215
1214
        k = self.make_test_knit(annotate=True, index=knit_index)
1216
1215
        self.add_stock_one_and_one_a(k)
1217
 
        k.clear_cache()
1218
1216
        self.assertEqualDiff(''.join(k.get_lines('text-1a')), TEXT_1A)
1219
1217
        # check the index had the right data added.
1220
1218
        self.assertEqual(set([
1397
1395
        # add texts with no required ordering
1398
1396
        k1.add_lines('base', [], ['text\n'])
1399
1397
        k1.add_lines('base2', [], ['text2\n'])
1400
 
        k1.clear_cache()
1401
1398
        # clear the logged activity, but preserve the list instance in case of
1402
1399
        # clones pointing at it.
1403
1400
        del instrumented_t._activity[:]
2031
2028
        self.failIf(WeaveToKnit.is_compatible(k, k))
2032
2029
 
2033
2030
 
2034
 
class TestKnitCaching(KnitTests):
2035
 
    
2036
 
    def create_knit(self):
2037
 
        k = self.make_test_knit(True)
2038
 
        k.add_lines('text-1', [], split_lines(TEXT_1))
2039
 
        k.add_lines('text-2', [], split_lines(TEXT_2))
2040
 
        return k
2041
 
 
2042
 
    def test_no_caching(self):
2043
 
        k = self.create_knit()
2044
 
        # Nothing should be cached without setting 'enable_cache'
2045
 
        self.assertEqual({}, k._data._cache)
2046
 
 
2047
 
    def test_cache_data_read_raw(self):
2048
 
        k = self.create_knit()
2049
 
 
2050
 
        # Now cache and read
2051
 
        k.enable_cache()
2052
 
 
2053
 
        def read_one_raw(version):
2054
 
            pos_map = k._get_components_positions([version])
2055
 
            method, index_memo, next = pos_map[version]
2056
 
            lst = list(k._data.read_records_iter_raw([(version, index_memo)]))
2057
 
            self.assertEqual(1, len(lst))
2058
 
            return lst[0]
2059
 
 
2060
 
        val = read_one_raw('text-1')
2061
 
        self.assertEqual({'text-1':val[1]}, k._data._cache)
2062
 
 
2063
 
        k.clear_cache()
2064
 
        # After clear, new reads are not cached
2065
 
        self.assertEqual({}, k._data._cache)
2066
 
 
2067
 
        val2 = read_one_raw('text-1')
2068
 
        self.assertEqual(val, val2)
2069
 
        self.assertEqual({}, k._data._cache)
2070
 
 
2071
 
    def test_cache_data_read(self):
2072
 
        k = self.create_knit()
2073
 
 
2074
 
        def read_one(version):
2075
 
            pos_map = k._get_components_positions([version])
2076
 
            method, index_memo, next = pos_map[version]
2077
 
            lst = list(k._data.read_records_iter([(version, index_memo)]))
2078
 
            self.assertEqual(1, len(lst))
2079
 
            return lst[0]
2080
 
 
2081
 
        # Now cache and read
2082
 
        k.enable_cache()
2083
 
 
2084
 
        val = read_one('text-2')
2085
 
        self.assertEqual(['text-2'], k._data._cache.keys())
2086
 
        self.assertEqual('text-2', val[0])
2087
 
        content, digest = k._data._parse_record('text-2',
2088
 
                                                k._data._cache['text-2'])
2089
 
        self.assertEqual(content, val[1])
2090
 
        self.assertEqual(digest, val[2])
2091
 
 
2092
 
        k.clear_cache()
2093
 
        self.assertEqual({}, k._data._cache)
2094
 
 
2095
 
        val2 = read_one('text-2')
2096
 
        self.assertEqual(val, val2)
2097
 
        self.assertEqual({}, k._data._cache)
2098
 
 
2099
 
    def test_cache_read(self):
2100
 
        k = self.create_knit()
2101
 
        k.enable_cache()
2102
 
 
2103
 
        text = k.get_text('text-1')
2104
 
        self.assertEqual(TEXT_1, text)
2105
 
        self.assertEqual(['text-1'], k._data._cache.keys())
2106
 
 
2107
 
        k.clear_cache()
2108
 
        self.assertEqual({}, k._data._cache)
2109
 
 
2110
 
        text = k.get_text('text-1')
2111
 
        self.assertEqual(TEXT_1, text)
2112
 
        self.assertEqual({}, k._data._cache)
2113
 
 
2114
 
 
2115
2031
class TestKnitIndex(KnitTests):
2116
2032
 
2117
2033
    def test_add_versions_dictionary_compresses(self):