adding some unit tests.
This commit is contained in:
parent
7d014da700
commit
0ed91f953a
4 changed files with 22 additions and 2 deletions
|
|
@ -7,7 +7,7 @@ public class ShutdownRequestedMessage extends Message {
|
|||
/**
|
||||
* The name used for the action field in {@link Message}.
|
||||
*/
|
||||
public static final String ACTION = "shutdownrequested";
|
||||
public static final String ACTION = "shutdownRequested";
|
||||
|
||||
/**
|
||||
* Convenience constructor.
|
||||
|
|
|
|||
|
|
@ -113,6 +113,16 @@ public class MessageWriterTest {
|
|||
Mockito.verify(this.stream, Mockito.atLeastOnce()).flush();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeShutdownRequestedMessageTest() throws IOException, InterruptedException, ExecutionException {
|
||||
Future<Boolean> future = this.messageWriter.writeShutdownRequestedMessage();
|
||||
future.get();
|
||||
|
||||
Mockito.verify(this.stream, Mockito.atLeastOnce()).write(Mockito.any(byte[].class), Mockito.anyInt(),
|
||||
Mockito.anyInt());
|
||||
Mockito.verify(this.stream, Mockito.atLeastOnce()).flush();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void streamIOExceptionTest() throws IOException, InterruptedException, ExecutionException {
|
||||
Mockito.doThrow(IOException.class).when(stream).flush();
|
||||
|
|
|
|||
|
|
@ -114,6 +114,16 @@ public class MultiLangProtocolTest {
|
|||
assertThat(protocol.shutdown(null, ShutdownReason.ZOMBIE), equalTo(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shutdownRequestedTest() {
|
||||
when(messageWriter.writeShutdownRequestedMessage()).thenReturn(buildFuture(true));
|
||||
when(messageReader.getNextMessageFromSTDOUT()).thenReturn(buildFuture(new StatusMessage("shutdownRequested"), Message.class));
|
||||
Mockito.doReturn(buildFuture(true)).when(messageWriter)
|
||||
.writeShutdownRequestedMessage();
|
||||
Mockito.doReturn(buildFuture(new StatusMessage("shutdownRequested"))).when(messageReader).getNextMessageFromSTDOUT();
|
||||
assertThat(protocol.shutdownRequested(null), equalTo(true));
|
||||
}
|
||||
|
||||
private Answer<Future<Message>> buildMessageAnswers(List<Message> messages) {
|
||||
return new Answer<Future<Message>>() {
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ public class MessageTest {
|
|||
});
|
||||
}
|
||||
})), new ShutdownMessage(ShutdownReason.ZOMBIE), new StatusMessage("processRecords"),
|
||||
new InitializeMessage(), new ProcessRecordsMessage() };
|
||||
new InitializeMessage(), new ProcessRecordsMessage(), new ShutdownRequestedMessage() };
|
||||
|
||||
for (int i = 0; i < messages.length; i++) {
|
||||
Assert.assertTrue("Each message should contain the action field", messages[i].toString().contains("action"));
|
||||
|
|
|
|||
Loading…
Reference in a new issue