test for resources cleanup
authorEugene Petrenko <eugene.petrenko@gmail.com>
Mon, 15 Aug 2011 16:30:09 +0000 (20:30 +0400)
committerEugene Petrenko <eugene.petrenko@gmail.com>
Mon, 15 Aug 2011 16:30:09 +0000 (20:30 +0400)
nuget-tests/src/jetbrains/buildServer/nuget/tests/integration/FeedReaderTest.java

index 6f19462e75a9992bd1e74969c5ba727167036a4c..65c59b620079fa7f923f25423f22ada09e51ec16 100644 (file)
@@ -22,15 +22,14 @@ import jetbrains.buildServer.nuget.server.feed.reader.FeedPackage;
 import jetbrains.buildServer.nuget.server.feed.reader.NuGetFeedReader;\r
 import jetbrains.buildServer.nuget.server.feed.reader.impl.*;\r
 import jetbrains.buildServer.util.FileUtil;\r
 import jetbrains.buildServer.nuget.server.feed.reader.NuGetFeedReader;\r
 import jetbrains.buildServer.nuget.server.feed.reader.impl.*;\r
 import jetbrains.buildServer.util.FileUtil;\r
+import jetbrains.buildServer.util.SimpleHttpServerBase;\r
 import org.testng.Assert;\r
 import org.testng.annotations.AfterMethod;\r
 import org.testng.annotations.BeforeMethod;\r
 import org.testng.annotations.Test;\r
 \r
 import org.testng.Assert;\r
 import org.testng.annotations.AfterMethod;\r
 import org.testng.annotations.BeforeMethod;\r
 import org.testng.annotations.Test;\r
 \r
-import java.io.BufferedInputStream;\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.io.IOException;\r
+import java.io.*;\r
+import java.util.Arrays;\r
 import java.util.Collection;\r
 import java.util.zip.ZipEntry;\r
 import java.util.zip.ZipInputStream;\r
 import java.util.Collection;\r
 import java.util.zip.ZipEntry;\r
 import java.util.zip.ZipInputStream;\r
@@ -103,4 +102,65 @@ public class FeedReaderTest extends BaseTestCase {
 \r
     Assert.assertTrue(hasNuGetExe, "package should contain nuget.exe");\r
   }\r
 \r
     Assert.assertTrue(hasNuGetExe, "package should contain nuget.exe");\r
   }\r
+\r
+\r
+  @Test\r
+  public void test_connection_leaks() throws Exception {\r
+    final SimpleHttpServerBase server = new SimpleHttpServerBase(){\r
+      @Override\r
+      protected Response getResponse(String s) {\r
+        if (s.startsWith("GET /aaa")) {\r
+          return redirectedResponse("bbb");\r
+        }\r
+        if (s.startsWith("GET /bbb")) {\r
+          return redirectedResponse("ccc");\r
+        }\r
+        if (s.startsWith("GET /ccc")) {\r
+          return redirectedResponse("ddd");\r
+        }\r
+        if (s.startsWith("GET /ddd")) {\r
+          return redirectedResponse("qqq");\r
+        }\r
+        if (s.startsWith("GET /qqq")) {\r
+          return new Response("HTTP/1.0 200 Ok", Arrays.asList("Encoding: utf-8", "Content-Type: text/xml")) {\r
+            @Override\r
+            public void printContent(PrintStream printStream) throws IOException {\r
+              final File path = Paths.getTestDataPath("feed/reader/feed-response.xml");\r
+              InputStream fis = new BufferedInputStream(new FileInputStream(path));\r
+              FileUtil.copyStreams(fis, printStream);\r
+            }\r
+\r
+            @Override\r
+            public Integer getLength() {\r
+              return null;\r
+            }\r
+          };\r
+        }\r
+        return null;\r
+      }\r
+\r
+      private Response redirectedResponse(String next) {\r
+        final String url = "http://localhost:" + getPort() + "/" + next;\r
+        return new Response("HTTP/1.0 301 Moved", Arrays.asList("Location: " + url)) {\r
+          @Override\r
+          public void printContent(PrintStream printStream) throws IOException {\r
+          }\r
+\r
+          @Override\r
+          public Integer getLength() {\r
+            return null;\r
+          }\r
+        };\r
+      }\r
+    };\r
+\r
+    server.start();\r
+    try {\r
+      for(int i = 0; i <100; i++) {\r
+        myReader.queryPackageVersions("http://localhost:" + server.getPort() + "/aaa", "NuGet");\r
+      }\r
+    } finally {\r
+      server.stop();\r
+    }\r
+  }\r
 }\r
 }\r