Skip to content

Commit

Permalink
Throw an error if the key was not specified for querying state (apach…
Browse files Browse the repository at this point in the history
  • Loading branch information
liketic authored and merlimat committed Sep 8, 2019
1 parent 44dcc5b commit c50abe8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,29 @@ public void testStateGetter() throws Exception {
verify(functions, times(1)).getFunctionState(eq(tenant), eq(namespace), eq(fnName), eq(key));
}

@Test
public void testStateGetterWithoutKey() throws Exception {
String tenant = TEST_NAME + "-tenant";
String namespace = TEST_NAME + "-namespace";
String fnName = TEST_NAME + "-function";
ConsoleOutputCapturer consoleOutputCapturer = new ConsoleOutputCapturer();
consoleOutputCapturer.start();
cmd.run(new String[] {
"querystate",
"--tenant", tenant,
"--namespace", namespace,
"--name", fnName,
});
consoleOutputCapturer.stop();
String output = consoleOutputCapturer.getStderr();
assertTrue(output.replace("\n", "").contains("State key needs to be specified"));
StateGetter stateGetter = cmd.getStateGetter();
assertEquals(tenant, stateGetter.getTenant());
assertEquals(namespace, stateGetter.getNamespace());
assertEquals(fnName, stateGetter.getFunctionName());
verify(functions, times(0)).getFunctionState(any(), any(), any(), any());
}

private static final String fnName = TEST_NAME + "-function";
private static final String inputTopicName = TEST_NAME + "-input-topic";
private static final String outputTopicName = TEST_NAME + "-output-topic";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -805,14 +805,17 @@ void runCmd() throws Exception {
@Parameters(commandDescription = "Fetch the current state associated with a Pulsar Function")
class StateGetter extends FunctionCommand {

@Parameter(names = { "-k", "--key" }, description = "key")
@Parameter(names = { "-k", "--key" }, description = "Key name of State")
private String key = null;

@Parameter(names = { "-w", "--watch" }, description = "Watch for changes in the value associated with a key for a Pulsar Function")
private boolean watch = false;

@Override
void runCmd() throws Exception {
if (isBlank(key)) {
throw new ParameterException("State key needs to be specified");
}
do {
try {
FunctionState functionState = admin.functions()
Expand Down

0 comments on commit c50abe8

Please sign in to comment.