JingsongLi commented on code in PR #1059:
URL: https://github.com/apache/incubator-paimon/pull/1059#discussion_r1184888751


##########
paimon-core/src/test/java/org/apache/paimon/utils/FailingConstructInputOutputIO.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.paimon.utils;
+
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.fs.PositionOutputStream;
+import org.apache.paimon.fs.SeekableInputStream;
+
+import javax.annotation.Nullable;
+
+import java.io.IOException;
+import java.util.Random;
+
+/** Fail the constructor of input or output stream. */
+public class FailingConstructInputOutputIO extends TraceableFileIO {
+
+    private final double rate;
+    private final Random random = new Random();
+    private String targetName;
+
+    public FailingConstructInputOutputIO(double rate, Class c) {
+        this(rate, c, (String) null);
+    }
+
+    public FailingConstructInputOutputIO(double rate, Class c, @Nullable 
String method) {
+        this.rate = rate;
+        targetName = "." + c.getSimpleName() + ".";
+
+        if (method != null) {
+            targetName += method;
+        }
+    }
+
+    @Override
+    public SeekableInputStream newInputStream(Path f) throws IOException {
+        throwError();
+        return super.newInputStream(f);
+    }
+
+    @Override
+    public PositionOutputStream newOutputStream(Path f, boolean overwrite) 
throws IOException {
+        throwError();
+        return super.newOutputStream(f, overwrite);
+    }
+
+    private void throwError() throws IOException {
+        if (ThreadUtils.stackContains(targetName)) {
+            if (Math.abs(random.nextInt(100)) < 100 * rate) {
+                throw new IOException("emulate real io exception");
+            }
+        }
+    }
+
+    public boolean noLeak() {
+        return openInputStreams(s -> true).size() == 0 && openOutputStreams(s 
-> true).size() == 0;

Review Comment:
   validate prefix? This way we can avoid the impact of multi-threaded tests 
because its path prefix is exclusive.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to