nastra commented on code in PR #10140:
URL: https://github.com/apache/iceberg/pull/10140#discussion_r1582748026


##########
core/src/test/java/org/apache/iceberg/TestClientPoolImpl.java:
##########
@@ -0,0 +1,146 @@
+/*
+ * 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.iceberg;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
+
+import org.junit.jupiter.api.Test;
+
+public class TestClientPoolImpl {
+
+  static class RetryableException extends RuntimeException {}
+
+  static class NonRetryableException extends RuntimeException {}
+
+  static class MockClient {
+    boolean closed = false;
+
+    int actions = 0;
+
+    int retryableFailures = 0;
+
+    public void close() {
+      closed = true;
+    }
+
+    public int successfulAction() {
+      actions++;
+      return actions;
+    }
+
+    int succeedAfter(int succeedAfterAttempts) {
+      if (retryableFailures == succeedAfterAttempts - 1) {
+        return successfulAction();
+      }
+
+      retryableFailures++;
+      throw new RetryableException();
+    }
+
+    int failWithNonRetryable() {
+      throw new NonRetryableException();
+    }
+  }
+
+  static class MockClientPoolImpl extends ClientPoolImpl<MockClient, 
Exception> {
+
+    private int reconnectionAttempts;
+
+    MockClientPoolImpl(
+        int poolSize,
+        Class<? extends Exception> reconnectExc,
+        boolean retryByDefault,
+        int numRetries) {
+      super(poolSize, reconnectExc, retryByDefault, numRetries);
+    }
+
+    @Override
+    protected MockClient newClient() {
+      return new MockClient();
+    }
+
+    @Override
+    protected MockClient reconnect(MockClient client) {
+      reconnectionAttempts++;
+      return client;
+    }
+
+    @Override
+    protected void close(MockClient client) {
+      client.close();
+    }
+
+    int reconnectionAttempts() {
+      return reconnectionAttempts;
+    }
+  }
+
+  @Test

Review Comment:
   I would probably move the tests to the top and the inner classes to the 
bottom



-- 
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...@iceberg.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to