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-8668: Implement Redis SELECT command (apache#5682)
- Loading branch information
Showing
9 changed files
with
202 additions
and
23 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
33 changes: 33 additions & 0 deletions
33
.../org/apache/geode/redis/internal/executor/connection/SelectNativeRedisAcceptanceTest.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,33 @@ | ||
/* | ||
* 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.connection; | ||
|
||
import org.junit.ClassRule; | ||
|
||
import org.apache.geode.NativeRedisTestRule; | ||
|
||
public class SelectNativeRedisAcceptanceTest extends AbstractSelectIntegrationTest { | ||
|
||
@ClassRule | ||
public static NativeRedisTestRule redis = new NativeRedisTestRule(); | ||
|
||
@Override | ||
public int getPort() { | ||
return redis.getPort(); | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
...va/org/apache/geode/redis/internal/executor/connection/AbstractSelectIntegrationTest.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,63 @@ | ||
/* | ||
* 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.connection; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import redis.clients.jedis.Jedis; | ||
import redis.clients.jedis.Protocol; | ||
|
||
import org.apache.geode.test.awaitility.GeodeAwaitility; | ||
import org.apache.geode.test.dunit.rules.RedisPortSupplier; | ||
|
||
public abstract class AbstractSelectIntegrationTest implements RedisPortSupplier { | ||
|
||
private static final int REDIS_CLIENT_TIMEOUT = | ||
Math.toIntExact(GeodeAwaitility.getTimeout().toMillis()); | ||
protected static Jedis jedis; | ||
|
||
@Before | ||
public void setUp() { | ||
jedis = new Jedis("localhost", getPort(), REDIS_CLIENT_TIMEOUT); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
jedis.close(); | ||
} | ||
|
||
@Test | ||
public void givenLessThanTwoArguments_returnsWrongNumberOfArgumentsError() { | ||
assertThatThrownBy(() -> jedis.sendCommand(Protocol.Command.SELECT)) | ||
.hasMessage("ERR wrong number of arguments for 'select' command"); | ||
} | ||
|
||
@Test | ||
public void givenMoreThanTwoArguments_returnsWrongNumberOfArgumentsError() { | ||
assertThatThrownBy(() -> jedis.sendCommand(Protocol.Command.SELECT, "notALong", "extraArg")) | ||
.hasMessage("ERR wrong number of arguments for 'select' command"); | ||
} | ||
|
||
@Test | ||
public void givenIndexOfZero_returnsOk() { | ||
assertThat(jedis.select(0)).isEqualTo("OK"); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...nTest/java/org/apache/geode/redis/internal/executor/connection/SelectIntegrationTest.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,44 @@ | ||
/* | ||
* 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.connection; | ||
|
||
import static org.apache.geode.redis.internal.RedisConstants.ERROR_SELECT; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import redis.clients.jedis.Protocol; | ||
|
||
import org.apache.geode.redis.GeodeRedisServerRule; | ||
|
||
public class SelectIntegrationTest extends AbstractSelectIntegrationTest { | ||
|
||
@ClassRule | ||
public static GeodeRedisServerRule server = new GeodeRedisServerRule(); | ||
|
||
@Override | ||
public int getPort() { | ||
return server.getPort(); | ||
} | ||
|
||
// our SELECT implementation diverges from Redis and only supports DB 0 | ||
@Test | ||
public void givenAnyDBIndexOtherThanZero_returnsSelectError() { | ||
assertThatThrownBy(() -> jedis.sendCommand(Protocol.Command.SELECT, "9223372036854775807")) | ||
.hasMessageContaining(ERROR_SELECT); | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
...dis/src/main/java/org/apache/geode/redis/internal/executor/connection/SelectExecutor.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,38 @@ | ||
/* | ||
* 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.connection; | ||
|
||
import static org.apache.geode.redis.internal.RedisConstants.ERROR_SELECT; | ||
|
||
import org.apache.geode.redis.internal.executor.AbstractExecutor; | ||
import org.apache.geode.redis.internal.executor.RedisResponse; | ||
import org.apache.geode.redis.internal.netty.Command; | ||
import org.apache.geode.redis.internal.netty.ExecutionHandlerContext; | ||
|
||
public class SelectExecutor extends AbstractExecutor { | ||
|
||
@Override | ||
public RedisResponse executeCommand(Command command, ExecutionHandlerContext context) { | ||
String dbIndexString = command.getStringKey(); | ||
|
||
if (!dbIndexString.equals("0")) { | ||
return RedisResponse.error(ERROR_SELECT); | ||
} | ||
|
||
return RedisResponse.ok(); | ||
} | ||
|
||
} |
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