Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
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
59 changes: 59 additions & 0 deletions
59
src/test/java/net/spy/memcached/transcoders/TranscodeServiceTest.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,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; | ||
} | ||
|
||
} | ||
} |