nonbinaryprogrammer commented on a change in pull request #6534: URL: https://github.com/apache/geode/pull/6534#discussion_r643568926
########## File path: geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/sortedset/AbstractZIncrByIntegrationTest.java ########## @@ -0,0 +1,290 @@ +/* + * 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 java.lang.Double.NEGATIVE_INFINITY; +import static java.lang.Double.POSITIVE_INFINITY; +import static org.apache.geode.redis.RedisCommandArgumentsTestHelper.assertExactNumberOfArgs; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.util.concurrent.ThreadLocalRandom; + +import com.google.common.util.concurrent.AtomicDouble; +import org.assertj.core.data.Offset; +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +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; +import org.apache.geode.redis.internal.RedisConstants; + +public abstract class AbstractZIncrByIntegrationTest implements RedisIntegrationTest { + JedisCluster jedis; + final byte[] KEY = "key".getBytes(); + final String STRING_KEY = "key"; + final byte[] MEMBER = "member".getBytes(); + final String STRING_MEMBER = "member"; + + @Before + public void setUp() { + jedis = new JedisCluster(new HostAndPort("localhost", getPort()), REDIS_CLIENT_TIMEOUT); + } + + @After + public void tearDown() { + flushAll(); + jedis.close(); + } + + /************* errors *************/ + @Test + public void shouldError_givenWrongKeyType() { + jedis.set(STRING_KEY, "value"); + assertThatThrownBy( + () -> jedis.sendCommand(STRING_KEY, Protocol.Command.ZINCRBY, STRING_KEY, "1", "member")) + .hasMessageContaining("WRONGTYPE " + RedisConstants.ERROR_WRONG_TYPE); + } + + @Test + public void shouldError_givenWrongNumberOfArguments() { + jedis.zadd(KEY, 0.0, MEMBER); + assertExactNumberOfArgs(jedis, Protocol.Command.ZINCRBY, 3); + } + + @Test + public void shouldError_givenNonFloatIncrement() { + String nonFloatIncrement = "q"; + jedis.zadd(KEY, 1.0, MEMBER); + + assertThatThrownBy(() -> jedis.sendCommand(STRING_KEY, Protocol.Command.ZINCRBY, STRING_KEY, + nonFloatIncrement, STRING_MEMBER)) + .hasMessageContaining(RedisConstants.ERROR_NOT_A_VALID_FLOAT); + } + + @Test + public void shouldError_givenNaNIncrement() { + String nanIncrement = "NaN"; + jedis.zadd(STRING_KEY, 1.0, STRING_MEMBER); + + assertThatThrownBy(() -> jedis.sendCommand(STRING_KEY, Protocol.Command.ZINCRBY, STRING_KEY, + nanIncrement, STRING_MEMBER)) + .hasMessageContaining(RedisConstants.ERROR_NOT_A_VALID_FLOAT); + } + + /************* infinity *************/ + @Test + public void shouldSetScoreToInfinity_ifIncrementWouldExceedMaxValue() { + double increment = Double.MAX_VALUE / 2; + + jedis.zadd(STRING_KEY, Double.MAX_VALUE, STRING_MEMBER); + jedis.zincrby(STRING_KEY, increment, STRING_MEMBER); + assertThat(jedis.zscore(STRING_KEY, STRING_MEMBER)).isEqualTo(POSITIVE_INFINITY); + + jedis.zadd(STRING_KEY, -Double.MAX_VALUE, STRING_MEMBER); + jedis.zincrby(STRING_KEY, -increment, STRING_MEMBER); + assertThat(jedis.zscore(STRING_KEY, STRING_MEMBER)).isEqualTo(NEGATIVE_INFINITY); + } + + @Test + public void shouldSetScoreToInfinity_givenInfiniteIncrement() { + jedis.zadd(STRING_KEY, 1.0, STRING_MEMBER); + assertThat(jedis.zincrby(STRING_KEY, POSITIVE_INFINITY, STRING_MEMBER)) + .isEqualTo(POSITIVE_INFINITY); + + jedis.zadd(STRING_KEY, 1.0, STRING_MEMBER); + assertThat(jedis.zincrby(STRING_KEY, NEGATIVE_INFINITY, STRING_MEMBER)) + .isEqualTo(NEGATIVE_INFINITY); + + jedis.zadd(STRING_KEY, 1.0, STRING_MEMBER); + jedis.sendCommand(STRING_KEY, Protocol.Command.ZINCRBY, STRING_KEY, "inf", STRING_MEMBER); + assertThat(jedis.zscore(STRING_KEY, STRING_MEMBER)).isEqualTo(POSITIVE_INFINITY); + + jedis.zadd(STRING_KEY, 1.0, STRING_MEMBER); + jedis.sendCommand(STRING_KEY, Protocol.Command.ZINCRBY, STRING_KEY, "+inf", STRING_MEMBER); + assertThat(jedis.zscore(STRING_KEY, STRING_MEMBER)).isEqualTo(POSITIVE_INFINITY); + + jedis.zadd(STRING_KEY, 1.0, STRING_MEMBER); + jedis.sendCommand(STRING_KEY, Protocol.Command.ZINCRBY, STRING_KEY, "-inf", STRING_MEMBER); + assertThat(jedis.zscore(STRING_KEY, STRING_MEMBER)).isEqualTo(NEGATIVE_INFINITY); + + jedis.zadd(STRING_KEY, 1.0, STRING_MEMBER); + jedis.sendCommand(STRING_KEY, Protocol.Command.ZINCRBY, STRING_KEY, "Infinity", STRING_MEMBER); + assertThat(jedis.zscore(STRING_KEY, STRING_MEMBER)).isEqualTo(POSITIVE_INFINITY); + + jedis.zadd(STRING_KEY, 1.0, STRING_MEMBER); + jedis.sendCommand(STRING_KEY, Protocol.Command.ZINCRBY, STRING_KEY, "+Infinity", STRING_MEMBER); + assertThat(jedis.zscore(STRING_KEY, STRING_MEMBER)).isEqualTo(POSITIVE_INFINITY); + + jedis.zadd(STRING_KEY, 1.0, STRING_MEMBER); + jedis.sendCommand(STRING_KEY, Protocol.Command.ZINCRBY, STRING_KEY, "-Infinity", STRING_MEMBER); + assertThat(jedis.zscore(STRING_KEY, STRING_MEMBER)).isEqualTo(NEGATIVE_INFINITY); + } + + @Test + public void nullRedisSetShouldCreateNonExistentMember_withIncrementOfPositiveInfinity() { Review comment: Line 145 uses "something" as the member, then 147 uses the `MEMBER` constant. I have to do that first zadd to initialize the key and sorted set, then the second one creates the member -- 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