Repository: incubator-reef Updated Branches: refs/heads/master f44a6599b -> 987d4f37d
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/987d4f37/lang/cs/Org.Apache.REEF.Tests/Network/NetworkServiceTests.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tests/Network/NetworkServiceTests.cs b/lang/cs/Org.Apache.REEF.Tests/Network/NetworkServiceTests.cs deleted file mode 100644 index 75f07c3..0000000 --- a/lang/cs/Org.Apache.REEF.Tests/Network/NetworkServiceTests.cs +++ /dev/null @@ -1,210 +0,0 @@ -/** - * 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.Globalization; -using System.Linq; -using System.Net; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Org.Apache.REEF.Common.Io; -using Org.Apache.REEF.Network.Naming; -using Org.Apache.REEF.Network.NetworkService; -using Org.Apache.REEF.Tang.Annotations; -using Org.Apache.REEF.Tang.Implementations.Tang; -using Org.Apache.REEF.Tang.Util; -using Org.Apache.REEF.Wake; -using Org.Apache.REEF.Wake.Remote; -using Org.Apache.REEF.Wake.Remote.Impl; -using Org.Apache.REEF.Wake.Util; - -namespace Org.Apache.REEF.Tests.Network -{ - [TestClass] - public class NetworkServiceTests - { - [TestMethod] - public void TestNetworkServiceOneWayCommunication() - { - int networkServicePort1 = NetworkUtils.GenerateRandomPort(6000, 7000); - int networkServicePort2 = NetworkUtils.GenerateRandomPort(7001, 8000); - - BlockingCollection<string> queue = new BlockingCollection<string>(); - - using (INameServer nameServer = new NameServer(0)) - { - IPEndPoint endpoint = nameServer.LocalEndpoint; - int nameServerPort = endpoint.Port; - string nameServerAddr = endpoint.Address.ToString(); - using (INetworkService<string> networkService1 = BuildNetworkService(networkServicePort1, nameServerPort, nameServerAddr, null)) - using (INetworkService<string> networkService2 = BuildNetworkService(networkServicePort2, nameServerPort, nameServerAddr, new MessageHandler(queue))) - { - IIdentifier id1 = new StringIdentifier("service1"); - IIdentifier id2 = new StringIdentifier("service2"); - networkService1.Register(id1); - networkService2.Register(id2); - - using (IConnection<string> connection = networkService1.NewConnection(id2)) - { - connection.Open(); - connection.Write("abc"); - connection.Write("def"); - connection.Write("ghi"); - - Assert.AreEqual("abc", queue.Take()); - Assert.AreEqual("def", queue.Take()); - Assert.AreEqual("ghi", queue.Take()); - } - } - } - } - - [TestMethod] - public void TestNetworkServiceTwoWayCommunication() - { - int networkServicePort1 = NetworkUtils.GenerateRandomPort(6000, 7000); - int networkServicePort2 = NetworkUtils.GenerateRandomPort(7001, 8000); - - BlockingCollection<string> queue1 = new BlockingCollection<string>(); - BlockingCollection<string> queue2 = new BlockingCollection<string>(); - - using (INameServer nameServer = new NameServer(0)) - { - IPEndPoint endpoint = nameServer.LocalEndpoint; - int nameServerPort = endpoint.Port; - string nameServerAddr = endpoint.Address.ToString(); - using (INetworkService<string> networkService1 = BuildNetworkService(networkServicePort1, nameServerPort, nameServerAddr, new MessageHandler(queue1))) - using (INetworkService<string> networkService2 = BuildNetworkService(networkServicePort2, nameServerPort, nameServerAddr, new MessageHandler(queue2))) - { - IIdentifier id1 = new StringIdentifier("service1"); - IIdentifier id2 = new StringIdentifier("service2"); - networkService1.Register(id1); - networkService2.Register(id2); - - using (IConnection<string> connection1 = networkService1.NewConnection(id2)) - using (IConnection<string> connection2 = networkService2.NewConnection(id1)) - { - connection1.Open(); - connection1.Write("abc"); - connection1.Write("def"); - connection1.Write("ghi"); - - connection2.Open(); - connection2.Write("jkl"); - connection2.Write("mno"); - - Assert.AreEqual("abc", queue2.Take()); - Assert.AreEqual("def", queue2.Take()); - Assert.AreEqual("ghi", queue2.Take()); - - Assert.AreEqual("jkl", queue1.Take()); - Assert.AreEqual("mno", queue1.Take()); - } - } - } - } - - private INetworkService<string> BuildNetworkService( - int networkServicePort, - int nameServicePort, - string nameServiceAddr, - IObserver<NsMessage<string>> handler) - { - // Test injection - if (handler == null) - { - var networkServiceConf = TangFactory.GetTang().NewConfigurationBuilder() - .BindNamedParameter<NetworkServiceOptions.NetworkServicePort, int>( - GenericType<NetworkServiceOptions.NetworkServicePort>.Class, - networkServicePort.ToString(CultureInfo.CurrentCulture)) - .BindNamedParameter<NamingConfigurationOptions.NameServerPort, int>( - GenericType<NamingConfigurationOptions.NameServerPort>.Class, - nameServicePort.ToString(CultureInfo.CurrentCulture)) - .BindNamedParameter<NamingConfigurationOptions.NameServerAddress, string>( - GenericType<NamingConfigurationOptions.NameServerAddress>.Class, - nameServiceAddr) - .BindImplementation(GenericType<INameClient>.Class, GenericType<NameClient>.Class) - .BindImplementation(GenericType<ICodec<string>>.Class, GenericType<StringCodec>.Class) - .BindImplementation(GenericType<IObserver<NsMessage<string>>>.Class, GenericType<NetworkMessageHandler>.Class) - .Build(); - - return TangFactory.GetTang().NewInjector(networkServiceConf).GetInstance<NetworkService<string>>(); - } - - var nameserverConf = TangFactory.GetTang().NewConfigurationBuilder() - .BindNamedParameter<NamingConfigurationOptions.NameServerPort, int>( - GenericType<NamingConfigurationOptions.NameServerPort>.Class, - nameServicePort.ToString(CultureInfo.CurrentCulture)) - .BindNamedParameter<NamingConfigurationOptions.NameServerAddress, string>( - GenericType<NamingConfigurationOptions.NameServerAddress>.Class, - nameServiceAddr) - .BindImplementation(GenericType<INameClient>.Class, GenericType<NameClient>.Class) - .Build(); - - var nameClient = TangFactory.GetTang().NewInjector(nameserverConf).GetInstance<NameClient>(); - return new NetworkService<string>(networkServicePort, - handler, new StringIdentifierFactory(), new StringCodec(), nameClient); - } - - private class MessageHandler : IObserver<NsMessage<string>> - { - private readonly BlockingCollection<string> _queue; - - public MessageHandler(BlockingCollection<string> queue) - { - _queue = queue; - } - - public void OnNext(NsMessage<string> value) - { - _queue.Add(value.Data.First()); - } - - public void OnError(Exception error) - { - throw new NotImplementedException(); - } - - public void OnCompleted() - { - throw new NotImplementedException(); - } - } - - private class NetworkMessageHandler : IObserver<NsMessage<string>> - { - [Inject] - public NetworkMessageHandler() - { - } - - public void OnNext(NsMessage<string> value) - { - } - - public void OnError(Exception error) - { - } - - public void OnCompleted() - { - } - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/987d4f37/lang/cs/Org.Apache.REEF.Tests/Org.Apache.REEF.Tests.csproj ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tests/Org.Apache.REEF.Tests.csproj b/lang/cs/Org.Apache.REEF.Tests/Org.Apache.REEF.Tests.csproj index a915f59..8cbcf61 100644 --- a/lang/cs/Org.Apache.REEF.Tests/Org.Apache.REEF.Tests.csproj +++ b/lang/cs/Org.Apache.REEF.Tests/Org.Apache.REEF.Tests.csproj @@ -73,11 +73,6 @@ under the License. <Compile Include="Functional\MPI\ScatterReduceTest\ScatterReduceTest.cs" /> <Compile Include="Functional\MPI\ScatterReduceTest\SlaveTask.cs" /> <Compile Include="Functional\ReefFunctionalTest.cs" /> - <Compile Include="Network\BlockingCollectionExtensionTests.cs" /> - <Compile Include="Network\GroupCommunicationTests.cs" /> - <Compile Include="Network\GroupCommunicationTreeTopologyTests.cs" /> - <Compile Include="Network\NameServerTests.cs" /> - <Compile Include="Network\NetworkServiceTests.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Utility\TestDriverConfigGenerator.cs" /> <Compile Include="Utility\TestExceptions.cs" /> http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/987d4f37/lang/cs/Org.Apache.REEF.sln ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.sln b/lang/cs/Org.Apache.REEF.sln index 8616032..69fc800 100644 Binary files a/lang/cs/Org.Apache.REEF.sln and b/lang/cs/Org.Apache.REEF.sln differ
