public void GraphInterpreter_should_implement_chained_identity() { WithTestSetup((setup, lastEvents) => { var source = setup.NewUpstreamProbe <int>("source"); var sink = setup.NewDownstreamProbe <int>("sink"); // Constructing an assembly by hand and resolving ambiguities var assembly = new GraphAssembly( stages: new IGraphStageWithMaterializedValue <Shape, object>[] { _identity, _identity }, originalAttributes: new[] { Attributes.None, Attributes.None }, inlets: new Inlet[] { _identity.Inlet, _identity.Inlet, null }, inletOwners: new[] { 0, 1, -1 }, outlets: new Outlet[] { null, _identity.Outlet, _identity.Outlet }, outletOwners: new[] { -1, 0, 1 } ); setup.ManualInit(assembly); setup.Interpreter.AttachDownstreamBoundary(2, sink); setup.Interpreter.AttachUpstreamBoundary(0, source); setup.Interpreter.Init(null); lastEvents().Should().BeEmpty(); sink.RequestOne(); lastEvents().Should().BeEquivalentTo(new RequestOne(source)); source.OnNext(1); lastEvents().Should().BeEquivalentTo(new OnNext(sink, 1)); }); }
private Flow <TIn, TOut2, NotUsed> FaultyFlow <TIn, TOut, TOut2>(Flow <TIn, TOut, NotUsed> flow) where TOut : TOut2 { Func <Flow <TOut, TOut2, NotUsed> > createGraph = () => { var stage = new FaultyFlowStage <TOut, TOut2>(); var assembly = new GraphAssembly(new IGraphStageWithMaterializedValue <Shape, object>[] { stage }, new[] { Attributes.None }, new Inlet[] { stage.Shape.Inlet, null }, new[] { 0, -1 }, new Outlet[] { null, stage.Shape.Outlet }, new[] { -1, 0 }); var t = assembly.Materialize(Attributes.None, assembly.Stages.Select(s => s.Module).ToArray(), new Dictionary <IModule, object>(), _ => { }); var inHandlers = t.Item1; var outHandlers = t.Item2; var logics = t.Item3; var shell = new GraphInterpreterShell(assembly, inHandlers, outHandlers, logics, stage.Shape, Settings, (ActorMaterializerImpl)Materializer); var props = Props.Create(() => new BrokenActorInterpreter(shell, "a3")) .WithDeploy(Deploy.Local) .WithDispatcher("akka.test.stream-dispatcher"); var impl = Sys.ActorOf(props, "broken-stage-actor"); var subscriber = new ActorGraphInterpreter.BoundarySubscriber <TOut>(impl, shell, 0); var publisher = new FaultyFlowPublisher <TOut2>(impl, shell); impl.Tell(new ActorGraphInterpreter.ExposedPublisher(shell, 0, publisher)); return(Flow.FromSinkAndSource(Sink.FromSubscriber(subscriber), Source.FromPublisher(publisher))); }; return(flow.Via(createGraph())); }
public void GraphInterpreter_should_implement_chained_identity() { WithTestSetup((setup, lastEvents) => { var source = setup.NewUpstreamProbe<int>("source"); var sink = setup.NewDownstreamProbe<int>("sink"); // Constructing an assembly by hand and resolving ambiguities var assembly = new GraphAssembly( stages: new IGraphStageWithMaterializedValue<Shape, object>[] {_identity, _identity}, originalAttributes: new[] {Attributes.None, Attributes.None}, inlets: new Inlet[] {_identity.Inlet, _identity.Inlet, null}, inletOwners: new[] {0, 1, -1}, outlets: new Outlet[] {null, _identity.Outlet, _identity.Outlet}, outletOwners: new[] {-1, 0, 1} ); setup.ManualInit(assembly); setup.Interpreter.AttachDownstreamBoundary(2, sink); setup.Interpreter.AttachUpstreamBoundary(0, source); setup.Interpreter.Init(null); lastEvents().Should().BeEmpty(); sink.RequestOne(); lastEvents().Should().BeEquivalentTo(new RequestOne(source)); source.OnNext(1); lastEvents().Should().BeEquivalentTo(new OnNext(sink, 1)); }); }
protected override object MaterializeAtomic(AtomicModule atomic, Attributes effectiveAttributes, IDictionary <IModule, object> materializedValues) { if (IsDebug) { Console.WriteLine($"materializing {atomic}"); } if (atomic is ISinkModule) { var sink = (ISinkModule)atomic; object materialized; var subscriber = sink.Create(CreateMaterializationContext(effectiveAttributes), out materialized); AssignPort(sink.Shape.Inlets.First(), subscriber); materializedValues.Add(atomic, materialized); } else if (atomic is ISourceModule) { var source = (ISourceModule)atomic; object materialized; var publisher = source.Create(CreateMaterializationContext(effectiveAttributes), out materialized); AssignPort(source.Shape.Outlets.First(), publisher); materializedValues.Add(atomic, materialized); } else if (atomic is IStageModule) { // FIXME: Remove this, only stream-of-stream ops need it var stage = (IStageModule)atomic; // assumes BaseType is StageModule<> var methodInfo = ProcessorForMethod.MakeGenericMethod(atomic.GetType().BaseType.GenericTypeArguments); var parameters = new object[] { stage, effectiveAttributes, _materializer.EffectiveSettings(effectiveAttributes), null }; var processor = methodInfo.Invoke(this, parameters); object materialized = parameters[3]; AssignPort(stage.In, UntypedSubscriber.FromTyped(processor)); AssignPort(stage.Out, UntypedPublisher.FromTyped(processor)); materializedValues.Add(atomic, materialized); } //else if (atomic is TlsModule) //{ //}) else if (atomic is GraphModule) { var graph = (GraphModule)atomic; MaterializeGraph(graph, effectiveAttributes, materializedValues); } else if (atomic is GraphStageModule) { var stage = (GraphStageModule)atomic; var graph = new GraphModule( GraphAssembly.Create(stage.Shape.Inlets, stage.Shape.Outlets, new[] { stage.Stage }), stage.Shape, stage.Attributes, new IModule[] { stage }); MaterializeGraph(graph, effectiveAttributes, materializedValues); } return(NotUsed.Instance); }
public void ManualInit(GraphAssembly assembly) { var mat = assembly.Materialize(Attributes.None, assembly.Stages.Select(s => s.Module).ToArray(), new Dictionary <IModule, object>(), s => { }); var inHandlers = mat.Item1; var outHandlers = mat.Item2; var logics = mat.Item3; _interpreter = new GraphInterpreter(assembly, NoMaterializer.Instance, _logger, inHandlers, outHandlers, logics, (l, o, a) => {}, false); }
protected override object MaterializeAtomic(AtomicModule atomic, Attributes effectiveAttributes, IDictionary <IModule, object> materializedValues) { if (IsDebug) { Console.WriteLine($"materializing {atomic}"); } if (atomic is ISinkModule) { var sink = (ISinkModule)atomic; object materialized; var subscriber = sink.Create(CreateMaterializationContext(effectiveAttributes), out materialized); AssignPort(sink.Shape.Inlets.First(), subscriber); materializedValues.Add(atomic, materialized); } else if (atomic is ISourceModule) { var source = (ISourceModule)atomic; object materialized; var publisher = source.Create(CreateMaterializationContext(effectiveAttributes), out materialized); AssignPort(source.Shape.Outlets.First(), publisher); materializedValues.Add(atomic, materialized); } else if (atomic is IProcessorModule) { var stage = atomic as IProcessorModule; var t = stage.CreateProcessor(); var processor = t.Item1; var materialized = t.Item2; AssignPort(stage.In, UntypedSubscriber.FromTyped(processor)); AssignPort(stage.Out, UntypedPublisher.FromTyped(processor)); materializedValues.Add(atomic, materialized); } //else if (atomic is TlsModule) //{ //}) else if (atomic is GraphModule) { var graph = (GraphModule)atomic; MaterializeGraph(graph, effectiveAttributes, materializedValues); } else if (atomic is GraphStageModule) { var stage = (GraphStageModule)atomic; var graph = new GraphModule( GraphAssembly.Create(stage.Shape.Inlets, stage.Shape.Outlets, new[] { stage.Stage }), stage.Shape, stage.Attributes, new IModule[] { stage }); MaterializeGraph(graph, effectiveAttributes, materializedValues); } return(NotUsed.Instance); }
public GraphInterpreter( GraphAssembly assembly, IMaterializer materializer, ILoggingAdapter log, IInHandler[] inHandlers, IOutHandler[] outHandlers, GraphStageLogic[] logics, Action<GraphStageLogic, object, Action<object>> onAsyncInput, bool fuzzingMode) { Logics = logics; Assembly = assembly; Materializer = materializer; Log = log; InHandlers = inHandlers; OutHandlers = outHandlers; OnAsyncInput = onAsyncInput; FuzzingMode = fuzzingMode; ConnectionSlots = new object[assembly.ConnectionCount]; for (var i = 0; i < ConnectionSlots.Length; i++) ConnectionSlots[i] = Empty.Instance; PortStates = new int[assembly.ConnectionCount]; for (var i = 0; i < PortStates.Length; i++) PortStates[i] = InReady; RunningStagesCount = Assembly.Stages.Length; _shutdownCounter = new int[assembly.Stages.Length]; for (var i = 0; i < _shutdownCounter.Length; i++) { var shape = assembly.Stages[i].Shape; _shutdownCounter[i] = shape.Inlets.Count() + shape.Outlets.Count(); } _eventQueue = new int[1 << (32 - (assembly.ConnectionCount - 1).NumberOfLeadingZeros())]; _mask = _eventQueue.Length - 1; }