private void Execute() { IREST <T> _rest; Func <IREST <T> > _command; T _response = null; int _retries; int _secDelay; //get all registered providers RoundRobin <string> rr = new RoundRobin <string>(GeneralSettings.roundRobin[0].direction); if (GeneralSettings.roundRobin[0].direction != RoundRobin <T> .FIXED) { foreach (var p in providers) { rr.Add(p.Key); } } //retrieve and update geocode, one rec at a time foreach (T rec in source().RecordSet) { _rest = null; _command = null; _response = null; while (_response == null) { providers.TryGetValue(provider, out _command); _rest = _command(); //hydrate instantiation _retries = GeneralSettings.retry[0].numOfRetries; _secDelay = GeneralSettings.retry[0].secondsDelay * Constants.MILLISECONDS; //convert to miliseconds while (_response == null && _retries != 0) //TODO: actually, _response won't be null, but an error bubbled up from Get method { _response = _rest.GetDataAsync(rec); //retrieve rec's from 3rd party //_response = null; //test if (_response != null) { break; } else { _retries--; Thread.Sleep(_secDelay); } } // _retries = 0; //test if (_response == null && _retries == 0 && rr.MethodName != RoundRobin <T> .FIXED) { rr.Move(); provider = rr.Current; } } target().Save(_response); //update local db with newly retrieved values } }
public void TestToArray() { var rr = new RoundRobin <int>(10); for (int i = 0; i < 15; i++) { rr.Add(i); } CollectionAssert.AreEqual(new int[] { 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }, rr.ToArray()); }
public void TestOverfill() { var rr = new RoundRobin <int>(10); for (int i = 0; i < 15; i++) { rr.Add(i); } Assert.AreEqual(10, rr.Count); CollectionAssert.AreEqual(new int[] { 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }, rr); }
public void RoundRobin_ShouldReturnTheOnlyEntry() { const string theOnlyOne = "theOnlyOne"; var sut = new RoundRobin <string>(); sut.Add(theOnlyOne); var result = sut.Get(); Assert.Equal(theOnlyOne, result); }
public void TestPartialFill() { var rr = new RoundRobin <int>(10); for (int i = 0; i < 5; i++) { rr.Add(i); } Assert.AreEqual(5, rr.Count); CollectionAssert.AreEqual(new int[] { 0, 1, 2, 3, 4 }, rr); }
public void RoundRobin_ShouldReturnTheOnlyEntryMultipleTimes() { const string theOnlyOne = "theOnlyOne"; var sut = new RoundRobin <string>(); sut.Add(theOnlyOne); Assert.Equal(theOnlyOne, sut.Get()); Assert.Equal(theOnlyOne, sut.Get()); Assert.Equal(theOnlyOne, sut.Get()); Assert.Equal(theOnlyOne, sut.Get()); }
public void TestClear() { var rr = new RoundRobin <int>(10); for (int i = 0; i < 5; i++) { rr.Add(i); } Assert.AreEqual(5, rr.Count); rr.Clear(); Assert.AreEqual(0, rr.Count); CollectionAssert.AreEquivalent(new int[] { }, rr); }
public void TestCopyToPartial() { var rr = new RoundRobin <int>(10); for (int i = 0; i < 5; i++) { rr.Add(i); } var test = new int[10]; rr.CopyTo(test, 0); CollectionAssert.AreEqual(new int[] { 0, 1, 2, 3, 4, 0, 0, 0, 0, 0 }, test); }
public void TestCopyToMiddle() { var rr = new RoundRobin <int>(10); for (int i = 0; i < 15; i++) { rr.Add(i); } var test = new int[12]; rr.CopyTo(test, 2); CollectionAssert.AreEqual(new int[] { 0, 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }, test); }
public void RoundRobin_ShouldReturnEntriesAddedAfterInitialisation() { const string firstEntry = "entry1"; const string secondEntry = "entry2"; const string thirdEntry = "entry3"; var sut = new RoundRobin <string> { firstEntry, secondEntry }; Assert.Equal(firstEntry, sut.Get()); Assert.Equal(secondEntry, sut.Get()); sut.Add(thirdEntry); Assert.Equal(thirdEntry, sut.Get()); }
public void TestEnumerate(string expected, string data) { int[] expectedInts = expected.Split(' ').Select(d => int.Parse(d, CultureInfo.InvariantCulture)).ToArray(); int[] dataInts = data.Split(' ').Select(d => int.Parse(d, CultureInfo.InvariantCulture)).ToArray(); var rr = new RoundRobin <int>(10); foreach (var di in dataInts) { rr.Add(di); } var enumerated = rr.Select(x => x).ToArray(); // use linq to enumerate the roundrobin CollectionAssert.AreEqual(expectedInts, enumerated); var enumeratedCount = rr.Select(x => x).Count(); Assert.AreEqual(rr.Count, enumeratedCount); }