yifan-c commented on code in PR #225:
URL: https://github.com/apache/cassandra-sidecar/pull/225#discussion_r2151030659


##########
adapters/adapters-base/src/main/java/org/apache/cassandra/sidecar/adapters/base/jmx/GossipDependentStorageJmxOperations.java:
##########
@@ -177,4 +177,26 @@ public String getClusterName()
     {
         return delegate.getClusterName();
     }
+
+    @Override
+    public void stopNativeTransport()
+    {
+        delegate.stopNativeTransport();
+    }
+
+    @Override
+    public void startNativeTransport()
+    {
+        delegate.startNativeTransport();
+    }
+
+    public void stopGossiping()
+    {
+        delegate.stopGossiping();
+    }
+
+    public void startGossiping()

Review Comment:
   Please add `@Override` to those 2 methods



##########
client/src/main/java/org/apache/cassandra/sidecar/client/SidecarClient.java:
##########
@@ -7,14 +7,13 @@
  * "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
+ *     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.
+ * 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.
  */

Review Comment:
   Revert those changes please. 



##########
server/src/main/java/org/apache/cassandra/sidecar/handlers/NativeUpdateHandler.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * 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.handlers;
+
+import java.util.Collections;
+import java.util.Set;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import io.vertx.core.http.HttpServerRequest;
+import io.vertx.core.net.SocketAddress;
+import io.vertx.ext.auth.authorization.Authorization;
+import io.vertx.ext.web.RoutingContext;
+import org.apache.cassandra.sidecar.acl.authorization.BasicPermissions;
+import 
org.apache.cassandra.sidecar.common.request.data.NodeCommandRequestPayload;
+import org.apache.cassandra.sidecar.common.server.StorageOperations;
+import org.apache.cassandra.sidecar.concurrent.ExecutorPools;
+import org.apache.cassandra.sidecar.utils.InstanceMetadataFetcher;
+import org.jetbrains.annotations.NotNull;
+
+import static org.apache.cassandra.sidecar.modules.HealthCheckModule.OK_STATUS;
+
+
+/**
+ * Handler for starting or stopping native transport on a Cassandra node.
+ * <p>
+ * Expects a JSON body:
+ * { "state": "start" }  or  { "state": "stop" }
+ * </p>
+ */
+@Singleton
+public class NativeUpdateHandler extends NodeCommandHandler implements 
AccessProtected
+{
+    @Inject
+    public NativeUpdateHandler(InstanceMetadataFetcher metadataFetcher, 
ExecutorPools executorPools)
+    {
+        super(metadataFetcher, executorPools, null);
+    }
+
+    @Override
+    public Set<Authorization> requiredAuthorizations()
+    {
+        return 
Collections.singleton(BasicPermissions.WRITE_NATIVE.toAuthorization());
+    }
+
+    @Override
+    protected void handleInternal(RoutingContext context, HttpServerRequest 
httpRequest, @NotNull String host, SocketAddress remoteAddress, 
NodeCommandRequestPayload request)
+    {
+        StorageOperations storageOps = 
metadataFetcher.delegate(host).storageOperations();
+
+        executorPools.service().runBlocking(() -> {
+            switch (request.state())
+            {
+                case START:
+                    storageOps.startNativeTransport();
+                    break;
+                case STOP:
+                    storageOps.stopNativeTransport();
+                    break;
+                default:
+                    throw new IllegalStateException("Unknown state: " + 
request.state());
+            }
+        })
+                     .onSuccess(ignored -> context.json(OK_STATUS))

Review Comment:
   Same, `OK_STATUS` is for health check response. Returning 200 is sufficient. 



##########
client/src/main/java/org/apache/cassandra/sidecar/client/SidecarClient.java:
##########
@@ -801,6 +801,46 @@ public CompletableFuture<OperationalJobResponse> 
nodeDecommission(SidecarInstanc
                                             .nodeDecommissionRequest()
                                             .build());
     }
+    /**

Review Comment:
   nit: add a new empty line before this line. 



##########
server/src/test/java/org/apache/cassandra/sidecar/handlers/GossipUpdateHandlerTest.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * 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.handlers;
+
+
+import java.util.Collections;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Module;
+import com.google.inject.Provides;
+import com.google.inject.Singleton;
+import com.google.inject.util.Modules;
+import io.vertx.core.Vertx;
+import io.vertx.core.json.JsonObject;
+import io.vertx.ext.web.client.WebClient;
+import io.vertx.ext.web.client.predicate.ResponsePredicate;
+import io.vertx.junit5.VertxExtension;
+import io.vertx.junit5.VertxTestContext;
+import org.apache.cassandra.sidecar.TestModule;
+import org.apache.cassandra.sidecar.cluster.CassandraAdapterDelegate;
+import org.apache.cassandra.sidecar.cluster.InstancesMetadata;
+import org.apache.cassandra.sidecar.cluster.instance.InstanceMetadata;
+import org.apache.cassandra.sidecar.common.server.StorageOperations;
+import org.apache.cassandra.sidecar.modules.SidecarModules;
+import org.apache.cassandra.sidecar.server.Server;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * Test for {@link GossipUpdateHandler}
+ */
+@ExtendWith(VertxExtension.class)
+public class GossipUpdateHandlerTest
+{
+    static final Logger LOGGER = 
LoggerFactory.getLogger(GossipUpdateHandlerTest.class);
+    Vertx vertx;
+    Server server;
+    StorageOperations mockStorageOperations = mock(StorageOperations.class);
+
+    @BeforeEach
+    void before() throws InterruptedException
+    {
+        Injector injector;
+        Module testOverride = Modules.override(new TestModule()).with(new 
GossipUpdateHandlerTest.GossipUpdateHandlerTestModule());
+        injector = 
Guice.createInjector(Modules.override(SidecarModules.all()).with(testOverride));
+        vertx = injector.getInstance(Vertx.class);
+        server = injector.getInstance(Server.class);
+        VertxTestContext context = new VertxTestContext();
+        server.start().onSuccess(s -> 
context.completeNow()).onFailure(context::failNow);
+        context.awaitCompletion(5, TimeUnit.SECONDS);
+    }
+
+    @AfterEach
+    void after() throws InterruptedException
+    {
+        CountDownLatch closeLatch = new CountDownLatch(1);
+        server.close().onSuccess(res -> closeLatch.countDown());
+        if (closeLatch.await(60, TimeUnit.SECONDS)) LOGGER.info("Close event 
received before timeout.");
+        else LOGGER.error("Close event timed out.");

Review Comment:
   One-liner alternative. 
   ```suggestion
           getBlocking(TestResourceReaper.create().with(server).close(), 60, 
TimeUnit.SECONDS, "Closing server");
   ```



##########
client-common/src/main/java/org/apache/cassandra/sidecar/common/request/data/NodeCommandRequestPayload.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.common.request.data;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.cassandra.sidecar.common.utils.Preconditions;
+
+/**
+ * Request payload for start/stop operations (gossip, native transport, etc.).
+ *
+ * <p>Valid JSON:</p>
+ * <pre>
+ *   { "state": "start" }
+ *   { "state": "stop"  }
+ * </pre>
+ */
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class NodeCommandRequestPayload
+{
+    /**
+     * Node Command State
+     */
+    public enum State
+    {
+        @JsonProperty("start")
+        START,
+
+        @JsonProperty("stop")
+        STOP;
+
+        @JsonCreator
+        public static State fromString(String s)
+        {
+            if (s == null)
+                throw new IllegalArgumentException("Null state");
+
+            switch (s.trim().toLowerCase())
+            {
+                case "start":
+                    return START;
+                case "stop":
+                    return STOP;
+                default:
+                    throw new IllegalArgumentException("Unknown state: " + s);
+            }
+        }
+
+        @JsonProperty
+        public String toValue()
+        {
+            return name().toLowerCase();
+        }
+    }
+
+    private final State state;
+
+    /**
+     * @param state the desired operation, must be "start" or "stop"
+     */
+    @JsonCreator
+    public NodeCommandRequestPayload(
+    @JsonProperty(value = "state", required = true) String state
+    )
+    {
+        Preconditions.checkArgument(state != null && !state.isEmpty(),

Review Comment:
   Please leverage `org.apache.cassandra.sidecar.common.utils.StringUtils` 
   
   ```suggestion
           Preconditions.checkArgument(StringUtils.isNotEmpty(state),
   ```



##########
adapters/adapters-base/src/main/java/org/apache/cassandra/sidecar/adapters/base/jmx/StorageJmxOperations.java:
##########
@@ -178,4 +178,24 @@ public interface StorageJmxOperations
      * @return the name of the cluster
      */
     String getClusterName();
+
+    /**
+     * Triggers stop native transport
+     */
+    void stopNativeTransport();
+
+    /**
+     * Triggers start native transport
+     */
+    void startNativeTransport();
+
+    /**
+     * Triggers start gossip

Review Comment:
   ```suggestion
        * Triggers stop gossip
   ```



##########
server/src/main/java/org/apache/cassandra/sidecar/handlers/GossipUpdateHandler.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.handlers;
+
+import java.util.Collections;
+import java.util.Set;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import io.vertx.core.http.HttpServerRequest;
+import io.vertx.core.net.SocketAddress;
+import io.vertx.ext.auth.authorization.Authorization;
+import io.vertx.ext.web.RoutingContext;
+import org.apache.cassandra.sidecar.acl.authorization.BasicPermissions;
+import 
org.apache.cassandra.sidecar.common.request.data.NodeCommandRequestPayload;
+import org.apache.cassandra.sidecar.common.server.StorageOperations;
+import org.apache.cassandra.sidecar.concurrent.ExecutorPools;
+import org.apache.cassandra.sidecar.utils.InstanceMetadataFetcher;
+import org.jetbrains.annotations.NotNull;
+
+import static org.apache.cassandra.sidecar.modules.HealthCheckModule.OK_STATUS;
+
+/**
+ * Handles {@code PUT /api/v1/cassandra/gossip} requests to start or stop 
Cassandra gossip.
+ *
+ * <p>Expects a JSON payload:
+ * { "state": "start" } or { "state": "stop" }
+ * and will asynchronously invoke the corresponding JMX operation.</p>
+ */
+@Singleton
+public class GossipUpdateHandler extends NodeCommandHandler implements 
AccessProtected
+{
+    @Inject
+    public GossipUpdateHandler(InstanceMetadataFetcher metadataFetcher, 
ExecutorPools executorPools)
+    {
+        super(metadataFetcher, executorPools, null);
+    }
+
+    @Override
+    public Set<Authorization> requiredAuthorizations()
+    {
+        return 
Collections.singleton(BasicPermissions.WRITE_GOSSIP.toAuthorization());
+    }
+
+    @Override
+    protected void handleInternal(RoutingContext context, HttpServerRequest 
httpRequest, @NotNull String host, SocketAddress remoteAddress, 
NodeCommandRequestPayload request)
+    {
+        StorageOperations storageOps = 
metadataFetcher.delegate(host).storageOperations();
+
+        executorPools.service().runBlocking(() -> {
+            switch (request.state())
+            {
+                case START:
+                    storageOps.startGossiping();
+                    break;
+                case STOP:
+                    storageOps.stopGossiping();
+                    break;
+                default:
+                    throw new IllegalStateException("Unknown state: " + 
request.state());
+            }
+        })
+                     .onSuccess(ignored -> context.json(OK_STATUS))

Review Comment:
   I do not this this response is expected. 
   `OK_STATUS` is used in the context of health check. It is defined in 
`HealthCheckModule`. 
   
   I realized that the discussion in JIRA did not cover the response of the new 
APIs. My suggestion is to return 200 w/o body when the operation is successful. 



##########
server/src/main/java/org/apache/cassandra/sidecar/acl/authorization/BasicPermissions.java:
##########
@@ -70,9 +70,12 @@ public class BasicPermissions
     public static final Permission READ_SCHEMA = new 
DomainAwarePermission("SCHEMA:READ", CLUSTER_SCOPE);
     public static final Permission READ_SCHEMA_KEYSPACE_SCOPED = new 
DomainAwarePermission("SCHEMA:READ", KEYSPACE_SCOPE);
     public static final Permission READ_GOSSIP = new 
DomainAwarePermission("GOSSIP:READ", CLUSTER_SCOPE);
+    public static final Permission WRITE_GOSSIP = new 
DomainAwarePermission("GOSSIP:WRITE", CLUSTER_SCOPE);

Review Comment:
   naming is hard. I do not like `write` as the name, since the permission is 
to permit whether gossip can start/stop by the client. On the other hand, I do 
not have suggestions. So feel free to ignore. 



##########
server/src/test/integration/org/apache/cassandra/sidecar/routes/NodeGossipIntegrationTest.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 com.google.common.util.concurrent.Uninterruptibles;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import io.netty.handler.codec.http.HttpResponseStatus;
+import io.vertx.core.buffer.Buffer;
+import io.vertx.ext.web.client.HttpResponse;
+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 java.util.concurrent.TimeUnit.SECONDS;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Test the /cassandra/gossip endpoint with cassandra container.
+ */
+@ExtendWith(VertxExtension.class)
+public class NodeGossipIntegrationTest extends IntegrationTestBase

Review Comment:
   What do you think about combining `NodeGossipIntegrationTest` and 
`NodeNativeIntegrationTest`, and extending the test class from 
`SharedClusterIntegrationTestBase`? It would allow reusing the same cluster, 
saving some test time.  



##########
server/src/test/java/org/apache/cassandra/sidecar/handlers/GossipUpdateHandlerTest.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * 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.handlers;
+
+
+import java.util.Collections;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Module;
+import com.google.inject.Provides;
+import com.google.inject.Singleton;
+import com.google.inject.util.Modules;
+import io.vertx.core.Vertx;
+import io.vertx.core.json.JsonObject;
+import io.vertx.ext.web.client.WebClient;
+import io.vertx.ext.web.client.predicate.ResponsePredicate;
+import io.vertx.junit5.VertxExtension;
+import io.vertx.junit5.VertxTestContext;
+import org.apache.cassandra.sidecar.TestModule;
+import org.apache.cassandra.sidecar.cluster.CassandraAdapterDelegate;
+import org.apache.cassandra.sidecar.cluster.InstancesMetadata;
+import org.apache.cassandra.sidecar.cluster.instance.InstanceMetadata;
+import org.apache.cassandra.sidecar.common.server.StorageOperations;
+import org.apache.cassandra.sidecar.modules.SidecarModules;
+import org.apache.cassandra.sidecar.server.Server;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * Test for {@link GossipUpdateHandler}
+ */
+@ExtendWith(VertxExtension.class)
+public class GossipUpdateHandlerTest
+{
+    static final Logger LOGGER = 
LoggerFactory.getLogger(GossipUpdateHandlerTest.class);
+    Vertx vertx;
+    Server server;
+    StorageOperations mockStorageOperations = mock(StorageOperations.class);
+
+    @BeforeEach
+    void before() throws InterruptedException
+    {
+        Injector injector;
+        Module testOverride = Modules.override(new TestModule()).with(new 
GossipUpdateHandlerTest.GossipUpdateHandlerTestModule());
+        injector = 
Guice.createInjector(Modules.override(SidecarModules.all()).with(testOverride));
+        vertx = injector.getInstance(Vertx.class);
+        server = injector.getInstance(Server.class);
+        VertxTestContext context = new VertxTestContext();
+        server.start().onSuccess(s -> 
context.completeNow()).onFailure(context::failNow);
+        context.awaitCompletion(5, TimeUnit.SECONDS);
+    }
+
+    @AfterEach
+    void after() throws InterruptedException
+    {
+        CountDownLatch closeLatch = new CountDownLatch(1);
+        server.close().onSuccess(res -> closeLatch.countDown());
+        if (closeLatch.await(60, TimeUnit.SECONDS)) LOGGER.info("Close event 
received before timeout.");
+        else LOGGER.error("Close event timed out.");
+    }
+
+    @Test
+    void testStartGossip(VertxTestContext ctx)
+    {
+        WebClient client = WebClient.create(vertx);
+        String payload = "{\"state\":\"start\"}";
+        client.put(server.actualPort(), "127.0.0.1", 
"/api/v1/cassandra/gossip").expect(ResponsePredicate.SC_OK).sendBuffer(io.vertx.core.buffer.Buffer.buffer(payload),
 ctx.succeeding(resp -> {

Review Comment:
   - This line is too long. If you run `./gradlew codeCheckTasks`, it would 
complain the line is too long. 
   - `expect(ResponsePredicate.SC_OK)` is deprecated, can you update to its 
successor. 
   
   The same applies to the other test assertions in this file and 
`NativeUpdateHandlerTest`. 



##########
server/src/test/java/org/apache/cassandra/sidecar/handlers/NativeUpdateHandlerTest.java:
##########
@@ -0,0 +1,163 @@
+/*
+ * 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.handlers;
+
+import java.util.Collections;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Module;
+import com.google.inject.Provides;
+import com.google.inject.Singleton;
+import com.google.inject.util.Modules;
+import io.vertx.core.Vertx;
+import io.vertx.core.json.JsonObject;
+import io.vertx.ext.web.client.WebClient;
+import io.vertx.ext.web.client.predicate.ResponsePredicate;
+import io.vertx.junit5.VertxExtension;
+import io.vertx.junit5.VertxTestContext;
+import org.apache.cassandra.sidecar.TestModule;
+import org.apache.cassandra.sidecar.cluster.CassandraAdapterDelegate;
+import org.apache.cassandra.sidecar.cluster.InstancesMetadata;
+import org.apache.cassandra.sidecar.cluster.instance.InstanceMetadata;
+import org.apache.cassandra.sidecar.common.server.StorageOperations;
+import org.apache.cassandra.sidecar.modules.SidecarModules;
+import org.apache.cassandra.sidecar.server.Server;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * Test for {@link NativeUpdateHandler}
+ */
+@ExtendWith(VertxExtension.class)
+public class NativeUpdateHandlerTest
+{
+    static final Logger LOGGER = 
LoggerFactory.getLogger(NativeUpdateHandlerTest.class);
+    Vertx vertx;
+    Server server;
+    StorageOperations mockStorageOperations = mock(StorageOperations.class);
+
+    @BeforeEach
+    void before() throws InterruptedException
+    {
+        Injector injector;
+        Module testOverride = Modules.override(new TestModule()).with(new 
NativeUpdateHandlerTest.NativeUpdateHandlerTestModule());
+        injector = 
Guice.createInjector(Modules.override(SidecarModules.all()).with(testOverride));
+        vertx = injector.getInstance(Vertx.class);
+        server = injector.getInstance(Server.class);
+        VertxTestContext context = new VertxTestContext();
+        server.start().onSuccess(s -> 
context.completeNow()).onFailure(context::failNow);
+        context.awaitCompletion(5, TimeUnit.SECONDS);
+    }
+
+    @AfterEach
+    void after() throws InterruptedException
+    {
+        CountDownLatch closeLatch = new CountDownLatch(1);
+        server.close().onSuccess(res -> closeLatch.countDown());
+        if (closeLatch.await(60, TimeUnit.SECONDS)) LOGGER.info("Close event 
received before timeout.");
+        else LOGGER.error("Close event timed out.");

Review Comment:
   One-liner alternative. 
   ```suggestion
           getBlocking(TestResourceReaper.create().with(server).close(), 60, 
TimeUnit.SECONDS, "Closing server");
   ```



-- 
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: pr-unsubscr...@cassandra.apache.org

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


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

Reply via email to