sarankk commented on code in PR #132:
URL: https://github.com/apache/cassandra-sidecar/pull/132#discussion_r1725496022


##########
src/test/containerTest/org/apache/cassandra/sidecar/restore/StorageClientTest.java:
##########
@@ -23,31 +23,41 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.URI;
+import java.net.URISyntaxException;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.time.Duration;
+import java.util.Arrays;
 import java.util.UUID;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ThreadLocalRandom;
 import java.util.concurrent.TimeUnit;
 
 import com.google.common.util.concurrent.SidecarRateLimiter;
+import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.AfterEach;

Review Comment:
   Nit: Unused



##########
src/main/java/org/apache/cassandra/sidecar/restore/HttpRangesIterator.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.cassandra.sidecar.restore;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import org.apache.cassandra.sidecar.common.utils.HttpRange;
+
+public class HttpRangesIterator implements Iterator<HttpRange>
+{
+    private final long totalBytes;
+    private final int rangeSize;
+    private long offset = 0;
+    private HttpRange current;
+
+    public HttpRangesIterator(long totalBytes, int rangeSize)
+    {
+        this.totalBytes = totalBytes;
+        this.rangeSize = rangeSize;
+    }
+
+    @Override
+    public boolean hasNext()
+    {
+        // not consumed yet
+        if (current != null)
+        {
+            return true;
+        }
+
+        if (offset < totalBytes)
+        {
+            long end = Math.min(offset + rangeSize, totalBytes) - 1;
+            current = HttpRange.of(offset, end);
+            offset = end + 1;
+        }
+
+        return current != null;

Review Comment:
   Nit: Since next() is called in only 1 place at a time, how about this?
   
   ```
    @Override
    public boolean hasNext()
    {
   return offset < totalBytes;
   }
   
   @Override
   public HttpRange next()
    {
          if (!hasNext())
          {
              throw new NoSuchElementException("No more HttpRanges");
          }
         long end = Math.min(offset + rangeSize, totalBytes) - 1;
         HttpRange range = HttpRange.of(offset, end);
         offset = end + 1;
         return range;
   }
   ```
   
   



##########
src/test/containerTest/org/apache/cassandra/sidecar/restore/StorageClientTest.java:
##########
@@ -23,31 +23,41 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.URI;
+import java.net.URISyntaxException;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.time.Duration;
+import java.util.Arrays;
 import java.util.UUID;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ThreadLocalRandom;
 import java.util.concurrent.TimeUnit;
 
 import com.google.common.util.concurrent.SidecarRateLimiter;
+import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.BeforeEach;

Review Comment:
   Nit: Unused



##########
src/test/containerTest/org/apache/cassandra/sidecar/restore/StorageClientTest.java:
##########
@@ -192,42 +210,68 @@ void testGetObject() throws Exception
     void testGetObjectHasExistingFileOnDisk() throws Exception
     {
         Path existingPath = testFolder.resolve(UUID.randomUUID().toString());
+        Files.createDirectories(existingPath);
+        Files.createFile(existingPath.resolve("key"));
         RestoreRange sliceHasFileOnDisk = getMockRange(restoreJob.jobId, 
testBucket, "key", checksum, existingPath);
-        File downloaded = 
client.downloadObjectIfAbsent(sliceHasFileOnDisk).get();
+        File downloaded = client.downloadObjectIfAbsent(sliceHasFileOnDisk, 
taskExecutorPool)
+                                
.toCompletionStage().toCompletableFuture().get();
         
assertThat(downloaded.getAbsolutePath()).isEqualTo(existingPath.resolve("key").toString());
     }
 
     @Test
     void testGetObjectThroughputRateLimited() throws Exception
     {
-        // only allow 1/4 the speed of transfer
-        client = new StorageClient(s3AsyncClient, 
SidecarRateLimiter.create(LARGE_FILE_IN_BYTES >> 2));
+        // only allow 1/4 the speed of transfer; each request downloads 1024 
bytes (it is an extremely low value only for testing)
+        client = new StorageClient(s3AsyncClient, 1024, 
SidecarRateLimiter.create(LARGE_FILE_IN_BYTES >> 2));

Review Comment:
   Won't this be a problem if we run tests parallelly? spot bugs is complaining 
about this 



##########
src/test/containerTest/org/apache/cassandra/sidecar/restore/StorageClientTest.java:
##########
@@ -23,31 +23,41 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.URI;
+import java.net.URISyntaxException;

Review Comment:
   Nit: Unused



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to