public List <WriterDescription> GetDestination(InnerData data, bool needAllServers) { Logger.Logger.Instance.Trace( string.Format("Distributor: Get destination event hash = {0}, distr hash = {1}", data.Transaction.EventHash, data.Transaction.DistributorHash)); data.Transaction.IsNeedAllServes = needAllServers; List <WriterDescription> ret = null; if (!needAllServers) { ret = _modelOfDbWriters.GetDestination(data); } else { ret = _modelOfDbWriters.GetAllAvailableServers(); } if (ret.Count == 0) { return(null); } return(ret); }
public void WriterSystemModel_GetDestination_ChechAvailableServers() { var config = new DistributorHashConfiguration(1); var writer = new HashWriter(new HashMapConfiguration("test", HashMapCreationMode.CreateNew, 6, 3, HashFileType.Distributor)); writer.CreateMap(); writer.SetServer(0, "local", 11010, 157); writer.SetServer(1, "local", 11011, 157); writer.SetServer(2, "local", 11012, 157); writer.SetServer(3, "local", 11010, 157); writer.SetServer(4, "local", 11011, 157); writer.SetServer(5, "local", 11012, 157); writer.Save(); var model = new WriterSystemModel(config, new HashMapConfiguration("test", HashMapCreationMode.ReadFromFile, 1, 1, HashFileType.Distributor)); model.Start(); var ev = new InnerData(new Transaction("123", "")) { Transaction = new Transaction(HashConvertor.GetString("1"), "") }; ev.Transaction.Destination = new List <ServerId>(); var ret = model.GetDestination(ev); Assert.IsTrue(ret.Count == 1); model.ServerNotAvailable(ret.First()); var ret2 = model.GetDestination(ev); Assert.IsTrue(ret2.Count == 1); Assert.AreNotEqual(ret.First(), ret2.First()); model.ServerNotAvailable(ret2.First()); var ret3 = model.GetDestination(ev); Assert.IsTrue(ret3.Count == 1); Assert.AreNotEqual(ret.First(), ret3.First()); Assert.AreNotEqual(ret3.First(), ret2.First()); model.ServerNotAvailable(ret3.First()); var ret4 = model.GetDestination(ev); Assert.IsTrue(ret4.Count == 0); }
public void WriterSystemModel_GetDestination_CountReplics() { var config = new DistributorHashConfiguration(4); var writer = new HashWriter(new HashMapConfiguration("testhash", HashMapCreationMode.CreateNew, 6, 3, HashFileType.Distributor)); writer.CreateMap(); writer.SetServer(0, "local", 11010, 157); writer.SetServer(1, "local", 11011, 157); writer.SetServer(2, "local", 11012, 157); writer.SetServer(3, "local", 11010, 157); writer.SetServer(4, "local", 11011, 157); writer.SetServer(5, "local", 11012, 157); writer.Save(); var model = new WriterSystemModel(config, new HashMapConfiguration("testhash", HashMapCreationMode.ReadFromFile, 1, 1, HashFileType.Distributor)); model.Start(); var ev = new InnerData(new Transaction("123", "")) { Transaction = new Transaction(HashConvertor.GetString("1"), "") }; ev.Transaction.Destination = new List <ServerId>(); var ret = model.GetDestination(ev); Assert.IsTrue(ret.Count == 0); model = new WriterSystemModel(new DistributorHashConfiguration(3), new HashMapConfiguration("testhash", HashMapCreationMode.ReadFromFile, 1, 1, HashFileType.Distributor)); model.Start(); ret = model.GetDestination(ev); Assert.AreEqual(3, ret.Count); Assert.AreNotEqual(ret[0], ret[1]); Assert.AreNotEqual(ret[0], ret[2]); Assert.AreNotEqual(ret[2], ret[1]); }