bbotella commented on code in PR #152:
URL: https://github.com/apache/cassandra-sidecar/pull/152#discussion_r1909493153


##########
server/src/main/java/org/apache/cassandra/sidecar/routes/GetPreemptiveOpenIntervalHandler.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.routes;
+
+import javax.inject.Singleton;
+
+import com.google.inject.Inject;
+import io.netty.handler.codec.http.HttpResponseStatus;
+import io.vertx.core.http.HttpServerRequest;
+import io.vertx.core.net.SocketAddress;
+import io.vertx.ext.web.RoutingContext;
+import org.apache.cassandra.sidecar.common.server.DataStorageUnit;
+import org.apache.cassandra.sidecar.common.server.StorageOperations;
+import org.apache.cassandra.sidecar.concurrent.ExecutorPools;
+import org.apache.cassandra.sidecar.utils.CassandraInputValidator;
+import org.apache.cassandra.sidecar.utils.InstanceMetadataFetcher;
+import org.apache.cassandra.sidecar.utils.RequestUtils;
+
+import static 
org.apache.cassandra.sidecar.utils.HttpExceptions.wrapHttpException;
+
+/**
+ * Functionality to retrieve sstable's preemptive open interval value
+ * unit is an optional param, only supported value is "MiB" defaults to the 
same if not provided
+ */
+@Singleton
+public class GetPreemptiveOpenIntervalHandler extends 
AbstractHandler<DataStorageUnit>
+{
+    @Inject
+    protected GetPreemptiveOpenIntervalHandler(InstanceMetadataFetcher 
metadataFetcher,
+                                               ExecutorPools executorPools,
+                                               CassandraInputValidator 
validator)
+    {
+        super(metadataFetcher, executorPools, validator);
+    }
+
+    @Override
+    protected DataStorageUnit extractParamsOrThrow(RoutingContext context)
+    {
+        // Only supported unit for preemptive open interval value is MB
+        String unit = RequestUtils.parseStringQueryParam(context.request(), 
"unit", "MiB");

Review Comment:
   Super nit: Maybe extracting the string `MiB` to a static `DEFAULT_UNIT` 
string type variable helps with readability. 



##########
server/src/test/integration/org/apache/cassandra/testing/CassandraIntegrationTest.java:
##########
@@ -67,6 +67,8 @@
      */
     int numDataDirsPerInstance() default 1;
 
+    String yamlProps() default "";

Review Comment:
   Why is this needed?



##########
server/src/test/integration/org/apache/cassandra/sidecar/routes/cassandra/GetPreemptiveOpenIntervalHandlerIntegrationTest.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * 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.routes.cassandra;
+
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import io.vertx.core.buffer.Buffer;
+import io.vertx.core.json.JsonObject;
+import io.vertx.ext.web.client.HttpResponse;
+import io.vertx.ext.web.client.predicate.ResponsePredicate;
+import io.vertx.junit5.VertxExtension;
+import io.vertx.junit5.VertxTestContext;
+import org.apache.cassandra.sidecar.testing.IntegrationTestBase;
+import org.apache.cassandra.testing.CassandraIntegrationTest;
+
+import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST;
+import static io.netty.handler.codec.http.HttpResponseStatus.OK;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Test GET preemptive-open-interval endpoint with C* container
+ */
+@ExtendWith(VertxExtension.class)
+public class GetPreemptiveOpenIntervalHandlerIntegrationTest extends 
IntegrationTestBase
+{
+    private static final String testRoute = 
"/api/v1/cassandra/sstable/preemptive-open-interval";
+
+    @CassandraIntegrationTest(yamlProps = 
"sstable_preemptive_open_interval_in_mb=60")
+    void testPreemptiveOpenInterval60(VertxTestContext testContext)
+    {
+        client.get(server.actualPort(), "127.0.0.1", testRoute)
+              .expect(ResponsePredicate.SC_OK)
+              .send(testContext.succeeding(response -> 
verifyValidResponse(testContext, response, 60)));
+    }
+
+    @CassandraIntegrationTest(yamlProps = 
"sstable_preemptive_open_interval_in_mb=-1")
+    void testPreemptiveOpenIntervalNegative(VertxTestContext testContext)
+    {
+        client.get(server.actualPort(), "127.0.0.1", testRoute)
+              .expect(ResponsePredicate.SC_OK)
+              .send(testContext.succeeding(response -> 
verifyValidResponse(testContext, response, -1)));
+    }
+
+    @CassandraIntegrationTest(yamlProps = 
"sstable_preemptive_open_interval_in_mb=80")
+    void testPreemptiveOpenIntervalWithUnit(VertxTestContext testContext)
+    {
+        client.get(server.actualPort(), "127.0.0.1", testRoute + "?unit=MiB")
+              .expect(ResponsePredicate.SC_OK)
+              .send(testContext.succeeding(response -> 
verifyValidResponse(testContext, response, 80)));
+    }
+
+    @CassandraIntegrationTest(yamlProps = 
"sstable_preemptive_open_interval_in_mb=90")
+    void testPreemptiveOpenIntervalInvalidUnit(VertxTestContext testContext)
+    {
+        client.get(server.actualPort(), "127.0.0.1", testRoute + "?unit=KiB")

Review Comment:
   Nit: We may add support for KiB in the future, which would change the 
behavior of this test. Maybe just having a string that will never be a unit? 
Something like `foo`?



##########
server/src/main/java/org/apache/cassandra/sidecar/utils/RequestUtils.java:
##########
@@ -61,4 +61,14 @@ public static Integer 
parseIntegerQueryParam(HttpServerRequest request, String p
         }
         return defaultValue;
     }
+
+    public static String parseStringQueryParam(HttpServerRequest request, 
String paramName, String defaultValue)

Review Comment:
   nit: You are technically getting the param, not parsing it. Consider 
renaming the method



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