Skip to content

Commit

Permalink
Rewrote most methods in Redis Failure class to interact with the stat…
Browse files Browse the repository at this point in the history
…ic redis object in Resque instead of the Resque instance methods. Wrote additional unit tests for Failure
  • Loading branch information
adamjreilly committed Feb 16, 2010
1 parent cedf3d9 commit c40a420
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
10 changes: 5 additions & 5 deletions resque-sharp/Failure/Redis.cs
Expand Up @@ -28,28 +28,28 @@ public override void save()
data.Add("worker", worker.ToString());
data.Add("queue", queue.ToString());

Resque.Push("failed", data);

Resque.redis().RightPush("resque:failed", Resque.encode(data));
}

public override int count()
{
return Resque.size("failed");
return Resque.redis().ListLength("resque:failed");
}

public Byte[][] all(int start, int end)
{
return Resque.redis().ListRange("failed", start, end);
return Resque.redis().ListRange("resque:failed", start, end);
}

public override string url()
{
return Resque.redis().Host;
}

//TODO: Redo this to delete the resque:failure queue from the redis object
public override void clear()
{
Resque.redis().FlushAll();
Resque.redis().Remove("resque:failed");
}
}
}
41 changes: 29 additions & 12 deletions tests/FailureTest.cs
Expand Up @@ -28,8 +28,9 @@ public void Init()
{
// This is the IP address of my computer running Redis.
server = "ec2-184-73-7-218.compute-1.amazonaws.com";
new Redis(server, 6379).FlushAll();

Resque.setRedis(new Redis(server, 6379));
Resque.redis().FlushAll();

Exception ex = new Exception(testString);
Worker worker = new Worker();
Expand All @@ -40,7 +41,7 @@ public void Init()
}

[Test]
public void canCreateFailure()
public void CanCreateFailure()
{

Assert.AreEqual(testString, myRedis.exception.Message);
Expand All @@ -53,19 +54,19 @@ public void canCreateFailure()
}

[Test]
public void canGetURL()
public void CanGetURL()
{
Assert.AreEqual(myRedis.url(), server);
}

[Test]
public void canCheckEmptyQueue()
public void CanCheckEmptyQueue()
{
Assert.AreEqual(0, myRedis.count());
}

[Test]
public void canSaveOnItemToQueue()
public void CanSaveOnItemToQueue()
{
myRedis.save();

Expand All @@ -75,7 +76,7 @@ public void canSaveOnItemToQueue()
}

[Test]
public void canSaveRandomNumberOfItemsToQueue()
public void CanSaveRandomNumberOfItemsToQueue()
{
int random = new System.Random().Next(5, 20);

Expand All @@ -87,24 +88,40 @@ public void canSaveRandomNumberOfItemsToQueue()
Assert.AreEqual(random, myRedis.count());
}

//TODO: Will this clear everything from all queues?
// If so, should probably do one that just clears failures
[Test]
public void canClear()
public void CanClear()
{
int random = new System.Random().Next(5, 20);
int randNumOfJobs = new System.Random().Next(5, 20);

for (int i = 0; i < random; i++)
for (int i = 0; i < randNumOfJobs; i++)
{
myRedis.save();
}

Assert.AreEqual(random, myRedis.count());
Assert.AreEqual(randNumOfJobs, myRedis.count());

myRedis.clear();

Assert.AreEqual(0, myRedis.count());
}

[Test]
public void CanRetrieveAllKeys()
{
int randNumOfJobs = new System.Random().Next(5, 20);

for (int i = 0; i < randNumOfJobs; i++)
{
myRedis.save();
}

Byte[][] allKeys = myRedis.all(0, randNumOfJobs);

Assert.AreEqual(allKeys.Length, randNumOfJobs);

}



}
}

0 comments on commit c40a420

Please sign in to comment.