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)
Example #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)
Example #3
0
    def is_compatible(self, other):
        '''check if compatible with other Hypothesis object'''
        if self.invalid or other.invalid:
            return False
        graph_collision = self.block_closure.collision(other.block_closure)
        if not graph_collision:
            return True

        c1 = self.closure
        c2 = other.closure

        build_compatibility_closure(self._ref_translator, c1, graph_collision.nodes, self.block_closure)
        build_compatibility_closure(self._ref_translator, c2, graph_collision.nodes, other.block_closure)
        return c1.conflicts(c2) == 0
Example #4
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)
Example #5
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)
    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)
Example #7
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)
Example #8
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)
Example #9
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_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)