Search in sources :

Example 1 with CreateFunction

use of org.apache.pulsar.admin.cli.CmdFunctions.CreateFunction in project incubator-pulsar by apache.

the class CmdFunctionsTest method testCreateWithoutFunctionName.

@Test
public void testCreateWithoutFunctionName() throws Exception {
    String inputTopicName = TEST_NAME + "-input-topic";
    String outputTopicName = TEST_NAME + "-output-topic";
    cmd.run(new String[] { "create", "--inputs", inputTopicName, "--output", outputTopicName, "--jar", "SomeJar.jar", "--tenant", "sample", "--namespace", "ns1", "--className", DummyFunction.class.getName() });
    CreateFunction creater = cmd.getCreater();
    assertEquals("CmdFunctionsTest$DummyFunction", creater.getFunctionConfig().getName());
    verify(functions, times(1)).createFunction(any(FunctionConfig.class), anyString());
}
Also used : FunctionConfig(org.apache.pulsar.functions.proto.Function.FunctionConfig) CreateFunction(org.apache.pulsar.admin.cli.CmdFunctions.CreateFunction) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with CreateFunction

use of org.apache.pulsar.admin.cli.CmdFunctions.CreateFunction in project incubator-pulsar by apache.

the class CmdFunctionsTest method testCreateWithoutNamespace.

@Test
public void testCreateWithoutNamespace() throws Exception {
    String fnName = TEST_NAME + "-function";
    String inputTopicName = "persistent://tenant/standalone/namespace/input-topic";
    String outputTopicName = "persistent://tenant/standalone/namespace/output-topic";
    cmd.run(new String[] { "create", "--name", fnName, "--inputs", inputTopicName, "--output", outputTopicName, "--jar", "SomeJar.jar", "--className", DummyFunction.class.getName() });
    CreateFunction creater = cmd.getCreater();
    assertEquals("tenant", creater.getFunctionConfig().getTenant());
    assertEquals("namespace", creater.getFunctionConfig().getNamespace());
    verify(functions, times(1)).createFunction(any(FunctionConfig.class), anyString());
}
Also used : FunctionConfig(org.apache.pulsar.functions.proto.Function.FunctionConfig) CreateFunction(org.apache.pulsar.admin.cli.CmdFunctions.CreateFunction) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with CreateFunction

use of org.apache.pulsar.admin.cli.CmdFunctions.CreateFunction in project incubator-pulsar by apache.

the class CmdFunctionsTest method testCreateWithoutOutputTopic.

@Test
public void testCreateWithoutOutputTopic() throws Exception {
    String inputTopicName = TEST_NAME + "-input-topic";
    cmd.run(new String[] { "create", "--inputs", inputTopicName, "--jar", "SomeJar.jar", "--tenant", "sample", "--namespace", "ns1", "--className", DummyFunction.class.getName() });
    CreateFunction creater = cmd.getCreater();
    assertEquals(inputTopicName + "-" + "CmdFunctionsTest$DummyFunction" + "-output", creater.getFunctionConfig().getOutput());
    verify(functions, times(1)).createFunction(any(FunctionConfig.class), anyString());
}
Also used : FunctionConfig(org.apache.pulsar.functions.proto.Function.FunctionConfig) CreateFunction(org.apache.pulsar.admin.cli.CmdFunctions.CreateFunction) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with CreateFunction

use of org.apache.pulsar.admin.cli.CmdFunctions.CreateFunction in project incubator-pulsar by apache.

the class CmdFunctionsTest method testCreateWithoutTenant.

@Test
public void testCreateWithoutTenant() throws Exception {
    String fnName = TEST_NAME + "-function";
    String inputTopicName = "persistent://tenant/standalone/namespace/input-topic";
    String outputTopicName = "persistent://tenant/standalone/namespace/output-topic";
    cmd.run(new String[] { "create", "--name", fnName, "--inputs", inputTopicName, "--output", outputTopicName, "--jar", "SomeJar.jar", "--namespace", "ns1", "--className", DummyFunction.class.getName() });
    CreateFunction creater = cmd.getCreater();
    assertEquals("tenant", creater.getFunctionConfig().getTenant());
    verify(functions, times(1)).createFunction(any(FunctionConfig.class), anyString());
}
Also used : FunctionConfig(org.apache.pulsar.functions.proto.Function.FunctionConfig) CreateFunction(org.apache.pulsar.admin.cli.CmdFunctions.CreateFunction) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with CreateFunction

use of org.apache.pulsar.admin.cli.CmdFunctions.CreateFunction in project incubator-pulsar by apache.

the class CmdFunctionsTest method testCreateFunction.

/*
    TODO(sijie):- Can we fix this?
    @Test
    public void testLocalRunnerCmdSettings() throws Exception {
        String fnName = TEST_NAME + "-function";
        String sourceTopicName = TEST_NAME + "-source-topic";
        String output = TEST_NAME + "-sink-topic";
        cmd.run(new String[] {
            "localrun",
            "--name", fnName,
            "--source-topics", sourceTopicName,
            "--output", output
        });

        LocalRunner runner = cmd.getLocalRunner();
        assertEquals(fnName, runner.getFunctionName());
        assertEquals(sourceTopicName, runner.getInputs());
        assertEquals(output, runner.getOutput());
        assertNull(runner.getFnConfigFile());
    }

    @Test
    public void testLocalRunnerCmdYaml() throws Exception {
        URL yamlUrl = getClass().getClassLoader().getResource("test_function_config.yml");
        String configFile = yamlUrl.getPath();
        cmd.run(new String[] {
            "localrun",
            "--function-config", configFile
        });

        LocalRunner runner = cmd.getLocalRunner();
        assertNull(runner.getFunctionName());
        assertNull(runner.getInputs());
        assertNull(runner.getOutput());
        assertEquals(configFile, runner.getFnConfigFile());
    }
    */
@Test
public void testCreateFunction() throws Exception {
    String fnName = TEST_NAME + "-function";
    String inputTopicName = TEST_NAME + "-input-topic";
    String outputTopicName = TEST_NAME + "-output-topic";
    cmd.run(new String[] { "create", "--name", fnName, "--inputs", inputTopicName, "--output", outputTopicName, "--jar", "SomeJar.jar", "--tenant", "sample", "--namespace", "ns1", "--className", DummyFunction.class.getName() });
    CreateFunction creater = cmd.getCreater();
    assertEquals(fnName, creater.getFunctionName());
    assertEquals(inputTopicName, creater.getInputs());
    assertEquals(outputTopicName, creater.getOutput());
    verify(functions, times(1)).createFunction(any(FunctionConfig.class), anyString());
}
Also used : FunctionConfig(org.apache.pulsar.functions.proto.Function.FunctionConfig) CreateFunction(org.apache.pulsar.admin.cli.CmdFunctions.CreateFunction) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

CreateFunction (org.apache.pulsar.admin.cli.CmdFunctions.CreateFunction)5 FunctionConfig (org.apache.pulsar.functions.proto.Function.FunctionConfig)5 Matchers.anyString (org.mockito.Matchers.anyString)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Test (org.testng.annotations.Test)5