public void TestProxySetupHostAndPortOnly() { var dummyConfig = new AmazonEC2Config(); dummyConfig.ProxyHost = Host; dummyConfig.ProxyPort = Port; WebProxy proxy = dummyConfig.GetWebProxy(); var address = proxy.Address; Assert.AreEqual(address.Host, Host); Assert.AreEqual(address.Port, Port); Assert.AreEqual(0, proxy.BypassList.Length); Assert.IsFalse(proxy.BypassProxyOnLocal); }
public void TestProxySetupWithSchemedHost() { // verifies bug fix that the http:// scheme is not doubled // up in the proxy address if the user specifies it when setting // proxy host (the bug yielded an address like http://http/host) var dummyConfig = new AmazonEC2Config(); var host = string.Concat("http://", Host); dummyConfig.ProxyHost = host; dummyConfig.ProxyPort = Port; WebProxy proxy = dummyConfig.GetWebProxy(); Assert.IsTrue(proxy.Address.ToString().StartsWith(host, StringComparison.OrdinalIgnoreCase)); }
public void TestProxySetupWithBypass() { var dummyConfig = new AmazonEC2Config(); dummyConfig.ProxyHost = Host; dummyConfig.ProxyPort = Port; dummyConfig.ProxyBypassList = new List <string>(BypassList); dummyConfig.ProxyBypassOnLocal = true; WebProxy proxy = dummyConfig.GetWebProxy(); Assert.AreEqual(BypassList.Count, proxy.BypassList.Length); // making assumption here that order is retained on assignment // inside WebProxy - seems to be the case for (int i = 0; i < BypassList.Count; i++) { Assert.AreEqual(BypassList[i], proxy.BypassList[i]); } Assert.IsTrue(proxy.BypassProxyOnLocal); }
private static void LoadDefinitionsFromWeb(AmazonEC2Config ec2Config) { lock (LOCK_OBJECT) { if (ImageDefinitionsLoaded) return; } IWebProxy webProxy = null; if (ec2Config != null) webProxy = ec2Config.GetWebProxy(); int retries = 0; while (retries < MAX_DOWNLOAD_RETRIES) { try { HttpWebResponse response = null; foreach (var location in DownloadLocations) { try { response = DownloadControlFile(location, webProxy); if (response != null) break; } catch (Exception e) { Logger.InfoFormat("Failed to download stockamis.json from {0}, exception {1}", location, e); } } if (response == null) throw new AmazonClientException("Failed to download ImageUtilities metadata file stockamis.json from known locations."); using (response) { using (var reader = new StreamReader(response.GetResponseStream())) { lock (LOCK_OBJECT) { ParseAMIDefinitions(reader); ImageDefinitionsLoaded = true; return; } } } } catch (AmazonClientException e) { retries++; if (retries == MAX_DOWNLOAD_RETRIES) { Logger.Error(e, "Error downloading AMI definition file, ImageDescriptors were not initialized."); break; } } int delay = (int)(Math.Pow(4, retries) * 100); delay = Math.Min(delay, 30 * 1000); Thread.Sleep(delay); } }
private static void LoadDefinitionsFromWeb(AmazonEC2Config ec2Config) { lock (LOCK_OBJECT) { if (ImageDefinitionsLoaded) { return; } } IWebProxy webProxy = null; if (ec2Config != null) { webProxy = ec2Config.GetWebProxy(); } int retries = 0; while (retries < MAX_DOWNLOAD_RETRIES) { try { HttpWebResponse response = null; foreach (var location in DownloadLocations) { try { response = DownloadControlFile(location, webProxy); if (response != null) { break; } } catch (Exception e) { Logger.InfoFormat("Failed to download stockamis.json from {0}, exception {1}", location, e); } } if (response == null) { throw new AmazonClientException("Failed to download ImageUtilities metadata file stockamis.json from known locations."); } using (response) { using (var reader = new StreamReader(response.GetResponseStream())) { lock (LOCK_OBJECT) { ParseAMIDefinitions(reader); ImageDefinitionsLoaded = true; return; } } } } catch (AmazonClientException e) { retries++; if (retries == MAX_DOWNLOAD_RETRIES) { Logger.Error(e, "Error downloading AMI definition file, ImageDescriptors were not initialized."); break; } } int delay = (int)(Math.Pow(4, retries) * 100); delay = Math.Min(delay, 30 * 1000); Thread.Sleep(delay); } }