Search in sources :

Example 1 with Sources

use of org.apache.pulsar.client.admin.Sources in project pulsar by apache.

the class FunctionRuntimeManagerTest method testKubernetesFunctionInstancesRestart.

@Test
public void testKubernetesFunctionInstancesRestart() throws Exception {
    WorkerConfig workerConfig = new WorkerConfig();
    workerConfig.setWorkerId("worker-1");
    workerConfig.setPulsarServiceUrl(PULSAR_SERVICE_URL);
    workerConfig.setStateStorageServiceUrl("foo");
    workerConfig.setFunctionAssignmentTopicName("assignments");
    WorkerConfig.KubernetesContainerFactory kubernetesContainerFactory = new WorkerConfig.KubernetesContainerFactory();
    workerConfig.setKubernetesContainerFactory(kubernetesContainerFactory);
    try (MockedConstruction<KubernetesRuntimeFactory> mocked = Mockito.mockConstruction(KubernetesRuntimeFactory.class, (mockedKubernetesRuntimeFactory, context) -> {
        doNothing().when(mockedKubernetesRuntimeFactory).initialize(any(WorkerConfig.class), any(AuthenticationConfig.class), any(SecretsProviderConfigurator.class), any(), any(), any());
        doNothing().when(mockedKubernetesRuntimeFactory).setupClient();
        doReturn(true).when(mockedKubernetesRuntimeFactory).externallyManaged();
    })) {
        PulsarWorkerService workerService = mock(PulsarWorkerService.class);
        // mock pulsarAdmin sources sinks functions
        PulsarAdmin pulsarAdmin = mock(PulsarAdmin.class);
        Sources sources = mock(Sources.class);
        doNothing().when(sources).restartSource(ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any());
        doReturn(sources).when(pulsarAdmin).sources();
        Sinks sinks = mock(Sinks.class);
        doReturn(sinks).when(pulsarAdmin).sinks();
        Functions functions = mock(Functions.class);
        doNothing().when(functions).restartFunction(ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any());
        doReturn(functions).when(pulsarAdmin).functions();
        doReturn(pulsarAdmin).when(workerService).getFunctionAdmin();
        try (final MockedStatic<RuntimeFactory> runtimeFactoryMockedStatic = Mockito.mockStatic(RuntimeFactory.class)) {
            mockRuntimeFactory(runtimeFactoryMockedStatic);
            List<WorkerInfo> workerInfos = new LinkedList<>();
            workerInfos.add(WorkerInfo.of("worker-1", "localhost", 0));
            workerInfos.add(WorkerInfo.of("worker-2", "localhost", 0));
            MembershipManager membershipManager = mock(MembershipManager.class);
            doReturn(workerInfos).when(membershipManager).getCurrentMembership();
            // build three types of FunctionMetaData
            Function.FunctionMetaData function = Function.FunctionMetaData.newBuilder().setFunctionDetails(Function.FunctionDetails.newBuilder().setTenant("test-tenant").setNamespace("test-namespace").setName("function").setComponentType(Function.FunctionDetails.ComponentType.FUNCTION)).build();
            Function.FunctionMetaData source = Function.FunctionMetaData.newBuilder().setFunctionDetails(Function.FunctionDetails.newBuilder().setTenant("test-tenant").setNamespace("test-namespace").setName("source").setComponentType(Function.FunctionDetails.ComponentType.SOURCE)).build();
            Function.FunctionMetaData sink = Function.FunctionMetaData.newBuilder().setFunctionDetails(Function.FunctionDetails.newBuilder().setTenant("test-tenant").setNamespace("test-namespace").setName("sink").setComponentType(Function.FunctionDetails.ComponentType.SINK)).build();
            FunctionRuntimeManager functionRuntimeManager = spy(new FunctionRuntimeManager(workerConfig, workerService, mock(Namespace.class), membershipManager, mock(ConnectorsManager.class), mock(FunctionsManager.class), mock(FunctionMetaDataManager.class), mock(WorkerStatsManager.class), mock(ErrorNotifier.class)));
            // verify restart function/source/sink using different assignment
            verifyRestart(functionRuntimeManager, function, "worker-1", true, false);
            verifyRestart(functionRuntimeManager, function, "worker-2", true, true);
            verifyRestart(functionRuntimeManager, source, "worker-1", true, false);
            verifyRestart(functionRuntimeManager, source, "worker-2", true, true);
            verifyRestart(functionRuntimeManager, sink, "worker-1", true, false);
            verifyRestart(functionRuntimeManager, sink, "worker-2", true, true);
        }
    }
}
Also used : Sinks(org.apache.pulsar.client.admin.Sinks) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) WorkerInfo(org.apache.pulsar.common.functions.WorkerInfo) Functions(org.apache.pulsar.client.admin.Functions) KubernetesRuntimeFactory(org.apache.pulsar.functions.runtime.kubernetes.KubernetesRuntimeFactory) Sources(org.apache.pulsar.client.admin.Sources) RuntimeFactory(org.apache.pulsar.functions.runtime.RuntimeFactory) KubernetesRuntimeFactory(org.apache.pulsar.functions.runtime.kubernetes.KubernetesRuntimeFactory) ProcessRuntimeFactory(org.apache.pulsar.functions.runtime.process.ProcessRuntimeFactory) ThreadRuntimeFactory(org.apache.pulsar.functions.runtime.thread.ThreadRuntimeFactory) LinkedList(java.util.LinkedList) AuthenticationConfig(org.apache.pulsar.functions.instance.AuthenticationConfig) Function(org.apache.pulsar.functions.proto.Function) SecretsProviderConfigurator(org.apache.pulsar.functions.secretsproviderconfigurator.SecretsProviderConfigurator) Test(org.testng.annotations.Test)

Example 2 with Sources

use of org.apache.pulsar.client.admin.Sources in project pulsar by yahoo.

the class FunctionRuntimeManagerTest method testThreadFunctionInstancesRestart.

@Test
public void testThreadFunctionInstancesRestart() throws Exception {
    WorkerConfig workerConfig = new WorkerConfig();
    workerConfig.setWorkerId("worker-1");
    workerConfig.setFunctionRuntimeFactoryClassName(ThreadRuntimeFactory.class.getName());
    workerConfig.setFunctionRuntimeFactoryConfigs(ObjectMapperFactory.getThreadLocal().convertValue(new ThreadRuntimeFactoryConfig().setThreadGroupName("test"), Map.class));
    workerConfig.setPulsarServiceUrl(PULSAR_SERVICE_URL);
    workerConfig.setStateStorageServiceUrl("foo");
    workerConfig.setFunctionAssignmentTopicName("assignments");
    PulsarWorkerService workerService = mock(PulsarWorkerService.class);
    // mock pulsarAdmin sources sinks functions
    PulsarAdmin pulsarAdmin = mock(PulsarAdmin.class);
    Sources sources = mock(Sources.class);
    doNothing().when(sources).restartSource(ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any());
    doReturn(sources).when(pulsarAdmin).sources();
    Sinks sinks = mock(Sinks.class);
    doReturn(sinks).when(pulsarAdmin).sinks();
    Functions functions = mock(Functions.class);
    doNothing().when(functions).restartFunction(ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any());
    doReturn(functions).when(pulsarAdmin).functions();
    doReturn(pulsarAdmin).when(workerService).getFunctionAdmin();
    try (final MockedStatic<RuntimeFactory> runtimeFactoryMockedStatic = Mockito.mockStatic(RuntimeFactory.class)) {
        mockRuntimeFactory(runtimeFactoryMockedStatic);
        List<WorkerInfo> workerInfos = new LinkedList<>();
        workerInfos.add(WorkerInfo.of("worker-1", "localhost", 0));
        workerInfos.add(WorkerInfo.of("worker-2", "localhost", 0));
        MembershipManager membershipManager = mock(MembershipManager.class);
        doReturn(workerInfos).when(membershipManager).getCurrentMembership();
        // build three types of FunctionMetaData
        Function.FunctionMetaData function = Function.FunctionMetaData.newBuilder().setFunctionDetails(Function.FunctionDetails.newBuilder().setTenant("test-tenant").setNamespace("test-namespace").setName("function").setComponentType(Function.FunctionDetails.ComponentType.FUNCTION)).build();
        Function.FunctionMetaData source = Function.FunctionMetaData.newBuilder().setFunctionDetails(Function.FunctionDetails.newBuilder().setTenant("test-tenant").setNamespace("test-namespace").setName("source").setComponentType(Function.FunctionDetails.ComponentType.SOURCE)).build();
        Function.FunctionMetaData sink = Function.FunctionMetaData.newBuilder().setFunctionDetails(Function.FunctionDetails.newBuilder().setTenant("test-tenant").setNamespace("test-namespace").setName("sink").setComponentType(Function.FunctionDetails.ComponentType.SINK)).build();
        FunctionRuntimeManager functionRuntimeManager = spy(new FunctionRuntimeManager(workerConfig, workerService, mock(Namespace.class), membershipManager, mock(ConnectorsManager.class), mock(FunctionsManager.class), mock(FunctionMetaDataManager.class), mock(WorkerStatsManager.class), mock(ErrorNotifier.class)));
        // verify restart function/source/sink using different assignment
        verifyRestart(functionRuntimeManager, function, "worker-1", false, false);
        verifyRestart(functionRuntimeManager, function, "worker-2", false, true);
        verifyRestart(functionRuntimeManager, source, "worker-1", false, false);
        verifyRestart(functionRuntimeManager, source, "worker-2", false, true);
        verifyRestart(functionRuntimeManager, sink, "worker-1", false, false);
        verifyRestart(functionRuntimeManager, sink, "worker-2", false, true);
    }
}
Also used : ThreadRuntimeFactoryConfig(org.apache.pulsar.functions.runtime.thread.ThreadRuntimeFactoryConfig) Sinks(org.apache.pulsar.client.admin.Sinks) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) WorkerInfo(org.apache.pulsar.common.functions.WorkerInfo) Functions(org.apache.pulsar.client.admin.Functions) Sources(org.apache.pulsar.client.admin.Sources) RuntimeFactory(org.apache.pulsar.functions.runtime.RuntimeFactory) KubernetesRuntimeFactory(org.apache.pulsar.functions.runtime.kubernetes.KubernetesRuntimeFactory) ProcessRuntimeFactory(org.apache.pulsar.functions.runtime.process.ProcessRuntimeFactory) ThreadRuntimeFactory(org.apache.pulsar.functions.runtime.thread.ThreadRuntimeFactory) LinkedList(java.util.LinkedList) Function(org.apache.pulsar.functions.proto.Function) ThreadRuntimeFactory(org.apache.pulsar.functions.runtime.thread.ThreadRuntimeFactory) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Example 3 with Sources

use of org.apache.pulsar.client.admin.Sources in project incubator-pulsar by apache.

the class FunctionRuntimeManagerTest method testThreadFunctionInstancesRestart.

@Test
public void testThreadFunctionInstancesRestart() throws Exception {
    WorkerConfig workerConfig = new WorkerConfig();
    workerConfig.setWorkerId("worker-1");
    workerConfig.setFunctionRuntimeFactoryClassName(ThreadRuntimeFactory.class.getName());
    workerConfig.setFunctionRuntimeFactoryConfigs(ObjectMapperFactory.getThreadLocal().convertValue(new ThreadRuntimeFactoryConfig().setThreadGroupName("test"), Map.class));
    workerConfig.setPulsarServiceUrl(PULSAR_SERVICE_URL);
    workerConfig.setStateStorageServiceUrl("foo");
    workerConfig.setFunctionAssignmentTopicName("assignments");
    PulsarWorkerService workerService = mock(PulsarWorkerService.class);
    // mock pulsarAdmin sources sinks functions
    PulsarAdmin pulsarAdmin = mock(PulsarAdmin.class);
    Sources sources = mock(Sources.class);
    doNothing().when(sources).restartSource(ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any());
    doReturn(sources).when(pulsarAdmin).sources();
    Sinks sinks = mock(Sinks.class);
    doReturn(sinks).when(pulsarAdmin).sinks();
    Functions functions = mock(Functions.class);
    doNothing().when(functions).restartFunction(ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any());
    doReturn(functions).when(pulsarAdmin).functions();
    doReturn(pulsarAdmin).when(workerService).getFunctionAdmin();
    try (final MockedStatic<RuntimeFactory> runtimeFactoryMockedStatic = Mockito.mockStatic(RuntimeFactory.class)) {
        mockRuntimeFactory(runtimeFactoryMockedStatic);
        List<WorkerInfo> workerInfos = new LinkedList<>();
        workerInfos.add(WorkerInfo.of("worker-1", "localhost", 0));
        workerInfos.add(WorkerInfo.of("worker-2", "localhost", 0));
        MembershipManager membershipManager = mock(MembershipManager.class);
        doReturn(workerInfos).when(membershipManager).getCurrentMembership();
        // build three types of FunctionMetaData
        Function.FunctionMetaData function = Function.FunctionMetaData.newBuilder().setFunctionDetails(Function.FunctionDetails.newBuilder().setTenant("test-tenant").setNamespace("test-namespace").setName("function").setComponentType(Function.FunctionDetails.ComponentType.FUNCTION)).build();
        Function.FunctionMetaData source = Function.FunctionMetaData.newBuilder().setFunctionDetails(Function.FunctionDetails.newBuilder().setTenant("test-tenant").setNamespace("test-namespace").setName("source").setComponentType(Function.FunctionDetails.ComponentType.SOURCE)).build();
        Function.FunctionMetaData sink = Function.FunctionMetaData.newBuilder().setFunctionDetails(Function.FunctionDetails.newBuilder().setTenant("test-tenant").setNamespace("test-namespace").setName("sink").setComponentType(Function.FunctionDetails.ComponentType.SINK)).build();
        FunctionRuntimeManager functionRuntimeManager = spy(new FunctionRuntimeManager(workerConfig, workerService, mock(Namespace.class), membershipManager, mock(ConnectorsManager.class), mock(FunctionsManager.class), mock(FunctionMetaDataManager.class), mock(WorkerStatsManager.class), mock(ErrorNotifier.class)));
        // verify restart function/source/sink using different assignment
        verifyRestart(functionRuntimeManager, function, "worker-1", false, false);
        verifyRestart(functionRuntimeManager, function, "worker-2", false, true);
        verifyRestart(functionRuntimeManager, source, "worker-1", false, false);
        verifyRestart(functionRuntimeManager, source, "worker-2", false, true);
        verifyRestart(functionRuntimeManager, sink, "worker-1", false, false);
        verifyRestart(functionRuntimeManager, sink, "worker-2", false, true);
    }
}
Also used : ThreadRuntimeFactoryConfig(org.apache.pulsar.functions.runtime.thread.ThreadRuntimeFactoryConfig) Sinks(org.apache.pulsar.client.admin.Sinks) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) WorkerInfo(org.apache.pulsar.common.functions.WorkerInfo) Functions(org.apache.pulsar.client.admin.Functions) Sources(org.apache.pulsar.client.admin.Sources) RuntimeFactory(org.apache.pulsar.functions.runtime.RuntimeFactory) KubernetesRuntimeFactory(org.apache.pulsar.functions.runtime.kubernetes.KubernetesRuntimeFactory) ProcessRuntimeFactory(org.apache.pulsar.functions.runtime.process.ProcessRuntimeFactory) ThreadRuntimeFactory(org.apache.pulsar.functions.runtime.thread.ThreadRuntimeFactory) LinkedList(java.util.LinkedList) Function(org.apache.pulsar.functions.proto.Function) ThreadRuntimeFactory(org.apache.pulsar.functions.runtime.thread.ThreadRuntimeFactory) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Example 4 with Sources

use of org.apache.pulsar.client.admin.Sources in project incubator-pulsar by apache.

the class FunctionRuntimeManagerTest method testKubernetesFunctionInstancesRestart.

@Test
public void testKubernetesFunctionInstancesRestart() throws Exception {
    WorkerConfig workerConfig = new WorkerConfig();
    workerConfig.setWorkerId("worker-1");
    workerConfig.setPulsarServiceUrl(PULSAR_SERVICE_URL);
    workerConfig.setStateStorageServiceUrl("foo");
    workerConfig.setFunctionAssignmentTopicName("assignments");
    WorkerConfig.KubernetesContainerFactory kubernetesContainerFactory = new WorkerConfig.KubernetesContainerFactory();
    workerConfig.setKubernetesContainerFactory(kubernetesContainerFactory);
    try (MockedConstruction<KubernetesRuntimeFactory> mocked = Mockito.mockConstruction(KubernetesRuntimeFactory.class, (mockedKubernetesRuntimeFactory, context) -> {
        doNothing().when(mockedKubernetesRuntimeFactory).initialize(any(WorkerConfig.class), any(AuthenticationConfig.class), any(SecretsProviderConfigurator.class), any(), any(), any());
        doNothing().when(mockedKubernetesRuntimeFactory).setupClient();
        doReturn(true).when(mockedKubernetesRuntimeFactory).externallyManaged();
    })) {
        PulsarWorkerService workerService = mock(PulsarWorkerService.class);
        // mock pulsarAdmin sources sinks functions
        PulsarAdmin pulsarAdmin = mock(PulsarAdmin.class);
        Sources sources = mock(Sources.class);
        doNothing().when(sources).restartSource(ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any());
        doReturn(sources).when(pulsarAdmin).sources();
        Sinks sinks = mock(Sinks.class);
        doReturn(sinks).when(pulsarAdmin).sinks();
        Functions functions = mock(Functions.class);
        doNothing().when(functions).restartFunction(ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any());
        doReturn(functions).when(pulsarAdmin).functions();
        doReturn(pulsarAdmin).when(workerService).getFunctionAdmin();
        try (final MockedStatic<RuntimeFactory> runtimeFactoryMockedStatic = Mockito.mockStatic(RuntimeFactory.class)) {
            mockRuntimeFactory(runtimeFactoryMockedStatic);
            List<WorkerInfo> workerInfos = new LinkedList<>();
            workerInfos.add(WorkerInfo.of("worker-1", "localhost", 0));
            workerInfos.add(WorkerInfo.of("worker-2", "localhost", 0));
            MembershipManager membershipManager = mock(MembershipManager.class);
            doReturn(workerInfos).when(membershipManager).getCurrentMembership();
            // build three types of FunctionMetaData
            Function.FunctionMetaData function = Function.FunctionMetaData.newBuilder().setFunctionDetails(Function.FunctionDetails.newBuilder().setTenant("test-tenant").setNamespace("test-namespace").setName("function").setComponentType(Function.FunctionDetails.ComponentType.FUNCTION)).build();
            Function.FunctionMetaData source = Function.FunctionMetaData.newBuilder().setFunctionDetails(Function.FunctionDetails.newBuilder().setTenant("test-tenant").setNamespace("test-namespace").setName("source").setComponentType(Function.FunctionDetails.ComponentType.SOURCE)).build();
            Function.FunctionMetaData sink = Function.FunctionMetaData.newBuilder().setFunctionDetails(Function.FunctionDetails.newBuilder().setTenant("test-tenant").setNamespace("test-namespace").setName("sink").setComponentType(Function.FunctionDetails.ComponentType.SINK)).build();
            FunctionRuntimeManager functionRuntimeManager = spy(new FunctionRuntimeManager(workerConfig, workerService, mock(Namespace.class), membershipManager, mock(ConnectorsManager.class), mock(FunctionsManager.class), mock(FunctionMetaDataManager.class), mock(WorkerStatsManager.class), mock(ErrorNotifier.class)));
            // verify restart function/source/sink using different assignment
            verifyRestart(functionRuntimeManager, function, "worker-1", true, false);
            verifyRestart(functionRuntimeManager, function, "worker-2", true, true);
            verifyRestart(functionRuntimeManager, source, "worker-1", true, false);
            verifyRestart(functionRuntimeManager, source, "worker-2", true, true);
            verifyRestart(functionRuntimeManager, sink, "worker-1", true, false);
            verifyRestart(functionRuntimeManager, sink, "worker-2", true, true);
        }
    }
}
Also used : Sinks(org.apache.pulsar.client.admin.Sinks) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) WorkerInfo(org.apache.pulsar.common.functions.WorkerInfo) Functions(org.apache.pulsar.client.admin.Functions) KubernetesRuntimeFactory(org.apache.pulsar.functions.runtime.kubernetes.KubernetesRuntimeFactory) Sources(org.apache.pulsar.client.admin.Sources) RuntimeFactory(org.apache.pulsar.functions.runtime.RuntimeFactory) KubernetesRuntimeFactory(org.apache.pulsar.functions.runtime.kubernetes.KubernetesRuntimeFactory) ProcessRuntimeFactory(org.apache.pulsar.functions.runtime.process.ProcessRuntimeFactory) ThreadRuntimeFactory(org.apache.pulsar.functions.runtime.thread.ThreadRuntimeFactory) LinkedList(java.util.LinkedList) AuthenticationConfig(org.apache.pulsar.functions.instance.AuthenticationConfig) Function(org.apache.pulsar.functions.proto.Function) SecretsProviderConfigurator(org.apache.pulsar.functions.secretsproviderconfigurator.SecretsProviderConfigurator) Test(org.testng.annotations.Test)

Example 5 with Sources

use of org.apache.pulsar.client.admin.Sources in project pulsar by yahoo.

the class FunctionRuntimeManagerTest method testKubernetesFunctionInstancesRestart.

@Test
public void testKubernetesFunctionInstancesRestart() throws Exception {
    WorkerConfig workerConfig = new WorkerConfig();
    workerConfig.setWorkerId("worker-1");
    workerConfig.setPulsarServiceUrl(PULSAR_SERVICE_URL);
    workerConfig.setStateStorageServiceUrl("foo");
    workerConfig.setFunctionAssignmentTopicName("assignments");
    WorkerConfig.KubernetesContainerFactory kubernetesContainerFactory = new WorkerConfig.KubernetesContainerFactory();
    workerConfig.setKubernetesContainerFactory(kubernetesContainerFactory);
    try (MockedConstruction<KubernetesRuntimeFactory> mocked = Mockito.mockConstruction(KubernetesRuntimeFactory.class, (mockedKubernetesRuntimeFactory, context) -> {
        doNothing().when(mockedKubernetesRuntimeFactory).initialize(any(WorkerConfig.class), any(AuthenticationConfig.class), any(SecretsProviderConfigurator.class), any(), any(), any());
        doNothing().when(mockedKubernetesRuntimeFactory).setupClient();
        doReturn(true).when(mockedKubernetesRuntimeFactory).externallyManaged();
    })) {
        PulsarWorkerService workerService = mock(PulsarWorkerService.class);
        // mock pulsarAdmin sources sinks functions
        PulsarAdmin pulsarAdmin = mock(PulsarAdmin.class);
        Sources sources = mock(Sources.class);
        doNothing().when(sources).restartSource(ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any());
        doReturn(sources).when(pulsarAdmin).sources();
        Sinks sinks = mock(Sinks.class);
        doReturn(sinks).when(pulsarAdmin).sinks();
        Functions functions = mock(Functions.class);
        doNothing().when(functions).restartFunction(ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any());
        doReturn(functions).when(pulsarAdmin).functions();
        doReturn(pulsarAdmin).when(workerService).getFunctionAdmin();
        try (final MockedStatic<RuntimeFactory> runtimeFactoryMockedStatic = Mockito.mockStatic(RuntimeFactory.class)) {
            mockRuntimeFactory(runtimeFactoryMockedStatic);
            List<WorkerInfo> workerInfos = new LinkedList<>();
            workerInfos.add(WorkerInfo.of("worker-1", "localhost", 0));
            workerInfos.add(WorkerInfo.of("worker-2", "localhost", 0));
            MembershipManager membershipManager = mock(MembershipManager.class);
            doReturn(workerInfos).when(membershipManager).getCurrentMembership();
            // build three types of FunctionMetaData
            Function.FunctionMetaData function = Function.FunctionMetaData.newBuilder().setFunctionDetails(Function.FunctionDetails.newBuilder().setTenant("test-tenant").setNamespace("test-namespace").setName("function").setComponentType(Function.FunctionDetails.ComponentType.FUNCTION)).build();
            Function.FunctionMetaData source = Function.FunctionMetaData.newBuilder().setFunctionDetails(Function.FunctionDetails.newBuilder().setTenant("test-tenant").setNamespace("test-namespace").setName("source").setComponentType(Function.FunctionDetails.ComponentType.SOURCE)).build();
            Function.FunctionMetaData sink = Function.FunctionMetaData.newBuilder().setFunctionDetails(Function.FunctionDetails.newBuilder().setTenant("test-tenant").setNamespace("test-namespace").setName("sink").setComponentType(Function.FunctionDetails.ComponentType.SINK)).build();
            FunctionRuntimeManager functionRuntimeManager = spy(new FunctionRuntimeManager(workerConfig, workerService, mock(Namespace.class), membershipManager, mock(ConnectorsManager.class), mock(FunctionsManager.class), mock(FunctionMetaDataManager.class), mock(WorkerStatsManager.class), mock(ErrorNotifier.class)));
            // verify restart function/source/sink using different assignment
            verifyRestart(functionRuntimeManager, function, "worker-1", true, false);
            verifyRestart(functionRuntimeManager, function, "worker-2", true, true);
            verifyRestart(functionRuntimeManager, source, "worker-1", true, false);
            verifyRestart(functionRuntimeManager, source, "worker-2", true, true);
            verifyRestart(functionRuntimeManager, sink, "worker-1", true, false);
            verifyRestart(functionRuntimeManager, sink, "worker-2", true, true);
        }
    }
}
Also used : Sinks(org.apache.pulsar.client.admin.Sinks) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) WorkerInfo(org.apache.pulsar.common.functions.WorkerInfo) Functions(org.apache.pulsar.client.admin.Functions) KubernetesRuntimeFactory(org.apache.pulsar.functions.runtime.kubernetes.KubernetesRuntimeFactory) Sources(org.apache.pulsar.client.admin.Sources) RuntimeFactory(org.apache.pulsar.functions.runtime.RuntimeFactory) KubernetesRuntimeFactory(org.apache.pulsar.functions.runtime.kubernetes.KubernetesRuntimeFactory) ProcessRuntimeFactory(org.apache.pulsar.functions.runtime.process.ProcessRuntimeFactory) ThreadRuntimeFactory(org.apache.pulsar.functions.runtime.thread.ThreadRuntimeFactory) LinkedList(java.util.LinkedList) AuthenticationConfig(org.apache.pulsar.functions.instance.AuthenticationConfig) Function(org.apache.pulsar.functions.proto.Function) SecretsProviderConfigurator(org.apache.pulsar.functions.secretsproviderconfigurator.SecretsProviderConfigurator) Test(org.testng.annotations.Test)

Aggregations

LinkedList (java.util.LinkedList)6 Functions (org.apache.pulsar.client.admin.Functions)6 PulsarAdmin (org.apache.pulsar.client.admin.PulsarAdmin)6 Sinks (org.apache.pulsar.client.admin.Sinks)6 Sources (org.apache.pulsar.client.admin.Sources)6 WorkerInfo (org.apache.pulsar.common.functions.WorkerInfo)6 Function (org.apache.pulsar.functions.proto.Function)6 RuntimeFactory (org.apache.pulsar.functions.runtime.RuntimeFactory)6 KubernetesRuntimeFactory (org.apache.pulsar.functions.runtime.kubernetes.KubernetesRuntimeFactory)6 ProcessRuntimeFactory (org.apache.pulsar.functions.runtime.process.ProcessRuntimeFactory)6 ThreadRuntimeFactory (org.apache.pulsar.functions.runtime.thread.ThreadRuntimeFactory)6 Test (org.testng.annotations.Test)6 HashMap (java.util.HashMap)3 Map (java.util.Map)3 AuthenticationConfig (org.apache.pulsar.functions.instance.AuthenticationConfig)3 ThreadRuntimeFactoryConfig (org.apache.pulsar.functions.runtime.thread.ThreadRuntimeFactoryConfig)3 SecretsProviderConfigurator (org.apache.pulsar.functions.secretsproviderconfigurator.SecretsProviderConfigurator)3