Skip to content

Commit

Permalink
GEODE-7947 Implement tests for EXPIRE-related functionality (#4904)
Browse files Browse the repository at this point in the history
* 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
3 people committed Apr 6, 2020
1 parent d4b7c14 commit 1b1ad6b
Show file tree
Hide file tree
Showing 19 changed files with 544 additions and 52 deletions.
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();
}

}
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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class GeoDockerAcceptanceTest extends GeoIntegrationTest {

@BeforeClass
public static void setUp() {
GenericContainer redisContainer = new GenericContainer("redis:5.0.6").withExposedPorts(6379);
GenericContainer redisContainer = new GenericContainer<>("redis:5.0.6").withExposedPorts(6379);
redisContainer.start();
jedis = new Jedis("localhost", redisContainer.getFirstMappedPort(), 10000000);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class HashesDockerAcceptanceTest extends HashesIntegrationTest {

@BeforeClass
public static void setUp() {
GenericContainer redisContainer = new GenericContainer("redis:5.0.6").withExposedPorts(6379);
GenericContainer redisContainer = new GenericContainer<>("redis:5.0.6").withExposedPorts(6379);
redisContainer.start();
rand = new Random();
jedis = new Jedis("localhost", redisContainer.getFirstMappedPort(), 10000000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ListsDockerAcceptanceTest extends ListsIntegrationTest {

@BeforeClass
public static void setUp() {
GenericContainer redisContainer = new GenericContainer("redis:5.0.6").withExposedPorts(6379);
GenericContainer redisContainer = new GenericContainer<>("redis:5.0.6").withExposedPorts(6379);
redisContainer.start();
jedis = new Jedis("localhost", redisContainer.getFirstMappedPort(), 10000000);
}
Expand Down
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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class PubSubDockerAcceptanceTest extends PubSubIntegrationTest {

@BeforeClass
public static void setUp() {
redisContainer = new GenericContainer("redis:5.0.6").withExposedPorts(6379);
redisContainer = new GenericContainer<>("redis:5.0.6").withExposedPorts(6379);
redisContainer.start();
subscriber = new Jedis("localhost", redisContainer.getFirstMappedPort(), REDIS_CLIENT_TIMEOUT);
publisher = new Jedis("localhost", redisContainer.getFirstMappedPort(), REDIS_CLIENT_TIMEOUT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class RenameDockerAcceptanceTest extends RenameIntegrationTest {
@BeforeClass
public static void setUp() {
rand = new Random();
redisContainer = new GenericContainer("redis:5.0.6").withExposedPorts(6379);
redisContainer = new GenericContainer<>("redis:5.0.6").withExposedPorts(6379);
redisContainer.start();
jedis = new Jedis("localhost", redisContainer.getFirstMappedPort(), REDIS_CLIENT_TIMEOUT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class SetsDockerAcceptanceTest extends SetsIntegrationTest {

@BeforeClass
public static void setUp() {
GenericContainer redisContainer = new GenericContainer("redis:5.0.6").withExposedPorts(6379);
GenericContainer redisContainer = new GenericContainer<>("redis:5.0.6").withExposedPorts(6379);
redisContainer.start();
jedis = new Jedis("localhost", redisContainer.getFirstMappedPort(), 10000000);
jedis2 = new Jedis("localhost", redisContainer.getFirstMappedPort(), 10000000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class SortedSetsDockerAcceptanceTest extends SortedSetsIntegrationTest {

@BeforeClass
public static void setUp() {
GenericContainer redisContainer = new GenericContainer("redis:5.0.6").withExposedPorts(6379);
GenericContainer redisContainer = new GenericContainer<>("redis:5.0.6").withExposedPorts(6379);
redisContainer.start();
jedis = new Jedis("localhost", redisContainer.getFirstMappedPort(), 10000000);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class StringsDockerAcceptanceTest extends StringsIntegrationTest {

@BeforeClass
public static void setUp() {
GenericContainer redisContainer = new GenericContainer("redis:5.0.6").withExposedPorts(6379);
GenericContainer redisContainer = new GenericContainer<>("redis:5.0.6").withExposedPorts(6379);
redisContainer.start();
rand = new Random();
jedis = new Jedis("localhost", redisContainer.getFirstMappedPort(), 10000000);
Expand Down
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
import static org.assertj.core.api.Assertions.assertThat;

import java.util.Random;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
Expand All @@ -37,25 +35,23 @@

public class ExpireIntegrationTest {

private static Jedis jedis;
public static Jedis jedis;
public static int REDIS_CLIENT_TIMEOUT = 10000000;
private static GeodeRedisServer server;
private static GemFireCache cache;
private static Random rand;
private static int port = 6379;

@BeforeClass
public static void setUp() {
rand = new Random();
CacheFactory cf = new CacheFactory();
cf.set(LOG_LEVEL, "error");
cf.set(MCAST_PORT, "0");
cf.set(LOCATORS, "");
cache = cf.create();
port = AvailablePortHelper.getRandomAvailableTCPPort();
int port = AvailablePortHelper.getRandomAvailableTCPPort();
server = new GeodeRedisServer("localhost", port);

server.start();
jedis = new Jedis("localhost", port, 10000000);
jedis = new Jedis("localhost", port, REDIS_CLIENT_TIMEOUT);
}

@After
Expand All @@ -64,7 +60,7 @@ public void flushAll() {
}

@AfterClass
public static void tearDown() {
public static void classLevelTearDown() {
jedis.close();
cache.close();
server.shutdown();
Expand Down

0 comments on commit 1b1ad6b

Please sign in to comment.