Beispiel #1
0
    def test_interface(self):
        cell_id1 = ID((0, 0, 0))
        content_id1 = ID((0, 0, 0))
        cell_id2 = ID((0, 1, 0))
        content_id2 = ID((0, 1, 0))
        brl0 = BRLBlock('user/user/block/master')
        brl1 = BRLBlock('user/user/block2/master')
        v0 = BlockVersion(brl0, 0)
        v1 = BlockVersion(brl0, 1)
        v2 = BlockVersion(brl1, 0)

        c1 = CompatibilityClosure()
        c1.add_item((cell_id1, content_id1),  cell_id1, v0, 'file1')
        self.assertEqual("{0:0:0: ((0:0:0, 0:0:0), user/block: 0, 'file1')}", str(c1))

        # adding a compatible item is no problem
        c1.add_item((cell_id1, content_id1),  cell_id1, v1, 'file1')
        self.assertEqual("{0:0:0: ((0:0:0, 0:0:0), user/block: 1, 'file1')}", str(c1))

        c1.add_item((cell_id2, content_id2),  cell_id2, v2, 'file2')
        self.assertIn("0:0:0: ((0:0:0, 0:0:0), user/block: 1, 'file1')", str(c1))
        self.assertIn("0:1:0: ((0:1:0, 0:1:0), user/block2: 0, 'file2')", str(c1))

        self.assertEqual({v0.block_name + 'file1', v2.block_name + 'file2'}, c1.block_cell_names)

        refs = References()
        refs[v1].add('file1')
        refs[v2].add('file2')
        self.assertEqual(refs, c1.references)
Beispiel #2
0
    def test_basic(self):
        store = TestingMemServerStore()
        brl_user = '******'
        store.create_user(User(brl_user))
        brl_block = BRLBlock('user/user/block/master')
        publisher = TestPublisher(brl_user, store)
        publisher.publish(
            brl_block, {
                'r1.h': ('r1', ['user/block/r2.h']),
                'r2.h': ('r2', []),
                'r3.h': ('r3', [])
            })

        store = MemServerStore(store)
        translator = ReferenceTranslatorService(store, brl_user)
        ver = BlockVersion(brl_block, 0)
        missing = References()
        missing[ver].add('r1.h')
        closure = CompatibilityClosure(missing)
        full_graph = BlockVersionGraph()
        full_graph.add_nodes([ver])
        build_compatibility_closure(translator, closure, {ver}, full_graph)
        self.assertEqual(References(), closure.broken)

        expected = set()
        expected.add('user/block/r1.h')
        expected.add('user/block/r2.h')
        self.assertEqual(expected, closure.block_cell_names)
Beispiel #3
0
 def closure(self):  # Lazy computation of closures
     if self._closure is None:
         missing = References()
         for targets in self.dep_dict.values():
             for target in targets:
                 missing[self.block_version].add(target.cell_name)
         self._closure = CompatibilityClosure(missing)
     return self._closure
Beispiel #4
0
    def test_incompatible(self):
        c1 = CompatibilityClosure()
        c2 = CompatibilityClosure()

        brl0 = BRLBlock('user/user/block/master')
        v0 = BlockVersion(brl0, 0)
        v1 = BlockVersion(brl0, 1)

        cell_id1 = ID((0, 0, 0))
        cell_id2 = ID((0, 0, 1))

        content_id1 = ID((0, 0, 0))

        c1.add_item((cell_id1, content_id1),  cell_id1, v0, 'file1')
        c2.add_item((cell_id2, content_id1),  cell_id1, v1, 'file1')
        self.assertEqual(1, c1.conflicts(c2))
        self.assertEqual(1, c2.conflicts(c1))
    def test_interface(self):
        cell_id1 = ID((0, 0, 0))
        content_id1 = ID((0, 0, 0))
        cell_id2 = ID((0, 1, 0))
        content_id2 = ID((0, 1, 0))
        brl0 = BRLBlock("user/user/block/master")
        brl1 = BRLBlock("user/user/block2/master")
        v0 = BlockVersion(brl0, 0)
        v1 = BlockVersion(brl0, 1)
        v2 = BlockVersion(brl1, 0)

        c1 = CompatibilityClosure()
        c1.add_item((cell_id1, content_id1), cell_id1, v0, "file1")
        self.assertEqual("{0:0:0: ((0:0:0, 0:0:0), user/block: 0, 'file1')}", str(c1))

        # adding a compatible item is no problem
        c1.add_item((cell_id1, content_id1), cell_id1, v1, "file1")
        self.assertEqual("{0:0:0: ((0:0:0, 0:0:0), user/block: 1, 'file1')}", str(c1))

        c1.add_item((cell_id2, content_id2), cell_id2, v2, "file2")
        self.assertIn("0:0:0: ((0:0:0, 0:0:0), user/block: 1, 'file1')", str(c1))
        self.assertIn("0:1:0: ((0:1:0, 0:1:0), user/block2: 0, 'file2')", str(c1))

        self.assertEqual({v0.block_name + "file1", v2.block_name + "file2"}, c1.block_cell_names)

        refs = References()
        refs[v1].add("file1")
        refs[v2].add("file2")
        self.assertEqual(refs, c1.references)
    def test_incompatible(self):
        c1 = CompatibilityClosure()
        c2 = CompatibilityClosure()

        brl0 = BRLBlock("user/user/block/master")
        v0 = BlockVersion(brl0, 0)
        v1 = BlockVersion(brl0, 1)

        cell_id1 = ID((0, 0, 0))
        cell_id2 = ID((0, 0, 1))

        content_id1 = ID((0, 0, 0))

        c1.add_item((cell_id1, content_id1), cell_id1, v0, "file1")
        c2.add_item((cell_id2, content_id1), cell_id1, v1, "file1")
        self.assertEqual(1, c1.conflicts(c2))
        self.assertEqual(1, c2.conflicts(c1))
Beispiel #7
0
    def test_performance_breadth(self):
        store = MongoServerStore(self.conn, self.__class__.__name__)
        store.create_user(User("user2"))
        publisher = TestPublisher("user2", store)
        brl_block = BRLBlock('user2/user2/block/master')

        count = 1000
        resource_info = {}
        for i in xrange(count):
            deps = DependencySet()
            if i > 0:
                deps = DependencySet()
                for j in range(max(0, i - 25), i):
                    deps.explicit.add(BlockCellName('user2/block/cell%d.h' %
                                                    j))
                    deps.resolved.add(
                        CPPDeclaration('user2/block/cell%d.h' % j))
                deps.unresolved.add(CPPDeclaration('path/to/file.h'))
                deps.implicit.add(BlockCellName('user2/block/cell%d.h' % j))
            resource_info['cell%d.h' % i] = 'content %d' % i, deps
        publisher.publish(brl_block, resource_info)

        timer = self.get_timer()
        start_time = timer()

        store = MemServerStore(store)
        #print 'MEMSTORE SIZE 0', asizeof(store) / 1000000.0

        translator = ReferenceTranslatorService(store, "user2")
        version = BlockVersion(brl_block, 0)
        missing = References()
        missing[version].add('cell%d.h' % (count - 1))
        closure = CompatibilityClosure(missing)
        full_graph = BlockVersionGraph()
        full_graph.add_nodes([version])
        build_compatibility_closure(translator, closure, [version], full_graph)

        elapsed_time = timer() - start_time
        #print 'Closure time', elapsed_time

        #print 'CLOSURE SIZE ', asizeof(closure) / 1000000.0
        #print 'MEMSTORE SIZE ', asizeof(store) / 1000000.0
        # print 'MINCELLS SIZE ', asizeof(store.min_cells)/1000000.0

        self.assertEqual({brl_block.block_name + c
                          for c in resource_info}, closure.block_cell_names)
        self.assertLess(elapsed_time, 7)
Beispiel #8
0
    def test_build_closure_different_versions_restricted(self):
        '''Computes a CompatibilityClosure in which two versions of blockA actually point to the
        same unmodified resource with the typical diamond layout
        Also computes and checks the BlockClosure for that layout'''
        ref_translator = Mock()

        depA1 = BlockVersion(BRLBlock('user/user/blockA/branch'), 4)
        depA2 = BlockVersion(BRLBlock('user/user/blockA/branch'), 5)
        baseB = BlockVersion(BRLBlock('user/user/blockB/branch'), 2)
        baseC = BlockVersion(BRLBlock('user/user/blockC/branch'), 3)

        full_graph = BlockVersionGraph()
        full_graph.add_nodes([baseB, baseC, depA1, depA2])
        full_graph.add_edge(baseB, depA1)
        full_graph.add_edge(baseC, depA2)

        def res_method(*args):
            depsb = [BlockCellName('user/blockA/a.h')]
            depsc = [BlockCellName('user/blockA/a.h')]
            result = ReferencedResources()
            for ref in args[0].explode():
                result[ref.block_version][ref.ref] = \
                {Reference(depA1, 'a.h'): ((0, 0), 0, []),
                 Reference(depA2, 'a.h'): ((0, 0), 0, []),
                 Reference(baseB, 'b.h'): ((1, 4), 1, depsb),
                 Reference(baseC, 'c.h'): ((2, 3), 2, depsc)}[ref]
            return result

        ref_translator.get_published_min_refs.side_effect = res_method

        missing = References()
        missing.add(Reference(baseB, 'b.h'))
        missing.add(Reference(baseC, 'c.h'))
        closure = CompatibilityClosure(missing)
        build_compatibility_closure(ref_translator, closure, {baseC}, full_graph)

        self.assertEqual(References(), closure.broken)
        self.assertEqual({BlockCellName('user/blockC/c.h')}, closure.block_cell_names)
        #self.assertIn(Reference(depA1, 'a.h'), closure.references)
        self.assertNotIn(baseB, closure.references)
        self.assertNotIn(depA1, closure.references)
        self.assertNotIn(depA2, closure.references)
        self.assertIn(baseC, closure.references)
        expected_frontier = References()
        expected_frontier[baseB].add('b.h')
        expected_frontier[depA2].add('a.h')
        self.assertEqual(expected_frontier, closure.frontier)
Beispiel #9
0
    def test_virtual_no_settings(self):
        '''builds a very simple closure in which virtual cells are involved. Maybe it is not very
        useful, as now virtuality is not handled at this level, only at the MemServerStore level,
        so this test might be redundant'''
        ref_translator, depA, depB, baseC, full_graph = self._virtual_setup()

        missing = References()
        missing.add(Reference(baseC, 'c.h'))
        closure = CompatibilityClosure(missing)
        build_compatibility_closure(ref_translator, closure, full_graph.nodes, full_graph)
        self.assertEqual(References(), closure.broken)

        self.assertEqual(set([BlockCellName('user/blockA/a.h'),
                              BlockCellName('user/blockB/b.h'),
                              BlockCellName('user/blockC/c.h'),
                              BlockCellName('user/blockC/win/c.h'),
                              BlockCellName('user/blockC/nix/c.h')]),
                              closure.block_cell_names)
Beispiel #10
0
    def test_broken_closure(self):
        '''computes a closure in which cell blockB/b.h depends on blockA/a.h, but that a.h
        is not found. The algorithms of closures must return that as a missing or broken dependency

        '''
        ref_translator = Mock()
        baseB = BlockVersion(BRLBlock('user/user/blockB/branch'), 2)
        depA1 = BlockVersion(BRLBlock('user/user/blockA/branch'), 4)

        full_graph = BlockVersionGraph()
        full_graph.add_nodes([baseB, depA1])
        full_graph.add_edge(baseB, depA1)

        def res_method(*args):
            depsb = [BlockCellName('user/blockA/a.h')]

            result = ReferencedResources()
            for ref in args[0].explode():
                try:
                    result[ref.block_version][ref.ref] = \
                    {
                     Reference(baseB, 'b.h'): ((0, 0), 0, depsb),
                     }[ref]
                except KeyError:
                    pass
            return result

        ref_translator.get_published_min_refs.side_effect = res_method

        missing = References()
        missing.add(Reference(baseB, 'b.h'))
        closure = CompatibilityClosure(missing)
        build_compatibility_closure(ref_translator, closure, full_graph.nodes, full_graph)

        self.assertEqual({BlockCellName('user/blockB/b.h')}, closure.block_cell_names)
        self.assertIn(baseB, closure.references)

        expected_missing = References()
        expected_missing[depA1].add('a.h')
        self.assertEqual(closure.broken, expected_missing)
Beispiel #11
0
    def test_performance_depth(self):
        brl_user = '******'
        store = MongoServerStore(self.conn, self.__class__.__name__)
        store.create_user(User(brl_user))
        publisher = TestPublisher(brl_user, store)
        brl_block = BRLBlock('user/user/block/master')

        count = 500
        resource_info = {
            'cell%d.h' % i:
            ('content %d' % i, ['user/block/cell%d.h' % (i - 1)] if i else [])
            for i in range(count)
        }
        publisher.publish(brl_block, resource_info)

        timer = self.get_timer()
        start_time = timer()
        # prof = cProfile.Profile()
        # prof.enable()
        store = MemServerStore(store)
        # print 'MEMSTORE DEPTH SIZE 0', asizeof(store) / 1000000.0
        translator = ReferenceTranslatorService(store, brl_user)
        version = BlockVersion(brl_block, 0)
        missing = References()
        missing[version].add('cell%d.h' % (count - 1))
        closure = CompatibilityClosure(missing)
        full_graph = BlockVersionGraph()
        full_graph.add_nodes([version])
        build_compatibility_closure(translator, closure, [version], full_graph)
        self.assertEqual(References(), closure.broken)
        #print 'CLOSURE SIZE ', asizeof(closure) / 1000000.0
        #print 'MEMSTORE SIZE ', asizeof(store) / 1000000.0
        elapsed_time = timer() - start_time
        #print 'Closure time', elapsed_time

        self.assertEqual({brl_block.block_name + c
                          for c in resource_info}, closure.block_cell_names)
        self.assertLess(elapsed_time, 5)
    def test_empty(self):
        """when one is empty, always compatible"""
        c1 = CompatibilityClosure()
        c2 = CompatibilityClosure()
        self.assertEqual(0, c1.conflicts(c2))
        self.assertEqual(0, c2.conflicts(c1))

        brl0 = BRLBlock("user/user/block/master")
        brl1 = BRLBlock("user/user/block2/master")
        v0 = BlockVersion(brl0, 0)
        v2 = BlockVersion(brl1, 0)

        cell_id1 = ID((0, 0, 0))
        cell_id2 = ID((0, 0, 1))

        content_id1 = ID((0, 0, 0))
        content_id2 = ID((0, 0, 1))

        c1.add_item((cell_id1, content_id1), cell_id1, v0, "file1")
        self.assertEqual(0, c1.conflicts(c2))
        self.assertEqual(0, c2.conflicts(c1))

        c1.add_item((cell_id2, content_id2), cell_id2, v2, "file2")
        self.assertEqual(0, c1.conflicts(c2))
        self.assertEqual(0, c2.conflicts(c1))
Beispiel #13
0
    def test_empty(self):
        '''when one is empty, always compatible'''
        c1 = CompatibilityClosure()
        c2 = CompatibilityClosure()
        self.assertEqual(0, c1.conflicts(c2))
        self.assertEqual(0, c2.conflicts(c1))

        brl0 = BRLBlock('user/user/block/master')
        brl1 = BRLBlock('user/user/block2/master')
        v0 = BlockVersion(brl0, 0)
        v2 = BlockVersion(brl1, 0)

        cell_id1 = ID((0, 0, 0))
        cell_id2 = ID((0, 0, 1))

        content_id1 = ID((0, 0, 0))
        content_id2 = ID((0, 0, 1))

        c1.add_item((cell_id1, content_id1),  cell_id1, v0, 'file1')
        self.assertEqual(0, c1.conflicts(c2))
        self.assertEqual(0, c2.conflicts(c1))

        c1.add_item((cell_id2, content_id2),  cell_id2, v2, 'file2')
        self.assertEqual(0, c1.conflicts(c2))
        self.assertEqual(0, c2.conflicts(c1))