Exemplo n.º 1
0
    def compose(self, left: topology.Composable) -> pipeline.Segment:
        """Composition implementation.

        Args:
            left: Left side.

        Returns:
            Composed track.
        """
        left: pipeline.Segment = left.expand()
        train_dumper: node.Worker = node.Worker(
            TrainDumper.spec(path=self._path('train'), label=self.label), 1, 1)
        apply_dumper: node.Worker = node.Worker(
            ApplyDumper.spec(path=self._path('apply')), 1, 1)
        train_dumper.train(left.train.publisher, left.label.publisher)
        self._instances += 1
        return left.extend(apply=view.Path(apply_dumper),
                           train=view.Path(train_dumper.fork()))
Exemplo n.º 2
0
 def path(request, head: grnode.Worker, spec: task.Spec) -> view.Path:
     """Path fixture."""
     grnode1 = grnode.Worker(spec, 1, 2)
     grnode2 = grnode.Worker(spec, 2, 1)
     grnode1[0].subscribe(head[0])
     grnode2[0].subscribe(grnode1[0])
     grnode2[1].subscribe(grnode1[1])
     if request.param:  # stateful
         grnode3 = grnode.Worker(spec, 1, 1)
         grnode2[0].publish(grnode3, port.Train())
     return view.Path(head)
Exemplo n.º 3
0
    def compose(self, left: topology.Composable) -> pipeline.Segment:
        """Compose the source segment track.

        Returns:
            Source segment track.
        """
        if not isinstance(left, topology.Origin):
            raise error.Unexpected('Source not origin')
        apply: view.Path = view.Path(node.Worker(self._apply, 0, 1))
        train: view.Path = view.Path(node.Worker(self._train, 0, 1))
        label: typing.Optional[view.Path] = None
        if self._label:
            train_tail = node.Future()
            label_tail = node.Future()
            extract = node.Worker(self._label, 1, 2)
            extract[0].subscribe(train.publisher)
            train_tail[0].subscribe(extract[0])
            label_tail[0].subscribe(extract[1])
            train = train.extend(tail=train_tail)
            label = train.extend(tail=label_tail)
        return pipeline.Segment(apply, train, label)
Exemplo n.º 4
0
    def compose(self, left: topology.Composable) -> pipeline.Segment:
        """Composition implementation.

        Args:
            left: Left side.

        Returns:
            Composed track.
        """
        left: pipeline.Segment = left.expand()
        inserter: node.Worker = node.Worker(self.inserter, 1, 1)
        inserter.train(left.train.publisher, left.label.publisher)
        return left.extend(train=view.Path(inserter.fork()))
Exemplo n.º 5
0
        def init(
            mode: typing.Optional[typing.Union[view.Path, nodemod.Atomic]]
        ) -> view.Path:
            """Apply default cleaning to the mode segment.

            Args:
                mode: Mode segment provided either as a path or just a node.

            Returns:
                Cleaned mode path.
            """
            if not mode:
                mode = nodemod.Future()
            if isinstance(mode, nodemod.Atomic):
                mode = view.Path(mode)
            return mode
Exemplo n.º 6
0
def path(node1: node.Worker, node2: node.Worker, node3: node.Worker):
    """Path fixture."""
    node2[0].subscribe(node1[0])
    node3[0].subscribe(node2[0])
    return view.Path(node1)
Exemplo n.º 7
0
 def test_new(self):
     """Test segment setup."""
     assert all(
         isinstance(m, view.Path) for m in pipeline.Segment(
             view.Path(node.Future()), node.Future(), None))
Exemplo n.º 8
0
 def test_pubsub(self, path: view.Path, simple: grnode.Worker,
                 multi: grnode.Worker):
     """Testing path publishing."""
     multi.train(path.publisher, path.publisher)
     path.subscribe(simple[0])
     assert view.Path(simple)._tail is path._tail
Exemplo n.º 9
0
 def test_invalid(self, multi: grnode.Worker):
     """Testing invalid path."""
     with pytest.raises(error.Topology):  # not a simple edge gnode
         view.Path(multi)