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 9f5c135ea7 IGNITE-19953 Fix --verbose/-v option in CLI interactive
mode (#2419)
9f5c135ea7 is described below
commit 9f5c135ea77edcbc12148abe492b1d748ead4b4b
Author: Ivan Zlenko <[email protected]>
AuthorDate: Tue Aug 8 19:11:59 2023 +0500
IGNITE-19953 Fix --verbose/-v option in CLI interactive mode (#2419)
---
.../ignite/internal/cli/logger/HttpLogging.java | 5 ++++
.../internal/cli/logger/HttpLoggingTest.java | 35 +++++++++++++++++-----
2 files changed, 33 insertions(+), 7 deletions(-)
diff --git
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/logger/HttpLogging.java
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/logger/HttpLogging.java
index dc8bf52db0..cfb031185d 100644
---
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/logger/HttpLogging.java
+++
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/logger/HttpLogging.java
@@ -22,10 +22,13 @@ import okhttp3.OkHttpClient.Builder;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.logging.HttpLoggingInterceptor.Level;
import org.apache.ignite.rest.client.invoker.ApiClient;
+import org.jetbrains.annotations.Nullable;
/** Helper class for logging HTTP requests/responses from generated REST API
client. */
class HttpLogging {
private final ApiClient client;
+
+ @Nullable
private HttpLoggingInterceptor interceptor;
HttpLogging(ApiClient client) {
@@ -59,6 +62,8 @@ class HttpLogging {
builder.interceptors().remove(interceptor);
client.setHttpClient(builder.build());
+
+ interceptor = null;
}
}
}
diff --git
a/modules/cli/src/test/java/org/apache/ignite/internal/cli/logger/HttpLoggingTest.java
b/modules/cli/src/test/java/org/apache/ignite/internal/cli/logger/HttpLoggingTest.java
index 5c0e4ed210..0da3db1d07 100644
---
a/modules/cli/src/test/java/org/apache/ignite/internal/cli/logger/HttpLoggingTest.java
+++
b/modules/cli/src/test/java/org/apache/ignite/internal/cli/logger/HttpLoggingTest.java
@@ -27,35 +27,56 @@ import java.io.StringWriter;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient.Builder;
import org.apache.ignite.rest.client.invoker.ApiClient;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class HttpLoggingTest {
+ private static final PrintWriter WRITER = new PrintWriter(new
StringWriter());
+
+ private ApiClient client;
+
+ private HttpLogging logger;
+
+ @BeforeEach
+ void setUp() {
+ client = new ApiClient();
+ logger = new HttpLogging(client);
+ }
+
@Test
void startAndStopLogging() {
- ApiClient client = new ApiClient();
assertThat(client.getHttpClient().interceptors(), empty());
- HttpLogging logger = new HttpLogging(client);
+ logger.startHttpLogging(WRITER);
+ assertThat(client.getHttpClient().interceptors(), not(empty()));
+
+ logger.stopHttpLogging();
+ assertThat(client.getHttpClient().interceptors(), empty());
+ }
+
+ @Test
+ void restartLogging() {
+ assertThat(client.getHttpClient().interceptors(), empty());
- logger.startHttpLogging(new PrintWriter(new StringWriter()));
+ logger.startHttpLogging(WRITER);
assertThat(client.getHttpClient().interceptors(), not(empty()));
logger.stopHttpLogging();
assertThat(client.getHttpClient().interceptors(), empty());
+
+ logger.startHttpLogging(WRITER);
+ assertThat(client.getHttpClient().interceptors(), not(empty()));
}
@Test
void stopLoggingRemoveOnlyOneInterceptor() {
- ApiClient client = new ApiClient();
Interceptor interceptor = chain -> chain.proceed(chain.request());
Builder builder = client.getHttpClient().newBuilder();
builder.interceptors().add(interceptor);
client.setHttpClient(builder.build());
- HttpLogging logger = new HttpLogging(client);
-
- logger.startHttpLogging(new PrintWriter(new StringWriter()));
+ logger.startHttpLogging(WRITER);
logger.stopHttpLogging();
assertThat(client.getHttpClient().interceptors(),
contains(interceptor));