EP / tokyotyrant-java (http://code.google.com/p/tokyotyrant-java)
Java client for Tokyo Tyrant.
Clone this repository (size: 503.6 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/EP/tokyotyrant-java/
| commit 214: | 36980b4d678d |
| parent 213: | 01fde5b6b2dc |
| branch: | default |
Refactor test code.
11 months ago
Changed (Δ681 bytes):
raw changeset »
src/main/java/tokyotyrant/protocol/CommandFuture.java (0 lines added, 4 lines removed)
src/test/java/tokyotyrant/protocol/CommandFutureTest.java (16 lines added, 33 lines removed)
Up to file-list src/main/java/tokyotyrant/protocol/CommandFuture.java:
| … | … | @@ -12,10 +12,6 @@ public class CommandFuture<T> implements |
12 |
12 |
private final CountDownLatch latch; |
13 |
13 |
private long globalTimeout; |
14 |
14 |
|
15 |
public CommandFuture(Command<T> command) { |
|
16 |
this(command, Long.MAX_VALUE); |
|
17 |
} |
|
18 |
||
19 |
15 |
public CommandFuture(Command<T> command, long globalTimeout) { |
20 |
16 |
this.command = command; |
21 |
17 |
this.latch = command.getLatch(); |
Up to file-list src/test/java/tokyotyrant/protocol/CommandFutureTest.java:
| … | … | @@ -7,64 +7,47 @@ import java.util.concurrent.Future; |
7 |
7 |
import java.util.concurrent.TimeUnit; |
8 |
8 |
import java.util.concurrent.TimeoutException; |
9 |
9 |
|
10 |
import org.j |
|
10 |
import org.junit.Before; |
|
11 |
11 |
import org.junit.Test; |
12 |
12 |
|
13 |
13 |
public class CommandFutureTest { |
14 |
static class DummyCommand extends Command<Object> { |
|
15 |
public DummyCommand() { |
|
16 |
super((byte) 0xff, null, null); |
|
17 |
} |
|
18 |
||
19 |
public boolean decode(ChannelBuffer in) { |
|
20 |
return true; |
|
21 |
} |
|
14 |
private PingCommand command; |
|
15 |
private Future<Boolean> dut; |
|
22 |
16 |
|
23 |
public void encode(ChannelBuffer out) { |
|
24 |
} |
|
25 |
||
26 |
public Object getReturnValue() { |
|
27 |
return 42; |
|
28 |
} |
|
29 |
|
|
17 |
@Before public void beforeEach() { |
|
18 |
command = new PingCommand(42); |
|
19 |
dut = new CommandFuture<Boolean>(command, Long.MAX_VALUE); |
|
20 |
} |
|
30 |
21 |
|
31 |
22 |
@Test public void whenComplete() throws InterruptedException, ExecutionException { |
32 |
DummyCommand command = new DummyCommand(); |
|
33 |
Future<Object> future = new CommandFuture<Object>(command); |
|
34 |
23 |
assertFalse(command.isReading()); |
35 |
24 |
command.reading(); |
36 |
25 |
assertTrue(command.isReading()); |
37 |
assertFalse( |
|
26 |
assertFalse(dut.isDone()); |
|
38 |
27 |
command.complete(); |
39 |
assertTrue(future.isDone()); |
|
40 |
assertEquals(42, future.get()); |
|
28 |
assertTrue(dut.isDone()); |
|
29 |
assertTrue(dut.get()); |
|
41 |
30 |
} |
42 |
31 |
|
43 |
32 |
@Test(expected=ExecutionException.class) public void whenError() throws InterruptedException, ExecutionException { |
44 |
DummyCommand command = new DummyCommand(); |
|
45 |
Future<Object> future = new CommandFuture<Object>(command); |
|
46 |
33 |
Exception exception = new Exception(); |
47 |
34 |
command.error(exception); |
48 |
35 |
assertTrue(command.hasError()); |
49 |
36 |
assertSame(exception, command.getErrorException()); |
50 |
assertTrue(future.isDone()); |
|
51 |
future.get(); |
|
37 |
assertTrue(dut.isDone()); |
|
38 |
dut.get(); |
|
52 |
39 |
} |
53 |
40 |
|
54 |
41 |
@Test(expected=ExecutionException.class) |
55 |
42 |
public void whenCancel() throws InterruptedException, ExecutionException { |
56 |
DummyCommand command = new DummyCommand(); |
|
57 |
Future<Object> future = new CommandFuture<Object>(command); |
|
58 |
|
|
43 |
dut.cancel(true); |
|
59 |
44 |
assertTrue(command.isCancelled()); |
60 |
assertTrue(future.isDone()); |
|
61 |
future.get(); |
|
45 |
assertTrue(dut.isDone()); |
|
46 |
dut.get(); |
|
62 |
47 |
} |
63 |
48 |
|
64 |
49 |
@Test(expected=TimeoutException.class) |
65 |
50 |
public void getThrowsTimeoutExceptionWhenTimeoutExpired() throws InterruptedException, ExecutionException, TimeoutException { |
66 |
DummyCommand command = new DummyCommand(); |
|
67 |
Future<Object> future = new CommandFuture<Object>(command); |
|
68 |
|
|
51 |
dut.get(10, TimeUnit.MILLISECONDS); |
|
69 |
52 |
} |
70 |
53 |
} |
