public void NetModule_Process_SendDatatoAvaliableAndUnavalilableServers() { var server1 = new ServerId("localhost", 21121); var server2 = new ServerId("localhost", 21122); var server3 = new ServerId("localhost", 21123); var netconfig = new ConnectionConfiguration("testService", 10); var queueconfig = new QueueConfiguration(1, 100); var distrconfig = new DistributorHashConfiguration(2); var s1 = TestHelper.OpenWriterHost(server1, netconfig); var s2 = TestHelper.OpenWriterHost(server2, netconfig); var net = new DistributorNetModule(netconfig, new ConnectionTimeoutConfiguration(Consts.OpenTimeout, Consts.SendTimeout)); var distributor = new DistributorModule(new AsyncTasksConfiguration(TimeSpan.FromMinutes(5)), new AsyncTasksConfiguration(TimeSpan.FromMinutes(5)), distrconfig, queueconfig, net, new ServerId("localhost", 1), new ServerId("localhost", 1), new HashMapConfiguration("test12", HashMapCreationMode.CreateNew, 1, 1, HashFileType.Distributor)); net.SetDistributor(distributor); distributor.Start(); net.Start(); GlobalQueue.Queue.Start(); net.ConnectToWriter(server1); net.ConnectToWriter(server2); var ev = new InnerData(new Transaction("", "")) { Transaction = { Destination = new List <ServerId> { server1 } } }; var ret1 = net.Process(server1, ev); var ret2 = net.Process(server2, ev); var ret3 = net.Process(server3, ev); Assert.AreEqual(1, s1.Value); Assert.AreEqual(1, s2.Value); Assert.AreEqual(typeof(SuccessResult), ret1.GetType()); Assert.AreEqual(typeof(SuccessResult), ret2.GetType()); Assert.AreEqual(typeof(ServerNotFoundResult), ret3.GetType()); GlobalQueue.Queue.Dispose(); net.Dispose(); }
public void AsyncTaskModule_PingServers_AvalilableAfterSomeTime() { const int storageServer1 = 22131; const int storageServer2 = 22132; const int distrServer1 = 22134; const int distrServer12 = 23134; var writer = new HashWriter(new HashMapConfiguration("TestAsyncPing", HashMapCreationMode.CreateNew, 2, 3, HashFileType.Distributor)); writer.CreateMap(); writer.SetServer(0, "localhost", storageServer1, 157); writer.SetServer(1, "localhost", storageServer2, 157); writer.Save(); #region hell var connection = new ConnectionConfiguration("testService", 10); var distrconfig = new DistributorHashConfiguration(1); var queueconfig = new QueueConfiguration(1, 100); var dnet = new DistributorNetModule(connection, new ConnectionTimeoutConfiguration(Consts.OpenTimeout, Consts.SendTimeout)); var ddistributor = new DistributorModule(new AsyncTasksConfiguration(TimeSpan.FromMilliseconds(200)), new AsyncTasksConfiguration(TimeSpan.FromMilliseconds(200)), distrconfig, queueconfig, dnet, new ServerId("localhost", distrServer1), new ServerId("localhost", distrServer12), new HashMapConfiguration("TestAsyncPing", HashMapCreationMode.ReadFromFile, 1, 1, HashFileType.Distributor)); dnet.SetDistributor(ddistributor); dnet.Start(); ddistributor.Start(); GlobalQueue.Queue.Start(); #endregion var data1 = new InnerData(new Transaction("", "")); var data2 = new InnerData(new Transaction("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", "")); var dest = ddistributor.GetDestination(data1, false); var dest2 = ddistributor.GetDestination(data2, false); dnet.Process(dest.First(), data1); dnet.Process(dest2.First(), data1); Thread.Sleep(100); dest = ddistributor.GetDestination(data1, false); dest2 = ddistributor.GetDestination(data2, false); Assert.AreEqual(null, dest); Assert.AreEqual(null, dest2); TestHelper.OpenWriterHost(new ServerId("localhost", storageServer1), new ConnectionConfiguration("testService", 10)); TestHelper.OpenWriterHost(new ServerId("localhost", storageServer2), new ConnectionConfiguration("testService", 10)); Thread.Sleep(TimeSpan.FromMilliseconds(800)); Assert.AreEqual(1, ddistributor.GetDestination(data1, false).Count); Assert.AreEqual(1, ddistributor.GetDestination(data2, false).Count); ddistributor.Dispose(); }