Skip to content

Commit

Permalink
Test for TranscodeService.
Browse files Browse the repository at this point in the history
  • Loading branch information
dustin committed Sep 6, 2009
1 parent c4fd35d commit f850e9d
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
Expand Up @@ -50,6 +50,13 @@ public void shutdown() {
pool.shutdown();
}

/**
* Ask whether this service has been shut down.
*/
public boolean isShutdown() {
return pool.isShutdown();
}

private static class Task<T> extends FutureTask<T> {
private final AtomicBoolean isRunning = new AtomicBoolean(false);

Expand Down Expand Up @@ -77,4 +84,5 @@ public void run() {
}
}
}

}
@@ -0,0 +1,59 @@
package net.spy.memcached.transcoders;

import java.util.concurrent.Future;

import junit.framework.TestCase;
import net.spy.memcached.CachedData;

/**
* Test the transcode service.
*/
public class TranscodeServiceTest extends TestCase {

private TranscodeService ts = null;

@Override
protected void setUp() throws Exception {
super.setUp();
ts = new TranscodeService();
}

@Override
protected void tearDown() throws Exception {
ts.shutdown();
assertTrue(ts.isShutdown());
super.tearDown();
}

public void testNonExecuting() throws Exception {
CachedData cd = new CachedData(0, new byte[0], 0);
Future<String> fs = ts.decode(new TestTranscoder(), cd);
assertEquals("Stuff!", fs.get());
}

public void testExecuting() throws Exception {
CachedData cd = new CachedData(1, new byte[0], 0);
Future<String> fs = ts.decode(new TestTranscoder(), cd);
assertEquals("Stuff!", fs.get());
}

private static final class TestTranscoder implements Transcoder<String> {

public boolean asyncDecode(CachedData d) {
return d.getFlags() == 1;
}

public String decode(CachedData d) {
return "Stuff!";
}

public CachedData encode(String o) {
throw new RuntimeException("Not invoked.");
}

public int getMaxSize() {
return 5;
}

}
}

0 comments on commit f850e9d

Please sign in to comment.