using System.Collections;\r
using System.IO;\r
using System.Net;\r
+using System.Reflection;\r
using System.Threading;\r
\r
namespace MonoTests.System.Net\r
public class ServicePointTest\r
{\r
static private int max;\r
+\r
+#if !FEATURE_NO_BSD_SOCKETS\r
[SetUp]\r
public void SaveMax () {\r
max = ServicePointManager.MaxServicePoints;\r
public void RestoreMax () {\r
ServicePointManager.MaxServicePoints = max;\r
}\r
+#endif\r
\r
[Test]\r
[Category ("InetAccess")]\r
-#if TARGET_JVM\r
- [Ignore ("Unsupported - ServicePointManager.FindServicePoint")]\r
-#endif\r
public void All ()\r
{\r
ServicePoint p = ServicePointManager.FindServicePoint (new Uri ("mailto:xx@yyy.com"));\r
HttpWebRequest req = (HttpWebRequest) WebRequest.Create ("http://www.google.com");\r
HttpWebResponse res = (HttpWebResponse) req.GetResponse (); \r
\r
+#if FOUND_SOME_OTHER_URL\r
+ // URL is no longer found, disabled the test until a more reliable URL is found :P\r
//WriteServicePoint ("google after getting a response", google);\r
ServicePoint google2 = ServicePointManager.FindServicePoint (new Uri ("http://www.google.com/dilbert.html"));\r
Assert.AreEqual (google, google2, "#equals");\r
res.Close ();\r
+#endif\r
\r
// in both instances property CurrentConnections is 0 according to ms.net.\r
// let's see what it says when we do async operations...\r
//Console.WriteLine ("ContentLength: " + res2.ContentLength);\r
res2.Close ();\r
\r
- \r
+ ServicePoint sp2;\r
+#if FOUND_SOME_OTHER_URL\r
// unless of course some buffering is taking place.. let's check\r
Uri uri2 = new Uri ("http://freedesktop.org/Software/pkgconfig/releases/pkgconfig-0.15.0.tar.gz");\r
- ServicePoint sp2 = ServicePointManager.FindServicePoint (uri2);\r
+ sp2 = ServicePointManager.FindServicePoint (uri2);\r
req2 = (HttpWebRequest) WebRequest.Create (uri2);\r
async = req2.BeginGetResponse (null, null);\r
//WriteServicePoint ("Large file: after async BeginGetResponse", sp2);\r
// and so it shows\r
//Console.WriteLine ("ContentLength: " + res2.ContentLength);\r
res2.Close ();\r
+#endif\r
\r
\r
// what's the limit of the cache?\r
\r
[Test]\r
[Category ("InetAccess")]\r
-#if TARGET_JVM\r
- [Ignore ("The System.Net.ServicePointManager.FindServicePoint(Uri) is not supported")]\r
-#endif \r
public void ConnectionLimit ()\r
{ \r
// the default is already 2, just in case it isn't..\r
}\r
}\r
\r
-#if NET_2_0\r
[Test]\r
[Category ("InetAccess")]\r
-#if TARGET_JVM\r
- [Ignore ("The System.Net.ServicePointManager.FindServicePoint(Uri) is not supported")]\r
-#endif \r
+ [Category ("AndroidNotWorking")] // #A1 fails\r
public void EndPointBind ()\r
{\r
Uri uri = new Uri ("http://www.go-mono.com/");\r
HttpWebRequest req = (HttpWebRequest) WebRequest.Create (uri);\r
\r
bool called = false;\r
-#if !TARGET_JVM\r
sp.BindIPEndPointDelegate = delegate {\r
Assert.IsTrue (!called);\r
called = true;\r
return null;\r
};\r
-#endif\r
req.GetResponse ().Close ();\r
\r
- Assert.IsTrue (called);\r
+ Assert.IsTrue (called, "#A1");\r
\r
req = (HttpWebRequest) WebRequest.Create (uri);\r
called = false;\r
-#if !TARGET_JVM\r
sp.BindIPEndPointDelegate = delegate(ServicePoint point, IPEndPoint remote, int times) {\r
Assert.IsTrue (times < 5);\r
called = true;\r
return new IPEndPoint(IPAddress.Parse("0.0.0.0"), 12345 + times);\r
};\r
-#endif\r
req.GetResponse ().Close ();\r
\r
- Assert.IsTrue (called);\r
+ Assert.IsTrue (called, "#A2");\r
}\r
+\r
+ public static void GetRequestStreamCallback (IAsyncResult asynchronousResult)\r
+ {\r
+ }\r
+\r
+ [Test] //Covers #19823\r
+#if FEATURE_NO_BSD_SOCKETS\r
+ // This test uses HttpWebRequest\r
+ [ExpectedException (typeof (PlatformNotSupportedException))]\r
#endif\r
+ public void CloseConnectionGroupConcurency ()\r
+ {\r
+ // Try with multiple service points\r
+ for (var i = 0; i < 10; i++) {\r
+ Uri targetUri = new Uri ("http://" + i + ".mono-project.com");\r
+ var req = (HttpWebRequest) HttpWebRequest.Create (targetUri);\r
+ req.ContentType = "application/x-www-form-urlencoded";\r
+ req.Method = "POST";\r
+ req.ConnectionGroupName = "" + i;\r
+ req.ServicePoint.MaxIdleTime = 1;\r
+\r
+ req.BeginGetRequestStream (new AsyncCallback (GetRequestStreamCallback), req);\r
+ Thread.Sleep (1);\r
+ req.ServicePoint.CloseConnectionGroup (req.ConnectionGroupName);\r
+ }\r
+ }\r
+\r
+\r
+ [Test]\r
+ [Category ("RequiresBSDSockets")] // Tests internals, so it doesn't make sense to assert that PlatformNotSupportedExceptions are thrown.\r
+ public void DnsRefreshTimeout ()\r
+ {\r
+ const int dnsRefreshTimeout = 2000;\r
+\r
+ ServicePoint sp;\r
+ IPHostEntry host0, host1, host2;\r
+ Uri uri;\r
+ PropertyInfo hostEntryProperty;\r
+\r
+ ServicePointManager.DnsRefreshTimeout = dnsRefreshTimeout;\r
+\r
+ uri = new Uri ("http://localhost/");\r
+ sp = ServicePointManager.FindServicePoint (uri);\r
+\r
+ hostEntryProperty = typeof (ServicePoint).GetProperty ("HostEntry", BindingFlags.NonPublic | BindingFlags.Instance);\r
+\r
+ host0 = hostEntryProperty.GetValue (sp, null) as IPHostEntry;\r
+ host1 = hostEntryProperty.GetValue (sp, null) as IPHostEntry;\r
+\r
+ Assert.AreSame (host0, host1, "HostEntry should result in the same IPHostEntry object.");\r
+\r
+ Thread.Sleep (dnsRefreshTimeout * 2);\r
+ host2 = hostEntryProperty.GetValue (sp, null) as IPHostEntry;\r
+\r
+ Assert.AreNotSame(host0, host2, "HostEntry should result in a new IPHostEntry " +\r
+ "object when DnsRefreshTimeout is reached.");\r
+ }\r
\r
// Debug code not used now, but could be useful later\r
/*\r