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



##########
File path: 
geode-for-redis/src/integrationTest/java/org/apache/geode/redis/internal/commands/executor/set/AbstractSDiffStoreIntegrationTest.java
##########
@@ -0,0 +1,243 @@
+/*
+ * 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_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 java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.AtomicReference;
+
+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 AbstractSDiffStoreIntegrationTest implements 
RedisIntegrationTest {
+  private JedisCluster jedis;
+
+  private static final String destinationKey = "{user1}destinationKey";
+  private static final String[] destinationMembers =
+      {"six", "seven", "eight", "nine", "ten", "one", "two"};
+  private static final String setKey = "{user1}setKey";
+  private static final String[] setMembers = {"one", "two", "three", "four", 
"five"};
+  private static final String nonExistentSetKey = "{user1}nonExistentSet";
+
+  @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 sdiffstoreTooFewArguments_returnsError() {
+    assertAtLeastNArgs(jedis, Protocol.Command.SDIFFSTORE, 2);
+  }
+
+  @Test
+  public void sdiffstore_DifferentyKeyType_returnsWrongTypeError() {
+    jedis.set("{user1}ding", "{user1}dong");
+    assertThatThrownBy(() -> jedis.sdiffstore(destinationKey, "{user1}ding"))
+        .hasMessageContaining(ERROR_WRONG_TYPE);
+  }
+
+  // Destination Key does not have members
+  @Test
+  public void sdiffstoreNonExistentDest_Set_returnsSetSize() {
+    jedis.sadd(setKey, setMembers);
+    assertThat(jedis.sdiffstore(destinationKey, 
setKey)).isEqualTo(setMembers.length);
+    
assertThat(jedis.smembers(destinationKey)).containsExactlyInAnyOrder(setMembers);
+  }
+
+  @Test
+  public void sdiffstoreNonExistentDest_NonExistentSet_returnsZero() {
+    jedis.sadd(setKey, setMembers);
+    assertThat(jedis.sdiffstore(destinationKey, 
nonExistentSetKey)).isEqualTo(0);
+    assertThat(jedis.smembers(destinationKey)).isEmpty();

Review comment:
       Rather than asserting that an smembers call on the destination returns 
an empty set, a better check would be that calling 
`jedis.exists(destinationKey)` returns false, because we shouldn't ever have a 
set that exists, but is empty. This applies to all other places in this test 
where you want to check that the result of the diff is an empty set.




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