changeset 3123:58ea4ef84c92

reproduced issue #32 in Java
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 15 Jan 2019 18:46:59 +0100
parents df4f977c2f88
children 8296f0f75716 b1787ba94eef
files Resources/Testing/Issue32/Java/README.txt Resources/Testing/Issue32/Java/pom.xml Resources/Testing/Issue32/Java/src/test/java/io/osimis/AppTest.java
diffstat 3 files changed, 98 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/Testing/Issue32/Java/README.txt	Tue Jan 15 18:46:59 2019 +0100
@@ -0,0 +1,2 @@
+$ sudo apt-get install maven
+$ mvn test
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/Testing/Issue32/Java/pom.xml	Tue Jan 15 18:46:59 2019 +0100
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>io.osimis</groupId>
+  <artifactId>issue32</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <name>issue32</name>
+  <!-- FIXME change it to the project's website -->
+  <url>http://www.example.com</url>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <maven.compiler.source>1.8</maven.compiler.source>
+    <maven.compiler.target>1.8</maven.compiler.target>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.httpcomponents</groupId>
+      <artifactId>httpclient</artifactId>
+      <version>4.5.3</version>
+    </dependency>
+
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.11</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+</project>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/Testing/Issue32/Java/src/test/java/io/osimis/AppTest.java	Tue Jan 15 18:46:59 2019 +0100
@@ -0,0 +1,61 @@
+package io.osimis;
+
+import java.io.IOException;
+import org.apache.http.HttpEntity;
+import org.apache.http.client.HttpRequestRetryHandler;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpRequestBase;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+import org.apache.http.util.EntityUtils;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class AppTest 
+{
+  @Test
+  public void testKeepAlive()
+  {
+    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
+
+    CloseableHttpClient client = HttpClients
+      .custom()
+      .setConnectionManager(cm)
+      .setRetryHandler((HttpRequestRetryHandler) (exception, executionCount, context) -> {
+          System.out.println("ERROR");
+          assertTrue(false);
+          return false;
+        }).build();
+
+    HttpRequestBase request = new HttpGet("http://localhost:8042/system");
+
+    // The following call works
+    //HttpRequestBase request = new HttpGet("https://api.ipify.org?format=json");
+    
+    for (int i = 0; i < 5; i++) {
+      System.out.println("================================");
+      try (CloseableHttpResponse httpResponse = client.execute(request)) {
+        String responseContent = null;
+
+        HttpEntity entity = httpResponse.getEntity();
+        if (entity != null) {
+          responseContent = EntityUtils.toString(entity);
+        }
+
+        System.out.println(httpResponse.getStatusLine().getStatusCode());
+        System.out.println(responseContent);
+
+        EntityUtils.consume(entity);
+        httpResponse.close();
+      } catch (IOException e) {
+        System.out.println("Request error " + e);
+      }
+    }
+      
+    assertTrue(true);
+  }
+}