public void testInstanceMultiSite() { Dictionary <string, string> _config = new Dictionary <string, string> { { "proxyHost", "websenseproxy" }, { "proxyPort", "8080" }, { "multiSite", "true" }, { "printxml", "false" }, { "printMultiSiteDebug", "true" }, { "merchantId", "101" }, { "username", "DOTNET" }, { "password", "TESTCASE" }, { "url", legacyUrl }, { "multiSiteUrl1", site1Url }, { "multiSiteUrl2", site2Url }, { "multiSiteErrorThreshold", "4" }, { "maxHoursWithoutSwitch", "48" } }; CommManager.reset(); CommManager cmg = CommManager.instance(_config); Assert.IsNotNull(cmg); Assert.IsTrue(cmg.getMultiSite()); Assert.AreEqual(cmg.getMultiSiteThreshold(), 4); Assert.AreEqual(cmg.getMultiSiteUrls().Count(), 2); }
public void testFindUrl_MultiSiteMaxHours() { // test that url is switched when number of hours since last switch exceeds threshold Dictionary <string, string> _config = new Dictionary <string, string> { { "proxyHost", "websenseproxy" }, { "proxyPort", "8080" }, { "printxml", "false" }, { "merchantId", "101" }, { "username", "DOTNET" }, { "password", "TESTCASE" }, { "multiSite", "true" }, { "printMultiSiteDebug", "true" }, { "url", legacyUrl }, { "multiSiteUrl1", site1Url }, { "multiSiteUrl2", site2Url }, { "multiSiteErrorThreshold", "3" }, { "maxHoursWithoutSwitch", "4" } }; CommManager.reset(); CommManager cmg = CommManager.instance(_config); Assert.IsNotNull(cmg); Assert.IsTrue(cmg.getMultiSite()); Assert.AreEqual(cmg.getMultiSiteThreshold(), 3); RequestTarget rt1 = cmg.findUrl(); Assert.AreEqual(cmg.getMultiSiteUrls()[cmg.getCurrentMultiSiteUrlIndex()], rt1.getUrl()); cmg.reportResult(rt1, CommManager.REQUEST_RESULT_RESPONSE_RECEIVED, 200); RequestTarget rt2 = cmg.findUrl(); Assert.AreEqual(rt1.getUrl(), rt2.getUrl()); cmg.reportResult(rt2, CommManager.REQUEST_RESULT_RESPONSE_RECEIVED, 200); // set last switch time to 6 hours earlier DateTime gc = new DateTime(cmg.getLastSiteSwitchTime() * 10000); gc = gc.Add(new System.TimeSpan(-6, 0, 0)); cmg.setLastSiteSwitchTime((gc.Ticks / 10000)); RequestTarget rt3 = cmg.findUrl(); Assert.IsFalse(rt3.getUrl().Equals(rt1.getUrl())); }
public void testFindUrl_MultiSite2() { // test that url is switched when errors reach threshold Dictionary <string, string> _config = new Dictionary <string, string> { { "proxyHost", "websenseproxy" }, { "proxyPort", "8080" }, { "printxml", "false" }, { "merchantId", "101" }, { "username", "DOTNET" }, { "password", "TESTCASE" }, { "multiSite", "true" }, { "printMultiSiteDebug", "false" }, { "url", legacyUrl }, { "multiSiteUrl1", site1Url }, { "multiSiteUrl2", site2Url }, { "multiSiteErrorThreshold", "3" }, { "maxHoursWithoutSwitch", "48" } }; CommManager.reset(); CommManager cmg = CommManager.instance(_config); Assert.IsNotNull(cmg); Assert.IsTrue(cmg.getMultiSite()); Assert.AreEqual(cmg.getMultiSiteThreshold(), 3); RequestTarget rt1 = cmg.findUrl(); Assert.AreEqual(cmg.getMultiSiteUrls()[cmg.getCurrentMultiSiteUrlIndex()], rt1.getUrl()); cmg.reportResult(rt1, CommManager.REQUEST_RESULT_RESPONSE_TIMEOUT, 0); RequestTarget rt2 = cmg.findUrl(); Assert.AreEqual(rt1.getUrl(), rt2.getUrl()); cmg.reportResult(rt2, CommManager.REQUEST_RESULT_RESPONSE_TIMEOUT, 0); RequestTarget rt3 = cmg.findUrl(); Assert.AreEqual(rt1.getUrl(), rt3.getUrl()); cmg.reportResult(rt3, CommManager.REQUEST_RESULT_RESPONSE_TIMEOUT, 0); Assert.AreEqual(cmg.getErrorCount(), 3); RequestTarget rt4 = cmg.findUrl(); Assert.IsFalse(rt4.getUrl().Equals(rt1.getUrl())); }