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/27 14:35:45 UTC

[GitHub] [geode] ringles opened a new pull request #6908: LOLWUT command

ringles opened a new pull request #6908:
URL: https://github.com/apache/geode/pull/6908


   This implements a version of the Redis LOLWUT command, which is supposed to (a) algorithmically generate compuer art, and (b) output the program version. Optionally, the LOLWUT command can take arguments to affect the output.
   
   This implementation generates arbitrary-height mazes. By default, it generates a 40-cell-wide maze of height 10, but given an argument can generate a valid maze of any height, while consuming a small, fixed amount of memory. Finally, it outputs the Geode version.


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



[GitHub] [geode] ringles commented on a change in pull request #6908: GEODE-9650: LOLWUT command

Posted by GitBox <gi...@apache.org>.
ringles commented on a change in pull request #6908:
URL: https://github.com/apache/geode/pull/6908#discussion_r718820791



##########
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:
       Will do.




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



[GitHub] [geode] ringles commented on a change in pull request #6908: GEODE-9650: LOLWUT command

Posted by GitBox <gi...@apache.org>.
ringles commented on a change in pull request #6908:
URL: https://github.com/apache/geode/pull/6908#discussion_r719721361



##########
File path: geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/server/LolWutIntegrationTest.java
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.distributed.ConfigurationProperties.LOG_LEVEL;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import redis.clients.jedis.Jedis;
+import redis.clients.jedis.commands.ProtocolCommand;
+import redis.clients.jedis.util.SafeEncoder;
+
+import org.apache.geode.internal.serialization.KnownVersion;
+import org.apache.geode.redis.GeodeRedisServerRule;
+import org.apache.geode.redis.RedisIntegrationTest;
+import org.apache.geode.redis.internal.netty.Coder;
+import org.apache.geode.test.awaitility.GeodeAwaitility;
+
+public class LolWutIntegrationTest implements RedisIntegrationTest {
+  private static final int REDIS_CLIENT_TIMEOUT =
+      Math.toIntExact(GeodeAwaitility.getTimeout().toMillis());

Review comment:
       I'm gonna make a PR that gets rid of all the old ones. Too easy to miss.




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



[GitHub] [geode] ringles commented on a change in pull request #6908: GEODE-9650: LOLWUT command

Posted by GitBox <gi...@apache.org>.
ringles commented on a change in pull request #6908:
URL: https://github.com/apache/geode/pull/6908#discussion_r719506767



##########
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:
       Should be fixed.




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



[GitHub] [geode] ringles commented on a change in pull request #6908: GEODE-9650: LOLWUT command

Posted by GitBox <gi...@apache.org>.
ringles commented on a change in pull request #6908:
URL: https://github.com/apache/geode/pull/6908#discussion_r718820668



##########
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:
       Actually, it _should_ be a private method. Originally the sub-methods took width and height arguments but it made the arg list a bit unwieldy.




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



[GitHub] [geode] DonalEvans commented on a change in pull request #6908: GEODE-9650: LOLWUT command

Posted by GitBox <gi...@apache.org>.
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`.

##########
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:
       If it's private, then it probably doesn't need to be static, since there's no static context in which it could be called.




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



[GitHub] [geode] DonalEvans commented on a change in pull request #6908: GEODE-9650: LOLWUT command

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

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



[GitHub] [geode] DonalEvans commented on a change in pull request #6908: GEODE-9650: LOLWUT command

Posted by GitBox <gi...@apache.org>.
DonalEvans commented on a change in pull request #6908:
URL: https://github.com/apache/geode/pull/6908#discussion_r719709026



##########
File path: geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/server/LolWutIntegrationTest.java
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.distributed.ConfigurationProperties.LOG_LEVEL;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import redis.clients.jedis.Jedis;
+import redis.clients.jedis.commands.ProtocolCommand;
+import redis.clients.jedis.util.SafeEncoder;
+
+import org.apache.geode.internal.serialization.KnownVersion;
+import org.apache.geode.redis.GeodeRedisServerRule;
+import org.apache.geode.redis.RedisIntegrationTest;
+import org.apache.geode.redis.internal.netty.Coder;
+import org.apache.geode.test.awaitility.GeodeAwaitility;
+
+public class LolWutIntegrationTest implements RedisIntegrationTest {
+  private static final int REDIS_CLIENT_TIMEOUT =
+      Math.toIntExact(GeodeAwaitility.getTimeout().toMillis());
+  private static final String GEODE_VERSION_STRING = KnownVersion.getCurrentVersion().toString();
+  private static final int DEFAULT_MAZE_HEIGHT = 10 + 2; // Top & bottom walls, version string
+  private static final int MAX_MAZE_HEIGHT = (1024 * 1024) + 2;
+  private Jedis jedis;
+
+  @ClassRule
+  public static GeodeRedisServerRule server = new GeodeRedisServerRule()
+      .withProperty(LOG_LEVEL, "info");
+
+  @Override
+  public int getPort() {
+    return server.getPort();
+  }
+
+  @Before
+  public void setUp() {
+    jedis = new Jedis("localhost", getPort(), REDIS_CLIENT_TIMEOUT);
+  }
+
+  @After
+  public void tearDown() {
+    jedis.flushAll();
+    jedis.close();
+  }
+
+  @Test
+  public void shouldReturnGeodeVersion() {
+    String actualResult = Coder.bytesToString((byte[]) jedis.sendCommand(new ProtocolCommand() {
+      @Override
+      public byte[] getRaw() {
+        return SafeEncoder.encode("lolwut");
+      }
+    }));

Review comment:
       This can be simplified to:
   ```
       String actualResult = Coder.bytesToString((byte[]) jedis.sendCommand(
           () -> SafeEncoder.encode("lolwut")));
   ```
   Similarly, other uses of `new ProtocolCommand` in this class can be replaced with lambdas.

##########
File path: geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/server/LolWutIntegrationTest.java
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.distributed.ConfigurationProperties.LOG_LEVEL;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import redis.clients.jedis.Jedis;
+import redis.clients.jedis.commands.ProtocolCommand;
+import redis.clients.jedis.util.SafeEncoder;
+
+import org.apache.geode.internal.serialization.KnownVersion;
+import org.apache.geode.redis.GeodeRedisServerRule;
+import org.apache.geode.redis.RedisIntegrationTest;
+import org.apache.geode.redis.internal.netty.Coder;
+import org.apache.geode.test.awaitility.GeodeAwaitility;
+
+public class LolWutIntegrationTest implements RedisIntegrationTest {
+  private static final int REDIS_CLIENT_TIMEOUT =
+      Math.toIntExact(GeodeAwaitility.getTimeout().toMillis());

Review comment:
       This can be removed, and the constant from `RedisClusterStartupRule` with the same name can be used instead.




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



[GitHub] [geode] ringles commented on a change in pull request #6908: GEODE-9650: LOLWUT command

Posted by GitBox <gi...@apache.org>.
ringles commented on a change in pull request #6908:
URL: https://github.com/apache/geode/pull/6908#discussion_r718819979



##########
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:
       Yeah, that's a better approach for sure.




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



[GitHub] [geode] ringles commented on a change in pull request #6908: GEODE-9650: LOLWUT command

Posted by GitBox <gi...@apache.org>.
ringles commented on a change in pull request #6908:
URL: https://github.com/apache/geode/pull/6908#discussion_r718819979



##########
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:
       Yeah, that's a better approach for sure.

##########
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:
       Actually, it _should_ be a private method. Originally the sub-methods took width and height arguments but it made the arg list a bit unwieldy.

##########
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:
       Will do.




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



[GitHub] [geode] DonalEvans commented on a change in pull request #6908: GEODE-9650: LOLWUT command

Posted by GitBox <gi...@apache.org>.
DonalEvans commented on a change in pull request #6908:
URL: https://github.com/apache/geode/pull/6908#discussion_r718840747



##########
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:
       If it's private, then it probably doesn't need to be static, since there's no static context in which it could be called.




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



[GitHub] [geode] ringles commented on a change in pull request #6908: GEODE-9650: LOLWUT command

Posted by GitBox <gi...@apache.org>.
ringles commented on a change in pull request #6908:
URL: https://github.com/apache/geode/pull/6908#discussion_r719721645



##########
File path: geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/server/LolWutIntegrationTest.java
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.distributed.ConfigurationProperties.LOG_LEVEL;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import redis.clients.jedis.Jedis;
+import redis.clients.jedis.commands.ProtocolCommand;
+import redis.clients.jedis.util.SafeEncoder;
+
+import org.apache.geode.internal.serialization.KnownVersion;
+import org.apache.geode.redis.GeodeRedisServerRule;
+import org.apache.geode.redis.RedisIntegrationTest;
+import org.apache.geode.redis.internal.netty.Coder;
+import org.apache.geode.test.awaitility.GeodeAwaitility;
+
+public class LolWutIntegrationTest implements RedisIntegrationTest {
+  private static final int REDIS_CLIENT_TIMEOUT =
+      Math.toIntExact(GeodeAwaitility.getTimeout().toMillis());
+  private static final String GEODE_VERSION_STRING = KnownVersion.getCurrentVersion().toString();
+  private static final int DEFAULT_MAZE_HEIGHT = 10 + 2; // Top & bottom walls, version string
+  private static final int MAX_MAZE_HEIGHT = (1024 * 1024) + 2;
+  private Jedis jedis;
+
+  @ClassRule
+  public static GeodeRedisServerRule server = new GeodeRedisServerRule()
+      .withProperty(LOG_LEVEL, "info");
+
+  @Override
+  public int getPort() {
+    return server.getPort();
+  }
+
+  @Before
+  public void setUp() {
+    jedis = new Jedis("localhost", getPort(), REDIS_CLIENT_TIMEOUT);
+  }
+
+  @After
+  public void tearDown() {
+    jedis.flushAll();
+    jedis.close();
+  }
+
+  @Test
+  public void shouldReturnGeodeVersion() {
+    String actualResult = Coder.bytesToString((byte[]) jedis.sendCommand(new ProtocolCommand() {
+      @Override
+      public byte[] getRaw() {
+        return SafeEncoder.encode("lolwut");
+      }
+    }));

Review comment:
       Done. Was working from old code before.




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



[GitHub] [geode] ringles merged pull request #6908: GEODE-9650: LOLWUT command

Posted by GitBox <gi...@apache.org>.
ringles merged pull request #6908:
URL: https://github.com/apache/geode/pull/6908


   


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