public void Start() { if (_isBuild) { _distributorSystem.Start(); _isStarted = true; } else { throw new Exception("System not build"); } }
public void ProxyAndDistributor_Read_DirectReadFromOneServerMock() { const int storageServer = 22261; var writer = new HashWriter(new HashMapConfiguration("TestProxyAndDistributorRead1Servers", HashMapCreationMode.CreateNew, 1, 3, HashFileType.Distributor)); writer.CreateMap(); writer.SetServer(0, "localhost", storageServer, 157); writer.Save(); var dhc = new DistributorHashConfiguration(1); var queue = new QueueConfiguration(1, 100); var connection = new ConnectionConfiguration("testService", 10); var dcc = new DistributorCacheConfiguration(TimeSpan.FromMilliseconds(600), TimeSpan.FromMilliseconds(1000)); var ndrc = new NetReceiverConfiguration(22260, "localhost", "testService"); var ndrc12 = new NetReceiverConfiguration(23260, "localhost", "testService"); var distr = new DistributorSystem(new ServerId("localhost", 22260), new ServerId("localhost", 23260), dhc, queue, connection, dcc, ndrc, ndrc12, new TransactionConfiguration(1), new HashMapConfiguration("TestProxyAndDistributorRead1Servers", HashMapCreationMode.ReadFromFile, 1, 1, HashFileType.Distributor), new AsyncTasksConfiguration(TimeSpan.FromMinutes(5)), new AsyncTasksConfiguration(TimeSpan.FromMinutes(5)), new ConnectionTimeoutConfiguration(Consts.OpenTimeout, Consts.SendTimeout)); var server = new ServerId("localhost", 23260); distr.Build(); _proxy.Start(); distr.Start(); GlobalQueue.Queue.Start(); _proxy.Distributor.SayIAmHere(server); var s = TestHelper.OpenWriterHost(new ServerId("localhost", storageServer), connection); s.retData = TestHelper.CreateEvent(new StoredDataHashCalculator(), 10); var api = _proxy.CreateApi("Event", false, new StoredDataHashCalculator()); UserTransaction transaction; var read = (StoredData)api.Read(10, out transaction); Assert.AreEqual(10, read.Id); _proxy.Dispose(); distr.Dispose(); }
public void Writer_ProcessDataFromDistributor_CRUD_TwoWriters() { const int distrServer1 = 22201; const int distrServer12 = 22202; const int storageServer1 = 22203; const int storageServer2 = 22204; var writer = new HashWriter(new HashMapConfiguration("TestCreateReadDelete", 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(2, 100); var netReceive4 = new NetReceiverConfiguration(distrServer1, "localhost", "testService"); var netReceive42 = new NetReceiverConfiguration(distrServer12, "localhost", "testService"); var d = new DistributorSystem(new ServerId("localhost", distrServer1), new ServerId("localhost", distrServer12), distrconfig, queueconfig, connection, new DistributorCacheConfiguration(TimeSpan.FromSeconds(20), TimeSpan.FromSeconds(20)), netReceive4, netReceive42, new TransactionConfiguration(4), new HashMapConfiguration("TestCreateReadDelete", HashMapCreationMode.ReadFromFile, 1, 1, HashFileType.Distributor), new AsyncTasksConfiguration(TimeSpan.FromMinutes(5)), new AsyncTasksConfiguration(TimeSpan.FromMinutes(5)), new ConnectionTimeoutConfiguration(Consts.OpenTimeout, Consts.SendTimeout)); _writer1.Build(storageServer1, "TestCreateReadDelete", 2); _writer2.Build(storageServer2, "TestCreateReadDelete", 2); var mem = _writer1.Db.GetDbModules.First() as TestDbInMemory; var mem2 = _writer2.Db.GetDbModules.First() as TestDbInMemory; _proxy.Start(); d.Build(); d.Start(); _writer1.Start(); _writer2.Start(); _proxy.Distributor.SayIAmHere(new ServerId("localhost", distrServer12)); #endregion const int count = 50; var api = _proxy.CreateApi("Int", false, new IntHashConvertor()); for (int i = 0; i < count; i++) { var task = api.CreateSync(i, i); task.Wait(); Assert.AreEqual(i + 1, mem.Local + mem2.Local); } for (int i = 0; i < count; i++) { UserTransaction user; var data = api.Read(i, out user); Assert.AreEqual(i, data); } for (int i = 0; i < count; i++) { var task = api.DeleteSync(i); task.Wait(); Assert.AreEqual(count - i - 1, mem.Local + mem2.Local); } for (int i = 0; i < count; i++) { UserTransaction user; var data = api.Read(i, out user); Assert.IsNull(data); } _writer2.Dispose(); _writer1.Dispose(); d.Dispose(); _proxy.Dispose(); }
public void ProxyAndDistributor_Read_DirectReadFromTwoServer_TwoReplics_LongRead() { const int storageServer1 = 22281; const int storageServer2 = 22282; const int distrServerForProxy = 23283; const int distrServerForDb = 22283; var writer = new HashWriter(new HashMapConfiguration("TestProxyAndDistributorRead2Servers2ReplicsFullLongRead", HashMapCreationMode.CreateNew, 2, 3, HashFileType.Distributor)); writer.CreateMap(); writer.SetServer(0, "localhost", storageServer1, 157); writer.SetServer(1, "localhost", storageServer2, 157); writer.Save(); var dhc = new DistributorHashConfiguration(2); var queue = new QueueConfiguration(1, 100); var connection = new ConnectionConfiguration("testService", 10); var dcc = new DistributorCacheConfiguration(TimeSpan.FromMilliseconds(600), TimeSpan.FromMilliseconds(1000)); var ndrc = new NetReceiverConfiguration(distrServerForDb, "localhost", "testService"); var ndrc12 = new NetReceiverConfiguration(distrServerForProxy, "localhost", "testService"); var distr = new DistributorSystem(new ServerId("localhost", distrServerForDb), new ServerId("localhost", distrServerForProxy), dhc, queue, connection, dcc, ndrc, ndrc12, new TransactionConfiguration(1), new HashMapConfiguration("TestProxyAndDistributorRead2Servers2ReplicsFullLongRead", HashMapCreationMode.ReadFromFile, 1, 2, HashFileType.Distributor), new AsyncTasksConfiguration(TimeSpan.FromSeconds(2)), new AsyncTasksConfiguration(TimeSpan.FromSeconds(2)), new ConnectionTimeoutConfiguration(Consts.OpenTimeout, Consts.SendTimeout)); var server = new ServerId("localhost", distrServerForProxy); var storage1 = new WriterSystem(new ServerId("localhost", storageServer1), queue, new NetReceiverConfiguration(storageServer1, "localhost", "testService") , new NetReceiverConfiguration(1, "fake", "fake"), new HashMapConfiguration("TestProxyAndDistributorRead2Servers2ReplicsFullLongRead", HashMapCreationMode.ReadFromFile, 1, 1, HashFileType.Writer), connection, new RestoreModuleConfiguration(10, new TimeSpan()), new RestoreModuleConfiguration(10, new TimeSpan()), new ConnectionTimeoutConfiguration(Consts.OpenTimeout, Consts.SendTimeout), new RestoreModuleConfiguration(-1, TimeSpan.FromHours(1), false, TimeSpan.FromHours(1))); var storage2 = new WriterSystem(new ServerId("localhost", storageServer2), queue, new NetReceiverConfiguration(storageServer2, "localhost", "testService") , new NetReceiverConfiguration(1, "fake", "fake"), new HashMapConfiguration("TestProxyAndDistributorRead2Servers2ReplicsFullLongRead", HashMapCreationMode.ReadFromFile, 1, 1, HashFileType.Writer), connection, new RestoreModuleConfiguration(10, new TimeSpan()), new RestoreModuleConfiguration(10, new TimeSpan()), new ConnectionTimeoutConfiguration(Consts.OpenTimeout, Consts.SendTimeout), new RestoreModuleConfiguration(-1, TimeSpan.FromHours(1), false, TimeSpan.FromHours(1))); storage1.Build(); storage2.Build(); distr.Build(); storage1.DbModule.AddDbModule(new TestDbInMemory()); storage2.DbModule.AddDbModule(new TestDbInMemory()); _proxy.Start(); distr.Start(); _proxy.Distributor.SayIAmHere(server); var api = _proxy.CreateApi("Int", false, new IntHashConvertor()); var task = api.CreateSync(10, 10); task.Wait(); storage1.Start(); storage2.Start(); Thread.Sleep(TimeSpan.FromMilliseconds(4000)); task = api.CreateSync(10, 10); task.Wait(); Assert.AreEqual(TransactionState.Complete, task.Result.State); UserTransaction transaction; var data = api.Read(10, out transaction); Assert.AreEqual(10, data); _proxy.Dispose(); distr.Dispose(); storage1.Dispose(); storage2.Dispose(); }
public void ProxyAndDistributor_Create_WriterMock() { var writer = new HashWriter(new HashMapConfiguration("test5", HashMapCreationMode.CreateNew, 1, 3, HashFileType.Collector)); writer.CreateMap(); writer.SetServer(0, "localhost", 21181, 157); writer.Save(); var dhc = new DistributorHashConfiguration(1); var queue = new QueueConfiguration(1, 100); var connection = new ConnectionConfiguration("testService", 10); var dcc = new DistributorCacheConfiguration(TimeSpan.FromMilliseconds(600), TimeSpan.FromMilliseconds(1000)); var ndrc = new NetReceiverConfiguration(22222, "localhost", "testService"); var ndrc12 = new NetReceiverConfiguration(23222, "localhost", "testService"); var distr = new DistributorSystem(new ServerId("localhost", 22222), new ServerId("localhost", 23222), dhc, queue, connection, dcc, ndrc, ndrc12, new TransactionConfiguration(1), new HashMapConfiguration("test5", HashMapCreationMode.ReadFromFile, 1, 1, HashFileType.Distributor), new AsyncTasksConfiguration(TimeSpan.FromMilliseconds(200)), new AsyncTasksConfiguration(TimeSpan.FromMinutes(5)), new ConnectionTimeoutConfiguration(Consts.OpenTimeout, Consts.SendTimeout)); var server = new ServerId("localhost", 23222); try { distr.Build(); _proxy.Start(); distr.Start(); GlobalQueue.Queue.Start(); _proxy.Distributor.SayIAmHere(server); var api = _proxy.CreateApi("", false, new StoredDataHashCalculator()); var transaction = api.Create(10, TestHelper.CreateStoredData(10)); Assert.IsNotNull(transaction); Thread.Sleep(200); transaction = _proxy.GetTransaction(transaction); Assert.IsNotNull(transaction); Assert.AreEqual(TransactionState.TransactionInProcess, transaction.State); Thread.Sleep(1000); transaction = _proxy.GetTransaction(transaction); Assert.IsNotNull(transaction); Assert.AreEqual(TransactionState.DontExist, transaction.State); var server1 = new ServerId("localhost", 21181); var netconfig = new ConnectionConfiguration("testService", 1); TestHelper.OpenWriterHost(server1, netconfig); Thread.Sleep(TimeSpan.FromMilliseconds(1000)); transaction = api.Create(11, TestHelper.CreateStoredData(11)); Assert.IsNotNull(transaction); Thread.Sleep(200); transaction = _proxy.GetTransaction(transaction); GlobalQueue.Queue.TransactionQueue.Add(new Transaction(transaction)); Thread.Sleep(100); transaction = _proxy.GetTransaction(transaction); Assert.IsNotNull(transaction); if (transaction.State == TransactionState.TransactionInProcess) { Thread.Sleep(100); transaction = _proxy.GetTransaction(transaction); } Assert.AreEqual(TransactionState.Complete, transaction.State); Thread.Sleep(1000); transaction = _proxy.GetTransaction(transaction); Assert.IsNotNull(transaction); Assert.AreEqual(TransactionState.DontExist, transaction.State); } finally { _proxy.Dispose(); distr.Dispose(); } }
public void ProxyAndDistributor_Read_DirectReadFromOneServer() { const int storageServer1 = 22462; const int distrServerForProxy = 23263; const int distrServerForDb = 22263; var writer = new HashWriter(new HashMapConfiguration("TestProxyAndDistributorRead1ServerFull", HashMapCreationMode.CreateNew, 1, 3, HashFileType.Distributor)); writer.CreateMap(); writer.SetServer(0, "localhost", storageServer1, 157); writer.Save(); var dhc = new DistributorHashConfiguration(1); var queue = new QueueConfiguration(1, 100); var connection = new ConnectionConfiguration("testService", 10); var dcc = new DistributorCacheConfiguration(TimeSpan.FromMilliseconds(600), TimeSpan.FromMilliseconds(1000)); var ndrc = new NetReceiverConfiguration(distrServerForDb, "localhost", "testService"); var ndrc12 = new NetReceiverConfiguration(distrServerForProxy, "localhost", "testService"); var distr = new DistributorSystem(new ServerId("localhost", distrServerForDb), new ServerId("localhost", distrServerForProxy), dhc, queue, connection, dcc, ndrc, ndrc12, new TransactionConfiguration(1), new HashMapConfiguration("TestProxyAndDistributorRead1ServerFull", HashMapCreationMode.ReadFromFile, 1, 1, HashFileType.Distributor), new AsyncTasksConfiguration(TimeSpan.FromMinutes(5)), new AsyncTasksConfiguration(TimeSpan.FromMinutes(5)), new ConnectionTimeoutConfiguration(Consts.OpenTimeout, Consts.SendTimeout)); var server = new ServerId("localhost", distrServerForProxy); var storage = new WriterSystem(new ServerId("localhost", storageServer1), queue, new NetReceiverConfiguration(storageServer1, "localhost", "testService") , new NetReceiverConfiguration(1, "fake", "fake"), new HashMapConfiguration("TestProxyAndDistributorRead1ServerFull", HashMapCreationMode.ReadFromFile, 1, 1, HashFileType.Writer), connection, new RestoreModuleConfiguration(10, new TimeSpan()), new RestoreModuleConfiguration(10, new TimeSpan()), new ConnectionTimeoutConfiguration(Consts.OpenTimeout, Consts.SendTimeout), new RestoreModuleConfiguration(-1, TimeSpan.FromHours(1), false, TimeSpan.FromHours(1))); storage.Build(); distr.Build(); storage.DbModule.AddDbModule(new TestDbInMemory()); storage.Start(); _proxy.Start(); distr.Start(); GlobalQueue.Queue.Start(); _proxy.Distributor.SayIAmHere(server); const int count = 50; var api = _proxy.CreateApi("Int", false, new IntHashConvertor()); for (int i = 1; i < count; i++) { var task = api.CreateSync(i, i); task.Wait(); Assert.AreEqual(TransactionState.Complete, task.Result.State); } for (int i = 1; i < count; i++) { UserTransaction transaction; var read = (int)api.Read(i, out transaction); Assert.AreEqual(i, read); } _proxy.Dispose(); distr.Dispose(); storage.Dispose(); }
public void ProxyAndDistributor_Create_WriterMock_TwoReplics() { var writer = new HashWriter(new HashMapConfiguration("test3", HashMapCreationMode.CreateNew, 2, 3, HashFileType.Writer)); writer.CreateMap(); writer.SetServer(0, "localhost", 21191, 157); writer.SetServer(1, "localhost", 21192, 157); writer.Save(); writer = new HashWriter(new HashMapConfiguration("test4", HashMapCreationMode.CreateNew, 2, 3, HashFileType.Writer)); writer.CreateMap(); writer.SetServer(0, "localhost", 21193, 157); writer.SetServer(1, "localhost", 21192, 157); writer.Save(); var dhc = new DistributorHashConfiguration(2); var queue = new QueueConfiguration(1, 100); var connection = new ConnectionConfiguration("testService", 10); var dcc = new DistributorCacheConfiguration(TimeSpan.FromMilliseconds(400), TimeSpan.FromMilliseconds(1000)); var ndrc = new NetReceiverConfiguration(22223, "localhost", "testService"); var ndrc12 = new NetReceiverConfiguration(23223, "localhost", "testService"); var ndrc2 = new NetReceiverConfiguration(22224, "localhost", "testService"); var ndrc22 = new NetReceiverConfiguration(23224, "localhost", "testService"); var distr = new DistributorSystem(new ServerId("localhost", 22223), new ServerId("localhost", 23223), dhc, queue, connection, dcc, ndrc, ndrc12, new TransactionConfiguration(1), new HashMapConfiguration("test3", HashMapCreationMode.ReadFromFile, 1, 1, HashFileType.Distributor), new AsyncTasksConfiguration(TimeSpan.FromMinutes(5)), new AsyncTasksConfiguration(TimeSpan.FromMinutes(5)), new ConnectionTimeoutConfiguration(Consts.OpenTimeout, Consts.SendTimeout)); var distr2 = new DistributorSystem(new ServerId("localhost", 22224), new ServerId("localhost", 23224), dhc, queue, connection, dcc, ndrc2, ndrc22, new TransactionConfiguration(1), new HashMapConfiguration("test4", HashMapCreationMode.ReadFromFile, 1, 1, HashFileType.Distributor), new AsyncTasksConfiguration(TimeSpan.FromMinutes(5)), new AsyncTasksConfiguration(TimeSpan.FromMinutes(5)), new ConnectionTimeoutConfiguration(Consts.OpenTimeout, Consts.SendTimeout)); var ser = new ServerId("localhost", 23223); var ser2 = new ServerId("localhost", 23224); try { distr.Build(); distr2.Build(); _proxy.Start(); distr.Start(); distr2.Start(); _proxy.Distributor.SayIAmHere(ser); _proxy.Distributor.SayIAmHere(ser2); var server1 = new ServerId("localhost", 21191); var server2 = new ServerId("localhost", 21192); var server3 = new ServerId("localhost", 21193); var netconfig = new ConnectionConfiguration("testService", 1); var s1 = TestHelper.OpenWriterHost(server1, netconfig); var s2 = TestHelper.OpenWriterHost(server2, netconfig); var s3 = TestHelper.OpenWriterHost(server3, netconfig); Thread.Sleep(TimeSpan.FromMilliseconds(300)); var api = _proxy.CreateApi("", false, new StoredDataHashCalculator()); api.Create(10, TestHelper.CreateStoredData(10)); api.Create(11, TestHelper.CreateStoredData(11)); Thread.Sleep(TimeSpan.FromMilliseconds(1000)); Assert.AreEqual(1, s1.Value); Assert.AreEqual(2, s2.Value); Assert.AreEqual(1, s3.Value); } finally { _proxy.Dispose(); distr.Dispose(); distr2.Dispose(); } }
public void ClientProxy_CrudOperations() { const int distrServer1 = 22206; const int distrServer12 = 22207; const int storageServer = 22208; #region hell var writer = new HashWriter(new HashMapConfiguration("TestClientProxy", HashMapCreationMode.CreateNew, 1, 1, HashFileType.Distributor)); writer.CreateMap(); writer.SetServer(0, "localhost", storageServer, 157); writer.Save(); var distrHash = new DistributorHashConfiguration(1); var queue = new QueueConfiguration(1, 100); var connection = new ConnectionConfiguration("testService", 10); var distrCache = new DistributorCacheConfiguration(TimeSpan.FromMilliseconds(10000), TimeSpan.FromMilliseconds(1000000)); var netReceive1 = new NetReceiverConfiguration(distrServer1, "localhost", "testService"); var netReceive12 = new NetReceiverConfiguration(distrServer12, "localhost", "testService"); var trans = new TransactionConfiguration(1); var hashMap = new HashMapConfiguration("TestClientProxy", HashMapCreationMode.ReadFromFile, 1, 1, HashFileType.Writer); var async = new AsyncTasksConfiguration(TimeSpan.FromSeconds(10)); var distr = new DistributorSystem(new ServerId("localhost", distrServer1), new ServerId("localhost", distrServer12), distrHash, queue, connection, distrCache, netReceive1, netReceive12, trans, new HashMapConfiguration("TestClientProxy", HashMapCreationMode.ReadFromFile, 1, 1, HashFileType.Distributor), async, async, new ConnectionTimeoutConfiguration(Consts.OpenTimeout, Consts.SendTimeout)); var netReceivedb = new NetReceiverConfiguration(storageServer, "localhost", "testService"); var restore = new RestoreModuleConfiguration(4, TimeSpan.FromMinutes(1)); var storage = new WriterSystem(new ServerId("localhost", storageServer), queue, netReceivedb, new NetReceiverConfiguration(1, "fake", "fake"), hashMap, connection, restore, restore, new ConnectionTimeoutConfiguration(Consts.OpenTimeout, Consts.SendTimeout), new RestoreModuleConfiguration(-1, TimeSpan.FromHours(1), false, TimeSpan.FromHours(1))); #endregion distr.Build(); distr.Start(); _proxy.Int.SayIAmHere("localhost", distrServer12); storage.Build(); storage.DbModule.AddDbModule(new TestDbInMemory()); storage.Start(); const int count = 50; for (int i = 0; i < count; i++) { var state = _proxy.Int.CreateSync(i, i); Assert.AreEqual(RequestState.Complete, state.State); } for (int i = 0; i < count; i++) { RequestDescription description; var read = _proxy.Int.Read(i, out description); Assert.AreEqual(i, read); Assert.AreEqual(RequestState.Complete, description.State); } for (int i = 0; i < count; i++) { var state = _proxy.Int.DeleteSync(i); Assert.AreEqual(RequestState.Complete, state.State); } for (int i = 0; i < count; i++) { RequestDescription description; _proxy.Int.Read(i, out description); Assert.AreEqual(RequestState.DataNotFound, description.State); } distr.Dispose(); storage.Dispose(); }