You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ap...@apache.org on 2023/09/08 13:42:18 UTC

[ignite-3] branch main updated: IGNITE-20351 Log response body in REST test if it fails (#2553)

This is an automated email from the ASF dual-hosted git repository.

apkhmv pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new de51d814b8 IGNITE-20351 Log response body in REST test if it fails (#2553)
de51d814b8 is described below

commit de51d814b83b079ef1bc19af2a86f18f201fcbd5
Author: Aleksandr Pakhomov <ap...@gmail.com>
AuthorDate: Fri Sep 8 17:42:12 2023 +0400

    IGNITE-20351 Log response body in REST test if it fails (#2553)
---
 .../rest/authentication/ItAuthenticationTest.java  |  5 ++--
 .../ignite/internal/rest/ssl/ItRestSslTest.java    | 27 +++++++++++-----------
 2 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/rest/authentication/ItAuthenticationTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/rest/authentication/ItAuthenticationTest.java
index 038a54d992..6d76c101e4 100644
--- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/rest/authentication/ItAuthenticationTest.java
+++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/rest/authentication/ItAuthenticationTest.java
@@ -256,13 +256,14 @@ public class ItAuthenticationTest extends BaseIgniteAbstractTest {
         HttpRequest clusterConfigRequest = HttpRequest.newBuilder(clusterConfigUri)
                 .header("Authorization", basicAuthenticationHeader(username, password))
                 .build();
-        int code = sendRequest(client, clusterConfigRequest).statusCode();
+        HttpResponse<String> response = sendRequest(client, clusterConfigRequest);
+        int code = response.statusCode();
         if (code == 200) {
             return true;
         } else if (code == 401) {
             return false;
         } else {
-            throw new IllegalStateException("Unexpected response code: " + code);
+            throw new IllegalStateException("Unexpected response code: " + code +  ", body: " + response.body());
         }
     }
 
diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/rest/ssl/ItRestSslTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/rest/ssl/ItRestSslTest.java
index 9455e37eb2..c8e22e80d9 100644
--- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/rest/ssl/ItRestSslTest.java
+++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/rest/ssl/ItRestSslTest.java
@@ -18,7 +18,6 @@
 package org.apache.ignite.internal.rest.ssl;
 
 import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
-import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
 import java.io.File;
@@ -181,8 +180,14 @@ public class ItRestSslTest extends IgniteIntegrationTest {
         HttpRequest request = HttpRequest.newBuilder(uri).build();
 
         // Then response code is 200
-        HttpResponse<String> response = sslClient.send(request, BodyHandlers.ofString());
-        assertEquals(200, response.statusCode());
+        assertResponseCodeIs(200, request, sslClient);
+    }
+
+    private static void assertResponseCodeIs(int code, HttpRequest request, HttpClient client) throws IOException, InterruptedException {
+        HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
+        if (response.statusCode() != code) {
+            throw new AssertionError("Expected response code " + code + " but was " + response.statusCode() + ", body: " + response.body());
+        }
     }
 
     @Test
@@ -192,8 +197,7 @@ public class ItRestSslTest extends IgniteIntegrationTest {
         HttpRequest request = HttpRequest.newBuilder(uri).build();
 
         // Then response code is 200
-        HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
-        assertEquals(200, response.statusCode());
+        assertResponseCodeIs(200, request, client);
     }
 
     @Test
@@ -206,12 +210,10 @@ public class ItRestSslTest extends IgniteIntegrationTest {
         HttpRequest httpsRequest = HttpRequest.newBuilder(httpsUri).build();
 
         // Then HTTP response code is 200
-        HttpResponse<String> httpResponse = client.send(httpRequest, BodyHandlers.ofString());
-        assertEquals(200, httpResponse.statusCode());
+        assertResponseCodeIs(200, httpRequest, client);
 
         // And HTTPS response code is 200
-        httpResponse = sslClient.send(httpsRequest, BodyHandlers.ofString());
-        assertEquals(200, httpResponse.statusCode());
+        assertResponseCodeIs(200, httpsRequest, sslClient);
     }
 
     @Test
@@ -241,8 +243,7 @@ public class ItRestSslTest extends IgniteIntegrationTest {
         HttpRequest request = HttpRequest.newBuilder(uri).build();
 
         // Then response code is 200
-        HttpResponse<String> response = sslClientWithClientAuth.send(request, BodyHandlers.ofString());
-        assertEquals(200, response.statusCode());
+        assertResponseCodeIs(200, request, sslClientWithClientAuth);
     }
 
     @Test
@@ -255,14 +256,14 @@ public class ItRestSslTest extends IgniteIntegrationTest {
         assertThrows(IOException.class, () -> sslClient.send(request, BodyHandlers.ofString()));
     }
 
+    @Test
     void httpsWithCustomCipher(TestInfo testInfo) throws Exception {
         // When GET /management/v1/configuration/node
         URI uri = URI.create(httpsWithCustomCipherNode.httpsAddress() + "/management/v1/configuration/node");
         HttpRequest request = HttpRequest.newBuilder(uri).build();
 
         // Then response code is 200
-        HttpResponse<String> response = sslClient.send(request, BodyHandlers.ofString());
-        assertEquals(200, response.statusCode());
+        assertResponseCodeIs(200, request, sslClient);
     }
 
     @Test