Repository: incubator-reef Updated Branches: refs/heads/master 5cc607158 -> 2ae282de1
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Tests/TangTests/TangTests.csproj ---------------------------------------------------------------------- diff --git a/lang/cs/Tests/TangTests/TangTests.csproj b/lang/cs/Tests/TangTests/TangTests.csproj new file mode 100644 index 0000000..ee925b8 --- /dev/null +++ b/lang/cs/Tests/TangTests/TangTests.csproj @@ -0,0 +1,180 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProjectGuid>{D5EB94D0-3ABA-4853-9050-E36B196E17D2}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>Org.Apache.Reef.Tang.Test</RootNamespace> + <AssemblyName>Org.Apache.Reef.Tang.Test</AssemblyName> + <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <RestorePackages>true</RestorePackages> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>..\..\bin\Debug\Org.Apache.Reef.Tang.Test\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>..\..\bin\Release\Microsoft.Tang.Tests\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <Reference Include="Microsoft.Hadoop.Avro"> + <HintPath>..\..\packages\Microsoft.Hadoop.Avro.1.4.0.0\lib\net40\Microsoft.Hadoop.Avro.dll</HintPath> + </Reference> + <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> + <Reference Include="Newtonsoft.Json"> + <HintPath>..\..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath> + </Reference> + <Reference Include="protobuf-net"> + <HintPath>..\..\packages\protobuf-net.2.0.0.668\lib\net40\protobuf-net.dll</HintPath> + </Reference> + <Reference Include="System" /> + <Reference Include="System.Core" /> + <Reference Include="System.Xml.Linq" /> + <Reference Include="System.Data.DataSetExtensions" /> + <Reference Include="Microsoft.CSharp" /> + <Reference Include="System.Data" /> + <Reference Include="System.Xml" /> + </ItemGroup> + <ItemGroup> + <Compile Include="ClassHierarchy\TestAnonymousType.cs" /> + <Compile Include="ClassHierarchy\TestClassHierarchy.cs" /> + <Compile Include="ClassHierarchy\TestClassHierarchyRoundTrip.cs" /> + <Compile Include="ClassHierarchy\TestGeneric.cs" /> + <Compile Include="ClassHierarchy\TestMultipleInterface.cs" /> + <Compile Include="ClassHierarchy\TestParameterParser.cs" /> + <Compile Include="ClassHierarchy\TestSerilization.cs" /> + <Compile Include="Configuration\TestAvroConfiguration.cs" /> + <Compile Include="Configuration\TestAvroSerializerRoundTrip.cs" /> + <Compile Include="Configuration\TestConfiguration.cs" /> + <Compile Include="Configuration\TestCsConfigurationBuilderExtension.cs" /> + <Compile Include="Format\TestConfigurationModule.cs" /> + <Compile Include="Format\TestConfigurationModuleForList.cs" /> + <Compile Include="Format\TestTaskConfiguration.cs" /> + <Compile Include="Injection\TestAmbigousConstructors.cs" /> + <Compile Include="Injection\TestForkInjection.cs" /> + <Compile Include="Injection\TestInjection.cs" /> + <Compile Include="Injection\TestInjectionFuture.cs" /> + <Compile Include="Injection\TestListInjection.cs" /> + <Compile Include="Injection\TestMissingParameters.cs" /> + <Compile Include="Injection\TestMissingParamtersInNested.cs" /> + <Compile Include="Injection\TestMultipleConstructors.cs" /> + <Compile Include="Injection\TestNamedParameter.cs" /> + <Compile Include="Injection\TestSetInjection.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="ScenarioTest\HttpHandlerConfiguration.cs" /> + <Compile Include="ScenarioTest\HttpRuntimeConfiguration.cs" /> + <Compile Include="ScenarioTest\HttpRuntimeStartHandler.cs" /> + <Compile Include="ScenarioTest\HttpRuntimeStopHandler.cs" /> + <Compile Include="ScenarioTest\HttpServer.cs" /> + <Compile Include="ScenarioTest\IHttpHandler.cs" /> + <Compile Include="ScenarioTest\JettyHandler.cs" /> + <Compile Include="ScenarioTest\TestDefaultConstructor.cs" /> + <Compile Include="ScenarioTest\TestHttpService.cs" /> + <Compile Include="ScenarioTest\TestRuntimeClock.cs" /> + <Compile Include="ScenarioTest\TestTrackingURIProvider.cs" /> + <Compile Include="ScenarioTest\TrackingURIProvider.cs" /> + <Compile Include="ScenarioTest\TrackingYRIProvider.cs" /> + <Compile Include="SmokeTest\AnInterface.cs" /> + <Compile Include="SmokeTest\AnInterfaceImplementation.cs" /> + <Compile Include="SmokeTest\CyclicDependency.cs" /> + <Compile Include="SmokeTest\CyclicDependencyClassOne.cs" /> + <Compile Include="SmokeTest\CyclicDependencyClassTwo.cs" /> + <Compile Include="SmokeTest\Handler.cs" /> + <Compile Include="SmokeTest\InjectableClass.cs" /> + <Compile Include="SmokeTest\ListOfBaseTypes.cs" /> + <Compile Include="SmokeTest\ObjectTreeTest.cs" /> + <Compile Include="SmokeTest\RootImplementation.cs" /> + <Compile Include="SmokeTest\RootInterface.cs" /> + <Compile Include="SmokeTest\RoundTripTest.cs" /> + <Compile Include="SmokeTest\SetInterface.cs" /> + <Compile Include="SmokeTest\SetInterfaceImplOne.cs" /> + <Compile Include="SmokeTest\SetInterfaceImplTwo.cs" /> + <Compile Include="SmokeTest\SetOfBaseTypes.cs" /> + <Compile Include="SmokeTest\SetOfImplementations.cs" /> + <Compile Include="SmokeTest\TestConfigurationModuleBuilder.cs" /> + <Compile Include="Tang\TestDefaultImpementaion.cs" /> + <Compile Include="Tang\TestExternalConstructors.cs" /> + <Compile Include="Tang\TestLegacyConstructors.cs" /> + <Compile Include="Tang\TestTang.cs" /> + <Compile Include="Utilities\TestUtilities.cs" /> + <Compile Include="Utilities\Utilities.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="evaluator.conf"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </None> + <None Include="packages.config" /> + <None Include="simpleConstructorJavaProto.bin"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </None> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\Source\REEF\reef-common\ReefCommon\ReefCommon.csproj"> + <Project>{545a0582-4105-44ce-b99c-b1379514a630}</Project> + <Name>ReefCommon</Name> + </ProjectReference> + <ProjectReference Include="..\..\Source\REEF\reef-tasks\Tasks\Tasks.csproj"> + <Project>{75503f90-7b82-4762-9997-94b5c68f15db}</Project> + <Name>Tasks</Name> + </ProjectReference> + <ProjectReference Include="..\..\Source\TANG\Examples\Examples.csproj"> + <Project>{31b4389e-925a-4181-a1f6-21a1a0ad8a1c}</Project> + <Name>Examples</Name> + </ProjectReference> + <ProjectReference Include="..\..\Source\TANG\Tang\Tang.csproj"> + <Project>{97dbb573-3994-417a-9f69-ffa25f00d2a6}</Project> + <Name>Tang</Name> + </ProjectReference> + <ProjectReference Include="..\..\Source\WAKE\Wake\Wake.csproj"> + <Project>{cdfb3464-4041-42b1-9271-83af24cd5008}</Project> + <Name>Wake</Name> + </ProjectReference> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> + <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" /> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> + --> +</Project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Tests/TangTests/Utilities/TestUtilities.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Tests/TangTests/Utilities/TestUtilities.cs b/lang/cs/Tests/TangTests/Utilities/TestUtilities.cs new file mode 100644 index 0000000..8d81738 --- /dev/null +++ b/lang/cs/Tests/TangTests/Utilities/TestUtilities.cs @@ -0,0 +1,294 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +using System; +using System.Collections.Generic; +using System.Reflection; +using Org.Apache.Reef.Tang.Formats; +using Org.Apache.Reef.Tang.Interface; +using Org.Apache.Reef.Tang.Util; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Org.Apache.Reef.Tang.Examples; + +namespace Org.Apache.Reef.Tang.Test.Utilities +{ + [TestClass] + public class TestUtilities + { + [TestMethod] + public void TestIsAssignableFromIgnoreGeneric() + { + var result = ReflectionUtilities.IsAssignableFromIgnoreGeneric(typeof(IExternalConstructor<>), typeof(Foo)); + Assert.IsTrue(result); + } + + [TestMethod] + public void TestIsAssignableFromIgnoreGenericNegtive() + { + var result = ReflectionUtilities.IsAssignableFromIgnoreGeneric(typeof(ISet<>), typeof(Foo)); + Assert.IsFalse(result); + } + + [TestMethod] + public void TestIsInstanceOfGeneric() + { + var p1 = new OptionalParameter<int>(); + bool r1 = ReflectionUtilities.IsInstanceOfGeneric(p1, typeof(OptionalParameter<>)); + var p2 = new RequiredParameter<string>(); + bool r2 = ReflectionUtilities.IsInstanceOfGeneric(p2, typeof(RequiredParameter<>)); + Assert.IsTrue(r1); + Assert.IsTrue(r2); + } + + [TestMethod] + public void TestGetInterfaceTargetForTypeInheritFromGeneric() + { + Type result = ReflectionUtilities.GetInterfaceTarget(typeof(IExternalConstructor<>), typeof(Foo)); + Assert.AreEqual(result, typeof(Int32)); + } + + class Foo : IExternalConstructor<Int32> + { + public Int32 NewInstance() + { + return 3; + } + } + + [TestMethod] + public void TestGetEnclosingClassShortNameByType() + { + var asm = Assembly.Load(FileNames.Examples); + Type seconds = asm.GetType(FileNames.Seconds); + Type timer = asm.GetType(FileNames.Timer); + + string[] pathSeconds = ReflectionUtilities.GetEnclosingClassNames(seconds); + Assert.AreEqual(pathSeconds[0], timer.AssemblyQualifiedName); + Assert.AreEqual(pathSeconds[1], seconds.AssemblyQualifiedName); + + string[] pathTime = ReflectionUtilities.GetEnclosingClassNames(timer); + Assert.AreEqual(pathTime[0], timer.AssemblyQualifiedName); + } + + [TestMethod] + public void TestGetName() + { + var asm = Assembly.Load(FileNames.Examples); + Type B2 = asm.GetType(FileNames.B2); + + string n = ReflectionUtilities.GetName(B2); + Assert.AreEqual(n, B2.FullName); + } + + [TestMethod] + public void TestGetEnclosingTypesInclusive() + { + var asm = Assembly.Load(FileNames.Examples); + Type B2 = asm.GetType(FileNames.B2); + Type[] ts = ReflectionUtilities.GetEnclosingClasses(B2); + Assert.AreEqual(ts[0], asm.GetType(FileNames.B)); + Assert.AreEqual(ts[1], asm.GetType(FileNames.B1)); + Assert.AreEqual(ts[2], asm.GetType(FileNames.B2)); + } + + [TestMethod] + public void TestGetEnclosingClassShortNameByName() + { + var asm = Assembly.Load(FileNames.Examples); + Type b = asm.GetType(FileNames.B); + Type b1 = asm.GetType(FileNames.B1); + Type b2 = asm.GetType(FileNames.B2); + + string[] path = ReflectionUtilities.GetEnclosingClassNames(FileNames.B2); + Assert.AreEqual(path[0], b.AssemblyQualifiedName); + Assert.AreEqual(path[1], b1.AssemblyQualifiedName); + Assert.AreEqual(path[2], b2.AssemblyQualifiedName); + } + + [TestMethod] + public void TestGetEnclosingClassShortNameByFullName() + { + var asm = Assembly.Load(FileNames.Examples); + Type c = asm.GetType(FileNames.B2); + Type b = asm.GetType(FileNames.B); + Type b1 = asm.GetType(FileNames.B1); + Type b2 = asm.GetType(FileNames.B2); + string[] path = ReflectionUtilities.GetEnclosingClassNames(c.FullName); + Assert.AreEqual(path[0], b.AssemblyQualifiedName); + Assert.AreEqual(path[1], b1.AssemblyQualifiedName); + Assert.AreEqual(path[2], b2.AssemblyQualifiedName); + } + + [TestMethod] + public void TestGetEnclosingClassShortNameByAssemblyQualifiedName() + { + var asm = Assembly.Load(FileNames.Examples); + Type c = asm.GetType(FileNames.B2); + Type b = asm.GetType(FileNames.B); + Type b1 = asm.GetType(FileNames.B1); + Type b2 = asm.GetType(FileNames.B2); + + string[] path = ReflectionUtilities.GetEnclosingClassNames(c.AssemblyQualifiedName); + + Assert.AreEqual(path[0], b.AssemblyQualifiedName); + Assert.AreEqual(path[1], b1.AssemblyQualifiedName); + Assert.AreEqual(path[2], b2.AssemblyQualifiedName); + } + + [TestMethod] + public void AssemblyNamesTest() + { + var asm = Assembly.Load(FileNames.Examples); + Type seconds = asm.GetType(FileNames.Seconds); + + var name = seconds.Name; + var fullName = seconds.FullName; + var assemblyName = seconds.AssemblyQualifiedName; + + Type[] i = seconds.GetInterfaces(); + + foreach (Type t in i) + { + var name1 = t.Name; + var fullName1 = t.FullName; + var assemblyName1 = t.AssemblyQualifiedName; + } + } + + [TestMethod] + public void TestGetInterfaceTargetForGenericType() + { + Type iface = typeof(ISet<>); + Type type = typeof(MySet<string>); + Type p = ReflectionUtilities.GetInterfaceTarget(iface, type); + Assert.IsTrue(p.Equals(typeof (string))); + } + + [TestMethod] + public void TestGetInterfaceTargetForSystemGenericType() + { + Type iface = typeof(ISet<>); + Type type = typeof(ISet<int>); + Type p = ReflectionUtilities.GetInterfaceTarget(iface, type); + Assert.IsTrue(p.Equals(typeof(int))); + } + } + + public class MySet<T> : ISet<T> + { + public bool Add(T item) + { + throw new NotImplementedException(); + } + + public void ExceptWith(IEnumerable<T> other) + { + throw new NotImplementedException(); + } + + public void IntersectWith(IEnumerable<T> other) + { + throw new NotImplementedException(); + } + + public bool IsProperSubsetOf(IEnumerable<T> other) + { + throw new NotImplementedException(); + } + + public bool IsProperSupersetOf(IEnumerable<T> other) + { + throw new NotImplementedException(); + } + + public bool IsSubsetOf(IEnumerable<T> other) + { + throw new NotImplementedException(); + } + + public bool IsSupersetOf(IEnumerable<T> other) + { + throw new NotImplementedException(); + } + + public bool Overlaps(IEnumerable<T> other) + { + throw new NotImplementedException(); + } + + public bool SetEquals(IEnumerable<T> other) + { + throw new NotImplementedException(); + } + + public void SymmetricExceptWith(IEnumerable<T> other) + { + throw new NotImplementedException(); + } + + public void UnionWith(IEnumerable<T> other) + { + throw new NotImplementedException(); + } + + void ICollection<T>.Add(T item) + { + throw new NotImplementedException(); + } + + public void Clear() + { + throw new NotImplementedException(); + } + + public bool Contains(T item) + { + throw new NotImplementedException(); + } + + public void CopyTo(T[] array, int arrayIndex) + { + throw new NotImplementedException(); + } + + public int Count + { + get { throw new NotImplementedException(); } + } + + public bool IsReadOnly + { + get { throw new NotImplementedException(); } + } + + public bool Remove(T item) + { + throw new NotImplementedException(); + } + + public IEnumerator<T> GetEnumerator() + { + throw new NotImplementedException(); + } + + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Tests/TangTests/Utilities/Utilities.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Tests/TangTests/Utilities/Utilities.cs b/lang/cs/Tests/TangTests/Utilities/Utilities.cs new file mode 100644 index 0000000..eb31d6a --- /dev/null +++ b/lang/cs/Tests/TangTests/Utilities/Utilities.cs @@ -0,0 +1,62 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +using System.Collections.Generic; + +namespace Org.Apache.Reef.Tang.Test.Utilities +{ + public class Utilities + { + public static bool Equals<T>(ICollection<T> s1, ISet<T> s2) + { + if (s1 == s2) + { + return true; + } + if (s1 == null || s2 == null) + { + return false; + } + if (s1.Count != s2.Count) + { + return false; + } + foreach (T t in s1) + { + if (!Contains<T>(s2, t)) + { + return false; + } + } + return true; + } + + public static bool Contains<T>(ICollection<T> s, T t) + { + foreach (T t1 in s) + { + if (t1.Equals(t)) + { + return true; + } + } + return false; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Tests/TangTests/evaluator.conf ---------------------------------------------------------------------- diff --git a/lang/cs/Tests/TangTests/evaluator.conf b/lang/cs/Tests/TangTests/evaluator.conf new file mode 100644 index 0000000..67256f5 Binary files /dev/null and b/lang/cs/Tests/TangTests/evaluator.conf differ http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Tests/TangTests/packages.config ---------------------------------------------------------------------- diff --git a/lang/cs/Tests/TangTests/packages.config b/lang/cs/Tests/TangTests/packages.config new file mode 100644 index 0000000..933b7e1 --- /dev/null +++ b/lang/cs/Tests/TangTests/packages.config @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> +<packages> + <package id="Microsoft.Hadoop.Avro" version="1.4.0.0" targetFramework="net45" /> + <package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" /> + <package id="protobuf-net" version="2.0.0.668" targetFramework="net45" /> +</packages> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Tests/TangTests/simpleConstructorJavaProto.bin ---------------------------------------------------------------------- diff --git a/lang/cs/Tests/TangTests/simpleConstructorJavaProto.bin b/lang/cs/Tests/TangTests/simpleConstructorJavaProto.bin new file mode 100644 index 0000000..f7bb871 Binary files /dev/null and b/lang/cs/Tests/TangTests/simpleConstructorJavaProto.bin differ http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Tests/WakeTests/ClockTest.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Tests/WakeTests/ClockTest.cs b/lang/cs/Tests/WakeTests/ClockTest.cs new file mode 100644 index 0000000..d401235 --- /dev/null +++ b/lang/cs/Tests/WakeTests/ClockTest.cs @@ -0,0 +1,183 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reactive; +using System.Reactive.Subjects; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Org.Apache.Reef.Tang.Formats; +using Org.Apache.Reef.Tang.Implementations; +using Org.Apache.Reef.Tang.Util; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Org.Apache.Reef.Wake.Time; +using Org.Apache.Reef.Wake.Time.Runtime; +using Org.Apache.Reef.Wake.Time.Runtime.Event; + +namespace Org.Apache.Reef.Wake.Test +{ + [TestClass] + public class ClockTest + { + [TestMethod] + public void TestClock() + { + using (RuntimeClock clock = BuildClock()) + { + Task.Run(new Action(clock.Run)); + + var heartBeat = new HeartbeatObserver(clock); + heartBeat.OnNext(null); + Thread.Sleep(5000); + + Assert.AreEqual(100, heartBeat.EventCount); + } + } + + [TestMethod] + public void TestAlarmRegistrationRaceConditions() + { + using (RuntimeClock clock = BuildClock()) + { + Task.Run(new Action(clock.Run)); + + List<Alarm> events1 = new List<Alarm>(); + List<Alarm> events2 = new List<Alarm>(); + + // Observers to record events that they have processed + IObserver<Alarm> earlierRecorder = Observer.Create<Alarm>(events1.Add); + IObserver<Alarm> laterRecorder = Observer.Create<Alarm>(events2.Add); + + // Schedule a later alarm in the future + clock.ScheduleAlarm(5000, laterRecorder); + + // After 1 second, schedule an earlier alarm that will fire before the later alarm + Thread.Sleep(1000); + clock.ScheduleAlarm(2000, earlierRecorder); + + // The earlier alarm should not have fired after 1 second + Thread.Sleep(1000); + Assert.AreEqual(0, events1.Count); + + // The earlier alarm will have fired after another 1.5 seconds, but the later will have not + Thread.Sleep(1500); + Assert.AreEqual(1, events1.Count); + Assert.AreEqual(0, events2.Count); + + // The later alarm will have fired after 2 seconds + Thread.Sleep(2000); + Assert.AreEqual(1, events1.Count); + } + } + + [TestMethod] + public void TestSimulatenousAlarms() + { + using (RuntimeClock clock = BuildClock()) + { + Task.Run(new Action(clock.Run)); + + List<Alarm> events = new List<Alarm>(); + IObserver<Alarm> eventRecorder = Observer.Create<Alarm>(events.Add); + + clock.ScheduleAlarm(1000, eventRecorder); + clock.ScheduleAlarm(1000, eventRecorder); + clock.ScheduleAlarm(1000, eventRecorder); + + Thread.Sleep(1500); + Assert.AreEqual(3, events.Count); + } + } + + [TestMethod] + public void TestAlarmOrder() + { + using (RuntimeClock clock = BuildLogicalClock()) + { + Task.Run(new Action(clock.Run)); + + // Event handler to record event time stamps + List<long> recordedTimestamps = new List<long>(); + IObserver<Alarm> eventRecorder = Observer.Create<Alarm>(alarm => recordedTimestamps.Add(alarm.TimeStamp)); + + // Schedule 10 alarms every 100 ms + List<long> expectedTimestamps = Enumerable.Range(0, 10).Select(offset => (long)offset * 100).ToList(); + expectedTimestamps.ForEach(offset => clock.ScheduleAlarm(offset, eventRecorder)); + + // Check that the recorded timestamps are in the same order that they were scheduled + Thread.Sleep(1500); + Assert.IsTrue(expectedTimestamps.SequenceEqual(recordedTimestamps)); + } + } + + private RuntimeClock BuildClock() + { + var builder = TangFactory.GetTang().NewConfigurationBuilder(); + + return TangFactory.GetTang() + .NewInjector(builder.Build()) + .GetInstance<RuntimeClock>(); + } + + private RuntimeClock BuildLogicalClock() + { + var builder = TangFactory.GetTang().NewConfigurationBuilder(); + builder.BindImplementation(GenericType<ITimer>.Class, GenericType<LogicalTimer>.Class); + + return TangFactory.GetTang() + .NewInjector(builder.Build()) + .GetInstance<RuntimeClock>(); + } + + private class HeartbeatObserver : IObserver<Alarm> + { + private RuntimeClock _clock; + + public HeartbeatObserver(RuntimeClock clock) + { + _clock = clock; + EventCount = 0; + } + + public int EventCount { get; set; } + + public void OnNext(Alarm value) + { + EventCount++; + if (EventCount < 100) + { + _clock.ScheduleAlarm(10, this); + } + } + + public void OnError(Exception error) + { + throw new NotImplementedException(); + } + + public void OnCompleted() + { + throw new NotImplementedException(); + } + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Tests/WakeTests/MultiCodecTest.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Tests/WakeTests/MultiCodecTest.cs b/lang/cs/Tests/WakeTests/MultiCodecTest.cs new file mode 100644 index 0000000..0a3240f --- /dev/null +++ b/lang/cs/Tests/WakeTests/MultiCodecTest.cs @@ -0,0 +1,102 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Org.Apache.Reef.Wake.Remote; +using Org.Apache.Reef.Wake.Remote.Impl; + +namespace Org.Apache.Reef.Wake.Test +{ + [TestClass] + public class MultiCodecTest + { + [TestMethod] + public void TestMultiCodec() + { + MultiCodec<BaseEvent> codec = new MultiCodec<BaseEvent>(); + codec.Register(new Event1Codec()); + codec.Register(new Event2Codec()); + + byte[] d1Data = codec.Encode(new Event1(42)); + byte[] d2Data = codec.Encode(new Event2("Tony")); + + Event1 e1 = (Event1)codec.Decode(d1Data); + Event2 e2 = (Event2)codec.Decode(d2Data); + + Assert.AreEqual(42, e1.Number); + Assert.AreEqual("Tony", e2.Name); + } + + private class BaseEvent + { + } + + private class Event1 : BaseEvent + { + public Event1(int number) + { + Number = number; + } + + public int Number { get; set; } + } + + private class Event2 : BaseEvent + { + public Event2(string name) + { + Name = name; + } + + public string Name { get; set; } + } + + private class Event1Codec : ICodec<Event1> + { + public byte[] Encode(Event1 obj) + { + return BitConverter.GetBytes(obj.Number); + } + + public Event1 Decode(byte[] data) + { + return new Event1(BitConverter.ToInt32(data, 0)); + } + } + + private class Event2Codec : ICodec<Event2> + { + public byte[] Encode(Event2 obj) + { + return Encoding.ASCII.GetBytes(obj.Name); + } + + public Event2 Decode(byte[] data) + { + return new Event2(Encoding.ASCII.GetString(data)); + } + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Tests/WakeTests/Properties/AssemblyInfo.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Tests/WakeTests/Properties/AssemblyInfo.cs b/lang/cs/Tests/WakeTests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..d126f3f --- /dev/null +++ b/lang/cs/Tests/WakeTests/Properties/AssemblyInfo.cs @@ -0,0 +1,55 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Org.Apache.Reef.Wake.Tests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Org.Apache.Reef.Wake.Tests")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("68a2ef80-e51b-4abb-9ccc-81354e152758")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Tests/WakeTests/PubSubSubjectTest.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Tests/WakeTests/PubSubSubjectTest.cs b/lang/cs/Tests/WakeTests/PubSubSubjectTest.cs new file mode 100644 index 0000000..be27782 --- /dev/null +++ b/lang/cs/Tests/WakeTests/PubSubSubjectTest.cs @@ -0,0 +1,209 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reactive; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Org.Apache.Reef.Wake.RX.Impl; + +namespace Test.Wake +{ + [TestClass] + public class PubSubSubjectTest + { + [TestMethod] + public void TestPubSubSubjectSingleThread() + { + int sum = 0; + + // Observer that adds sum of numbers up to and including x + PubSubSubject<int> subject = new PubSubSubject<int>(); + subject.Subscribe(Observer.Create<int>( + x => + { + for (int i = 0; i <= x; i++) + { + sum += i; + } + })); + + subject.OnNext(10); + subject.OnCompleted(); + Assert.AreEqual(sum, 55); + } + + [TestMethod] + public void TestPubSubSubjectMultipleThreads() + { + int sum = 0; + + PubSubSubject<int> subject = new PubSubSubject<int>(); + subject.Subscribe(Observer.Create<int>(x => sum += x)); + + Thread[] threads = new Thread[10]; + for (int i = 0; i < threads.Length; i++) + { + threads[i] = new Thread(() => + { + for (int j = 0; j < 10000; j++) + { + subject.OnNext(1); + } + }); + + threads[i].Start(); + } + + foreach (Thread thread in threads) + { + thread.Join(); + } + + Assert.AreEqual(sum, 100000); + } + + [TestMethod] + public void TestMultipleTypes() + { + int sum1 = 0; + int sum2 = 0; + + PubSubSubject<SuperEvent> subject = new PubSubSubject<SuperEvent>(); + subject.Subscribe(Observer.Create<SubEvent1>(x => sum1 += 100)); + subject.Subscribe(Observer.Create<SubEvent2>(x => sum2 += 500)); + + subject.OnNext(new SubEvent1()); + subject.OnNext(new SubEvent2()); + subject.OnNext(new SubEvent2()); + + Assert.AreEqual(sum1, 100); + Assert.AreEqual(sum2, 1000); + } + + [TestMethod] + public void TestOnCompleted() + { + int sum = 0; + + PubSubSubject<int> subject = new PubSubSubject<int>(); + subject.Subscribe(Observer.Create<int>(x => sum += x)); + + subject.OnNext(10); + Assert.AreEqual(10, sum); + + subject.OnNext(10); + Assert.AreEqual(20, sum); + + // Check that after calling OnCompleted, OnNext will do nothing + subject.OnCompleted(); + subject.OnNext(10); + Assert.AreEqual(20, sum); + } + + [TestMethod] + public void TestOnError() + { + int sum = 0; + + PubSubSubject<int> subject = new PubSubSubject<int>(); + subject.Subscribe(Observer.Create<int>(x => sum += x)); + + subject.OnNext(10); + Assert.AreEqual(10, sum); + + subject.OnNext(10); + Assert.AreEqual(20, sum); + + // Check that after calling OnError, OnNext will do nothing + subject.OnError(new Exception("error")); + subject.OnNext(10); + Assert.AreEqual(20, sum); + } + + [TestMethod] + public void TestDisposeSingleSubject() + { + int sum = 0; + + PubSubSubject<int> subject = new PubSubSubject<int>(); + var disposable = subject.Subscribe(Observer.Create<int>(x => sum += x)); + + subject.OnNext(10); + subject.OnNext(10); + subject.OnNext(10); + Assert.AreEqual(30, sum); + + // Unregister the subject and check that calling OnNext does nothing + disposable.Dispose(); + subject.OnNext(10); + Assert.AreEqual(30, sum); + } + + [TestMethod] + public void TestDisposeMultipleSubjects() + { + int sum1 = 0; + int sum2 = 0; + + SubEvent1 event1 = new SubEvent1(); + SubEvent2 event2 = new SubEvent2(); + + PubSubSubject<SuperEvent> subject = new PubSubSubject<SuperEvent>(); + var disposable1 = subject.Subscribe(Observer.Create<SubEvent1>(x => sum1 += 100)); + var disposable2 = subject.Subscribe(Observer.Create<SubEvent2>(x => sum2 += 500)); + + subject.OnNext(event1); + subject.OnNext(event2); + subject.OnNext(event2); + Assert.AreEqual(sum1, 100); + Assert.AreEqual(sum2, 1000); + + // Check that unsubscribing from SubEvent1 does not affect other subscriptions + disposable1.Dispose(); + subject.OnNext(event1); + subject.OnNext(event2); + Assert.AreEqual(sum1, 100); + Assert.AreEqual(sum2, 1500); + + // Unsubscribe from the remaining event types + disposable2.Dispose(); + subject.OnNext(event1); + subject.OnNext(event2); + Assert.AreEqual(sum1, 100); + Assert.AreEqual(sum2, 1500); + } + + class SuperEvent + { + } + + class SubEvent1 : SuperEvent + { + } + + class SubEvent2 : SuperEvent + { + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Tests/WakeTests/RemoteManagerTest.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Tests/WakeTests/RemoteManagerTest.cs b/lang/cs/Tests/WakeTests/RemoteManagerTest.cs new file mode 100644 index 0000000..3c4150a --- /dev/null +++ b/lang/cs/Tests/WakeTests/RemoteManagerTest.cs @@ -0,0 +1,344 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Org.Apache.Reef.Wake.Remote; +using Org.Apache.Reef.Wake.Remote.Impl; +using Org.Apache.Reef.Wake.RX; +using Org.Apache.Reef.Wake.Util; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Reactive; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace Org.Apache.Reef.Wake.Test +{ + [TestClass] + public class RemoteManagerTest + { + [TestMethod] + public void TestOneWayCommunication() + { + IPAddress listeningAddress = IPAddress.Parse("127.0.0.1"); + + BlockingCollection<string> queue = new BlockingCollection<string>(); + List<string> events = new List<string>(); + + using (var remoteManager1 = new DefaultRemoteManager<string>(listeningAddress, 0, new StringCodec())) + using (var remoteManager2 = new DefaultRemoteManager<string>(listeningAddress, 0, new StringCodec())) + { + var observer = Observer.Create<string>(queue.Add); + IPEndPoint endpoint1 = new IPEndPoint(listeningAddress, 0); + remoteManager2.RegisterObserver(endpoint1, observer); + + var remoteObserver = remoteManager1.GetRemoteObserver(remoteManager2.LocalEndpoint); + remoteObserver.OnNext("abc"); + remoteObserver.OnNext("def"); + remoteObserver.OnNext("ghi"); + + events.Add(queue.Take()); + events.Add(queue.Take()); + events.Add(queue.Take()); + } + + Assert.AreEqual(3, events.Count); + } + + [TestMethod] + public void TestOneWayCommunicationClientOnly() + { + int listeningPort = NetworkUtils.GenerateRandomPort(6000, 7000); + IPAddress listeningAddress = IPAddress.Parse("127.0.0.1"); + + BlockingCollection<string> queue = new BlockingCollection<string>(); + List<string> events = new List<string>(); + + using (var remoteManager1 = new DefaultRemoteManager<string>(new StringCodec())) + using (var remoteManager2 = new DefaultRemoteManager<string>(listeningAddress, listeningPort, new StringCodec())) + { + IPEndPoint remoteEndpoint = new IPEndPoint(listeningAddress, 0); + var observer = Observer.Create<string>(queue.Add); + remoteManager2.RegisterObserver(remoteEndpoint, observer); + + var remoteObserver = remoteManager1.GetRemoteObserver(remoteManager2.LocalEndpoint); + remoteObserver.OnNext("abc"); + remoteObserver.OnNext("def"); + remoteObserver.OnNext("ghi"); + + events.Add(queue.Take()); + events.Add(queue.Take()); + events.Add(queue.Take()); + } + + Assert.AreEqual(3, events.Count); + } + + [TestMethod] + public void TestTwoWayCommunication() + { + IPAddress listeningAddress = IPAddress.Parse("127.0.0.1"); + + BlockingCollection<string> queue1 = new BlockingCollection<string>(); + BlockingCollection<string> queue2 = new BlockingCollection<string>(); + List<string> events1 = new List<string>(); + List<string> events2 = new List<string>(); + + using (var remoteManager1 = new DefaultRemoteManager<string>(listeningAddress, 0, new StringCodec())) + using (var remoteManager2 = new DefaultRemoteManager<string>(listeningAddress, 0, new StringCodec())) + { + // Register observers for remote manager 1 and remote manager 2 + var remoteEndpoint = new IPEndPoint(listeningAddress, 0); + var observer1 = Observer.Create<string>(queue1.Add); + var observer2 = Observer.Create<string>(queue2.Add); + remoteManager1.RegisterObserver(remoteEndpoint, observer1); + remoteManager2.RegisterObserver(remoteEndpoint, observer2); + + // Remote manager 1 sends 3 events to remote manager 2 + var remoteObserver1 = remoteManager1.GetRemoteObserver(remoteManager2.LocalEndpoint); + remoteObserver1.OnNext("abc"); + remoteObserver1.OnNext("def"); + remoteObserver1.OnNext("ghi"); + + // Remote manager 2 sends 4 events to remote manager 1 + var remoteObserver2 = remoteManager2.GetRemoteObserver(remoteManager1.LocalEndpoint); + remoteObserver2.OnNext("jkl"); + remoteObserver2.OnNext("mno"); + remoteObserver2.OnNext("pqr"); + remoteObserver2.OnNext("stu"); + + events1.Add(queue1.Take()); + events1.Add(queue1.Take()); + events1.Add(queue1.Take()); + events1.Add(queue1.Take()); + + events2.Add(queue2.Take()); + events2.Add(queue2.Take()); + events2.Add(queue2.Take()); + } + + Assert.AreEqual(4, events1.Count); + Assert.AreEqual(3, events2.Count); + } + + [TestMethod] + public void TestCommunicationThreeNodesOneWay() + { + IPAddress listeningAddress = IPAddress.Parse("127.0.0.1"); + + BlockingCollection<string> queue = new BlockingCollection<string>(); + List<string> events = new List<string>(); + + using (var remoteManager1 = new DefaultRemoteManager<string>(listeningAddress, 0, new StringCodec())) + using (var remoteManager2 = new DefaultRemoteManager<string>(listeningAddress, 0, new StringCodec())) + using (var remoteManager3 = new DefaultRemoteManager<string>(listeningAddress, 0, new StringCodec())) + { + var remoteEndpoint = new IPEndPoint(listeningAddress, 0); + var observer = Observer.Create<string>(queue.Add); + remoteManager3.RegisterObserver(remoteEndpoint, observer); + + var remoteObserver1 = remoteManager1.GetRemoteObserver(remoteManager3.LocalEndpoint); + var remoteObserver2 = remoteManager2.GetRemoteObserver(remoteManager3.LocalEndpoint); + + remoteObserver2.OnNext("abc"); + remoteObserver1.OnNext("def"); + remoteObserver2.OnNext("ghi"); + remoteObserver1.OnNext("jkl"); + remoteObserver2.OnNext("mno"); + + for (int i = 0; i < 5; i++) + { + events.Add(queue.Take()); + } + } + + Assert.AreEqual(5, events.Count); + } + + [TestMethod] + public void TestCommunicationThreeNodesBothWays() + { + IPAddress listeningAddress = IPAddress.Parse("127.0.0.1"); + + BlockingCollection<string> queue1 = new BlockingCollection<string>(); + BlockingCollection<string> queue2 = new BlockingCollection<string>(); + BlockingCollection<string> queue3 = new BlockingCollection<string>(); + List<string> events1 = new List<string>(); + List<string> events2 = new List<string>(); + List<string> events3 = new List<string>(); + + using (var remoteManager1 = new DefaultRemoteManager<string>(listeningAddress, 0, new StringCodec())) + using (var remoteManager2 = new DefaultRemoteManager<string>(listeningAddress, 0, new StringCodec())) + using (var remoteManager3 = new DefaultRemoteManager<string>(listeningAddress, 0, new StringCodec())) + { + var remoteEndpoint = new IPEndPoint(listeningAddress, 0); + + var observer = Observer.Create<string>(queue1.Add); + remoteManager1.RegisterObserver(remoteEndpoint, observer); + var observer2 = Observer.Create<string>(queue2.Add); + remoteManager2.RegisterObserver(remoteEndpoint, observer2); + var observer3 = Observer.Create<string>(queue3.Add); + remoteManager3.RegisterObserver(remoteEndpoint, observer3); + + var remoteObserver1 = remoteManager1.GetRemoteObserver(remoteManager3.LocalEndpoint); + var remoteObserver2 = remoteManager2.GetRemoteObserver(remoteManager3.LocalEndpoint); + + // Observer 1 and 2 send messages to observer 3 + remoteObserver1.OnNext("abc"); + remoteObserver1.OnNext("abc"); + remoteObserver1.OnNext("abc"); + remoteObserver2.OnNext("def"); + remoteObserver2.OnNext("def"); + + // Observer 3 sends messages back to observers 1 and 2 + var remoteObserver3a = remoteManager3.GetRemoteObserver(remoteManager1.LocalEndpoint); + var remoteObserver3b = remoteManager3.GetRemoteObserver(remoteManager2.LocalEndpoint); + + remoteObserver3a.OnNext("ghi"); + remoteObserver3a.OnNext("ghi"); + remoteObserver3b.OnNext("jkl"); + remoteObserver3b.OnNext("jkl"); + remoteObserver3b.OnNext("jkl"); + + events1.Add(queue1.Take()); + events1.Add(queue1.Take()); + + events2.Add(queue2.Take()); + events2.Add(queue2.Take()); + events2.Add(queue2.Take()); + + events3.Add(queue3.Take()); + events3.Add(queue3.Take()); + events3.Add(queue3.Take()); + events3.Add(queue3.Take()); + events3.Add(queue3.Take()); + } + + Assert.AreEqual(2, events1.Count); + Assert.AreEqual(3, events2.Count); + Assert.AreEqual(5, events3.Count); + } + + [TestMethod] + public void TestRemoteSenderCallback() + { + IPAddress listeningAddress = IPAddress.Parse("127.0.0.1"); + + BlockingCollection<string> queue = new BlockingCollection<string>(); + List<string> events = new List<string>(); + + using (var remoteManager1 = new DefaultRemoteManager<string>(listeningAddress, 0, new StringCodec())) + using (var remoteManager2 = new DefaultRemoteManager<string>(listeningAddress, 0, new StringCodec())) + { + // Register handler for when remote manager 2 receives events; respond + // with an ack + var remoteEndpoint = new IPEndPoint(listeningAddress, 0); + var remoteObserver2 = remoteManager2.GetRemoteObserver(remoteManager1.LocalEndpoint); + + var receiverObserver = Observer.Create<string>( + message => remoteObserver2.OnNext("received message: " + message)); + remoteManager2.RegisterObserver(remoteEndpoint, receiverObserver); + + // Register handler for remote manager 1 to record the ack + var senderObserver = Observer.Create<string>(queue.Add); + remoteManager1.RegisterObserver(remoteEndpoint, senderObserver); + + // Begin to send messages + var remoteObserver1 = remoteManager1.GetRemoteObserver(remoteManager2.LocalEndpoint); + remoteObserver1.OnNext("hello"); + remoteObserver1.OnNext("there"); + remoteObserver1.OnNext("buddy"); + + events.Add(queue.Take()); + events.Add(queue.Take()); + events.Add(queue.Take()); + } + + Assert.AreEqual(3, events.Count); + Assert.AreEqual("received message: hello", events[0]); + Assert.AreEqual("received message: there", events[1]); + Assert.AreEqual("received message: buddy", events[2]); + } + + [TestMethod] + public void TestRegisterObserverByType() + { + IPAddress listeningAddress = IPAddress.Parse("127.0.0.1"); + + BlockingCollection<string> queue = new BlockingCollection<string>(); + List<string> events = new List<string>(); + + using (var remoteManager1 = new DefaultRemoteManager<string>(listeningAddress, 0, new StringCodec())) + using (var remoteManager2 = new DefaultRemoteManager<string>(listeningAddress, 0, new StringCodec())) + { + // RemoteManager2 listens and records events of type IRemoteEvent<string> + var observer = Observer.Create<IRemoteMessage<string>>(message => queue.Add(message.Message)); + remoteManager2.RegisterObserver(observer); + + // Remote manager 1 sends 3 events to remote manager 2 + var remoteObserver = remoteManager1.GetRemoteObserver(remoteManager2.LocalEndpoint); + remoteObserver.OnNext("abc"); + remoteObserver.OnNext("def"); + remoteObserver.OnNext("ghi"); + + events.Add(queue.Take()); + events.Add(queue.Take()); + events.Add(queue.Take()); + } + + Assert.AreEqual(3, events.Count); + } + + [TestMethod] + public void TestCachedConnection() + { + IPAddress listeningAddress = IPAddress.Parse("127.0.0.1"); + + BlockingCollection<string> queue = new BlockingCollection<string>(); + List<string> events = new List<string>(); + + using (var remoteManager1 = new DefaultRemoteManager<string>(listeningAddress, 0, new StringCodec())) + using (var remoteManager2 = new DefaultRemoteManager<string>(listeningAddress, 0, new StringCodec())) + { + var observer = Observer.Create<string>(queue.Add); + IPEndPoint endpoint1 = new IPEndPoint(listeningAddress, 0); + remoteManager2.RegisterObserver(endpoint1, observer); + + var remoteObserver = remoteManager1.GetRemoteObserver(remoteManager2.LocalEndpoint); + remoteObserver.OnNext("abc"); + remoteObserver.OnNext("def"); + + var cachedObserver = remoteManager1.GetRemoteObserver(remoteManager2.LocalEndpoint); + cachedObserver.OnNext("ghi"); + cachedObserver.OnNext("jkl"); + + events.Add(queue.Take()); + events.Add(queue.Take()); + events.Add(queue.Take()); + events.Add(queue.Take()); + } + + Assert.AreEqual(4, events.Count); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Tests/WakeTests/TransportTest.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Tests/WakeTests/TransportTest.cs b/lang/cs/Tests/WakeTests/TransportTest.cs new file mode 100644 index 0000000..07671a5 --- /dev/null +++ b/lang/cs/Tests/WakeTests/TransportTest.cs @@ -0,0 +1,205 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Reactive; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Org.Apache.Reef.Wake.Remote; +using Org.Apache.Reef.Wake.Remote.Impl; +using Org.Apache.Reef.Wake.Util; + +namespace Org.Apache.Reef.Wake.Test +{ + [TestClass] + public class TransportTest + { + [TestMethod] + public void TestTransportServer() + { + ICodec<string> codec = new StringCodec(); + int port = NetworkUtils.GenerateRandomPort(6000, 7000); + + BlockingCollection<string> queue = new BlockingCollection<string>(); + List<string> events = new List<string>(); + + IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, port); + var remoteHandler = Observer.Create<TransportEvent<string>>(tEvent => queue.Add(tEvent.Data)); + + using (var server = new TransportServer<string>(endpoint, remoteHandler, codec)) + { + server.Run(); + + IPEndPoint remoteEndpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port); + using (var client = new TransportClient<string>(remoteEndpoint, codec)) + { + client.Send("Hello"); + client.Send(", "); + client.Send("World!"); + + events.Add(queue.Take()); + events.Add(queue.Take()); + events.Add(queue.Take()); + } + } + + Assert.AreEqual(3, events.Count); + } + + [TestMethod] + public void TestTransportServerEvent() + { + ICodec<TestEvent> codec = new TestEventCodec(); + int port = NetworkUtils.GenerateRandomPort(6000, 7000); + + BlockingCollection<TestEvent> queue = new BlockingCollection<TestEvent>(); + List<TestEvent> events = new List<TestEvent>(); + + IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, port); + var remoteHandler = Observer.Create<TransportEvent<TestEvent>>(tEvent => queue.Add(tEvent.Data)); + + using (var server = new TransportServer<TestEvent>(endpoint, remoteHandler, codec)) + { + server.Run(); + + IPEndPoint remoteEndpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port); + using (var client = new TransportClient<TestEvent>(remoteEndpoint, codec)) + { + client.Send(new TestEvent("Hello")); + client.Send(new TestEvent(", ")); + client.Send(new TestEvent("World!")); + + events.Add(queue.Take()); + events.Add(queue.Take()); + events.Add(queue.Take()); + } + } + + Assert.AreEqual(3, events.Count); + } + + [TestMethod] + public void TestTransportSenderStage() + { + ICodec<string> codec = new StringCodec(); + int port = NetworkUtils.GenerateRandomPort(6000, 7000); + IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, port); + + List<string> events = new List<string>(); + BlockingCollection<string> queue = new BlockingCollection<string>(); + + // Server echoes the message back to the client + var remoteHandler = Observer.Create<TransportEvent<string>>(tEvent => tEvent.Link.Write(tEvent.Data)); + + using (TransportServer<string> server = new TransportServer<string>(endpoint, remoteHandler, codec)) + { + server.Run(); + + var clientHandler = Observer.Create<TransportEvent<string>>(tEvent => queue.Add(tEvent.Data)); + IPEndPoint remoteEndpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port); + using (var client = new TransportClient<string>(remoteEndpoint, codec, clientHandler)) + { + client.Send("Hello"); + client.Send(", "); + client.Send(" World"); + + events.Add(queue.Take()); + events.Add(queue.Take()); + events.Add(queue.Take()); + } + } + + Assert.AreEqual(3, events.Count); + } + + [TestMethod] + public void TestRaceCondition() + { + ICodec<string> codec = new StringCodec(); + int port = NetworkUtils.GenerateRandomPort(6000, 7000); + + BlockingCollection<string> queue = new BlockingCollection<string>(); + List<string> events = new List<string>(); + int numEventsExpected = 150; + + IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, port); + var remoteHandler = Observer.Create<TransportEvent<string>>(tEvent => queue.Add(tEvent.Data)); + + using (var server = new TransportServer<string>(endpoint, remoteHandler, codec)) + { + server.Run(); + + for (int i = 0; i < numEventsExpected / 3; i++) + { + Task.Run(() => + { + IPEndPoint remoteEndpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port); + using (var client = new TransportClient<string>(remoteEndpoint, codec)) + { + client.Send("Hello"); + client.Send(", "); + client.Send("World!"); + } + }); + } + + for (int i = 0; i < numEventsExpected; i++) + { + events.Add(queue.Take()); + } + } + + Assert.AreEqual(numEventsExpected, events.Count); + } + + private class TestEvent + { + public TestEvent(string message) + { + Message = message; + } + + public string Message { get; set; } + + public override string ToString() + { + return "TestEvent: " + Message; + } + } + + private class TestEventCodec : ICodec<TestEvent> + { + public byte[] Encode(TestEvent obj) + { + return new StringCodec().Encode(obj.Message); + } + + public TestEvent Decode(byte[] data) + { + return new TestEvent(new StringCodec().Decode(data)); + } + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Tests/WakeTests/WakeTests.csproj ---------------------------------------------------------------------- diff --git a/lang/cs/Tests/WakeTests/WakeTests.csproj b/lang/cs/Tests/WakeTests/WakeTests.csproj new file mode 100644 index 0000000..0f90252 --- /dev/null +++ b/lang/cs/Tests/WakeTests/WakeTests.csproj @@ -0,0 +1,103 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProjectGuid>{214C64C6-04E5-4867-B69A-E3502EA50871}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>Org.Apache.Reef.Wake.Test</RootNamespace> + <AssemblyName>Org.Apache.Reef.Wake.Test</AssemblyName> + <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <RestorePackages>true</RestorePackages> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>..\..\bin\Debug\Org.Apache.Reef.Wake.Test\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>..\..\bin\Release\Microsoft.Wake.Tests\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> + <Reference Include="System" /> + <Reference Include="System.Core" /> + <Reference Include="System.Reactive.Core"> + <HintPath>..\..\packages\Rx-Core.2.2.5\lib\net45\System.Reactive.Core.dll</HintPath> + </Reference> + <Reference Include="System.Reactive.Interfaces"> + <HintPath>..\..\packages\Rx-Interfaces.2.2.5\lib\net45\System.Reactive.Interfaces.dll</HintPath> + </Reference> + <Reference Include="System.Xml.Linq" /> + <Reference Include="System.Data.DataSetExtensions" /> + <Reference Include="Microsoft.CSharp" /> + <Reference Include="System.Data" /> + <Reference Include="System.Xml" /> + </ItemGroup> + <ItemGroup> + <Compile Include="ClockTest.cs" /> + <Compile Include="MultiCodecTest.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="PubSubSubjectTest.cs" /> + <Compile Include="RemoteManagerTest.cs" /> + <Compile Include="TransportTest.cs" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\Source\TANG\Tang\Tang.csproj"> + <Project>{97dbb573-3994-417a-9f69-ffa25f00d2a6}</Project> + <Name>Tang</Name> + </ProjectReference> + <ProjectReference Include="..\..\Source\WAKE\Wake\Wake.csproj"> + <Project>{cdfb3464-4041-42b1-9271-83af24cd5008}</Project> + <Name>Wake</Name> + </ProjectReference> + </ItemGroup> + <ItemGroup> + <None Include="packages.config" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> + <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" /> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> + --> +</Project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Tests/WakeTests/packages.config ---------------------------------------------------------------------- diff --git a/lang/cs/Tests/WakeTests/packages.config b/lang/cs/Tests/WakeTests/packages.config new file mode 100644 index 0000000..75e5b34 --- /dev/null +++ b/lang/cs/Tests/WakeTests/packages.config @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> +<packages> + <package id="Rx-Core" version="2.2.5" targetFramework="net45" /> + <package id="Rx-Interfaces" version="2.2.5" targetFramework="net45" /> +</packages> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/java/reef-bridge-project/reef-bridge-clr/src/main/CSharp/CSharp/ClrHandler/externals/Org.Apache.Reef.Driver.dll ---------------------------------------------------------------------- diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/CSharp/CSharp/ClrHandler/externals/Org.Apache.Reef.Driver.dll b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/CSharp/CSharp/ClrHandler/externals/Org.Apache.Reef.Driver.dll index 63582c0..c9a581b 100644 Binary files a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/CSharp/CSharp/ClrHandler/externals/Org.Apache.Reef.Driver.dll and b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/CSharp/CSharp/ClrHandler/externals/Org.Apache.Reef.Driver.dll differ http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 26ae273..f90872e 100644 --- a/pom.xml +++ b/pom.xml @@ -235,11 +235,26 @@ under the License. <exclude>.gitattributes</exclude> <exclude>.gitignore</exclude> <exclude>.git/**</exclude> - <exclude>.idea/**</exclude> - <exclude>target/**</exclude> + <exclude>lang/java/.idea/**</exclude> + <exclude>**/target/**</exclude> <exclude>README.*</exclude> <!-- The below are sometimes created during tests --> <exclude>REEF_LOCAL_RUNTIME/**</exclude> + <!-- The Visual Studio build files --> + <exclude>lang/cs/ReefDotNet.sln</exclude> + <exclude>**/*.csproj.user</exclude> + <!-- The below are auto generated during the .Net build --> + <exclude>lang/cs/bin/**</exclude> + <exclude>**/obj/**</exclude> + <!-- NuGet dependencies downloaded as part of the build --> + <exclude>lang/cs/packages/**</exclude> + <!-- The below are auto generated files for serialization --> + <exclude>lang/cs/Source/REEF/reef-common/ReefCommon/protobuf/cs/*</exclude> + <exclude>lang/cs/Source/REEF/reef-common/ReefCommon/avro/*</exclude> + <!-- The below are binary data files used in tests --> + <exclude>lang/cs/Tests/ReefTests/ConfigFiles/evaluator.conf</exclude> + <exclude>lang/cs/Tests/TangTests/evaluator.conf</exclude> + <exclude>lang/cs/Tests/TangTests/simpleConstructorJavaProto.bin</exclude> </excludes> </configuration> </plugin>
