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-8582: Redis SCAN returns internal server error (apache#5603)
Co-authored-by: Darrel Schneider <[email protected]>
- Loading branch information
1 parent
73f6783
commit bcdf3ca
Showing
5 changed files
with
197 additions
and
18 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
...Test/java/org/apache/geode/redis/internal/executor/key/ScanNativeRedisAcceptanceTest.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,32 @@ | ||
/* | ||
* 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.key; | ||
|
||
import org.junit.ClassRule; | ||
|
||
import org.apache.geode.NativeRedisTestRule; | ||
|
||
public class ScanNativeRedisAcceptanceTest extends AbstractScanIntegrationTest { | ||
|
||
@ClassRule | ||
public static NativeRedisTestRule redis = new NativeRedisTestRule(); | ||
|
||
@Override | ||
public int getPort() { | ||
return redis.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
112 changes: 112 additions & 0 deletions
112
...onTest/java/org/apache/geode/redis/internal/executor/key/AbstractScanIntegrationTest.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,112 @@ | ||
/* | ||
* 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.key; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import redis.clients.jedis.Jedis; | ||
import redis.clients.jedis.ScanParams; | ||
import redis.clients.jedis.ScanResult; | ||
|
||
import org.apache.geode.test.awaitility.GeodeAwaitility; | ||
import org.apache.geode.test.dunit.rules.RedisPortSupplier; | ||
|
||
public abstract class AbstractScanIntegrationTest implements RedisPortSupplier { | ||
|
||
private Jedis jedis; | ||
private static final int REDIS_CLIENT_TIMEOUT = | ||
Math.toIntExact(GeodeAwaitility.getTimeout().toMillis()); | ||
|
||
@Before | ||
public void setUp() { | ||
jedis = new Jedis("localhost", getPort(), REDIS_CLIENT_TIMEOUT); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
jedis.flushAll(); | ||
jedis.close(); | ||
} | ||
|
||
@Test | ||
public void givenOneKey_scanReturnsKey() { | ||
jedis.set("a", "1"); | ||
ScanResult<String> result = jedis.scan("0"); | ||
|
||
assertThat(result.isCompleteIteration()).isTrue(); | ||
assertThat(result.getResult()).containsExactly("a"); | ||
} | ||
|
||
@Test | ||
public void givenEmptyDatabase_scanReturnsEmptyResult() { | ||
ScanResult<String> result = jedis.scan("0"); | ||
|
||
assertThat(result.isCompleteIteration()).isTrue(); | ||
assertThat(result.getResult()).isEmpty(); | ||
} | ||
|
||
@Test | ||
public void givenMultipleKeys_scanReturnsAllKeys() { | ||
jedis.set("a", "1"); | ||
jedis.sadd("b", "green", "orange"); | ||
jedis.hset("c", "potato", "sweet"); | ||
ScanResult<String> result = jedis.scan("0"); | ||
|
||
assertThat(result.isCompleteIteration()).isTrue(); | ||
assertThat(result.getResult()).containsExactlyInAnyOrder("a", "b", "c"); | ||
} | ||
|
||
@Test | ||
public void givenMultipleKeysWithCount_scanReturnsAllKeysWithoutDuplicates() { | ||
jedis.set("a", "1"); | ||
jedis.sadd("b", "green", "orange"); | ||
jedis.hset("c", "potato", "sweet"); | ||
ScanParams scanParams = new ScanParams(); | ||
scanParams.count(1); | ||
|
||
ScanResult<String> result = jedis.scan("0", scanParams); | ||
List<String> allKeysFromScan = new ArrayList<>(); | ||
allKeysFromScan.addAll(result.getResult()); | ||
|
||
while (!result.isCompleteIteration()) { | ||
result = jedis.scan(result.getCursor(), scanParams); | ||
allKeysFromScan.addAll(result.getResult()); | ||
} | ||
|
||
assertThat(result.isCompleteIteration()).isTrue(); | ||
assertThat(allKeysFromScan).containsExactlyInAnyOrder("a", "b", "c"); | ||
} | ||
|
||
@Test | ||
public void givenMultipleKeysWithMatch_scanReturnsAllMatchingKeysWithoutDuplicates() { | ||
jedis.set("a", "1"); | ||
jedis.sadd("b", "green", "orange"); | ||
jedis.hset("c", "potato", "sweet"); | ||
ScanParams scanParams = new ScanParams(); | ||
scanParams.match("a*"); | ||
|
||
ScanResult<String> result = jedis.scan("0", scanParams); | ||
|
||
assertThat(result.isCompleteIteration()).isTrue(); | ||
assertThat(result.getResult()).containsExactly("a"); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...ntegrationTest/java/org/apache/geode/redis/internal/executor/key/ScanIntegrationTest.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,32 @@ | ||
/* | ||
* 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.key; | ||
|
||
import org.junit.ClassRule; | ||
|
||
import org.apache.geode.redis.GeodeRedisServerRule; | ||
|
||
public class ScanIntegrationTest extends AbstractScanIntegrationTest { | ||
|
||
@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