sabbey37 commented on a change in pull request #6489: URL: https://github.com/apache/geode/pull/6489#discussion_r635584103
########## File path: geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/sortedset/AbstractZAddIntegrationTest.java ########## @@ -0,0 +1,253 @@ +/* + * 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.sortedset; + +import static org.apache.geode.redis.RedisCommandArgumentsTestHelper.assertAtLeastNArgs; +import static org.apache.geode.redis.internal.RedisConstants.ERROR_INVALID_ZADD_OPTION_NX_XX; +import static org.apache.geode.redis.internal.RedisConstants.ERROR_NOT_A_VALID_FLOAT; +import static org.apache.geode.redis.internal.RedisConstants.ERROR_SYNTAX; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import org.assertj.core.api.Assertions; +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 redis.clients.jedis.params.ZAddParams; + +import org.apache.geode.redis.RedisIntegrationTest; +import org.apache.geode.test.awaitility.GeodeAwaitility; + +public abstract class AbstractZAddIntegrationTest implements RedisIntegrationTest { + private JedisCluster jedis; + private static final int REDIS_CLIENT_TIMEOUT = + Math.toIntExact(GeodeAwaitility.getTimeout().toMillis()); + private static final String SORTED_SET_KEY = "ss_key"; + private static final int INITIAL_MEMBER_COUNT = 5; + + @Before + public void setUp() { + jedis = new JedisCluster(new HostAndPort("localhost", getPort()), REDIS_CLIENT_TIMEOUT); + } + + @After + public void tearDown() { + flushAll(); + jedis.close(); + } + + @Test + public void zaddErrors_givenTooFewArguments() { + assertAtLeastNArgs(jedis, Protocol.Command.ZADD, 3); + } + + @Test + public void zaddErrors_givenUnevenPairsOfArguments() { + assertThatThrownBy( + () -> jedis.sendCommand("fakeKey", Protocol.Command.ZADD, "fakeKey", "1", "member", "2")) + .hasMessageContaining("ERR syntax error"); + } + + @Test + public void zaddErrors_givenNonNumericScore() { + assertThatThrownBy( + () -> jedis.sendCommand("fakeKey", Protocol.Command.ZADD, "fakeKey", "xlerb", "member")) + .hasMessageContaining(ERROR_NOT_A_VALID_FLOAT); + } + + @Test + public void zaddErrors_givenBothNXAndXXOptions() { + assertThatThrownBy( + () -> jedis.sendCommand("fakeKey", Protocol.Command.ZADD, "fakeKey", "NX", "XX", "1.0", + "fakeMember")) + .hasMessageContaining(ERROR_INVALID_ZADD_OPTION_NX_XX); + } + + @Test + public void zaddErrors_givenBothNXAndGTOptions() { + assertThatThrownBy( + () -> jedis.sendCommand("fakeKey", Protocol.Command.ZADD, "fakeKey", "NX", "GT", "1.0", + "fakeMember")) + .hasMessageContaining(ERROR_SYNTAX); + } + + @Test + public void zaddErrors_givenBothNXAndLTOptions() { + assertThatThrownBy( + () -> jedis.sendCommand("fakeKey", Protocol.Command.ZADD, "fakeKey", "NX", "GT", "1.0", + "fakeMember")) + .hasMessageContaining(ERROR_SYNTAX); + } Review comment: LT/GT were only introduced in Redis 6.2 and are not part of the spec for 5.x (see my comments further down)... or try replacing LT/GT in your tests with `potato` (or anything that can't be converted to a float), they will still pass in native Redis. -- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org