feat(RedisScheduler) add flush function to clean redis data

add flush function to clean redis data
pull/672/head
chaos 7 years ago
parent e276b11ea9
commit bba7d7184d

@ -126,4 +126,19 @@ public class RedisScheduler extends DuplicateRemovedScheduler implements Monitor
pool.returnResource(jedis);
}
}
/**
* clean all current task redis queue
* @param task current task
*/
public void flush(Task task) {
Jedis jedis = pool.getResource();
try {
jedis.del(getSetKey(task));
jedis.del(getQueueKey(task));
jedis.del(getItemKey(task));
} finally {
pool.returnResource(jedis);
}
}
}

@ -15,16 +15,13 @@ import static org.assertj.core.api.Assertions.assertThat;
public class RedisSchedulerTest {
private RedisScheduler redisScheduler;
private Task task;
@Before
public void setUp() {
redisScheduler = new RedisScheduler("localhost");
}
@Ignore("environment depended")
@Test
public void test() {
Task task = new Task() {
task = new Task() {
@Override
public String getUUID() {
return "1";
@ -35,6 +32,11 @@ public class RedisSchedulerTest {
return null;
}
};
}
@Ignore("environment depended")
@Test
public void test() {
Request request = new Request("http://www.ibm.com/developerworks/cn/java/j-javadev2-22/");
request.putExtra("1","2");
redisScheduler.push(request, task);
@ -42,4 +44,20 @@ public class RedisSchedulerTest {
assertThat(poll).isEqualTo(request);
}
@Ignore("environment depended")
@Test
public void testFlush() {
Request request = new Request("http://www.baidu.com");
request.putExtra("1","2");
redisScheduler.push(request, task);
int totalRequestsCount = redisScheduler.getTotalRequestsCount(task);
assertThat(totalRequestsCount).isGreaterThan(0);
redisScheduler.flush(task);
totalRequestsCount = redisScheduler.getTotalRequestsCount(task);
assertThat(totalRequestsCount).isEqualTo(0);
int leftRequestsCount = redisScheduler.getLeftRequestsCount(task);
assertThat(leftRequestsCount).isEqualTo(0);
}
}

Loading…
Cancel
Save