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



##########
File path: 
geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/executor/server/LolWutExecutor.java
##########
@@ -0,0 +1,167 @@
+/*
+ * 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.redis.internal.RedisConstants.ERROR_NOT_INTEGER;
+
+import java.util.List;
+import java.util.Random;
+
+import org.apache.geode.internal.serialization.KnownVersion;
+import org.apache.geode.redis.internal.executor.AbstractExecutor;
+import org.apache.geode.redis.internal.executor.RedisResponse;
+import org.apache.geode.redis.internal.netty.Coder;
+import org.apache.geode.redis.internal.netty.Command;
+import org.apache.geode.redis.internal.netty.ExecutionHandlerContext;
+
+public class LolWutExecutor extends AbstractExecutor {
+
+  public static final int DEFAULT_WIDTH = 40;
+  public static final int DEFAULT_HEIGHT = 10;
+  private static int width = DEFAULT_WIDTH;
+  private static int height = DEFAULT_HEIGHT;
+
+  @Override
+  public RedisResponse executeCommand(Command command,
+      ExecutionHandlerContext context) {
+
+    long inputWidth = -1;
+    long inputHeight = -1;
+
+    List<byte[]> commands = command.getProcessedCommand();
+    if (commands.size() > 1) {
+      for (int i = 1; i < commands.size(); i++) {
+        if (Coder.bytesToString(commands.get(i)).equalsIgnoreCase("version")) {

Review comment:
       Could this instead use the pattern seen elsewhere in executors and 
compare the argument byte array to a constant defined in `StringBytesGlossary` 
using the `Coder.equalsIgnoreCaseBytes()` method?

##########
File path: 
geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/executor/server/LolWutExecutor.java
##########
@@ -0,0 +1,167 @@
+/*
+ * 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.redis.internal.RedisConstants.ERROR_NOT_INTEGER;
+
+import java.util.List;
+import java.util.Random;
+
+import org.apache.geode.internal.serialization.KnownVersion;
+import org.apache.geode.redis.internal.executor.AbstractExecutor;
+import org.apache.geode.redis.internal.executor.RedisResponse;
+import org.apache.geode.redis.internal.netty.Coder;
+import org.apache.geode.redis.internal.netty.Command;
+import org.apache.geode.redis.internal.netty.ExecutionHandlerContext;
+
+public class LolWutExecutor extends AbstractExecutor {
+
+  public static final int DEFAULT_WIDTH = 40;
+  public static final int DEFAULT_HEIGHT = 10;
+  private static int width = DEFAULT_WIDTH;
+  private static int height = DEFAULT_HEIGHT;
+
+  @Override
+  public RedisResponse executeCommand(Command command,
+      ExecutionHandlerContext context) {
+
+    long inputWidth = -1;
+    long inputHeight = -1;
+
+    List<byte[]> commands = command.getProcessedCommand();
+    if (commands.size() > 1) {
+      for (int i = 1; i < commands.size(); i++) {
+        if (Coder.bytesToString(commands.get(i)).equalsIgnoreCase("version")) {
+          i += 1; // skip next arg, we only have one version for now
+        } else {
+          try {
+            if (inputWidth < 0) {
+              inputWidth = Coder.bytesToLong(commands.get(i));
+            } else if (inputHeight < 0) {
+              inputHeight = Coder.bytesToLong(commands.get(i));
+            } else {
+              break; // all required args filled
+            }
+          } catch (NumberFormatException ignored) {
+            return RedisResponse.error(ERROR_NOT_INTEGER);
+          }
+        }
+      }
+    }
+    if (inputHeight >= 0) {
+      height = (int) inputHeight;
+    }
+    if (inputWidth >= 0) {
+      width = (int) inputWidth;
+    }
+
+    return RedisResponse.bulkString(makeArbitraryHeightMaze());
+  }
+
+  // Adapted from code here: https://tromp.github.io/maze.html
+  public static String makeArbitraryHeightMaze() {

Review comment:
       This method should probably take a `height` and `width` argument rather 
than relying on the static fields in this class, or it should be renamed, as 
otherwise, calling it from outside the class will not result in an arbitrary 
sized maze, but rather one of a fixed size based on `DEFAULT_WIDTH` and 
`DEFAULT_HEIGHT`.

##########
File path: 
geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/executor/server/LolWutExecutor.java
##########
@@ -0,0 +1,167 @@
+/*
+ * 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.redis.internal.RedisConstants.ERROR_NOT_INTEGER;
+
+import java.util.List;
+import java.util.Random;
+
+import org.apache.geode.internal.serialization.KnownVersion;
+import org.apache.geode.redis.internal.executor.AbstractExecutor;
+import org.apache.geode.redis.internal.executor.RedisResponse;
+import org.apache.geode.redis.internal.netty.Coder;
+import org.apache.geode.redis.internal.netty.Command;
+import org.apache.geode.redis.internal.netty.ExecutionHandlerContext;
+
+public class LolWutExecutor extends AbstractExecutor {
+
+  public static final int DEFAULT_WIDTH = 40;
+  public static final int DEFAULT_HEIGHT = 10;
+  private static int width = DEFAULT_WIDTH;
+  private static int height = DEFAULT_HEIGHT;
+
+  @Override
+  public RedisResponse executeCommand(Command command,
+      ExecutionHandlerContext context) {
+
+    long inputWidth = -1;
+    long inputHeight = -1;
+
+    List<byte[]> commands = command.getProcessedCommand();
+    if (commands.size() > 1) {
+      for (int i = 1; i < commands.size(); i++) {
+        if (Coder.bytesToString(commands.get(i)).equalsIgnoreCase("version")) {
+          i += 1; // skip next arg, we only have one version for now
+        } else {
+          try {
+            if (inputWidth < 0) {
+              inputWidth = Coder.bytesToLong(commands.get(i));

Review comment:
       Rather than defining this as a long then casting it to an int, which 
could cause overflow errors, it should be defined as an in from the start and 
the `Coder.narrowLongToInt()` method should be used here and for `inputHeight`.




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


Reply via email to