New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CLI: Close subcommands in MultiCommand #28954
Changes from 4 commits
39770da
be11085
bf6a3eb
33d78c4
63c3656
52a71d9
ee04957
103d175
050a9f1
b2ece8a
99dd6ce
4b42afd
6eb66e7
91d785e
862090e
f098095
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,14 @@ | |
|
||
import joptsimple.OptionSet; | ||
import org.junit.Before; | ||
import org.mockito.Mockito; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.spy; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
public class MultiCommandTests extends CommandTestCase { | ||
|
||
|
@@ -102,4 +110,32 @@ public void testSubcommandArguments() throws Exception { | |
assertFalse(output, output.contains("command1")); | ||
assertTrue(output, output.contains("Arguments: [foo, bar]")); | ||
} | ||
|
||
public void testClose() throws Exception { | ||
Command spySubCommand1 = spy(new DummySubCommand()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like mockito when it is necessary but sometimes it isn't and I feel that way here. I'd suggest having an AtomicBoolean or AtomicInteger that gets modified in the close method of a anonymous Command class. Then you can assert on that value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, Thank you. |
||
Command spySubCommand2 = spy(new DummySubCommand()); | ||
multiCommand.subcommands.put("command1", spySubCommand1); | ||
multiCommand.subcommands.put("command2", spySubCommand2); | ||
multiCommand.close(); | ||
verify(spySubCommand1, times(1)).close(); | ||
verify(spySubCommand2, times(1)).close(); | ||
} | ||
|
||
public void testCloseWhenSubCommandCloseThrowsException() throws Exception { | ||
Command subCommand1 = mock(DummySubCommand.class); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment about not really needing mockito There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, Thank you. |
||
Mockito.doThrow(new IOException()).when(subCommand1).close(); | ||
Command spySubCommand2 = spy(new DummySubCommand()); | ||
multiCommand.subcommands.put("command1", subCommand1); | ||
multiCommand.subcommands.put("command2", spySubCommand2); | ||
IOException ioe = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Thank you. |
||
try { | ||
multiCommand.close(); | ||
} catch (IOException e) { | ||
ioe = e; | ||
} | ||
// verify exception is thrown, as well as other non failed sub-commands closed | ||
// properly. | ||
assertNotNull("Expected IOException", ioe); | ||
verify(spySubCommand2, times(1)).close(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should copy this here. I think if we are going to copy it, it should be available everywhere and replace the usage of the Lucene
IOUtils
. I opened #29012.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, Jason. I was not sure if we needed other utils but looks like from your description of the PR there are others who use the same across source code.
Just one question, around can CLI be dependent on elasticsearch-core? In current project dependencies, it is not listed. I can update my change to depend on the internal IOUtils.