public void InputModuleWithParallel_ProcessAsync_SendToOneServersAndTimeoutInCache_Success() { const int distrServer1 = 22166; const int distrServer2 = 23166; const int storageServer1 = 22167; var q1 = new GlobalQueueInner(); var writer = new HashWriter(new HashMapConfiguration("testAsyncTrans1S", HashMapCreationMode.CreateNew, 1, 1, HashFileType.Distributor)); writer.CreateMap(); writer.SetServer(0, "localhost", storageServer1, 157); writer.Save(); #region hell GlobalQueue.SetQueue(q1); 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.FromMinutes(5)), new AsyncTasksConfiguration(TimeSpan.FromMinutes(5)), distrconfig, queueconfig, dnet, new ServerId("localhost", distrServer1), new ServerId("localhost", distrServer2), new HashMapConfiguration("testAsyncTrans1S", HashMapCreationMode.ReadFromFile, 1, 1, HashFileType.Distributor)); dnet.SetDistributor(ddistributor); var tranc = new TransactionModule(new QueueConfiguration(1, 1000), dnet, new TransactionConfiguration(4), distrconfig); var cache = new DistributorTimeoutCache(TimeSpan.FromMilliseconds(2000), TimeSpan.FromMilliseconds(200000)); var main = new MainLogicModule(cache, ddistributor, tranc); cache.SetMainLogicModule(main); var netReceive4 = new NetReceiverConfiguration(distrServer1, "localhost", "testService"); var netReceive42 = new NetReceiverConfiguration(distrServer2, "localhost", "testService"); var input = new InputModuleWithParallel(new QueueConfiguration(2, 100000), main, tranc); var receiver4 = new NetDistributorReceiver(main, input, ddistributor, netReceive4, netReceive42); #endregion var s = TestHelper.OpenWriterHost(new ServerId("localhost", storageServer1), new ConnectionConfiguration("testService", 10)); main.Start(); receiver4.Start(); input.Start(); dnet.Start(); ddistributor.Start(); q1.Start(); var list = new List <InnerData>(); const int count = 1; for (int i = 1; i < count + 1; i++) { var ev = new InnerData(new Transaction(HashConvertor.GetString(i.ToString(CultureInfo.InvariantCulture)), "") { OperationName = OperationName.Create, OperationType = OperationType.Async }) { Data = CommonDataSerializer.Serialize(i) }; list.Add(ev); } foreach (var data in list) { input.ProcessAsync(data); } Thread.Sleep(TimeSpan.FromMilliseconds(1000)); Assert.AreEqual(count, s.Value); foreach (var data in list) { var transaction = main.GetTransactionState(data.Transaction.UserTransaction); Assert.AreEqual(TransactionState.TransactionInProcess, transaction.State); } Thread.Sleep(TimeSpan.FromMilliseconds(2000)); foreach (var data in list) { var transaction = main.GetTransactionState(data.Transaction.UserTransaction); if (transaction.State == TransactionState.DontExist) { Thread.Sleep(1000); } transaction = main.GetTransactionState(data.Transaction.UserTransaction); Assert.AreEqual(TransactionState.Error, transaction.State); } q1.Dispose(); ddistributor.Dispose(); dnet.Dispose(); cache.Dispose(); }
public UserTransaction GetTransaction(UserTransaction transaction) { return(_mainLogic.GetTransactionState(transaction)); }
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(); }