예제 #1
0
 def test_find_multiple_cycles_two(self):
     node1 = 'node1'
     node2 = 'node2'
     node3 = 'node3'
     node4 = 'node4'
     node5 = 'node5'
     node6 = 'node6'
     tuples = [  # cycle 1 cycle 2
         (node1, node2),
         (node2, node4),
         (node4, node1),
         (node1, node6),
         (node6, node2),
         (node2, node4),
         (node4, node1),
     ]
     allnodes = set([
         node1,
         node2,
         node3,
         node4,
         node5,
         node6,
     ])
     # node6 only became present here once [ticket:2282] was addressed.
     eq_(topological.find_cycles(tuples, allnodes),
         set(['node1', 'node2', 'node4', 'node6']))
예제 #2
0
 def test_find_multiple_cycles_two(self):
     node1 = 'node1'
     node2 = 'node2'
     node3 = 'node3'
     node4 = 'node4'
     node5 = 'node5'
     node6 = 'node6'
     tuples = [  # cycle 1 cycle 2
         (node1, node2),
         (node2, node4),
         (node4, node1),
         (node1, node6),
         (node6, node2),
         (node2, node4),
         (node4, node1),
         ]
     allnodes = set([
         node1,
         node2,
         node3,
         node4,
         node5,
         node6,
         ])
     # node6 only became present here once [ticket:2282] was addressed.
     eq_(
         topological.find_cycles(tuples, allnodes),
         set(['node1', 'node2', 'node4', 'node6'])
     )
예제 #3
0
 def test_find_multiple_cycles_three(self):
     node1 = 'node1'
     node2 = 'node2'
     node3 = 'node3'
     node4 = 'node4'
     node5 = 'node5'
     node6 = 'node6'
     tuples = [  # cycle 1 cycle 2 cycle3 cycle4
         (node1, node2),
         (node2, node1),
         (node2, node3),
         (node3, node2),
         (node2, node4),
         (node4, node2),
         (node2, node5),
         (node5, node6),
         (node6, node2),
         ]
     allnodes = set([
         node1,
         node2,
         node3,
         node4,
         node5,
         node6,
         ])
     eq_(topological.find_cycles(tuples, allnodes), allnodes)
예제 #4
0
 def test_find_multiple_cycles_three(self):
     node1 = 'node1'
     node2 = 'node2'
     node3 = 'node3'
     node4 = 'node4'
     node5 = 'node5'
     node6 = 'node6'
     tuples = [  # cycle 1 cycle 2 cycle3 cycle4
         (node1, node2),
         (node2, node1),
         (node2, node3),
         (node3, node2),
         (node2, node4),
         (node4, node2),
         (node2, node5),
         (node5, node6),
         (node6, node2),
     ]
     allnodes = set([
         node1,
         node2,
         node3,
         node4,
         node5,
         node6,
     ])
     eq_(topological.find_cycles(tuples, allnodes), allnodes)
예제 #5
0
 def test_find_cycle_one(self):
     node1 = 'node1'
     node2 = 'node2'
     node3 = 'node3'
     node4 = 'node4'
     tuples = [(node1, node2), (node3, node1), (node2, node4),
               (node3, node2), (node2, node3)]
     eq_(topological.find_cycles(tuples,
         self._nodes_from_tuples(tuples)), set([node1, node2, node3]))
예제 #6
0
 def test_find_cycle_one(self):
     node1 = 'node1'
     node2 = 'node2'
     node3 = 'node3'
     node4 = 'node4'
     tuples = [(node1, node2), (node3, node1), (node2, node4),
               (node3, node2), (node2, node3)]
     eq_(topological.find_cycles(tuples, self._nodes_from_tuples(tuples)),
         set([node1, node2, node3]))
 def test_find_multiple_cycles_four(self):
     tuples = [
         ("node6", "node2"),
         ("node15", "node19"),
         ("node19", "node2"),
         ("node4", "node10"),
         ("node15", "node13"),
         ("node17", "node11"),
         ("node1", "node19"),
         ("node15", "node8"),
         ("node6", "node20"),
         ("node14", "node11"),
         ("node6", "node14"),
         ("node11", "node2"),
         ("node10", "node20"),
         ("node1", "node11"),
         ("node20", "node19"),
         ("node4", "node20"),
         ("node15", "node20"),
         ("node9", "node19"),
         ("node11", "node10"),
         ("node11", "node19"),
         ("node13", "node6"),
         ("node3", "node15"),
         ("node9", "node11"),
         ("node4", "node17"),
         ("node2", "node20"),
         ("node19", "node10"),
         ("node8", "node4"),
         ("node11", "node3"),
         ("node6", "node1"),
     ]
     allnodes = ["node%d" % i for i in range(1, 21)]
     eq_(
         topological.find_cycles(tuples, allnodes),
         set(
             [
                 "node11",
                 "node10",
                 "node13",
                 "node15",
                 "node14",
                 "node17",
                 "node19",
                 "node20",
                 "node8",
                 "node1",
                 "node3",
                 "node2",
                 "node4",
                 "node6",
             ]
         ),
     )
예제 #8
0
    def _generate_actions(self):
        """Generate the full, unsorted collection of PostSortRecs as
        well as dependency pairs for this UOWTransaction.

        """
        # execute presort_actions, until all states
        # have been processed.   a presort_action might
        # add new states to the uow.
        while True:
            ret = False
            for action in list(self.presort_actions.values()):
                if action.execute(self):
                    ret = True
            if not ret:
                break

        # see if the graph of mapper dependencies has cycles.
        self.cycles = cycles = topological.find_cycles(
                                        self.dependencies,
                                        self.postsort_actions.values())

        if cycles:
            # if yes, break the per-mapper actions into
            # per-state actions
            convert = dict(
                (rec, set(rec.per_state_flush_actions(self)))
                for rec in cycles
            )

            # rewrite the existing dependencies to point to
            # the per-state actions for those per-mapper actions
            # that were broken up.
            for edge in list(self.dependencies):
                if None in edge or \
                    edge[0].disabled or edge[1].disabled or \
                    cycles.issuperset(edge):
                    self.dependencies.remove(edge)
                elif edge[0] in cycles:
                    self.dependencies.remove(edge)
                    for dep in convert[edge[0]]:
                        self.dependencies.add((dep, edge[1]))
                elif edge[1] in cycles:
                    self.dependencies.remove(edge)
                    for dep in convert[edge[1]]:
                        self.dependencies.add((edge[0], dep))

        return set([a for a in self.postsort_actions.values()
                    if not a.disabled
                    ]
                ).difference(cycles)
예제 #9
0
    def _generate_actions(self):
        """Generate the full, unsorted collection of PostSortRecs as
        well as dependency pairs for this UOWTransaction.

        """
        # execute presort_actions, until all states
        # have been processed.   a presort_action might
        # add new states to the uow.
        while True:
            ret = False
            for action in list(self.presort_actions.values()):
                if action.execute(self):
                    ret = True
            if not ret:
                break

        # see if the graph of mapper dependencies has cycles.
        self.cycles = cycles = topological.find_cycles(
                                        self.dependencies,
                                        self.postsort_actions.values())

        if cycles:
            # if yes, break the per-mapper actions into
            # per-state actions
            convert = dict(
                (rec, set(rec.per_state_flush_actions(self)))
                for rec in cycles
            )

            # rewrite the existing dependencies to point to
            # the per-state actions for those per-mapper actions
            # that were broken up.
            for edge in list(self.dependencies):
                if None in edge or \
                    edge[0].disabled or edge[1].disabled or \
                    cycles.issuperset(edge):
                    self.dependencies.remove(edge)
                elif edge[0] in cycles:
                    self.dependencies.remove(edge)
                    for dep in convert[edge[0]]:
                        self.dependencies.add((dep, edge[1]))
                elif edge[1] in cycles:
                    self.dependencies.remove(edge)
                    for dep in convert[edge[1]]:
                        self.dependencies.add((edge[0], dep))

        return set([a for a in self.postsort_actions.values()
                    if not a.disabled
                    ]
                ).difference(cycles)
예제 #10
0
 def test_find_cycle_one(self):
     node1 = "node1"
     node2 = "node2"
     node3 = "node3"
     node4 = "node4"
     tuples = [
         (node1, node2),
         (node3, node1),
         (node2, node4),
         (node3, node2),
         (node2, node3),
     ]
     eq_(
         topological.find_cycles(tuples, self._nodes_from_tuples(tuples)),
         set([node1, node2, node3]),
     )
예제 #11
0
 def test_find_multiple_cycles_one(self):
     node1 = 'node1'
     node2 = 'node2'
     node3 = 'node3'
     node4 = 'node4'
     node5 = 'node5'
     node6 = 'node6'
     node7 = 'node7'
     node8 = 'node8'
     node9 = 'node9'
     tuples = [  # cycle 1 cycle 2 cycle 3 cycle 4, but only if cycle
         # 1 nodes are present
         (node1, node2),
         (node2, node4),
         (node4, node1),
         (node9, node9),
         (node7, node5),
         (node5, node7),
         (node1, node6),
         (node6, node8),
         (node8, node4),
         (node3, node1),
         (node3, node2),
     ]
     allnodes = set([
         node1,
         node2,
         node3,
         node4,
         node5,
         node6,
         node7,
         node8,
         node9,
     ])
     eq_(
         topological.find_cycles(tuples, allnodes),
         set([
             'node8',
             'node1',
             'node2',
             'node5',
             'node4',
             'node7',
             'node6',
             'node9',
         ]))
예제 #12
0
 def test_find_multiple_cycles_one(self):
     node1 = 'node1'
     node2 = 'node2'
     node3 = 'node3'
     node4 = 'node4'
     node5 = 'node5'
     node6 = 'node6'
     node7 = 'node7'
     node8 = 'node8'
     node9 = 'node9'
     tuples = [  # cycle 1 cycle 2 cycle 3 cycle 4, but only if cycle
                 # 1 nodes are present
         (node1, node2),
         (node2, node4),
         (node4, node1),
         (node9, node9),
         (node7, node5),
         (node5, node7),
         (node1, node6),
         (node6, node8),
         (node8, node4),
         (node3, node1),
         (node3, node2),
         ]
     allnodes = set([
         node1,
         node2,
         node3,
         node4,
         node5,
         node6,
         node7,
         node8,
         node9,
         ])
     eq_(topological.find_cycles(tuples, allnodes), set([
         'node8',
         'node1',
         'node2',
         'node5',
         'node4',
         'node7',
         'node6',
         'node9',
         ]))
예제 #13
0
 def test_find_multiple_cycles_one(self):
     node1 = "node1"
     node2 = "node2"
     node3 = "node3"
     node4 = "node4"
     node5 = "node5"
     node6 = "node6"
     node7 = "node7"
     node8 = "node8"
     node9 = "node9"
     tuples = [  # cycle 1 cycle 2 cycle 3 cycle 4, but only if cycle
         # 1 nodes are present
         (node1, node2),
         (node2, node4),
         (node4, node1),
         (node9, node9),
         (node7, node5),
         (node5, node7),
         (node1, node6),
         (node6, node8),
         (node8, node4),
         (node3, node1),
         (node3, node2),
     ]
     allnodes = set(
         [node1, node2, node3, node4, node5, node6, node7, node8, node9]
     )
     eq_(
         topological.find_cycles(tuples, allnodes),
         set(
             [
                 "node8",
                 "node1",
                 "node2",
                 "node5",
                 "node4",
                 "node7",
                 "node6",
                 "node9",
             ]
         ),
     )
예제 #14
0
 def test_find_multiple_cycles_three(self):
     node1 = "node1"
     node2 = "node2"
     node3 = "node3"
     node4 = "node4"
     node5 = "node5"
     node6 = "node6"
     tuples = [  # cycle 1 cycle 2 cycle3 cycle4
         (node1, node2),
         (node2, node1),
         (node2, node3),
         (node3, node2),
         (node2, node4),
         (node4, node2),
         (node2, node5),
         (node5, node6),
         (node6, node2),
     ]
     allnodes = set([node1, node2, node3, node4, node5, node6])
     eq_(topological.find_cycles(tuples, allnodes), allnodes)
예제 #15
0
 def test_find_multiple_cycles_four(self):
     tuples = [
         ('node6', 'node2'), ('node15', 'node19'), ('node19', 'node2'),
         ('node4', 'node10'), ('node15', 'node13'), ('node17', 'node11'),
         ('node1', 'node19'), ('node15', 'node8'), ('node6', 'node20'),
         ('node14', 'node11'), ('node6', 'node14'), ('node11', 'node2'),
         ('node10', 'node20'), ('node1', 'node11'), ('node20', 'node19'),
         ('node4', 'node20'), ('node15', 'node20'), ('node9', 'node19'),
         ('node11', 'node10'), ('node11', 'node19'), ('node13', 'node6'),
         ('node3', 'node15'), ('node9', 'node11'), ('node4', 'node17'),
         ('node2', 'node20'), ('node19', 'node10'), ('node8', 'node4'),
         ('node11', 'node3'), ('node6', 'node1')
     ]
     allnodes = ['node%d' % i for i in xrange(1, 21)]
     eq_(
         topological.find_cycles(tuples, allnodes),
         set([
             'node11', 'node10', 'node13', 'node15', 'node14', 'node17',
             'node19', 'node20', 'node8', 'node1', 'node3', 'node2',
             'node4', 'node6'
         ]))
예제 #16
0
 def test_find_multiple_cycles_four(self):
     tuples = [
         ('node6', 'node2'),
         ('node15', 'node19'),
         ('node19', 'node2'), ('node4', 'node10'),
         ('node15', 'node13'),
         ('node17', 'node11'), ('node1', 'node19'), ('node15', 'node8'),
         ('node6', 'node20'), ('node14', 'node11'), ('node6', 'node14'),
         ('node11', 'node2'), ('node10', 'node20'), ('node1', 'node11'),
         ('node20', 'node19'), ('node4', 'node20'), ('node15', 'node20'),
         ('node9', 'node19'), ('node11', 'node10'), ('node11', 'node19'),
         ('node13', 'node6'), ('node3', 'node15'), ('node9', 'node11'),
         ('node4', 'node17'), ('node2', 'node20'), ('node19', 'node10'),
         ('node8', 'node4'), ('node11', 'node3'), ('node6', 'node1')
     ]
     allnodes = ['node%d' % i for i in range(1, 21)]
     eq_(
         topological.find_cycles(tuples, allnodes),
         set(['node11', 'node10', 'node13', 'node15', 'node14', 'node17',
              'node19', 'node20', 'node8', 'node1', 'node3', 'node2',
              'node4', 'node6'])
     )
예제 #17
0
 def test_find_multiple_cycles_two(self):
     node1 = "node1"
     node2 = "node2"
     node3 = "node3"
     node4 = "node4"
     node5 = "node5"
     node6 = "node6"
     tuples = [  # cycle 1 cycle 2
         (node1, node2),
         (node2, node4),
         (node4, node1),
         (node1, node6),
         (node6, node2),
         (node2, node4),
         (node4, node1),
     ]
     allnodes = set([node1, node2, node3, node4, node5, node6])
     # node6 only became present here once [ticket:2282] was addressed.
     eq_(
         topological.find_cycles(tuples, allnodes),
         set(["node1", "node2", "node4", "node6"]),
     )