You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2021/09/28 23:52:32 UTC

[GitHub] [geode] DonalEvans commented on a change in pull request #6907: GEODE-9623: Add Radish COMMAND command

DonalEvans commented on a change in pull request #6907:
URL: https://github.com/apache/geode/pull/6907#discussion_r718039774



##########
File path: geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/server/CommandIntegrationTest.java
##########
@@ -0,0 +1,135 @@
+/*
+ * 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.geode.redis.internal.executor.server;
+
+import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.BIND_ADDRESS;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import io.lettuce.core.RedisClient;
+import io.lettuce.core.api.sync.RedisCommands;
+import org.assertj.core.api.SoftAssertions;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import org.apache.geode.NativeRedisTestRule;
+import org.apache.geode.redis.GeodeRedisServerRule;
+
+public class CommandIntegrationTest {
+
+  @ClassRule
+  public static NativeRedisTestRule redisServer = new NativeRedisTestRule("redis:6.2.4");
+
+  @ClassRule
+  public static GeodeRedisServerRule radishServer = new GeodeRedisServerRule();
+
+  private RedisCommands<String, String> redisClient;
+  private RedisCommands<String, String> radishClient;
+
+  @Before
+  public void setup() {
+    redisClient =
+        RedisClient.create(String.format("redis://%s:%d", BIND_ADDRESS, redisServer.getPort()))
+            .connect().sync();
+
+    radishClient =
+        RedisClient.create(String.format("redis://%s:%d", BIND_ADDRESS, radishServer.getPort()))
+            .connect().sync();
+  }
+
+  @After
+  public void teardown() {}
+
+  @Test
+  public void commandReturnsResultsMatchingNativeRedis() {
+    Map<String, CommandStructure> goldenResults = processRawCommands(redisClient.command());
+    Map<String, CommandStructure> results = processRawCommands(radishClient.command());
+
+    List<String> commands = new ArrayList<>(results.keySet());
+    Collections.sort(commands);
+
+    SoftAssertions softly = new SoftAssertions();
+    for (String command : commands) {
+      softly.assertThatCode(() -> compareCommands(results.get(command), goldenResults.get(command)))
+          .as("command: " + command)
+          .doesNotThrowAnyException();
+    }
+    softly.assertAll();
+  }
+
+  private void compareCommands(CommandStructure actual, CommandStructure expected) {
+    assertThat(actual).as("no metadata for " + expected.name).isNotNull();
+    SoftAssertions softly = new SoftAssertions();
+    softly.assertThat(actual.arity).as(expected.name + ".arity").isEqualTo(expected.arity);
+    softly.assertThat(actual.flags).as(expected.name + ".flags")
+        .containsExactlyInAnyOrderElementsOf(expected.flags);
+    softly.assertThat(actual.firstKey).as(expected.name + ".firstKey").isEqualTo(expected.firstKey);
+    softly.assertThat(actual.lastKey).as(expected.name + ".lastKey").isEqualTo(expected.lastKey);
+    softly.assertThat(actual.stepCount).as(expected.name + ".stepCount")
+        .isEqualTo(expected.stepCount);
+    softly.assertAll();
+  }
+
+  @SuppressWarnings("unchecked")
+  private Map<String, CommandStructure> processRawCommands(List<Object> rawCommands) {
+    Map<String, CommandStructure> commands = new HashMap<>();
+
+    for (Object rawEntry : rawCommands) {
+      List<Object> entry = (List<Object>) rawEntry;
+      String key = (String) entry.get(0);
+      List<String> flags = new ArrayList<>();
+      flags.addAll((List<String>) entry.get(2));
+
+      CommandStructure cmd = new CommandStructure(
+          key,
+          (long) entry.get(1),
+          flags,
+          (long) entry.get(3),
+          (long) entry.get(4),
+          (long) entry.get(5));

Review comment:
       This can be simplified slightly to inline the `flags` variable:
   ```
         CommandStructure cmd = new CommandStructure(
             key,
             (long) entry.get(1),
             (List<String>) entry.get(2),
             (long) entry.get(3),
             (long) entry.get(4),
             (long) entry.get(5));
   ```

##########
File path: geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/parameters/SpopParameterRequirements.java
##########
@@ -18,18 +18,22 @@
 import static org.apache.geode.redis.internal.RedisConstants.ERROR_NOT_INTEGER;
 import static org.apache.geode.redis.internal.netty.Coder.bytesToLong;
 
+import java.util.function.BiConsumer;
+
 import org.apache.geode.redis.internal.netty.Command;
 import org.apache.geode.redis.internal.netty.ExecutionHandlerContext;
 
-public class SpopParameterRequirements implements ParameterRequirements {
-  @Override
-  public void checkParameters(Command command, ExecutionHandlerContext context) {
-    if (command.getProcessedCommand().size() == 3) {
-      try {
-        bytesToLong(command.getProcessedCommand().get(2));
-      } catch (NumberFormatException nex) {
-        throw new RedisParametersMismatchException(ERROR_NOT_INTEGER);
+public class SpopParameterRequirements {

Review comment:
       Possibly out of scope for this PR, but this class probably shouldn't exist, and the check that it's doing to validate arguments being integers should be moved to the SPopExecutor.

##########
File path: geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/executor/server/CommandExecutor.java
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.geode.redis.internal.executor.server;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.apache.geode.redis.internal.RedisCommandType;
+import org.apache.geode.redis.internal.executor.AbstractExecutor;
+import org.apache.geode.redis.internal.executor.RedisResponse;
+import org.apache.geode.redis.internal.netty.Command;
+import org.apache.geode.redis.internal.netty.ExecutionHandlerContext;
+
+public class CommandExecutor extends AbstractExecutor {
+  @Override
+  public RedisResponse executeCommand(Command command, ExecutionHandlerContext context)
+      throws Exception {

Review comment:
       `Exception` is never thrown from this method.

##########
File path: geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/server/CommandIntegrationTest.java
##########
@@ -0,0 +1,135 @@
+/*
+ * 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.geode.redis.internal.executor.server;
+
+import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.BIND_ADDRESS;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import io.lettuce.core.RedisClient;
+import io.lettuce.core.api.sync.RedisCommands;
+import org.assertj.core.api.SoftAssertions;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import org.apache.geode.NativeRedisTestRule;
+import org.apache.geode.redis.GeodeRedisServerRule;
+
+public class CommandIntegrationTest {
+
+  @ClassRule
+  public static NativeRedisTestRule redisServer = new NativeRedisTestRule("redis:6.2.4");
+
+  @ClassRule
+  public static GeodeRedisServerRule radishServer = new GeodeRedisServerRule();
+
+  private RedisCommands<String, String> redisClient;
+  private RedisCommands<String, String> radishClient;
+
+  @Before
+  public void setup() {
+    redisClient =
+        RedisClient.create(String.format("redis://%s:%d", BIND_ADDRESS, redisServer.getPort()))
+            .connect().sync();
+
+    radishClient =
+        RedisClient.create(String.format("redis://%s:%d", BIND_ADDRESS, radishServer.getPort()))
+            .connect().sync();
+  }
+
+  @After
+  public void teardown() {}

Review comment:
       This can probably be removed.

##########
File path: geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/parameters/Parameter.java
##########
@@ -0,0 +1,162 @@
+/*
+ * 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.geode.redis.internal.parameters;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.function.BiConsumer;
+
+import org.apache.geode.redis.internal.RedisCommandType;
+import org.apache.geode.redis.internal.netty.Command;
+import org.apache.geode.redis.internal.netty.ExecutionHandlerContext;
+
+public class Parameter {
+
+  private int arity;
+  private List<RedisCommandType.Flag> flags = new ArrayList<>();
+  private int firstKey = 1;
+  private int lastKey = 1;
+  private int step = 1;
+  private List<BiConsumer<Command, ExecutionHandlerContext>> predicates = new ArrayList<>();

Review comment:
       None of the predicates use an `ExecutionHandlerContext`, so this could be changed to be just a `Consumer<Command>`.




-- 
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: notifications-unsubscribe@geode.apache.org

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