forked from apache/geode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GEODE-9826: SCARD command supported (apache#7160)
- Loading branch information
Showing
8 changed files
with
176 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...org/apache/geode/redis/internal/commands/executor/set/SCardNativeRedisAcceptanceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* 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 org.junit.ClassRule; | ||
|
||
import org.apache.geode.redis.NativeRedisClusterTestRule; | ||
|
||
public class SCardNativeRedisAcceptanceTest extends AbstractSCardIntegrationTest { | ||
@ClassRule | ||
public static NativeRedisClusterTestRule redis = new NativeRedisClusterTestRule(); | ||
|
||
@Override | ||
public int getPort() { | ||
return redis.getExposedPorts().get(0); | ||
} | ||
|
||
@Override | ||
public void flushAll() { | ||
redis.flushAll(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
...a/org/apache/geode/redis/internal/commands/executor/set/AbstractSCardIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* 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.assertExactNumberOfArgs; | ||
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.assertThatThrownBy; | ||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
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 AbstractSCardIntegrationTest implements RedisIntegrationTest { | ||
private JedisCluster jedis; | ||
private static final String key = "{user1}setKey"; | ||
|
||
@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 scardWrongNumOfArgs_returnsError() { | ||
assertExactNumberOfArgs(jedis, Protocol.Command.SCARD, 1); | ||
} | ||
|
||
@Test | ||
public void scardSet_returnsSize() { | ||
String[] values = new String[] {"Jeff", "Natalie", "Michelle", "Joe", "Kelley"}; | ||
jedis.sadd(key, values); | ||
assertThat(jedis.scard(key)).isEqualTo(values.length); | ||
} | ||
|
||
@Test | ||
public void scardNonExistentSet_returnsZero() { | ||
assertThat(jedis.scard("{user1}nonExistentSet")).isEqualTo(0); | ||
} | ||
|
||
@Test | ||
public void scardAfterSadd_returnsSize() { | ||
String[] valuesInitial = new String[] {"Jeff", "Natalie", "Michelle", "Joe", "Kelley"}; | ||
String[] valuesToAdd = new String[] {"one", "two", "three"}; | ||
|
||
jedis.sadd(key, valuesInitial); | ||
long size = jedis.scard(key); | ||
assertThat(size).isEqualTo(valuesInitial.length); | ||
jedis.sadd(key, valuesToAdd); | ||
assertThat(jedis.scard(key)).isEqualTo(size + valuesToAdd.length); | ||
} | ||
|
||
|
||
@Test | ||
public void scardWithConcurrentSAdd_returnsCorrectValue() { | ||
String[] valuesInitial = new String[] {"one", "two", "three"}; | ||
String[] valuesToAdd = new String[] {"pear", "apple", "plum", "orange", "peach"}; | ||
jedis.sadd(key, valuesInitial); | ||
|
||
final AtomicLong scardReference = new AtomicLong(); | ||
new ConcurrentLoopingThreads(1000, | ||
i -> jedis.sadd(key, valuesToAdd), | ||
i -> scardReference.set(jedis.scard(key))) | ||
.runWithAction(() -> { | ||
assertThat(scardReference).satisfiesAnyOf( | ||
scardResult -> assertThat(scardResult.get()).isEqualTo(valuesInitial.length), | ||
scardResult -> assertThat(scardResult.get()) | ||
.isEqualTo(valuesInitial.length + valuesToAdd.length)); | ||
jedis.srem(key, valuesToAdd); | ||
}); | ||
} | ||
|
||
@Test | ||
public void scardWithWrongKeyType_returnsWrongTypeError() { | ||
jedis.set("ding", "dong"); | ||
assertThatThrownBy(() -> jedis.scard("ding")).hasMessageContaining(ERROR_WRONG_TYPE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...Test/java/org/apache/geode/redis/internal/commands/executor/set/SCardIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* 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 org.junit.ClassRule; | ||
|
||
import org.apache.geode.redis.GeodeRedisServerRule; | ||
|
||
public class SCardIntegrationTest extends AbstractSCardIntegrationTest { | ||
@ClassRule | ||
public static GeodeRedisServerRule server = new GeodeRedisServerRule(); | ||
|
||
@Override | ||
public int getPort() { | ||
return server.getPort(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters