mohsenrezaeithe commented on code in PR #196:
URL: 
https://github.com/apache/flink-connector-aws/pull/196#discussion_r2064532605


##########
flink-connector-aws/flink-connector-aws-kinesis-streams/src/main/java/org/apache/flink/connector/kinesis/sink/KinesisStreamsSinkWriter.java:
##########
@@ -167,8 +204,18 @@ class KinesisStreamsSinkWriter<InputT> extends 
AsyncSinkWriter<InputT, PutRecord
         this.streamArn = streamArn;
         this.metrics = context.metricGroup();
         this.numRecordsOutErrorsCounter = 
metrics.getNumRecordsOutErrorsCounter();
-        this.httpClient = 
AWSGeneralUtil.createAsyncHttpClient(kinesisClientProperties);
-        this.kinesisClient = buildClient(kinesisClientProperties, 
this.httpClient);
+
+        this.kinesisClientProvider = kinesisClientProvider;
+
+        if (kinesisClientProvider != null) {
+            // Use the provided client for testing
+            this.httpClient = null;
+            this.kinesisClient = kinesisClientProvider.get();
+        } else {
+            // Create a new client as before
+            this.httpClient = 
AWSGeneralUtil.createAsyncHttpClient(kinesisClientProperties);
+            this.kinesisClient = buildClient(kinesisClientProperties, 
this.httpClient);
+        }

Review Comment:
   Nit: These can be pushed to their own constructors so you don't have to pass 
in `null` or do a `null` check.



##########
flink-connector-aws/flink-connector-aws-kinesis-streams/src/main/java/org/apache/flink/connector/kinesis/sink/KinesisClientProvider.java:
##########
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.connector.kinesis.sink;
+
+import org.apache.flink.annotation.Internal;
+
+import software.amazon.awssdk.services.kinesis.KinesisAsyncClient;
+
+/**
+ * Provider interface for KinesisAsyncClient instances. This is primarily used 
for testing to inject
+ * mock clients.
+ */
+@Internal
+interface KinesisClientProvider {

Review Comment:
   Can this also extend `SdkAutoCloseable` so it's inline with the other 
resource impls?



##########
flink-connector-aws/flink-connector-aws-kinesis-streams/src/main/java/org/apache/flink/connector/kinesis/sink/KinesisStreamsSinkWriter.java:
##########
@@ -244,34 +291,121 @@ private void handleFullyFailedRequest(
 
     @Override
     public void close() {
-        AWSGeneralUtil.closeResources(httpClient, kinesisClient);
+        if (kinesisClientProvider != null) {
+            kinesisClientProvider.close();
+        } else {
+            AWSGeneralUtil.closeResources(httpClient, kinesisClient);

Review Comment:
   IIUC, by having the provider extend `SdkAutoCloseable`, you can pass it as 
the last parameter to the util for resource cleanup.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to