public void ClientProxy_Dispose_DisposeWhenWriting() { const int distrServer1 = 22370; const int distrServer12 = 22371; const int storageServer = 22372; #region hell var writer = new HashWriter(new HashMapConfiguration("TestProxyDispose", HashMapCreationMode.CreateNew, 1, 1, HashFileType.Distributor)); writer.CreateMap(); writer.SetServer(0, "localhost", storageServer, 157); writer.Save(); var common = new CommonConfiguration(1, 100); var distr = new DistributorApi( new DistributorNetConfiguration("localhost", distrServer1, distrServer12, "testService"), new DistributorConfiguration(1, "TestProxyDispose"), common); var storage = new WriterApi( new StorageNetConfiguration("localhost", storageServer, 157, "testService"), new StorageConfiguration(1, "TestProxyDispose"), new CommonConfiguration()); #endregion distr.Build(); distr.Start(); var result = _proxy.Int.SayIAmHere("localhost", distrServer1); Assert.AreEqual(RequestState.Complete, result.State, result.ToString()); storage.Build(); storage.AddDbModule(new TestInMemoryDbFactory()); storage.Start(); const int count = 500; for (int i = 0; i < count; i++) { if (i == count / 4) { Task.Run(() => _proxy.Dispose()); } var state = _proxy.Int.CreateSync(i, i); if (!(state.State == RequestState.Complete || state.State == RequestState.Error && state.ErrorDescription == "System disposed" || i == count / 4)) { Assert.Fail(state + " " + i); } } distr.Dispose(); storage.Dispose(); }
public void Writer_Restore_TwoServersWhenOneServerNotAvailable() { #region hell var writer = new HashWriter(new HashMapConfiguration("TestRestore", HashMapCreationMode.CreateNew, 2, 1, HashFileType.Distributor)); writer.CreateMap(); writer.SetServer(0, "localhost", storageServer1, 157); writer.SetServer(1, "localhost", storageServer2, 157); writer.Save(); var common = new CommonConfiguration(1, 100); var storageNet1 = new StorageNetConfiguration("localhost", storageServer1, 157, "testService", 10); var storageConfig = new StorageConfiguration("TestRestore", 1, 10, TimeSpan.FromMilliseconds(10000), TimeSpan.FromMilliseconds(200), TimeSpan.FromHours(1), TimeSpan.FromHours(1), false); var storage1 = new WriterApi(storageNet1, storageConfig, common); var storageNet2 = new StorageNetConfiguration("localhost", storageServer2, 157, "testService", 10); var storage2 = new WriterApi(storageNet2, storageConfig, common); #endregion _proxy.Start(); _distr.Start(); storage1.Build(); storage1.AddDbModule(new TestInMemoryDbFactory()); storage1.Start(); storage1.Api.Restore(new ServerAddress("localhost", distrServer12), false); Thread.Sleep(4000); Assert.IsTrue(storage1.Api.IsRestoreCompleted()); var list = storage1.Api.FailedServers(); Assert.AreEqual(1, list.Count); storage2.Build(); storage2.AddDbModule(new TestInMemoryDbFactory()); storage2.Start(); storage1.Api.Restore(new ServerAddress("localhost", distrServer12), list, false); Thread.Sleep(1000); Assert.IsTrue(storage1.Api.IsRestoreCompleted()); Thread.Sleep(1000); _proxy.Dispose(); _distr.Dispose(); storage1.Dispose(); storage2.Dispose(); }
public void CollectorNet_ReadFromWriter() { const int proxyServer = 22337; const int distrServer1 = 22338; const int distrServer12 = 22339; const int st1 = 22335; const int st2 = 22336; #region hell var writer = new HashWriter(new HashMapConfiguration("TestCollectorNet", HashMapCreationMode.CreateNew, 1, 1, HashFileType.Distributor)); writer.CreateMap(); writer.SetServer(0, "localhost", st1, st2); writer.Save(); var common = new CommonConfiguration(1, 100); var netconfig = new NetConfiguration("localhost", proxyServer, "testService", 10); var toconfig = new ProxyConfiguration(TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(10)); var proxy = new TestGate(netconfig, toconfig, common); var distrNet = new DistributorNetConfiguration("localhost", distrServer1, distrServer12, "testService", 10); var distrConf = new DistributorConfiguration(1, "TestCollectorNet", TimeSpan.FromMilliseconds(100000), TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1), TimeSpan.FromMilliseconds(10000)); var distr = new DistributorApi(distrNet, distrConf, common); var storageNet = new StorageNetConfiguration("localhost", st1, st2, "testService", 10); var storageConfig = new StorageConfiguration("TestCollectorNet", 1, 10, TimeSpan.FromHours(1), TimeSpan.FromHours(1), TimeSpan.FromHours(1), TimeSpan.FromHours(1), false); var storage = new WriterApi(storageNet, storageConfig, common); var async = new AsyncTaskModule(new QueueConfiguration(4, 10)); var distributor = new DistributorModule(new CollectorModel(new DistributorHashConfiguration(1), new HashMapConfiguration("TestCollectorNet", HashMapCreationMode.ReadFromFile, 1, 1, HashFileType.Collector)), async, new AsyncTasksConfiguration(TimeSpan.FromMinutes(1))); var net = new CollectorNetModule(new ConnectionConfiguration("testService", 10), new ConnectionTimeoutConfiguration(Consts.OpenTimeout, Consts.SendTimeout), distributor); distributor.SetNetModule(net); var back = new BackgroundModule(new QueueConfiguration(5, 10)); var loader = new DataLoader(net, 100, back); var parser = new TestIntParser(); parser.SetCommandsHandler( new UserCommandsHandler <TestCommand, Type, TestCommand, int, int, TestDbReader>( new TestUserCommandCreator(), new TestMetaDataCommandCreator())); var merge = new OrderMerge(loader, parser); var searchModule = new SearchTaskModule("Int", merge, loader, distributor, back, parser); storage.Build(); proxy.Build(); distr.Build(); storage.AddDbModule(new TestInMemoryDbFactory()); storage.Start(); proxy.Start(); distr.Start(); searchModule.Start(); distributor.Start(); merge.Start(); back.Start(); net.Start(); async.Start(); #endregion proxy.Int.SayIAmHere("localhost", distrServer1); const int count = 20; for (int i = 0; i < count; i++) { var request = proxy.Int.CreateSync(i, i); Assert.AreEqual(RequestState.Complete, request.State); } var reader = searchModule.CreateReader("asc", -1, 20); reader.Start(); for (int i = 0; i < count; i++) { Assert.IsTrue(reader.IsCanRead); reader.ReadNext(); Assert.AreEqual(i, reader.GetValue(0)); } reader.ReadNext(); Assert.IsFalse(reader.IsCanRead); reader.Dispose(); back.Dispose(); net.Dispose(); storage.Dispose(); proxy.Dispose(); distr.Dispose(); async.Dispose(); }
public void Writer_Restore_TimeoutDelete() { #region hell var writer = new HashWriter(new HashMapConfiguration("TestRestore", HashMapCreationMode.CreateNew, 1, 1, HashFileType.Distributor)); writer.CreateMap(); writer.SetServer(0, "localhost", storageServer1, 157); writer.Save(); var storageNet1 = new StorageNetConfiguration("localhost", storageServer1, 157, "testService", 10); var storageConfig = new StorageConfiguration("TestRestore", 1, 10, TimeSpan.FromMilliseconds(10000), TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(1), TimeSpan.FromSeconds(1), false); var factory = new TestInMemoryDbFactory(); var storage1 = new WriterApi(storageNet1, storageConfig, new CommonConfiguration(1, 10)); #endregion _proxy.Start(); _distr.Start(); _proxy.Int.SayIAmHere("localhost", distrServer1); storage1.Build(); storage1.AddDbModule(factory); storage1.Start(); const int count = 50; for (int i = 0; i < count; i++) { var wait = _proxy.Int.CreateSync(i, i); Assert.AreEqual(RequestState.Complete, wait.State); } Assert.AreEqual(count, factory.Db.Local); for (int i = 0; i < count / 2; i++) { var wait = _proxy.Int.DeleteSync(i); Assert.AreEqual(RequestState.Complete, wait.State); } Assert.AreEqual(count / 2, factory.Db.Local); Assert.AreEqual(count / 2, factory.Db.Deleted); Thread.Sleep(4000); Assert.AreEqual(count / 2, factory.Db.Local); Assert.AreEqual(0, factory.Db.Deleted); _proxy.Dispose(); _distr.Dispose(); storage1.Dispose(); }
public void DistributorApi_ProcessAsyncOperationsFromProxy() { const int proxyServer = 22213; const int distrServer1 = 22214; const int distrServer12 = 22215; const int storageServer = 22216; #region hell var writer = new HashWriter(new HashMapConfiguration("TestClientDistributor", HashMapCreationMode.CreateNew, 1, 1, HashFileType.Distributor)); writer.CreateMap(); writer.SetServer(0, "localhost", storageServer, 157); writer.Save(); var netconfig = new NetConfiguration("localhost", proxyServer, "testService", 10); var toconfig = new ProxyConfiguration(TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(10)); var common = new CommonConfiguration(1, 100); var proxy = new TestGate(netconfig, toconfig, common); var distrNet = new DistributorNetConfiguration("localhost", distrServer1, distrServer12, "testService", 10); var distrConf = new DistributorConfiguration(1, "TestClientDistributor", TimeSpan.FromMilliseconds(100000), TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1), TimeSpan.FromMilliseconds(10000)); var distr = new DistributorApi(distrNet, distrConf, common); var storageNet = new StorageNetConfiguration("localhost", storageServer, 157, "testService", 10); var storageConfig = new StorageConfiguration("TestClientDistributor", 1, 10, TimeSpan.FromHours(1), TimeSpan.FromHours(1), TimeSpan.FromHours(1), TimeSpan.FromHours(1), false); var storage = new WriterApi(storageNet, storageConfig, common); #endregion proxy.Build(); proxy.Start(); distr.Build(); distr.Start(); proxy.Int.SayIAmHere("localhost", distrServer1); storage.Build(); storage.AddDbModule(new TestInMemoryDbFactory()); 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); } proxy.Dispose(); distr.Dispose(); storage.Dispose(); }
public void Proxy_Restore_HashFromValue() { const int distrServer1 = 22403; const int distrServer12 = 22404; const int st1 = 22405; const int st2 = 22406; const int st3 = 22407; const int st4 = 22408; #region hell var writer = new HashWriter(new HashMapConfiguration("TestHashFromValue", HashMapCreationMode.CreateNew, 2, 2, HashFileType.Distributor)); writer.CreateMap(); writer.SetServer(0, "localhost", st1, st2); writer.SetServer(1, "localhost", st3, st4); writer.Save(); var common = new CommonConfiguration(1, 100); var distrNet = new DistributorNetConfiguration("localhost", distrServer1, distrServer12, "testService", 10); var distrConf = new DistributorConfiguration(1, "TestHashFromValue", TimeSpan.FromMilliseconds(100000), TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1), TimeSpan.FromMilliseconds(10000)); var distr = new DistributorApi(distrNet, distrConf, common); var storageNet1 = new StorageNetConfiguration("localhost", st1, st2, "testService", 10); var storageNet2 = new StorageNetConfiguration("localhost", st3, st4, "testService", 10); var storageConfig = new StorageConfiguration("TestHashFromValue", 1, 10, TimeSpan.FromHours(1), TimeSpan.FromHours(1), TimeSpan.FromHours(1), TimeSpan.FromHours(1), false); var storage1 = new WriterApi(storageNet1, storageConfig, common); var storage2 = new WriterApi(storageNet2, storageConfig, common); #endregion storage1.Build(); storage2.Build(); distr.Build(); var f1 = new TestInMemoryDbFactory("Int3", new IntHashConvertor()); var f2 = new TestInMemoryDbFactory("Int3", new IntHashConvertor()); storage1.AddDbModule(f1); storage2.AddDbModule(f2); storage1.Start(); _proxy.Start(); distr.Start(); _proxy.Int.SayIAmHere("localhost", distrServer1); const int count = 50; for (int i = 0; i < count; i++) { _proxy.Int3.CreateSync(i, i); _proxy.Int3.CreateSync(i, i); } for (int i = 0; i < count; i++) { RequestDescription result; var value = _proxy.Int3.Read(i, out result); Assert.AreEqual(RequestState.Complete, result.State); Assert.AreEqual(i, value); } Assert.AreEqual(count, f1.Db.Local + f1.Db.Remote); storage2.Start(); storage2.Api.Restore(new ServerAddress("localhost", distrServer12), false); Thread.Sleep(TimeSpan.FromMilliseconds(2000)); Assert.AreEqual(count, f1.Db.Local + f2.Db.Local); Assert.AreEqual(0, f1.Db.Remote); Assert.AreEqual(0, f2.Db.Remote); _proxy.Dispose(); distr.Dispose(); storage1.Dispose(); storage2.Dispose(); }
public void Proxy_CRUD_TwoTables() { const int distrServer1 = 22379; const int distrServer12 = 22380; const int st1 = 22381; const int st2 = 22382; #region hell var writer = new HashWriter(new HashMapConfiguration("Test2Crud", HashMapCreationMode.CreateNew, 1, 1, HashFileType.Distributor)); writer.CreateMap(); writer.SetServer(0, "localhost", st1, st2); writer.Save(); var common = new CommonConfiguration(1, 100); var distrNet = new DistributorNetConfiguration("localhost", distrServer1, distrServer12, "testService", 10); var distrConf = new DistributorConfiguration(1, "Test2Crud", TimeSpan.FromMilliseconds(100000), TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1), TimeSpan.FromMilliseconds(10000)); var distr = new DistributorApi(distrNet, distrConf, common); var storageNet = new StorageNetConfiguration("localhost", st1, st2, "testService", 10); var storageConfig = new StorageConfiguration("Test2Crud", 1, 10, TimeSpan.FromHours(1), TimeSpan.FromHours(1), TimeSpan.FromHours(1), TimeSpan.FromHours(1), false); var storage = new WriterApi(storageNet, storageConfig, common); #endregion storage.Build(); distr.Build(); var f = new TestInMemoryDbFactory(); var f2 = new TestInMemoryDbFactory("Int2"); storage.AddDbModule(f); storage.AddDbModule(f2); storage.Start(); _proxy.Start(); distr.Start(); _proxy.Int.SayIAmHere("localhost", distrServer1); const int count = 5; for (int i = 0; i < count; i++) { RequestDescription result; _proxy.Int.Read(i, out result); Assert.AreEqual(RequestState.DataNotFound, result.State); _proxy.Int2.Read(i, out result); Assert.AreEqual(RequestState.DataNotFound, result.State); } for (int i = 0; i < count; i++) { RequestDescription result = _proxy.Int.CreateSync(i, i); Assert.AreEqual(RequestState.Complete, result.State); result = _proxy.Int2.CreateSync(i, i); Assert.AreEqual(RequestState.Complete, result.State); } for (int i = 0; i < count; i++) { RequestDescription result; var value = _proxy.Int.Read(i, out result); Assert.AreEqual(RequestState.Complete, result.State); Assert.AreEqual(i, value); value = _proxy.Int2.Read(i, out result); Assert.AreEqual(i, value); } Assert.AreEqual(count, f.Db.Local); Assert.AreEqual(count, f2.Db.Local); _proxy.Dispose(); distr.Dispose(); storage.Dispose(); }