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/08/04 14:07:00 UTC

[GitHub] [geode] jdeppe-pivotal opened a new pull request #6738: GEODE-9186: Add Radish ZPOPMIN command

jdeppe-pivotal opened a new pull request #6738:
URL: https://github.com/apache/geode/pull/6738


   Thank you for submitting a contribution to Apache Geode.
   
   In order to streamline the review of the contribution we ask you
   to ensure the following steps have been taken:
   
   ### For all changes:
   - [ ] Is there a JIRA ticket associated with this PR? Is it referenced in the commit message?
   
   - [ ] Has your PR been rebased against the latest commit within the target branch (typically `develop`)?
   
   - [ ] Is your initial contribution a single, squashed commit?
   
   - [ ] Does `gradlew build` run cleanly?
   
   - [ ] Have you written or updated unit tests to verify your changes?
   
   - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
   
   ### Note:
   Please ensure that once the PR is submitted, check Concourse for build issues and
   submit an update to your PR as soon as possible. If you need help, please send an
   email to dev@geode.apache.org.
   


-- 
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] jdeppe-pivotal commented on a change in pull request #6738: GEODE-9186: Add Radish ZPOPMIN command

Posted by GitBox <gi...@apache.org>.
jdeppe-pivotal commented on a change in pull request #6738:
URL: https://github.com/apache/geode/pull/6738#discussion_r690760595



##########
File path: geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/sortedset/AbstractZPopMinIntegrationTest.java
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.sortedset;
+
+import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.BIND_ADDRESS;
+import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.REDIS_CLIENT_TIMEOUT;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import redis.clients.jedis.HostAndPort;
+import redis.clients.jedis.JedisCluster;
+import redis.clients.jedis.Protocol;
+import redis.clients.jedis.Tuple;
+
+import org.apache.geode.redis.RedisIntegrationTest;
+import org.apache.geode.redis.internal.RedisConstants;
+
+public abstract class AbstractZPopMinIntegrationTest implements RedisIntegrationTest {
+  private JedisCluster jedis;
+
+  @Before
+  public void setUp() {
+    jedis = new JedisCluster(new HostAndPort(BIND_ADDRESS, getPort()), REDIS_CLIENT_TIMEOUT);
+  }
+
+  @After
+  public void tearDown() {
+    flushAll();
+    jedis.close();
+  }
+
+  @Test
+  public void shouldError_givenWrongNumberOfArguments() {
+    assertThatThrownBy(
+        () -> jedis.sendCommand("key", Protocol.Command.ZPOPMIN, "key", "1", "2"))
+            .hasMessageContaining(RedisConstants.ERROR_SYNTAX);

Review comment:
       Done.




-- 
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] jdeppe-pivotal commented on a change in pull request #6738: GEODE-9186: Add Radish ZPOPMIN command

Posted by GitBox <gi...@apache.org>.
jdeppe-pivotal commented on a change in pull request #6738:
URL: https://github.com/apache/geode/pull/6738#discussion_r690760595



##########
File path: geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/sortedset/AbstractZPopMinIntegrationTest.java
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.sortedset;
+
+import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.BIND_ADDRESS;
+import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.REDIS_CLIENT_TIMEOUT;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import redis.clients.jedis.HostAndPort;
+import redis.clients.jedis.JedisCluster;
+import redis.clients.jedis.Protocol;
+import redis.clients.jedis.Tuple;
+
+import org.apache.geode.redis.RedisIntegrationTest;
+import org.apache.geode.redis.internal.RedisConstants;
+
+public abstract class AbstractZPopMinIntegrationTest implements RedisIntegrationTest {
+  private JedisCluster jedis;
+
+  @Before
+  public void setUp() {
+    jedis = new JedisCluster(new HostAndPort(BIND_ADDRESS, getPort()), REDIS_CLIENT_TIMEOUT);
+  }
+
+  @After
+  public void tearDown() {
+    flushAll();
+    jedis.close();
+  }
+
+  @Test
+  public void shouldError_givenWrongNumberOfArguments() {
+    assertThatThrownBy(
+        () -> jedis.sendCommand("key", Protocol.Command.ZPOPMIN, "key", "1", "2"))
+            .hasMessageContaining(RedisConstants.ERROR_SYNTAX);

Review comment:
       Done.

##########
File path: geode-apis-compatible-with-redis/src/test/java/org/apache/geode/redis/internal/SupportedCommandsJUnitTest.java
##########
@@ -91,6 +91,7 @@
       "ZINCRBY",
       "ZCARD",
       "ZCOUNT",
+      "ZPOPMIN",

Review comment:
       Done

##########
File path: geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/server/AbstractHitsMissesIntegrationTest.java
##########
@@ -252,6 +252,11 @@ public void testZIncrBy() {
     runCommandAndAssertNoStatUpdates("key", (k, m) -> jedis.zincrby(k, 100.0, m));
   }
 
+  @Test
+  public void testZPopMin() {

Review comment:
       Done

##########
File path: geode-apis-compatible-with-redis/src/test/java/org/apache/geode/redis/internal/data/RedisSortedSetTest.java
##########
@@ -473,6 +473,70 @@ public void memberDummyOrderedSetEntryCompareTo_withEqualMemberNamesAndInclusive
     assertThat(inclusiveMax.compareTo(realEntry)).isEqualTo(1);
   }
 
+  @Test
+  public void zpopminRemovesMemberWithLowestScore() {
+    int originalSize = rangeSortedSet.getSortedSetSize();
+    RedisSortedSet sortedSet = spy(rangeSortedSet);
+    Region<RedisKey, RedisData> region = uncheckedCast(mock(Region.class));
+    RedisKey key = new RedisKey();
+    int count = 1;
+
+    List<byte[]> result = sortedSet.zpopmin(region, key, count);
+    assertThat(result).containsExactly("member1".getBytes(), "1".getBytes());
+
+    ArgumentCaptor<RemsDeltaInfo> argumentCaptor = ArgumentCaptor.forClass(RemsDeltaInfo.class);
+    verify(sortedSet).storeChanges(eq(region), eq(key), argumentCaptor.capture());
+    assertThat(argumentCaptor.getValue().getRemoves()).containsExactly("member1".getBytes());
+    assertThat(rangeSortedSet.getSortedSetSize()).isEqualTo(originalSize - count);
+  }
+
+  @Test
+  public void zpopminRemovesMembersWithHighestScores_whenCountIsGreaterThanOne() {

Review comment:
       Done.

##########
File path: geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/sortedset/AbstractZPopMinIntegrationTest.java
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.sortedset;
+
+import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.BIND_ADDRESS;
+import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.REDIS_CLIENT_TIMEOUT;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import redis.clients.jedis.HostAndPort;
+import redis.clients.jedis.JedisCluster;
+import redis.clients.jedis.Protocol;
+import redis.clients.jedis.Tuple;
+
+import org.apache.geode.redis.RedisIntegrationTest;
+import org.apache.geode.redis.internal.RedisConstants;
+
+public abstract class AbstractZPopMinIntegrationTest implements RedisIntegrationTest {

Review comment:
       Done.




-- 
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] jdeppe-pivotal commented on a change in pull request #6738: GEODE-9186: Add Radish ZPOPMIN command

Posted by GitBox <gi...@apache.org>.
jdeppe-pivotal commented on a change in pull request #6738:
URL: https://github.com/apache/geode/pull/6738#discussion_r690760650



##########
File path: geode-apis-compatible-with-redis/src/test/java/org/apache/geode/redis/internal/SupportedCommandsJUnitTest.java
##########
@@ -91,6 +91,7 @@
       "ZINCRBY",
       "ZCARD",
       "ZCOUNT",
+      "ZPOPMIN",

Review comment:
       Done




-- 
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 #6738: GEODE-9186: Add Radish ZPOPMIN command

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



##########
File path: geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/server/AbstractHitsMissesIntegrationTest.java
##########
@@ -252,6 +252,11 @@ public void testZIncrBy() {
     runCommandAndAssertNoStatUpdates("key", (k, m) -> jedis.zincrby(k, 100.0, m));
   }
 
+  @Test
+  public void testZPopMin() {

Review comment:
       Could this be moved to below `testZPopMax()` to maintain alphabetical ordering?

##########
File path: geode-apis-compatible-with-redis/src/test/java/org/apache/geode/redis/internal/data/RedisSortedSetTest.java
##########
@@ -473,6 +473,70 @@ public void memberDummyOrderedSetEntryCompareTo_withEqualMemberNamesAndInclusive
     assertThat(inclusiveMax.compareTo(realEntry)).isEqualTo(1);
   }
 
+  @Test
+  public void zpopminRemovesMemberWithLowestScore() {
+    int originalSize = rangeSortedSet.getSortedSetSize();
+    RedisSortedSet sortedSet = spy(rangeSortedSet);
+    Region<RedisKey, RedisData> region = uncheckedCast(mock(Region.class));
+    RedisKey key = new RedisKey();
+    int count = 1;
+
+    List<byte[]> result = sortedSet.zpopmin(region, key, count);
+    assertThat(result).containsExactly("member1".getBytes(), "1".getBytes());
+
+    ArgumentCaptor<RemsDeltaInfo> argumentCaptor = ArgumentCaptor.forClass(RemsDeltaInfo.class);
+    verify(sortedSet).storeChanges(eq(region), eq(key), argumentCaptor.capture());
+    assertThat(argumentCaptor.getValue().getRemoves()).containsExactly("member1".getBytes());
+    assertThat(rangeSortedSet.getSortedSetSize()).isEqualTo(originalSize - count);
+  }
+
+  @Test
+  public void zpopminRemovesMembersWithHighestScores_whenCountIsGreaterThanOne() {

Review comment:
       Should this test name instead be "zpopminRemovesMembersWithLowestScores_whenCountIsGreaterThanOne()"?

##########
File path: geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/sortedset/AbstractZPopMinIntegrationTest.java
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.sortedset;
+
+import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.BIND_ADDRESS;
+import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.REDIS_CLIENT_TIMEOUT;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import redis.clients.jedis.HostAndPort;
+import redis.clients.jedis.JedisCluster;
+import redis.clients.jedis.Protocol;
+import redis.clients.jedis.Tuple;
+
+import org.apache.geode.redis.RedisIntegrationTest;
+import org.apache.geode.redis.internal.RedisConstants;
+
+public abstract class AbstractZPopMinIntegrationTest implements RedisIntegrationTest {

Review comment:
       Could we also get a test for the behaviour when the `count` argument is greater than the number of elements in the set?

##########
File path: geode-apis-compatible-with-redis/src/test/java/org/apache/geode/redis/internal/SupportedCommandsJUnitTest.java
##########
@@ -91,6 +91,7 @@
       "ZINCRBY",
       "ZCARD",
       "ZCOUNT",
+      "ZPOPMIN",

Review comment:
       Could this be moved to below ZPOPMAX to maintain alphabetical ordering?

##########
File path: geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/sortedset/AbstractZPopMinIntegrationTest.java
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.sortedset;
+
+import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.BIND_ADDRESS;
+import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.REDIS_CLIENT_TIMEOUT;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import redis.clients.jedis.HostAndPort;
+import redis.clients.jedis.JedisCluster;
+import redis.clients.jedis.Protocol;
+import redis.clients.jedis.Tuple;
+
+import org.apache.geode.redis.RedisIntegrationTest;
+import org.apache.geode.redis.internal.RedisConstants;
+
+public abstract class AbstractZPopMinIntegrationTest implements RedisIntegrationTest {
+  private JedisCluster jedis;
+
+  @Before
+  public void setUp() {
+    jedis = new JedisCluster(new HostAndPort(BIND_ADDRESS, getPort()), REDIS_CLIENT_TIMEOUT);
+  }
+
+  @After
+  public void tearDown() {
+    flushAll();
+    jedis.close();
+  }
+
+  @Test
+  public void shouldError_givenWrongNumberOfArguments() {
+    assertThatThrownBy(
+        () -> jedis.sendCommand("key", Protocol.Command.ZPOPMIN, "key", "1", "2"))
+            .hasMessageContaining(RedisConstants.ERROR_SYNTAX);

Review comment:
       There are two distinct error messages that could be returned for zpopmin (and zpopmax) with the wrong number of arguments. For more than 3 arguments, like in this test, `ERROR_SYNTAX` is returned, but for less than 2 (i.e. missing both the `key` and `count` arguments) then "ERR wrong number of arguments for 'zpopmin' command" is returned. We need tests for both cases, I think.




-- 
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] jdeppe-pivotal commented on a change in pull request #6738: GEODE-9186: Add Radish ZPOPMIN command

Posted by GitBox <gi...@apache.org>.
jdeppe-pivotal commented on a change in pull request #6738:
URL: https://github.com/apache/geode/pull/6738#discussion_r690447462



##########
File path: geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/sortedset/AbstractZPopMinIntegrationTest.java
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.sortedset;
+
+import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.BIND_ADDRESS;
+import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.REDIS_CLIENT_TIMEOUT;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import redis.clients.jedis.HostAndPort;
+import redis.clients.jedis.JedisCluster;
+import redis.clients.jedis.Protocol;
+import redis.clients.jedis.Tuple;
+
+import org.apache.geode.redis.RedisIntegrationTest;
+import org.apache.geode.redis.internal.RedisConstants;
+
+public abstract class AbstractZPopMinIntegrationTest implements RedisIntegrationTest {
+  private JedisCluster jedis;
+
+  @Before
+  public void setUp() {
+    jedis = new JedisCluster(new HostAndPort(BIND_ADDRESS, getPort()), REDIS_CLIENT_TIMEOUT);
+  }
+
+  @After
+  public void tearDown() {
+    flushAll();
+    jedis.close();
+  }
+
+  @Test
+  public void shouldError_givenWrongNumberOfArguments() {
+    assertThatThrownBy(
+        () -> jedis.sendCommand("key", Protocol.Command.ZPOPMIN, "key", "1", "2"))
+            .hasMessageContaining(RedisConstants.ERROR_SYNTAX);
+  }
+
+  @Test
+  public void shouldError_givenWrongNumberFormat() {
+    assertThatThrownBy(
+        () -> jedis.sendCommand("key", Protocol.Command.ZPOPMIN, "key", "wat"))
+            .hasMessageContaining(RedisConstants.ERROR_NOT_INTEGER);
+  }
+
+  @Test
+  public void shouldReturnEmpty_givenNonExistentSortedSet() {
+    assertThat(jedis.zpopmin("unknown", 1)).isEmpty();
+  }
+
+  @Test
+  public void shouldReturnEmpty_givenNegativeCount() {
+    jedis.zadd("key", 1, "player1");
+
+    List<?> result = (List<?>) jedis.sendCommand("key", Protocol.Command.ZPOPMIN, "key", "-1");
+    assertThat(result).isEmpty();
+    assertThat(jedis.zrange("key", 0, 10)).containsExactly("player1");
+  }
+
+  @Test
+  public void shouldReturn_highestLex_whenScoresAreEqual() {
+    jedis.zadd("key", 1, "player1");
+    jedis.zadd("key", 1, "player2");
+    jedis.zadd("key", 1, "player3");
+
+    assertThat(jedis.zpopmin("key").getElement()).isEqualTo("player1");
+    assertThat(jedis.zrange("key", 0, 10))
+        .containsExactlyInAnyOrder("player2", "player3");
+  }
+
+  @Test
+  public void shouldReturn_lowestScore() {

Review comment:
       Done

##########
File path: geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/sortedset/AbstractZPopMinIntegrationTest.java
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.sortedset;
+
+import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.BIND_ADDRESS;
+import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.REDIS_CLIENT_TIMEOUT;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import redis.clients.jedis.HostAndPort;
+import redis.clients.jedis.JedisCluster;
+import redis.clients.jedis.Protocol;
+import redis.clients.jedis.Tuple;
+
+import org.apache.geode.redis.RedisIntegrationTest;
+import org.apache.geode.redis.internal.RedisConstants;
+
+public abstract class AbstractZPopMinIntegrationTest implements RedisIntegrationTest {
+  private JedisCluster jedis;
+
+  @Before
+  public void setUp() {
+    jedis = new JedisCluster(new HostAndPort(BIND_ADDRESS, getPort()), REDIS_CLIENT_TIMEOUT);
+  }
+
+  @After
+  public void tearDown() {
+    flushAll();
+    jedis.close();
+  }
+
+  @Test
+  public void shouldError_givenWrongNumberOfArguments() {
+    assertThatThrownBy(
+        () -> jedis.sendCommand("key", Protocol.Command.ZPOPMIN, "key", "1", "2"))
+            .hasMessageContaining(RedisConstants.ERROR_SYNTAX);
+  }
+
+  @Test
+  public void shouldError_givenWrongNumberFormat() {
+    assertThatThrownBy(
+        () -> jedis.sendCommand("key", Protocol.Command.ZPOPMIN, "key", "wat"))
+            .hasMessageContaining(RedisConstants.ERROR_NOT_INTEGER);
+  }
+
+  @Test
+  public void shouldReturnEmpty_givenNonExistentSortedSet() {
+    assertThat(jedis.zpopmin("unknown", 1)).isEmpty();
+  }
+
+  @Test
+  public void shouldReturnEmpty_givenNegativeCount() {
+    jedis.zadd("key", 1, "player1");
+
+    List<?> result = (List<?>) jedis.sendCommand("key", Protocol.Command.ZPOPMIN, "key", "-1");
+    assertThat(result).isEmpty();
+    assertThat(jedis.zrange("key", 0, 10)).containsExactly("player1");
+  }
+
+  @Test
+  public void shouldReturn_highestLex_whenScoresAreEqual() {
+    jedis.zadd("key", 1, "player1");
+    jedis.zadd("key", 1, "player2");
+    jedis.zadd("key", 1, "player3");
+
+    assertThat(jedis.zpopmin("key").getElement()).isEqualTo("player1");
+    assertThat(jedis.zrange("key", 0, 10))
+        .containsExactlyInAnyOrder("player2", "player3");
+  }
+
+  @Test
+  public void shouldReturn_lowestScore() {
+    jedis.zadd("key", 3, "player1");
+    jedis.zadd("key", 2, "player2");
+    jedis.zadd("key", 1, "player3");
+
+    assertThat(jedis.zpopmin("key").getElement()).isEqualTo("player3");
+    assertThat(jedis.zrange("key", 0, 10))
+        .containsExactlyInAnyOrder("player1", "player2");
+  }
+
+  @Test
+  public void withCountShouldReturn_membersInScoreOrder_whenScoresAreDifferent() {
+    List<Tuple> tuples = new ArrayList<>();
+    int count = 10;
+    // Make sure that the results are not somehow dependent on the order of insertion
+    List<Integer> shuffles = makeShuffledList(count);
+    for (int i = 0; i < count; i++) {
+      jedis.zadd("key", count - shuffles.get(i), "player" + shuffles.get(i));
+      tuples.add(new Tuple("player" + (count - i - 1), (double) (i + 1)));
+    }
+
+    assertThat(jedis.zpopmin("key", count)).containsExactlyElementsOf(tuples);
+  }
+
+  @Test
+  public void withCountShouldReturn_membersInReverseLexicalOrder_whenScoresAreTheSame() {
+    List<Tuple> tuples = new ArrayList<>();
+    int count = 10;
+    // Make sure that the results are not somehow dependent on the order of insertion
+    List<Integer> shuffles = makeShuffledList(count);
+    for (int i = 0; i < count; i++) {
+      jedis.zadd("key", 1D, "player" + shuffles.get(i));
+      tuples.add(new Tuple("player" + i, 1D));
+    }
+
+    assertThat(jedis.zpopmin("key", count)).containsExactlyElementsOf(tuples);
+  }
+
+  @Test
+  public void shouldReturn_countLowestScores() {

Review comment:
       Hopefully more descriptive now.




-- 
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] jdeppe-pivotal commented on a change in pull request #6738: GEODE-9186: Add Radish ZPOPMIN command

Posted by GitBox <gi...@apache.org>.
jdeppe-pivotal commented on a change in pull request #6738:
URL: https://github.com/apache/geode/pull/6738#discussion_r690447354



##########
File path: geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/sortedset/AbstractZPopMinIntegrationTest.java
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.sortedset;
+
+import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.BIND_ADDRESS;
+import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.REDIS_CLIENT_TIMEOUT;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import redis.clients.jedis.HostAndPort;
+import redis.clients.jedis.JedisCluster;
+import redis.clients.jedis.Protocol;
+import redis.clients.jedis.Tuple;
+
+import org.apache.geode.redis.RedisIntegrationTest;
+import org.apache.geode.redis.internal.RedisConstants;
+
+public abstract class AbstractZPopMinIntegrationTest implements RedisIntegrationTest {
+  private JedisCluster jedis;
+
+  @Before
+  public void setUp() {
+    jedis = new JedisCluster(new HostAndPort(BIND_ADDRESS, getPort()), REDIS_CLIENT_TIMEOUT);
+  }
+
+  @After
+  public void tearDown() {
+    flushAll();
+    jedis.close();
+  }
+
+  @Test
+  public void shouldError_givenWrongNumberOfArguments() {
+    assertThatThrownBy(
+        () -> jedis.sendCommand("key", Protocol.Command.ZPOPMIN, "key", "1", "2"))
+            .hasMessageContaining(RedisConstants.ERROR_SYNTAX);

Review comment:
       I don't see anything specific in `RedisCommandArgumentsTestHelper` to what this test is asserting.




-- 
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] jdeppe-pivotal commented on a change in pull request #6738: GEODE-9186: Add Radish ZPOPMIN command

Posted by GitBox <gi...@apache.org>.
jdeppe-pivotal commented on a change in pull request #6738:
URL: https://github.com/apache/geode/pull/6738#discussion_r690760976



##########
File path: geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/sortedset/AbstractZPopMinIntegrationTest.java
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.sortedset;
+
+import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.BIND_ADDRESS;
+import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.REDIS_CLIENT_TIMEOUT;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import redis.clients.jedis.HostAndPort;
+import redis.clients.jedis.JedisCluster;
+import redis.clients.jedis.Protocol;
+import redis.clients.jedis.Tuple;
+
+import org.apache.geode.redis.RedisIntegrationTest;
+import org.apache.geode.redis.internal.RedisConstants;
+
+public abstract class AbstractZPopMinIntegrationTest implements RedisIntegrationTest {

Review comment:
       Done.




-- 
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] jdeppe-pivotal commented on a change in pull request #6738: GEODE-9186: Add Radish ZPOPMIN command

Posted by GitBox <gi...@apache.org>.
jdeppe-pivotal commented on a change in pull request #6738:
URL: https://github.com/apache/geode/pull/6738#discussion_r690446232



##########
File path: geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/data/NullRedisSortedSet.java
##########
@@ -86,6 +86,11 @@ long zcount(SortedSetScoreRangeOptions rangeOptions) {
     return increment;
   }
 
+  @Override
+  List<byte[]> zpopmin(Region<RedisKey, RedisData> region, RedisKey key, int count) {

Review comment:
       Done

##########
File path: geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/data/RedisSortedSet.java
##########
@@ -401,10 +401,22 @@ long zrevrank(byte[] member) {
     return null;
   }
 
+  List<byte[]> zpopmin(Region<RedisKey, RedisData> region, RedisKey key, int count) {

Review comment:
       Done

##########
File path: geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/data/RedisSortedSetCommandsFunctionExecutor.java
##########
@@ -103,6 +103,12 @@ public long zrevrank(RedisKey key, byte[] member) {
     return stripedExecute(key, () -> getRedisSortedSet(key, true).zscore(member));
   }
 
+  @Override
+  public List<byte[]> zpopmin(RedisKey key, int count) {

Review comment:
       Done

##########
File path: geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/executor/sortedset/RedisSortedSetCommands.java
##########
@@ -46,5 +46,7 @@
 
   byte[] zscore(RedisKey key, byte[] member);
 
+  List<byte[]> zpopmin(RedisKey key, int count);

Review comment:
       Done




-- 
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] jdeppe-pivotal commented on a change in pull request #6738: GEODE-9186: Add Radish ZPOPMIN command

Posted by GitBox <gi...@apache.org>.
jdeppe-pivotal commented on a change in pull request #6738:
URL: https://github.com/apache/geode/pull/6738#discussion_r690760894



##########
File path: geode-apis-compatible-with-redis/src/test/java/org/apache/geode/redis/internal/data/RedisSortedSetTest.java
##########
@@ -473,6 +473,70 @@ public void memberDummyOrderedSetEntryCompareTo_withEqualMemberNamesAndInclusive
     assertThat(inclusiveMax.compareTo(realEntry)).isEqualTo(1);
   }
 
+  @Test
+  public void zpopminRemovesMemberWithLowestScore() {
+    int originalSize = rangeSortedSet.getSortedSetSize();
+    RedisSortedSet sortedSet = spy(rangeSortedSet);
+    Region<RedisKey, RedisData> region = uncheckedCast(mock(Region.class));
+    RedisKey key = new RedisKey();
+    int count = 1;
+
+    List<byte[]> result = sortedSet.zpopmin(region, key, count);
+    assertThat(result).containsExactly("member1".getBytes(), "1".getBytes());
+
+    ArgumentCaptor<RemsDeltaInfo> argumentCaptor = ArgumentCaptor.forClass(RemsDeltaInfo.class);
+    verify(sortedSet).storeChanges(eq(region), eq(key), argumentCaptor.capture());
+    assertThat(argumentCaptor.getValue().getRemoves()).containsExactly("member1".getBytes());
+    assertThat(rangeSortedSet.getSortedSetSize()).isEqualTo(originalSize - count);
+  }
+
+  @Test
+  public void zpopminRemovesMembersWithHighestScores_whenCountIsGreaterThanOne() {

Review comment:
       Done.




-- 
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 #6738: GEODE-9186: Add Radish ZPOPMIN command

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



##########
File path: geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/server/AbstractHitsMissesIntegrationTest.java
##########
@@ -252,6 +252,11 @@ public void testZIncrBy() {
     runCommandAndAssertNoStatUpdates("key", (k, m) -> jedis.zincrby(k, 100.0, m));
   }
 
+  @Test
+  public void testZPopMin() {

Review comment:
       Could this be moved to below `testZPopMax()` to maintain alphabetical ordering?

##########
File path: geode-apis-compatible-with-redis/src/test/java/org/apache/geode/redis/internal/data/RedisSortedSetTest.java
##########
@@ -473,6 +473,70 @@ public void memberDummyOrderedSetEntryCompareTo_withEqualMemberNamesAndInclusive
     assertThat(inclusiveMax.compareTo(realEntry)).isEqualTo(1);
   }
 
+  @Test
+  public void zpopminRemovesMemberWithLowestScore() {
+    int originalSize = rangeSortedSet.getSortedSetSize();
+    RedisSortedSet sortedSet = spy(rangeSortedSet);
+    Region<RedisKey, RedisData> region = uncheckedCast(mock(Region.class));
+    RedisKey key = new RedisKey();
+    int count = 1;
+
+    List<byte[]> result = sortedSet.zpopmin(region, key, count);
+    assertThat(result).containsExactly("member1".getBytes(), "1".getBytes());
+
+    ArgumentCaptor<RemsDeltaInfo> argumentCaptor = ArgumentCaptor.forClass(RemsDeltaInfo.class);
+    verify(sortedSet).storeChanges(eq(region), eq(key), argumentCaptor.capture());
+    assertThat(argumentCaptor.getValue().getRemoves()).containsExactly("member1".getBytes());
+    assertThat(rangeSortedSet.getSortedSetSize()).isEqualTo(originalSize - count);
+  }
+
+  @Test
+  public void zpopminRemovesMembersWithHighestScores_whenCountIsGreaterThanOne() {

Review comment:
       Should this test name instead be "zpopminRemovesMembersWithLowestScores_whenCountIsGreaterThanOne()"?

##########
File path: geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/sortedset/AbstractZPopMinIntegrationTest.java
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.sortedset;
+
+import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.BIND_ADDRESS;
+import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.REDIS_CLIENT_TIMEOUT;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import redis.clients.jedis.HostAndPort;
+import redis.clients.jedis.JedisCluster;
+import redis.clients.jedis.Protocol;
+import redis.clients.jedis.Tuple;
+
+import org.apache.geode.redis.RedisIntegrationTest;
+import org.apache.geode.redis.internal.RedisConstants;
+
+public abstract class AbstractZPopMinIntegrationTest implements RedisIntegrationTest {

Review comment:
       Could we also get a test for the behaviour when the `count` argument is greater than the number of elements in the set?

##########
File path: geode-apis-compatible-with-redis/src/test/java/org/apache/geode/redis/internal/SupportedCommandsJUnitTest.java
##########
@@ -91,6 +91,7 @@
       "ZINCRBY",
       "ZCARD",
       "ZCOUNT",
+      "ZPOPMIN",

Review comment:
       Could this be moved to below ZPOPMAX to maintain alphabetical ordering?

##########
File path: geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/sortedset/AbstractZPopMinIntegrationTest.java
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.sortedset;
+
+import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.BIND_ADDRESS;
+import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.REDIS_CLIENT_TIMEOUT;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import redis.clients.jedis.HostAndPort;
+import redis.clients.jedis.JedisCluster;
+import redis.clients.jedis.Protocol;
+import redis.clients.jedis.Tuple;
+
+import org.apache.geode.redis.RedisIntegrationTest;
+import org.apache.geode.redis.internal.RedisConstants;
+
+public abstract class AbstractZPopMinIntegrationTest implements RedisIntegrationTest {
+  private JedisCluster jedis;
+
+  @Before
+  public void setUp() {
+    jedis = new JedisCluster(new HostAndPort(BIND_ADDRESS, getPort()), REDIS_CLIENT_TIMEOUT);
+  }
+
+  @After
+  public void tearDown() {
+    flushAll();
+    jedis.close();
+  }
+
+  @Test
+  public void shouldError_givenWrongNumberOfArguments() {
+    assertThatThrownBy(
+        () -> jedis.sendCommand("key", Protocol.Command.ZPOPMIN, "key", "1", "2"))
+            .hasMessageContaining(RedisConstants.ERROR_SYNTAX);

Review comment:
       There are two distinct error messages that could be returned for zpopmin (and zpopmax) with the wrong number of arguments. For more than 3 arguments, like in this test, `ERROR_SYNTAX` is returned, but for less than 2 (i.e. missing both the `key` and `count` arguments) then "ERR wrong number of arguments for 'zpopmin' command" is returned. We need tests for both cases, I think.




-- 
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 #6738: GEODE-9186: Add Radish ZPOPMIN command

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



##########
File path: geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/data/RedisSortedSetCommandsFunctionExecutor.java
##########
@@ -103,6 +103,12 @@ public long zrevrank(RedisKey key, byte[] member) {
     return stripedExecute(key, () -> getRedisSortedSet(key, true).zscore(member));
   }
 
+  @Override
+  public List<byte[]> zpopmin(RedisKey key, int count) {

Review comment:
       Another call for alphabetization. :)

##########
File path: geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/executor/sortedset/RedisSortedSetCommands.java
##########
@@ -46,5 +46,7 @@
 
   byte[] zscore(RedisKey key, byte[] member);
 
+  List<byte[]> zpopmin(RedisKey key, int count);

Review comment:
       Gimme an alpha! Gimme a beta! What does that spell? Alphabeta, which is almost 'alpahbet'...

##########
File path: geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/data/RedisSortedSet.java
##########
@@ -401,10 +401,22 @@ long zrevrank(byte[] member) {
     return null;
   }
 
+  List<byte[]> zpopmin(Region<RedisKey, RedisData> region, RedisKey key, int count) {

Review comment:
       Again, we should probably stick to alphabetical order here. Though that means both zpop*'s should go above zscore...

##########
File path: geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/data/NullRedisSortedSet.java
##########
@@ -86,6 +86,11 @@ long zcount(SortedSetScoreRangeOptions rangeOptions) {
     return increment;
   }
 
+  @Override
+  List<byte[]> zpopmin(Region<RedisKey, RedisData> region, RedisKey key, int count) {

Review comment:
       I think this should go below "zpopmax" alphabetically.




-- 
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] nonbinaryprogrammer commented on a change in pull request #6738: GEODE-9186: Add Radish ZPOPMIN command

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



##########
File path: geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/sortedset/AbstractZPopMinIntegrationTest.java
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.sortedset;
+
+import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.BIND_ADDRESS;
+import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.REDIS_CLIENT_TIMEOUT;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import redis.clients.jedis.HostAndPort;
+import redis.clients.jedis.JedisCluster;
+import redis.clients.jedis.Protocol;
+import redis.clients.jedis.Tuple;
+
+import org.apache.geode.redis.RedisIntegrationTest;
+import org.apache.geode.redis.internal.RedisConstants;
+
+public abstract class AbstractZPopMinIntegrationTest implements RedisIntegrationTest {
+  private JedisCluster jedis;
+
+  @Before
+  public void setUp() {
+    jedis = new JedisCluster(new HostAndPort(BIND_ADDRESS, getPort()), REDIS_CLIENT_TIMEOUT);
+  }
+
+  @After
+  public void tearDown() {
+    flushAll();
+    jedis.close();
+  }
+
+  @Test
+  public void shouldError_givenWrongNumberOfArguments() {
+    assertThatThrownBy(
+        () -> jedis.sendCommand("key", Protocol.Command.ZPOPMIN, "key", "1", "2"))
+            .hasMessageContaining(RedisConstants.ERROR_SYNTAX);

Review comment:
       we have a helper to do this. RedisCommandArgumentsTestHelper

##########
File path: geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/sortedset/AbstractZPopMinIntegrationTest.java
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.sortedset;
+
+import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.BIND_ADDRESS;
+import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.REDIS_CLIENT_TIMEOUT;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import redis.clients.jedis.HostAndPort;
+import redis.clients.jedis.JedisCluster;
+import redis.clients.jedis.Protocol;
+import redis.clients.jedis.Tuple;
+
+import org.apache.geode.redis.RedisIntegrationTest;
+import org.apache.geode.redis.internal.RedisConstants;
+
+public abstract class AbstractZPopMinIntegrationTest implements RedisIntegrationTest {
+  private JedisCluster jedis;
+
+  @Before
+  public void setUp() {
+    jedis = new JedisCluster(new HostAndPort(BIND_ADDRESS, getPort()), REDIS_CLIENT_TIMEOUT);
+  }
+
+  @After
+  public void tearDown() {
+    flushAll();
+    jedis.close();
+  }
+
+  @Test
+  public void shouldError_givenWrongNumberOfArguments() {
+    assertThatThrownBy(
+        () -> jedis.sendCommand("key", Protocol.Command.ZPOPMIN, "key", "1", "2"))
+            .hasMessageContaining(RedisConstants.ERROR_SYNTAX);
+  }
+
+  @Test
+  public void shouldError_givenWrongNumberFormat() {
+    assertThatThrownBy(
+        () -> jedis.sendCommand("key", Protocol.Command.ZPOPMIN, "key", "wat"))
+            .hasMessageContaining(RedisConstants.ERROR_NOT_INTEGER);
+  }
+
+  @Test
+  public void shouldReturnEmpty_givenNonExistentSortedSet() {
+    assertThat(jedis.zpopmin("unknown", 1)).isEmpty();
+  }
+
+  @Test
+  public void shouldReturnEmpty_givenNegativeCount() {
+    jedis.zadd("key", 1, "player1");
+
+    List<?> result = (List<?>) jedis.sendCommand("key", Protocol.Command.ZPOPMIN, "key", "-1");
+    assertThat(result).isEmpty();
+    assertThat(jedis.zrange("key", 0, 10)).containsExactly("player1");
+  }
+
+  @Test
+  public void shouldReturn_highestLex_whenScoresAreEqual() {
+    jedis.zadd("key", 1, "player1");
+    jedis.zadd("key", 1, "player2");
+    jedis.zadd("key", 1, "player3");
+
+    assertThat(jedis.zpopmin("key").getElement()).isEqualTo("player1");
+    assertThat(jedis.zrange("key", 0, 10))
+        .containsExactlyInAnyOrder("player2", "player3");
+  }
+
+  @Test
+  public void shouldReturn_lowestScore() {
+    jedis.zadd("key", 3, "player1");
+    jedis.zadd("key", 2, "player2");
+    jedis.zadd("key", 1, "player3");
+
+    assertThat(jedis.zpopmin("key").getElement()).isEqualTo("player3");
+    assertThat(jedis.zrange("key", 0, 10))
+        .containsExactlyInAnyOrder("player1", "player2");
+  }
+
+  @Test
+  public void withCountShouldReturn_membersInScoreOrder_whenScoresAreDifferent() {
+    List<Tuple> tuples = new ArrayList<>();
+    int count = 10;
+    // Make sure that the results are not somehow dependent on the order of insertion
+    List<Integer> shuffles = makeShuffledList(count);
+    for (int i = 0; i < count; i++) {
+      jedis.zadd("key", count - shuffles.get(i), "player" + shuffles.get(i));
+      tuples.add(new Tuple("player" + (count - i - 1), (double) (i + 1)));
+    }
+
+    assertThat(jedis.zpopmin("key", count)).containsExactlyElementsOf(tuples);
+  }
+
+  @Test
+  public void withCountShouldReturn_membersInReverseLexicalOrder_whenScoresAreTheSame() {
+    List<Tuple> tuples = new ArrayList<>();
+    int count = 10;
+    // Make sure that the results are not somehow dependent on the order of insertion
+    List<Integer> shuffles = makeShuffledList(count);
+    for (int i = 0; i < count; i++) {
+      jedis.zadd("key", 1D, "player" + shuffles.get(i));
+      tuples.add(new Tuple("player" + i, 1D));
+    }
+
+    assertThat(jedis.zpopmin("key", count)).containsExactlyElementsOf(tuples);
+  }
+
+  @Test
+  public void shouldReturn_countLowestScores() {

Review comment:
       this test name also doesn't quite make sense to me

##########
File path: geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/sortedset/AbstractZPopMinIntegrationTest.java
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.sortedset;
+
+import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.BIND_ADDRESS;
+import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.REDIS_CLIENT_TIMEOUT;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import redis.clients.jedis.HostAndPort;
+import redis.clients.jedis.JedisCluster;
+import redis.clients.jedis.Protocol;
+import redis.clients.jedis.Tuple;
+
+import org.apache.geode.redis.RedisIntegrationTest;
+import org.apache.geode.redis.internal.RedisConstants;
+
+public abstract class AbstractZPopMinIntegrationTest implements RedisIntegrationTest {
+  private JedisCluster jedis;
+
+  @Before
+  public void setUp() {
+    jedis = new JedisCluster(new HostAndPort(BIND_ADDRESS, getPort()), REDIS_CLIENT_TIMEOUT);
+  }
+
+  @After
+  public void tearDown() {
+    flushAll();
+    jedis.close();
+  }
+
+  @Test
+  public void shouldError_givenWrongNumberOfArguments() {
+    assertThatThrownBy(
+        () -> jedis.sendCommand("key", Protocol.Command.ZPOPMIN, "key", "1", "2"))
+            .hasMessageContaining(RedisConstants.ERROR_SYNTAX);
+  }
+
+  @Test
+  public void shouldError_givenWrongNumberFormat() {
+    assertThatThrownBy(
+        () -> jedis.sendCommand("key", Protocol.Command.ZPOPMIN, "key", "wat"))
+            .hasMessageContaining(RedisConstants.ERROR_NOT_INTEGER);
+  }
+
+  @Test
+  public void shouldReturnEmpty_givenNonExistentSortedSet() {
+    assertThat(jedis.zpopmin("unknown", 1)).isEmpty();
+  }
+
+  @Test
+  public void shouldReturnEmpty_givenNegativeCount() {
+    jedis.zadd("key", 1, "player1");
+
+    List<?> result = (List<?>) jedis.sendCommand("key", Protocol.Command.ZPOPMIN, "key", "-1");
+    assertThat(result).isEmpty();
+    assertThat(jedis.zrange("key", 0, 10)).containsExactly("player1");
+  }
+
+  @Test
+  public void shouldReturn_highestLex_whenScoresAreEqual() {
+    jedis.zadd("key", 1, "player1");
+    jedis.zadd("key", 1, "player2");
+    jedis.zadd("key", 1, "player3");
+
+    assertThat(jedis.zpopmin("key").getElement()).isEqualTo("player1");
+    assertThat(jedis.zrange("key", 0, 10))
+        .containsExactlyInAnyOrder("player2", "player3");
+  }
+
+  @Test
+  public void shouldReturn_lowestScore() {

Review comment:
       I don't think this test name quite captures the intention behind the test. It just needs a little more to it




-- 
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] jdeppe-pivotal commented on a change in pull request #6738: GEODE-9186: Add Radish ZPOPMIN command

Posted by GitBox <gi...@apache.org>.
jdeppe-pivotal commented on a change in pull request #6738:
URL: https://github.com/apache/geode/pull/6738#discussion_r690760797



##########
File path: geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/server/AbstractHitsMissesIntegrationTest.java
##########
@@ -252,6 +252,11 @@ public void testZIncrBy() {
     runCommandAndAssertNoStatUpdates("key", (k, m) -> jedis.zincrby(k, 100.0, m));
   }
 
+  @Test
+  public void testZPopMin() {

Review comment:
       Done




-- 
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] jdeppe-pivotal merged pull request #6738: GEODE-9186: Add Radish ZPOPMIN command

Posted by GitBox <gi...@apache.org>.
jdeppe-pivotal merged pull request #6738:
URL: https://github.com/apache/geode/pull/6738


   


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