You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "github-code-scanning[bot] (via GitHub)" <gi...@apache.org> on 2023/04/20 09:15:15 UTC

[GitHub] [druid] github-code-scanning[bot] commented on a diff in pull request #14126: Add retry to opening retrying stream

github-code-scanning[bot] commented on code in PR #14126:
URL: https://github.com/apache/druid/pull/14126#discussion_r1172310633


##########
processing/src/test/java/org/apache/druid/data/input/impl/RetryingInputStreamTest.java:
##########
@@ -202,20 +209,52 @@
~  {
~    throwCustomExceptions = 1;
~    throwIOExceptions = 1;
~    final RetryingInputStream<File> retryingInputStream = new RetryingInputStream<>(
         testFile,
         objectOpenFunction,
         t -> t instanceof IOException || t instanceof CustomException,
-        MAX_RETRY
+        MAX_RETRY,
+        false
     );
 
-    retryingInputStream.setNoWait();
     retryHelper(retryingInputStream);
 
     Assert.assertEquals(0, throwCustomExceptions);
     Assert.assertEquals(0, throwIOExceptions);
   }
 
+  @Test
+  public void testRetryOnExceptionWhenOpeningStream() throws Exception
+  {
+    throwCustomExceptions = 2;
+
+    ObjectOpenFunction<File> spyObjectOpenFunction = spy(objectOpenFunction);
+    doAnswer(new Answer<InputStream>()
+    {
+      int retryCount = 0;
+      @Override
+      public InputStream answer(InvocationOnMock invocation) throws Throwable
+      {
+        if (retryCount < 2) {
+          retryCount += 1;
+          throwCustomExceptions -= 1;
+          throw new CustomException("I am a custom retryable exception", new RuntimeException());
+        } else {
+          return (InputStream) invocation.callRealMethod();
+        }
+      }
+    }).when(spyObjectOpenFunction).open(any(), anyLong());
+
+    final RetryingInputStream<File> retryingInputStream = new RetryingInputStream<>(
+        testFile,
+        spyObjectOpenFunction,
+        t -> t instanceof CustomException,
+        MAX_RETRY,
+        false
+    );

Review Comment:
   ## Potential input resource leak
   
   This RetryingInputStream<File> is not always closed on method exit.
   
   [Show more details](https://github.com/apache/druid/security/code-scanning/4852)



##########
processing/src/test/java/org/apache/druid/data/input/impl/RetryingInputStreamTest.java:
##########
@@ -202,20 +209,52 @@
~  {
~    throwCustomExceptions = 1;
~    throwIOExceptions = 1;
~    final RetryingInputStream<File> retryingInputStream = new RetryingInputStream<>(
         testFile,
         objectOpenFunction,
         t -> t instanceof IOException || t instanceof CustomException,
-        MAX_RETRY
+        MAX_RETRY,
+        false
     );
 
-    retryingInputStream.setNoWait();
     retryHelper(retryingInputStream);
 
     Assert.assertEquals(0, throwCustomExceptions);
     Assert.assertEquals(0, throwIOExceptions);
   }
 
+  @Test
+  public void testRetryOnExceptionWhenOpeningStream() throws Exception
+  {
+    throwCustomExceptions = 2;
+
+    ObjectOpenFunction<File> spyObjectOpenFunction = spy(objectOpenFunction);
+    doAnswer(new Answer<InputStream>()
+    {
+      int retryCount = 0;
+      @Override
+      public InputStream answer(InvocationOnMock invocation) throws Throwable
+      {
+        if (retryCount < 2) {
+          retryCount += 1;
+          throwCustomExceptions -= 1;
+          throw new CustomException("I am a custom retryable exception", new RuntimeException());
+        } else {
+          return (InputStream) invocation.callRealMethod();
+        }
+      }
+    }).when(spyObjectOpenFunction).open(any(), anyLong());
+
+    final RetryingInputStream<File> retryingInputStream = new RetryingInputStream<>(
+        testFile,
+        spyObjectOpenFunction,
+        t -> t instanceof CustomException,
+        MAX_RETRY,
+        false
+    );

Review Comment:
   ## Unread local variable
   
   Variable 'RetryingInputStream<File> retryingInputStream' is never read.
   
   [Show more details](https://github.com/apache/druid/security/code-scanning/4853)



-- 
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: commits-unsubscribe@druid.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org