/// <summary> /// Adds the Scatter Group Communication operator to the communication group. /// </summary> /// <typeparam name="T">The type of messages that operators will send</typeparam> /// <param name="configurations">The configuration for the scatter operator</param> /// <param name="operatorName">The name of the scatter operator</param> /// <param name="senderId">The sender id</param> /// <param name="topologyType">type of topology used in the operaor</param> /// <returns>The same CommunicationGroupDriver with the added Scatter operator info</returns> public ICommunicationGroupDriver AddScatter <T>(string operatorName, string senderId, TopologyTypes topologyType, params IConfiguration[] configurations) { if (_finalized) { throw new IllegalStateException("Can't add operators once the spec has been built."); } var spec = new ScatterOperatorSpec(senderId, configurations); ITopology <T> topology; if (topologyType == TopologyTypes.Flat) { topology = new FlatTopology <T>(operatorName, _groupName, spec.SenderId, _driverId, spec); } else { topology = new TreeTopology <T>(operatorName, _groupName, spec.SenderId, _driverId, spec, _fanOut); } _topologies[operatorName] = topology; _operatorSpecs[operatorName] = spec; return(this); }
public void TestConfigurationReduceSpec() { FlatTopology <int> topology = new FlatTopology <int>("Operator", "Group", "task1", "driverid", new ReduceOperatorSpec("task1", Configurations.Merge(GetDefaultCodecConfig(), GetDefaultDataConverterConfig(), GetDefaultReduceFuncConfig()))); topology.AddTask("task1"); var conf2 = topology.GetTaskConfiguration("task1"); IReduceFunction <int> reduceFunction = TangFactory.GetTang().NewInjector(conf2).GetInstance <IReduceFunction <int> >(); Assert.Equal(10, reduceFunction.Reduce(new int[] { 1, 2, 3, 4 })); }
public void TestConfigurationBroadcastSpec() { FlatTopology <int> topology = new FlatTopology <int>("Operator", "Operator", "task1", "driverid", new BroadcastOperatorSpec("Sender", GetDefaultCodecConfig(), GetDefaultDataConverterConfig())); topology.AddTask("task1"); var conf = topology.GetTaskConfiguration("task1"); IStreamingCodec <int> codec = TangFactory.GetTang().NewInjector(conf).GetInstance <IStreamingCodec <int> >(); var stream = new MemoryStream(); IDataWriter writer = new StreamDataWriter(stream); codec.Write(3, writer); stream.Position = 0; IDataReader reader = new StreamDataReader(stream); int res = codec.Read(reader); Assert.Equal(3, res); }