-
Notifications
You must be signed in to change notification settings - Fork 683
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GEODE-7947 Implement tests for EXPIRE-related functionality (#4904)
* GEODE-7947 Implement tests for EXPIRE-related functionality Co-authored-by: John Hutchison <jhutchison@pivotal.io> Co-authored-by: Sarah <sabbey@pivotal.io>
- Loading branch information
1 parent
d4b7c14
commit 1b1ad6b
Showing
19 changed files
with
544 additions
and
52 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
geode-redis/src/acceptanceTest/java/org/apache/geode/redis/ExpireAtDockerAcceptanceTest.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,42 @@ | ||
/* | ||
* 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; | ||
|
||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.experimental.categories.Category; | ||
import org.testcontainers.containers.GenericContainer; | ||
import redis.clients.jedis.Jedis; | ||
|
||
import org.apache.geode.redis.general.ExpireAtIntegrationTest; | ||
import org.apache.geode.test.junit.categories.RedisTest; | ||
|
||
@Category({RedisTest.class}) | ||
public class ExpireAtDockerAcceptanceTest extends ExpireAtIntegrationTest { | ||
|
||
@BeforeClass | ||
public static void setUp() { | ||
GenericContainer redisContainer = new GenericContainer<>("redis:5.0.6").withExposedPorts(6379); | ||
redisContainer.start(); | ||
jedis = new Jedis("localhost", redisContainer.getFirstMappedPort(), REDIS_CLIENT_TIMEOUT); | ||
} | ||
|
||
@AfterClass | ||
public static void classLevelTearDown() { | ||
jedis.close(); | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
geode-redis/src/acceptanceTest/java/org/apache/geode/redis/ExpireDockerAcceptanceTest.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; | ||
|
||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.experimental.categories.Category; | ||
import org.testcontainers.containers.GenericContainer; | ||
import redis.clients.jedis.Jedis; | ||
|
||
import org.apache.geode.redis.general.ExpireIntegrationTest; | ||
import org.apache.geode.test.junit.categories.RedisTest; | ||
|
||
@Category({RedisTest.class}) | ||
public class ExpireDockerAcceptanceTest extends ExpireIntegrationTest { | ||
|
||
private static GenericContainer redisContainer; | ||
|
||
@BeforeClass | ||
public static void setUp() { | ||
redisContainer = new GenericContainer<>("redis:5.0.6").withExposedPorts(6379); | ||
redisContainer.start(); | ||
jedis = new Jedis("localhost", redisContainer.getFirstMappedPort(), REDIS_CLIENT_TIMEOUT); | ||
} | ||
|
||
@AfterClass | ||
public static void classLevelTearDown() { | ||
jedis.close(); | ||
} | ||
|
||
} |
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
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
44 changes: 44 additions & 0 deletions
44
geode-redis/src/acceptanceTest/java/org/apache/geode/redis/PexpireDockerAcceptanceTest.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; | ||
|
||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.experimental.categories.Category; | ||
import org.testcontainers.containers.GenericContainer; | ||
import redis.clients.jedis.Jedis; | ||
|
||
import org.apache.geode.redis.general.PexpireIntegrationTest; | ||
import org.apache.geode.test.junit.categories.RedisTest; | ||
|
||
@Category({RedisTest.class}) | ||
public class PexpireDockerAcceptanceTest extends PexpireIntegrationTest { | ||
|
||
private static GenericContainer redisContainer; | ||
|
||
@BeforeClass | ||
public static void setUp() { | ||
redisContainer = new GenericContainer<>("redis:5.0.6").withExposedPorts(6379); | ||
redisContainer.start(); | ||
jedis = new Jedis("localhost", redisContainer.getFirstMappedPort(), REDIS_CLIENT_TIMEOUT); | ||
} | ||
|
||
@AfterClass | ||
public static void classLevelTearDown() { | ||
jedis.close(); | ||
} | ||
|
||
} |
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
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
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
128 changes: 128 additions & 0 deletions
128
...edis/src/integrationTest/java/org/apache/geode/redis/general/ExpireAtIntegrationTest.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,128 @@ | ||
/* | ||
* 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.general; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.After; | ||
import org.junit.AfterClass; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import redis.clients.jedis.Jedis; | ||
|
||
import org.apache.geode.internal.AvailablePortHelper; | ||
import org.apache.geode.redis.GeodeRedisServer; | ||
import org.apache.geode.test.awaitility.GeodeAwaitility; | ||
|
||
public class ExpireAtIntegrationTest { | ||
|
||
public static Jedis jedis; | ||
public static int REDIS_CLIENT_TIMEOUT = 10000000; | ||
private static GeodeRedisServer server; | ||
private long unixTimeStampInTheFutureInSeconds; | ||
private long unixTimeStampFromThePast = 0L; | ||
String key = "key"; | ||
String value = "value"; | ||
|
||
@BeforeClass | ||
public static void setUp() { | ||
int port = AvailablePortHelper.getRandomAvailableTCPPort(); | ||
|
||
server = new GeodeRedisServer("localhost", port); | ||
server.start(); | ||
jedis = new Jedis("localhost", port, REDIS_CLIENT_TIMEOUT); | ||
} | ||
|
||
@Before | ||
public void testSetUp() { | ||
unixTimeStampInTheFutureInSeconds = (System.currentTimeMillis() / 1000) + 60; | ||
} | ||
|
||
|
||
@After | ||
public void testLevelTearDown() { | ||
jedis.flushAll(); | ||
} | ||
|
||
@AfterClass | ||
public static void classLevelTearDown() { | ||
jedis.close(); | ||
server.shutdown(); | ||
} | ||
|
||
@Test | ||
public void should_return_1_given_validKey_andTimeStampInThePast() { | ||
jedis.set(key, value); | ||
|
||
Long result = jedis.expireAt(key, unixTimeStampFromThePast); | ||
|
||
assertThat(result).isEqualTo(1L); | ||
} | ||
|
||
@Test | ||
public void should_delete_key_given_aTimeStampInThePast() { | ||
jedis.set(key, value); | ||
|
||
jedis.expireAt(key, unixTimeStampFromThePast); | ||
|
||
assertThat(jedis.get(key)).isNull(); | ||
} | ||
|
||
@Test | ||
public void should_return_0_given_nonExistentKey_andTimeStampInFuture() { | ||
String non_existent_key = "I don't exist"; | ||
|
||
long result = jedis.expireAt( | ||
non_existent_key, | ||
unixTimeStampInTheFutureInSeconds); | ||
|
||
assertThat(result).isEqualTo(0); | ||
} | ||
|
||
@Test | ||
public void should_return_0_given_nonExistentKey_andTimeStampInPast() { | ||
String non_existent_key = "I don't exist"; | ||
|
||
long result = jedis.expireAt( | ||
non_existent_key, | ||
unixTimeStampFromThePast); | ||
|
||
assertThat(result).isEqualTo(0); | ||
} | ||
|
||
@Test | ||
public void should_return_1_given_validKey_andValidTimeStampInFuture() { | ||
|
||
jedis.set(key, value); | ||
|
||
long result = jedis.expireAt( | ||
key, | ||
unixTimeStampInTheFutureInSeconds); | ||
|
||
assertThat(result).isEqualTo(1); | ||
} | ||
|
||
@Test | ||
public void should_expireKeyAtTimeSpecified() { | ||
long unixTimeStampInTheNearFuture = (System.currentTimeMillis() / 1000) + 5; | ||
jedis.set(key, value); | ||
jedis.expireAt(key, unixTimeStampInTheNearFuture); | ||
|
||
GeodeAwaitility.await().until( | ||
() -> jedis.get(key) == null); | ||
} | ||
} |
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
Oops, something went wrong.