public void TransactionModule_ProcessSyncWithExecutor_RollbackNoEnoughServers() { var server1 = new ServerId("localhost", 21141); var server2 = new ServerId("localhost", 21142); var server3 = new ServerId("localhost", 21143); var netconfig = new ConnectionConfiguration("testService", 10); var queueconfig = new QueueConfiguration(1, 100); var distrconfig = new DistributorHashConfiguration(2); var distributor = new DistributorModule(new AsyncTasksConfiguration(TimeSpan.FromMinutes(5)), new AsyncTasksConfiguration(TimeSpan.FromMinutes(5)), distrconfig, queueconfig, null, new ServerId("localhost", 1), new ServerId("localhost", 1), new HashMapConfiguration("test10", HashMapCreationMode.CreateNew, 1, 1, HashFileType.Distributor)); var net = new DistributorNetModule(netconfig, new ConnectionTimeoutConfiguration(Consts.OpenTimeout, Consts.SendTimeout)); net.SetDistributor(distributor); distributor.Start(); net.Start(); GlobalQueue.Queue.Start(); var s1 = TestHelper.OpenWriterHost(server1, netconfig); var s2 = TestHelper.OpenWriterHost(server2, netconfig); net.ConnectToWriter(server1); net.ConnectToWriter(server2); Thread.Sleep(TimeSpan.FromMilliseconds(1000)); var ev = new InnerData(new Transaction("", "")) { Transaction = { Destination = new List <ServerId> { server1, server2, server3 } } }; var trm = new TransactionModule(new QueueConfiguration(1, 1000), net, new TransactionConfiguration(1), new DistributorHashConfiguration(3)); trm.Start(); using (var trans = trm.Rent()) { trm.ProcessSyncWithExecutor(ev, trans.Element); } Thread.Sleep(TimeSpan.FromMilliseconds(100)); Assert.IsTrue(s1.Value <= 0); Assert.IsTrue(s2.Value <= 0); Assert.IsTrue(ev.Transaction.IsError); net.Dispose(); trm.Dispose(); }
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(); }
private void RestoreServerCommand(RestoreCommand command) { //TODO тоже надо будет выпилить command.CountSends++; _distributorNet.ConnectToWriter(command.RestoreServer); _modelOfDbWriters.ServerAvailable(command.RestoreServer); if (command.CountSends < 2) { var list = _modelOfAnotherDistributors.GetDistributorList(); list.ForEach(x => _distributorNet.SendToDistributor(x, command)); } }
public void MainLogic_ProcessWithData_SendAllReplicsThenObsoleteDataInCache() { var writer = new HashWriter(new HashMapConfiguration("test9", HashMapCreationMode.CreateNew, 2, 3, HashFileType.Distributor)); writer.CreateMap(); writer.SetServer(0, "localhost", 21111, 157); writer.SetServer(1, "localhost", 21112, 157); writer.Save(); var cache = new DistributorTimeoutCache(TimeSpan.FromMilliseconds(400), TimeSpan.FromMilliseconds(1000)); var distrconfig = new DistributorHashConfiguration(2); var queueconfig = new QueueConfiguration(1, 100); var netconfig = new ConnectionConfiguration("testService", 10); 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("test9", HashMapCreationMode.ReadFromFile, 1, 1, HashFileType.Distributor)); net.SetDistributor(distributor); var transaction = new TransactionModule(new QueueConfiguration(1, 1000), net, new TransactionConfiguration(1), distrconfig); var main = new MainLogicModule(cache, distributor, transaction); cache.SetMainLogicModule(main); var server1 = new ServerId("localhost", 21111); var server2 = new ServerId("localhost", 21112); var s1 = TestHelper.OpenWriterHost(server1, netconfig); var s2 = TestHelper.OpenWriterHost(server2, netconfig); cache.Start(); distributor.Start(); net.Start(); transaction.Start(); main.Start(); GlobalQueue.Queue.Start(); net.ConnectToWriter(server1); net.ConnectToWriter(server2); Thread.Sleep(TimeSpan.FromMilliseconds(300)); var ev = new InnerData(new Transaction("123", "")) { Transaction = new Transaction(HashConvertor.GetString("1"), "") { OperationName = OperationName.Create, OperationType = OperationType.Async } }; ev.Transaction.Destination = new List <ServerId>(); using (var trans = transaction.Rent()) { main.ProcessWithData(ev, trans.Element); } GlobalQueue.Queue.TransactionQueue.Add(ev.Transaction); GlobalQueue.Queue.TransactionQueue.Add(ev.Transaction); Thread.Sleep(TimeSpan.FromMilliseconds(100)); Assert.IsTrue(s1.Value > 0); Assert.IsTrue(s2.Value > 0); Assert.AreEqual(main.GetTransactionState(ev.Transaction.UserTransaction).State, TransactionState.Complete); Thread.Sleep(TimeSpan.FromMilliseconds(1000)); Assert.AreEqual(main.GetTransactionState(ev.Transaction.UserTransaction).State, TransactionState.DontExist); net.Dispose(); distributor.Dispose(); transaction.Dispose(); }