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



##########
File path: 
geode-for-redis/src/integrationTest/java/org/apache/geode/redis/internal/commands/executor/set/AbstractSUnionStoreIntegrationTest.java
##########
@@ -58,7 +58,7 @@ public void tearDown() {
 
   @Test
   public void sunionstore_givenTooFewArguments_returnsError() {
-    assertAtLeastNArgs(jedis, Protocol.Command.SUNION, 1);
+    assertAtLeastNArgs(jedis, Protocol.Command.SUNIONSTORE, 2);

Review comment:
       Nice catch

##########
File path: 
geode-for-redis/src/main/java/org/apache/geode/redis/internal/commands/executor/set/SetOpExecutor.java
##########
@@ -14,185 +14,54 @@
  */
 package org.apache.geode.redis.internal.commands.executor.set;
 
-import static java.util.Collections.emptySet;
-import static org.apache.geode.redis.internal.data.RedisSet.sdiff;
-import static org.apache.geode.redis.internal.data.RedisSet.sdiffstore;
-import static org.apache.geode.redis.internal.data.RedisSet.sinter;
-import static org.apache.geode.redis.internal.data.RedisSet.sunion;
-import static org.apache.geode.redis.internal.data.RedisSet.sunionstore;
 
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
 
 import org.apache.geode.redis.internal.commands.Command;
-import org.apache.geode.redis.internal.commands.RedisCommandType;
 import org.apache.geode.redis.internal.commands.executor.CommandExecutor;
 import org.apache.geode.redis.internal.commands.executor.RedisResponse;
 import org.apache.geode.redis.internal.data.RedisKey;
-import org.apache.geode.redis.internal.data.RedisSet;
-import org.apache.geode.redis.internal.data.RedisSet.MemberSet;
 import org.apache.geode.redis.internal.netty.ExecutionHandlerContext;
 import org.apache.geode.redis.internal.services.RegionProvider;
 
 public abstract class SetOpExecutor implements CommandExecutor {
 
   @Override
   public RedisResponse executeCommand(Command command, ExecutionHandlerContext 
context) {
-    int setsStartIndex = 1;
-
-    if (isStorage()) {
-      setsStartIndex++;
-    }
-
-    List<RedisKey> commandElements = command.getProcessedCommandKeys();
-    List<RedisKey> setKeys = commandElements.subList(setsStartIndex, 
commandElements.size());
     RegionProvider regionProvider = context.getRegionProvider();
+    List<RedisKey> commandElements = command.getProcessedCommandKeys();
+    List<RedisKey> setKeys = commandElements.subList(1, 
commandElements.size());
 
-    /*
-     * SINTERSTORE currently use the else part of the code for their 
implementation.
-     * TODO: Once the above commands have been implemented remove the if else
-     * Refactor so the implementation is in the executor. After delete 
doActualSetOperation,
-     * doStoreSetOp, doStoreSetOpWhileLocked, computeStoreSetOp, fetchSets
-     */
-    List<RedisKey> keysToLock = new ArrayList<>(setKeys);
-    if (isStorage()) {
-      keysToLock.add(command.getKey());
-    }
-    if (command.isOfType(RedisCommandType.SDIFF) || 
command.isOfType(RedisCommandType.SDIFFSTORE)) {
-      if (isStorage()) {
-        RedisKey destinationKey = command.getKey();
-        int resultSize = context.lockedExecute(destinationKey, keysToLock,
-            () -> sdiffstore(regionProvider, destinationKey, setKeys));
-        return RedisResponse.integer(resultSize);
-      }
-
-      Set<byte[]> resultSet = context.lockedExecute(setKeys.get(0), keysToLock,
-          () -> sdiff(regionProvider, setKeys));
-      return RedisResponse.array(resultSet, true);
-
-    } else if (command.isOfType(RedisCommandType.SINTER)) {
-      Set<byte[]> resultSet = context.lockedExecute(setKeys.get(0), keysToLock,
-          () -> sinter(regionProvider, setKeys));
-      return RedisResponse.array(resultSet, true);
-
-    } else if (command.isOfType(RedisCommandType.SUNION)
-        || command.isOfType(RedisCommandType.SUNIONSTORE)) {
-      if (isStorage()) {
-        RedisKey destinationKey = command.getKey();
-        int resultSize = context.lockedExecute(destinationKey, keysToLock,
-            () -> sunionstore(regionProvider, destinationKey, setKeys));
-        return RedisResponse.integer(resultSize);
-      }
-
-      Set<byte[]> resultSet = context.lockedExecute(setKeys.get(0), keysToLock,
-          () -> sunion(regionProvider, setKeys));
-      return RedisResponse.array(resultSet, true);
-    }
+    RedisResponse result = context.lockedExecute(setKeys.get(0), new 
ArrayList<>(setKeys),
+        () -> performCommand(regionProvider, setKeys));

Review comment:
       This can just be:
   ```
   return context.lockedExecute(setKeys.get(0), new ArrayList<>(setKeys),
           () -> performCommand(regionProvider, setKeys));
   ```

##########
File path: 
geode-for-redis/src/integrationTest/java/org/apache/geode/redis/internal/commands/executor/set/AbstractSInterStoreIntegrationTest.java
##########
@@ -0,0 +1,237 @@
+/*
+ * 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.commands.executor.set;
+
+
+import static 
org.apache.geode.redis.RedisCommandArgumentsTestHelper.assertAtLeastNArgs;
+import static org.apache.geode.redis.internal.RedisConstants.ERROR_WRONG_SLOT;
+import static org.apache.geode.redis.internal.RedisConstants.ERROR_WRONG_TYPE;
+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 static redis.clients.jedis.Protocol.Command.SINTERSTORE;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+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 org.apache.geode.redis.ConcurrentLoopingThreads;
+import org.apache.geode.redis.RedisIntegrationTest;
+
+public abstract class AbstractSInterStoreIntegrationTest implements 
RedisIntegrationTest {
+  private JedisCluster jedis;
+  private static final String DESTINATION_KEY = "{tag1}destinationKey";
+  private static final String[] DESTINATION_MEMBERS =
+      {"six", "seven", "eight", "nine", "ten", "one", "two"};
+  private static final String SET_KEY_1 = "{tag1}setKey1";
+  private static final String[] SET_MEMBERS_1 = {"one", "two", "three", 
"four", "five"};
+  private static final String NON_EXISTENT_SET = "{tag1}nonExistentSet";
+  private static final String SET_KEY_2 = "{tag1}setKey2";
+
+  @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 sinterstore_givenTooFewArguments_returnsError() {
+    assertAtLeastNArgs(jedis, Protocol.Command.SINTERSTORE, 2);
+  }
+
+  @Test
+  public void sinterstore_withExistentSet_returnsInterSize_storesInter() {
+    jedis.sadd(SET_KEY_1, SET_MEMBERS_1);
+    assertThat(jedis.sinterstore(DESTINATION_KEY, 
SET_KEY_1)).isEqualTo(SET_MEMBERS_1.length);
+    
assertThat(jedis.smembers(DESTINATION_KEY)).containsExactlyInAnyOrder(SET_MEMBERS_1);
+  }
+
+  @Test
+  public void sinterstore_withNonExistentSet_returnsZero_destKeyDoesNotExist() 
{
+    assertThat(jedis.sinterstore(DESTINATION_KEY, 
NON_EXISTENT_SET)).isEqualTo(0);
+    assertThat(jedis.exists(DESTINATION_KEY)).isFalse();
+  }
+
+  @Test
+  public void 
sinterstore_withOneExistentAndOneNonExistentSet_returnsZero_destKeyDoesNotExist()
 {
+    jedis.sadd(SET_KEY_1, SET_MEMBERS_1);
+    assertThat(jedis.sinterstore(DESTINATION_KEY, SET_KEY_1, NON_EXISTENT_SET))
+        .isEqualTo(0);
+    assertThat(jedis.exists(DESTINATION_KEY)).isFalse();
+  }
+
+  @Test
+  public void 
sinterstore_withOneNonExistentAndOneExistentSet_returnsZero_destKeyDoesNotExist()
 {

Review comment:
       To differentiate between these two test cases, could the names be 
changed slightly to something like 
"sinterstore_withNonExistentFirstSetAndExistentSecondSet_returnsZero_doesNotCreateSetAtDestination"
 and 
"sinterstore_withExistentFirstSetAndNonExistentSecondSet_returnsZero_doesNotCreateSetAtDestination"
 to make it clear that the order of the sets is what we're mainly interested in?

##########
File path: 
geode-for-redis/src/integrationTest/java/org/apache/geode/redis/internal/commands/executor/set/AbstractSInterStoreIntegrationTest.java
##########
@@ -0,0 +1,237 @@
+/*
+ * 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.commands.executor.set;
+
+
+import static 
org.apache.geode.redis.RedisCommandArgumentsTestHelper.assertAtLeastNArgs;
+import static org.apache.geode.redis.internal.RedisConstants.ERROR_WRONG_SLOT;
+import static org.apache.geode.redis.internal.RedisConstants.ERROR_WRONG_TYPE;
+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 static redis.clients.jedis.Protocol.Command.SINTERSTORE;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+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 org.apache.geode.redis.ConcurrentLoopingThreads;
+import org.apache.geode.redis.RedisIntegrationTest;
+
+public abstract class AbstractSInterStoreIntegrationTest implements 
RedisIntegrationTest {
+  private JedisCluster jedis;
+  private static final String DESTINATION_KEY = "{tag1}destinationKey";
+  private static final String[] DESTINATION_MEMBERS =
+      {"six", "seven", "eight", "nine", "ten", "one", "two"};
+  private static final String SET_KEY_1 = "{tag1}setKey1";
+  private static final String[] SET_MEMBERS_1 = {"one", "two", "three", 
"four", "five"};
+  private static final String NON_EXISTENT_SET = "{tag1}nonExistentSet";
+  private static final String SET_KEY_2 = "{tag1}setKey2";
+
+  @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 sinterstore_givenTooFewArguments_returnsError() {
+    assertAtLeastNArgs(jedis, Protocol.Command.SINTERSTORE, 2);
+  }
+
+  @Test
+  public void sinterstore_withExistentSet_returnsInterSize_storesInter() {
+    jedis.sadd(SET_KEY_1, SET_MEMBERS_1);
+    assertThat(jedis.sinterstore(DESTINATION_KEY, 
SET_KEY_1)).isEqualTo(SET_MEMBERS_1.length);
+    
assertThat(jedis.smembers(DESTINATION_KEY)).containsExactlyInAnyOrder(SET_MEMBERS_1);
+  }
+
+  @Test
+  public void sinterstore_withNonExistentSet_returnsZero_destKeyDoesNotExist() 
{
+    assertThat(jedis.sinterstore(DESTINATION_KEY, 
NON_EXISTENT_SET)).isEqualTo(0);
+    assertThat(jedis.exists(DESTINATION_KEY)).isFalse();
+  }
+
+  @Test
+  public void 
sinterstore_withOneExistentAndOneNonExistentSet_returnsZero_destKeyDoesNotExist()
 {
+    jedis.sadd(SET_KEY_1, SET_MEMBERS_1);
+    assertThat(jedis.sinterstore(DESTINATION_KEY, SET_KEY_1, NON_EXISTENT_SET))
+        .isEqualTo(0);
+    assertThat(jedis.exists(DESTINATION_KEY)).isFalse();
+  }
+
+  @Test
+  public void 
sinterstore_withOneNonExistentAndOneExistentSet_returnsZero_destKeyDoesNotExist()
 {
+    jedis.sadd(SET_KEY_1, SET_MEMBERS_1);
+    assertThat(jedis.sinterstore(DESTINATION_KEY, NON_EXISTENT_SET, SET_KEY_1))
+        .isEqualTo(0);
+    assertThat(jedis.exists(DESTINATION_KEY)).isFalse();
+  }
+
+  @Test
+  public void 
sinterstore_withNoIntersectingMembers_returnsZero_destKeyDoesNotExist() {
+    String[] secondSetMembers = new String[] {"apple", "microsoft", "linux", 
"peach"};
+    jedis.sadd(SET_KEY_1, SET_MEMBERS_1);
+    jedis.sadd(SET_KEY_2, secondSetMembers);
+
+    assertThat(jedis.sinterstore(DESTINATION_KEY, SET_KEY_1, 
SET_KEY_2)).isEqualTo(0);
+    assertThat(jedis.exists(DESTINATION_KEY)).isFalse();
+  }
+
+  @Test
+  public void 
sinterstore_withSomeIntersectingMembers_returnsInterSize_storesInter() {
+    String[] secondSetMembers = new String[] {"one", "two", "linux", "peach"};
+    jedis.sadd(SET_KEY_1, SET_MEMBERS_1);
+    jedis.sadd(SET_KEY_2, secondSetMembers);
+
+    String[] result = {"one", "two"};
+    assertThat(jedis.sinterstore(DESTINATION_KEY, SET_KEY_1, 
SET_KEY_2)).isEqualTo(result.length);
+    
assertThat(jedis.smembers(DESTINATION_KEY)).containsExactlyInAnyOrder(result);
+  }
+
+  @Test
+  public void 
sinterstore_withAllIntersectingMembers_returnsInterSize_storesInter() {
+    jedis.sadd(SET_KEY_1, SET_MEMBERS_1);
+    jedis.sadd(SET_KEY_2, SET_MEMBERS_1);
+
+    assertThat(jedis.sinterstore(DESTINATION_KEY, SET_KEY_1, SET_KEY_2))
+        .isEqualTo(SET_MEMBERS_1.length);
+    
assertThat(jedis.smembers(DESTINATION_KEY)).containsExactlyInAnyOrder(SET_MEMBERS_1);
+  }
+
+  @Test
+  public void 
sinterstore_withMultipleNonExistentSets_returnsZero_destKeyDoesNotExist() {
+    assertThat(jedis.sinterstore(DESTINATION_KEY, NON_EXISTENT_SET, 
"{tag1}nonExistentSet2"))
+        .isEqualTo(0);
+    assertThat(jedis.exists(DESTINATION_KEY)).isFalse();
+  }
+
+  @Test
+  public void 
sinterstore_withExistentSet_returnsInterSize_destKeyOverwrittenWithInter() {
+    jedis.sadd(DESTINATION_KEY, DESTINATION_MEMBERS);
+    jedis.sadd(SET_KEY_1, SET_MEMBERS_1);
+    assertThat(jedis.sinterstore(DESTINATION_KEY, 
SET_KEY_1)).isEqualTo(SET_MEMBERS_1.length);
+    
assertThat(jedis.smembers(DESTINATION_KEY)).containsExactlyInAnyOrder(SET_MEMBERS_1);
+  }
+
+  @Test
+  public void sinterstore_withNonExistentSet_returnsZero_destKeyIsDeleted() {
+    jedis.sadd(DESTINATION_KEY, DESTINATION_MEMBERS);
+    assertThat(jedis.sinterstore(DESTINATION_KEY, 
NON_EXISTENT_SET)).isEqualTo(0);
+    assertThat(jedis.exists(DESTINATION_KEY)).isFalse();
+  }
+
+  @Test
+  public void 
sinterstore_withNonSetDestKey_withExistentSet_returnsInterSize_destKeyOverwrittenWithInter()
 {
+    String stringKey = "{tag1}ding";
+    jedis.set(stringKey, "dong");
+
+    jedis.sadd(SET_KEY_1, SET_MEMBERS_1);
+    assertThat(jedis.sinterstore(stringKey, 
SET_KEY_1)).isEqualTo(SET_MEMBERS_1.length);
+    
assertThat(jedis.smembers(stringKey)).containsExactlyInAnyOrder(SET_MEMBERS_1);
+  }
+
+  @Test
+  public void 
sinterstore_withNonSetDestKey_withNonExistentSet_returnsZero_destKeyIsDeleted() 
{
+    String stringKey = "{tag1}ding";
+    jedis.set(stringKey, "dong");
+
+    assertThat(jedis.sinterstore(stringKey, NON_EXISTENT_SET)).isEqualTo(0);
+    assertThat(jedis.exists(DESTINATION_KEY)).isFalse();
+  }
+
+  @Test
+  public void 
sinterstore_withNonExistentDest_withNonSetKeyAsFirstKey_returnsWrongTypeError() 
{
+    String stringKey = "{tag1}ding";
+    jedis.set(stringKey, "dong");
+
+    jedis.sadd(SET_KEY_1, SET_MEMBERS_1);
+    jedis.sadd(SET_KEY_2, "doorbell");
+    assertThatThrownBy(() -> jedis.sinterstore(DESTINATION_KEY, stringKey, 
SET_KEY_1, SET_KEY_2))
+        .hasMessageContaining(ERROR_WRONG_TYPE);
+  }
+
+  @Test
+  public void 
sinterstore_withExistentDest_withNonSetKeyAsThirdKey_returnsWrongTypeError() {
+    String stringKey = "{tag1}ding";
+    jedis.set(stringKey, "dong");
+
+    jedis.sadd(DESTINATION_KEY, DESTINATION_MEMBERS);
+    jedis.sadd(SET_KEY_1, SET_MEMBERS_1);
+    jedis.sadd(SET_KEY_2, "doorbell");
+    assertThatThrownBy(() -> jedis.sinterstore(DESTINATION_KEY, SET_KEY_1, 
SET_KEY_2, stringKey))
+        .hasMessageContaining(ERROR_WRONG_TYPE);
+  }
+
+  @Test
+  public void 
sinterstore_withNonExistentDest_withNonSetKeyAsThirdKeyAndNonExistentSetAsFirstKey_returnsWrongTypeError()
 {

Review comment:
       Just to simplify it a little, the "withNonExistentDest" part of this 
test name can be removed, I think, since we don't expect that whether the 
destination exists or not will effect the behavviour here.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to