public void TestSerirializeInjectionPlanForTimer() { Type timerType = typeof(Timer); ITang tang = TangFactory.GetTang(); ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { FileNames.Examples }); cb.BindNamedParameter<Timer.Seconds, Int32>(GenericType < Timer.Seconds>.Class, "2"); IConfiguration conf = cb.Build(); IInjector injector = tang.NewInjector(conf); Org.Apache.REEF.Tang.Implementations.InjectionPlan.InjectionPlan ip = injector.GetInjectionPlan(timerType); ProtocolBufferInjectionPlan.Serialize("timerplan.bin", ip); var ch = conf.GetClassHierarchy(); var ip1 = ProtocolBufferInjectionPlan.DeSerialize("timerplan.bin", ch); Assert.IsNotNull(ip1); }
public void TestSerirializeInjectionPlanForSimpleConstructor() { Type simpleConstructorType = typeof(SimpleConstructors); ITang tang = TangFactory.GetTang(); ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { FileNames.Examples }); IConfiguration conf = cb.Build(); IInjector injector = tang.NewInjector(conf); Org.Apache.REEF.Tang.Implementations.InjectionPlan.InjectionPlan ip = injector.GetInjectionPlan(simpleConstructorType); ProtocolBufferInjectionPlan.Serialize("plan.bin", ip); var ch = conf.GetClassHierarchy(); var ipRecovered = ProtocolBufferInjectionPlan.DeSerialize("plan.bin", ch); Assert.IsNotNull(ipRecovered); }
public void TestStreamActivity2() { var a = Assembly.Load(@"com.microsoft.reef.activity"); Type activityType = a.GetType("com.microsoft.reef.activity.StreamActivity2"); ITang tang = TangFactory.GetTang(); ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { @"com.microsoft.reef.activity", @"com.microsoft.reef.ActivityInterface" }); IConfiguration conf = cb.Build(); IInjector injector = tang.NewInjector(conf); var activityRef = (com.microsoft.reef.activity.IActivity)injector.GetInstance(activityType); Assert.IsNotNull(activityRef); //activityRef.Call(null); }
public void TestDocumentLoadNamedParameter() { Type documentedLocalNamedParameterType = typeof(Com.Microsoft.Tang.Examples.DocumentedLocalNamedParameter); Type namedParameter = asm.GetType(@"Com.Microsoft.Tang.Examples.DocumentedLocalNamedParameter+Foo"); ITang tang = TangFactory.GetTang(); ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { file }); cb.BindNamedParameter(namedParameter, "Hello"); IConfiguration conf = cb.Build(); IInjector injector = tang.NewInjector(conf); var doc = (Com.Microsoft.Tang.Examples.DocumentedLocalNamedParameter)injector.GetInstance(documentedLocalNamedParameterType); Assert.IsNotNull(doc); var s = doc.ToString(); }
public void TestGetConfgiFromProtoBufClassHierarchy() { Type activityInterfaceType = typeof(com.microsoft.reef.activity.IActivity); IClassHierarchy ns = TangFactory.GetTang().GetClassHierarchy(new string[] { file2, file3 }); ProtocolBufferClassHierarchy.Serialize("activity.bin", ns); IClassHierarchy ch = ProtocolBufferClassHierarchy.DeSerialize("activity.bin"); ITang tang = TangFactory.GetTang(); IConfigurationBuilder cb = tang.NewConfigurationBuilder(ch); cb.Bind("com.microsoft.reef.activity.IActivity", "com.microsoft.reef.activity.HelloActivity"); cb.Bind(@"com.microsoft.reef.driver.activity.ActivityConfigurationOptions+Identifier", "Hello Activity"); IConfiguration conf = cb.Build(); ConfigurationFile.WriteConfigurationFile(conf, "activityConf2.txt"); }
public void TestTimer() { Type timerType = typeof(Com.Microsoft.Tang.Examples.Timer); Type namedParameter = asm.GetType(@"Com.Microsoft.Tang.Examples.Timer+Seconds"); ITang tang = TangFactory.GetTang(); ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { file }); cb.BindNamedParameter(namedParameter, "2"); IConfiguration conf = cb.Build(); IInjector injector = tang.NewInjector(conf); var timer = (Com.Microsoft.Tang.Examples.Timer)injector.GetInstance(timerType); Assert.IsNotNull(timer); System.Console.WriteLine("Tick..."); timer.sleep(); System.Console.WriteLine("Tock..."); }
public void TestTweetExample() { Type tweeterType = typeof(Com.Microsoft.Tang.Examples.Tweeter); Type namedParameter = asm.GetType(@"Com.Microsoft.Tang.Examples.Tweeter+PhoneNumber"); ITang tang = TangFactory.GetTang(); ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { file }); cb.BindImplementation(typeof(TweetFactory), typeof(MockTweetFactory)); cb.BindImplementation(typeof(SMS), typeof(MockSMS)); cb.BindNamedParameter(namedParameter, "8675309"); IConfiguration conf = cb.Build(); IInjector injector = tang.NewInjector(conf); var tweeter = (Com.Microsoft.Tang.Examples.Tweeter)injector.GetInstance(tweeterType); tweeter.sendMessage(); var sms = (Com.Microsoft.Tang.Examples.SMS)injector.GetInstance(typeof(SMS)); var factory = (Com.Microsoft.Tang.Examples.TweetFactory)injector.GetInstance(typeof(TweetFactory)); }
public void TestTimerWithClassHierarchy() { Type timerType = typeof(Timer); ClassHierarchyImpl classHierarchyImpl = new ClassHierarchyImpl(FileNames.Examples); ITang tang = TangFactory.GetTang(); ICsConfigurationBuilder cb = tang.NewConfigurationBuilder((ICsClassHierarchy)classHierarchyImpl); cb.BindNamedParameter <Timer.Seconds, int>(GenericType <Timer.Seconds> .Class, "2"); IConfiguration conf = cb.Build(); IInjector injector = tang.NewInjector(conf); var timer = (Timer)injector.GetInstance(timerType); Assert.NotNull(timer); timer.sleep(); }
public void TestActivityWithBinding() { Type activityInterfaceType = typeof(ITask); ITang tang = TangFactory.GetTang(); ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { FileNames.Tasks, FileNames.Common }); cb.BindImplementation(GenericType <ITask> .Class, GenericType <HelloTask> .Class); cb.BindNamedParameter <TaskConfigurationOptions.Identifier, string>(GenericType <TaskConfigurationOptions.Identifier> .Class, "Hello Task"); IConfiguration conf = cb.Build(); IInjector injector = tang.NewInjector(conf); ITask activityRef1 = injector.GetInstance <ITask>(); var activityRef2 = (ITask)injector.GetInstance(activityInterfaceType); Assert.NotNull(activityRef2); Assert.NotNull(activityRef1); Assert.Equal(activityRef1, activityRef2); }
public void TestTweetConfig() { Type tweeterType = typeof(Com.Microsoft.Tang.Examples.Tweeter); Type namedParameter = asm.GetType(@"Com.Microsoft.Tang.Examples.Tweeter+PhoneNumber"); ITang tang = TangFactory.GetTang(); ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { file }); cb.BindImplementation(typeof(TweetFactory), typeof(MockTweetFactory)); cb.BindImplementation(typeof(SMS), typeof(MockSMS)); cb.BindNamedParameter(namedParameter, "8675309"); IConfiguration conf = cb.Build(); ConfigurationFile.WriteConfigurationFile(conf, "tweeterConf.txt"); IDictionary <string, string> p = ReadFromFile("tweeterConf.txt"); IInjector injector = tang.NewInjector(new string[] { file }, "tweeterConf.txt"); var tweeter = (Com.Microsoft.Tang.Examples.Tweeter)injector.GetInstance(tweeterType); tweeter.sendMessage(); }
public void TestActivityConfig() { Type activityInterfaceType = typeof(com.microsoft.reef.activity.IActivity); var a = Assembly.Load(@"com.microsoft.reef.activity"); Type activityType = a.GetType("com.microsoft.reef.activity.HelloActivity"); ITang tang = TangFactory.GetTang(); ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { file, file2, file3 }); cb.BindImplementation(activityInterfaceType, activityType); IConfiguration conf = cb.Build(); ConfigurationFile.WriteConfigurationFile(conf, "activityConf.txt"); IDictionary <string, string> p = ReadFromFile("activityConf.txt"); IInjector injector = tang.NewInjector(new string[] { file2, file3 }, "activityConf.txt"); var activityRef = (com.microsoft.reef.activity.IActivity)injector.GetInstance(activityInterfaceType); Assert.IsNotNull(activityRef); //byte[] b = new byte[10]; //activityRef.Call(b); }
public void TestDeserializedConfigMerge() { Type activityInterfaceType = typeof(ITask); ITang tang = TangFactory.GetTang(); ICsConfigurationBuilder cb1 = tang.NewConfigurationBuilder(); cb1.BindImplementation(GenericType <ITask> .Class, GenericType <HelloTask> .Class); cb1.BindNamedParameter <TaskConfigurationOptions.Identifier, string>( GenericType <TaskConfigurationOptions.Identifier> .Class, "Hello Task"); IConfiguration conf1 = cb1.Build(); var serializer = new AvroConfigurationSerializer(); serializer.ToFile(conf1, "task.config"); ProtocolBufferClassHierarchy.Serialize("Task.bin", conf1.GetClassHierarchy()); IClassHierarchy ns1 = ProtocolBufferClassHierarchy.DeSerialize("Task.bin"); ICsConfigurationBuilder cb2 = tang.NewConfigurationBuilder(); cb2.BindNamedParameter <Timer.Seconds, int>(GenericType <Timer.Seconds> .Class, "2"); IConfiguration conf2 = cb2.Build(); serializer.ToFile(conf2, "timer.config"); ProtocolBufferClassHierarchy.Serialize("Timer.bin", conf2.GetClassHierarchy()); IClassHierarchy ns2 = ProtocolBufferClassHierarchy.DeSerialize("Timer.bin"); AvroConfiguration taskAvroconfiguration = serializer.AvroDeserializeFromFile("task.config"); IConfiguration taskConfiguration = serializer.FromAvro(taskAvroconfiguration, ns1); AvroConfiguration timerAvroconfiguration = serializer.AvroDeserializeFromFile("timer.config"); IConfiguration timerConfiguration = serializer.FromAvro(timerAvroconfiguration, ns2); IConfiguration merged = Configurations.MergeDeserializedConfs(taskConfiguration, timerConfiguration); var b = merged.newBuilder().Build(); }
public void TestSetup() { tang = TangFactory.GetTang(); }
public TestLegacyConstructors() { tang = TangFactory.GetTang(); }