Search in sources :

Example 96 with SourceConfig

use of org.apache.pulsar.common.io.SourceConfig in project incubator-pulsar by apache.

the class SourceApiV3ResourceTest method testRegisterSourceConflictingFields.

@Test
public void testRegisterSourceConflictingFields() throws Exception {
    mockWorkerUtils();
    String actualTenant = "DIFFERENT_TENANT";
    String actualNamespace = "DIFFERENT_NAMESPACE";
    String actualName = "DIFFERENT_NAME";
    this.namespaceList.add(actualTenant + "/" + actualNamespace);
    when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(source))).thenReturn(true);
    when(mockedManager.containsFunction(eq(actualTenant), eq(actualNamespace), eq(actualName))).thenReturn(false);
    SourceConfig sourceConfig = new SourceConfig();
    sourceConfig.setTenant(tenant);
    sourceConfig.setNamespace(namespace);
    sourceConfig.setName(source);
    sourceConfig.setClassName(TWITTER_FIRE_HOSE);
    sourceConfig.setParallelism(parallelism);
    sourceConfig.setTopicName(outputTopic);
    sourceConfig.setSerdeClassName(outputSerdeClassName);
    try (InputStream inputStream = new FileInputStream(getPulsarIOTwitterNar())) {
        resource.registerSource(actualTenant, actualNamespace, actualName, inputStream, mockedFormData, null, sourceConfig, null, null);
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) SourceConfig(org.apache.pulsar.common.io.SourceConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FileInputStream(java.io.FileInputStream) Test(org.testng.annotations.Test)

Example 97 with SourceConfig

use of org.apache.pulsar.common.io.SourceConfig in project incubator-pulsar by apache.

the class SourceApiV3ResourceTest method createDefaultSourceConfig.

private SourceConfig createDefaultSourceConfig() {
    SourceConfig sourceConfig = new SourceConfig();
    sourceConfig.setTenant(tenant);
    sourceConfig.setNamespace(namespace);
    sourceConfig.setName(source);
    sourceConfig.setClassName(TWITTER_FIRE_HOSE);
    sourceConfig.setParallelism(parallelism);
    sourceConfig.setTopicName(outputTopic);
    sourceConfig.setSerdeClassName(outputSerdeClassName);
    return sourceConfig;
}
Also used : SourceConfig(org.apache.pulsar.common.io.SourceConfig)

Example 98 with SourceConfig

use of org.apache.pulsar.common.io.SourceConfig in project incubator-pulsar by apache.

the class SourceApiV3ResourceTest method registerDefaultSourceWithPackageUrl.

private void registerDefaultSourceWithPackageUrl(String packageUrl) throws IOException {
    SourceConfig sourceConfig = createDefaultSourceConfig();
    resource.registerSource(tenant, namespace, source, null, null, packageUrl, sourceConfig, null, null);
}
Also used : SourceConfig(org.apache.pulsar.common.io.SourceConfig)

Example 99 with SourceConfig

use of org.apache.pulsar.common.io.SourceConfig in project incubator-pulsar by apache.

the class SourceApiV3ResourceTest method testRegisterSourceMissingArguments.

private void testRegisterSourceMissingArguments(String tenant, String namespace, String function, InputStream inputStream, FormDataContentDisposition details, String outputTopic, String outputSerdeClassName, String className, Integer parallelism, String pkgUrl) {
    SourceConfig sourceConfig = new SourceConfig();
    if (tenant != null) {
        sourceConfig.setTenant(tenant);
    }
    if (namespace != null) {
        sourceConfig.setNamespace(namespace);
    }
    if (function != null) {
        sourceConfig.setName(function);
    }
    if (outputTopic != null) {
        sourceConfig.setTopicName(outputTopic);
    }
    if (outputSerdeClassName != null) {
        sourceConfig.setSerdeClassName(outputSerdeClassName);
    }
    if (className != null) {
        sourceConfig.setClassName(className);
    }
    if (parallelism != null) {
        sourceConfig.setParallelism(parallelism);
    }
    resource.registerSource(tenant, namespace, function, inputStream, details, pkgUrl, sourceConfig, null, null);
}
Also used : SourceConfig(org.apache.pulsar.common.io.SourceConfig)

Example 100 with SourceConfig

use of org.apache.pulsar.common.io.SourceConfig in project incubator-pulsar by apache.

the class SourceApiV3ResourceTest method testUpdateSourceMissingArguments.

private void testUpdateSourceMissingArguments(String tenant, String namespace, String function, InputStream inputStream, FormDataContentDisposition details, String outputTopic, String outputSerdeClassName, String className, Integer parallelism, String expectedError) throws Exception {
    mockStatic(ConnectorUtils.class, c -> {
    });
    mockStatic(ClassLoaderUtils.class, c -> {
    });
    mockStatic(FunctionCommon.class, ctx -> {
        ctx.when(() -> FunctionCommon.createPkgTempFile()).thenCallRealMethod();
        ctx.when(() -> FunctionCommon.getClassLoaderFromPackage(any(), any(), any(), any())).thenCallRealMethod();
        ctx.when(() -> FunctionCommon.getSourceType(argThat(clazz -> clazz.getName().equals(TWITTER_FIRE_HOSE)))).thenReturn(String.class);
        ctx.when(() -> FunctionCommon.extractNarClassLoader(any(), any())).thenReturn(narClassLoader);
    });
    this.mockedFunctionMetaData = FunctionMetaData.newBuilder().setFunctionDetails(createDefaultFunctionDetails()).build();
    when(mockedManager.getFunctionMetaData(any(), any(), any())).thenReturn(mockedFunctionMetaData);
    when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(true);
    SourceConfig sourceConfig = new SourceConfig();
    if (tenant != null) {
        sourceConfig.setTenant(tenant);
    }
    if (namespace != null) {
        sourceConfig.setNamespace(namespace);
    }
    if (function != null) {
        sourceConfig.setName(function);
    }
    if (outputTopic != null) {
        sourceConfig.setTopicName(outputTopic);
    }
    if (outputSerdeClassName != null) {
        sourceConfig.setSerdeClassName(outputSerdeClassName);
    }
    if (className != null) {
        sourceConfig.setClassName(className);
    }
    if (parallelism != null) {
        sourceConfig.setParallelism(parallelism);
    }
    if (expectedError != null) {
        doThrow(new IllegalArgumentException(expectedError)).when(mockedManager).updateFunctionOnLeader(any(FunctionMetaData.class), Mockito.anyBoolean());
    }
    resource.updateSource(tenant, namespace, function, inputStream, details, null, sourceConfig, null, null, null);
}
Also used : Tenants(org.apache.pulsar.client.admin.Tenants) FormDataContentDisposition(org.glassfish.jersey.media.multipart.FormDataContentDisposition) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Level(org.apache.logging.log4j.Level) FunctionMetaData(org.apache.pulsar.functions.proto.Function.FunctionMetaData) Test(org.testng.annotations.Test) AfterMethod(org.testng.annotations.AfterMethod) SinkApiV3ResourceTest.getPulsarIOTwitterNar(org.apache.pulsar.functions.worker.rest.api.v3.SinkApiV3ResourceTest.getPulsarIOTwitterNar) Mockito.doThrow(org.mockito.Mockito.doThrow) Packages(org.apache.pulsar.client.admin.Packages) NarClassLoader(org.apache.pulsar.common.nar.NarClassLoader) FunctionDetails(org.apache.pulsar.functions.proto.Function.FunctionDetails) PulsarWorkerService(org.apache.pulsar.functions.worker.PulsarWorkerService) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) TopicSchema(org.apache.pulsar.functions.source.TopicSchema) RuntimeFactory(org.apache.pulsar.functions.runtime.RuntimeFactory) ClassLoaderUtils(org.apache.pulsar.common.util.ClassLoaderUtils) WorkerUtils(org.apache.pulsar.functions.worker.WorkerUtils) BeforeClass(org.testng.annotations.BeforeClass) BeforeMethod(org.testng.annotations.BeforeMethod) WorkerConfig(org.apache.pulsar.functions.worker.WorkerConfig) SourcesImpl(org.apache.pulsar.functions.worker.rest.api.SourcesImpl) FunctionMetaDataManager(org.apache.pulsar.functions.worker.FunctionMetaDataManager) List(java.util.List) MockedStatic(org.mockito.MockedStatic) Response(javax.ws.rs.core.Response) TenantInfoImpl(org.apache.pulsar.common.policies.data.TenantInfoImpl) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Utils(org.apache.pulsar.common.functions.Utils) ConnectorUtils(org.apache.pulsar.functions.utils.io.ConnectorUtils) SourceSpec(org.apache.pulsar.functions.proto.Function.SourceSpec) LeaderService(org.apache.pulsar.functions.worker.LeaderService) SourceConfigUtils(org.apache.pulsar.functions.utils.SourceConfigUtils) Assert.assertEquals(org.testng.Assert.assertEquals) HashMap(java.util.HashMap) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) Mockito.spy(org.mockito.Mockito.spy) RestException(org.apache.pulsar.common.util.RestException) StandardCopyOption(java.nio.file.StandardCopyOption) Lists(com.google.common.collect.Lists) Namespaces(org.apache.pulsar.client.admin.Namespaces) NarClassLoaderBuilder(org.apache.pulsar.common.nar.NarClassLoaderBuilder) Configurator(org.apache.logging.log4j.core.config.Configurator) IdentityFunction(org.apache.pulsar.functions.api.utils.IdentityFunction) LinkedList(java.util.LinkedList) Functions(org.apache.pulsar.client.admin.Functions) PulsarFunctionTestTemporaryDirectory(org.apache.pulsar.functions.worker.rest.api.PulsarFunctionTestTemporaryDirectory) AfterClass(org.testng.annotations.AfterClass) SourceConfig(org.apache.pulsar.common.io.SourceConfig) Files(java.nio.file.Files) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) Assert.fail(org.testng.Assert.fail) PackageLocationMetaData(org.apache.pulsar.functions.proto.Function.PackageLocationMetaData) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) FileInputStream(java.io.FileInputStream) File(java.io.File) Consumer(java.util.function.Consumer) Namespace(org.apache.distributedlog.api.namespace.Namespace) Mockito(org.mockito.Mockito) SinkApiV3ResourceTest.getPulsarIOCassandraNar(org.apache.pulsar.functions.worker.rest.api.v3.SinkApiV3ResourceTest.getPulsarIOCassandraNar) FunctionCommon(org.apache.pulsar.functions.utils.FunctionCommon) Paths(java.nio.file.Paths) SinkSpec(org.apache.pulsar.functions.proto.Function.SinkSpec) FunctionRuntimeManager(org.apache.pulsar.functions.worker.FunctionRuntimeManager) ProcessingGuarantees(org.apache.pulsar.functions.proto.Function.ProcessingGuarantees) SinkApiV3ResourceTest.getPulsarIOInvalidNar(org.apache.pulsar.functions.worker.rest.api.v3.SinkApiV3ResourceTest.getPulsarIOInvalidNar) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) InputStream(java.io.InputStream) FunctionMetaData(org.apache.pulsar.functions.proto.Function.FunctionMetaData) SourceConfig(org.apache.pulsar.common.io.SourceConfig)

Aggregations

SourceConfig (org.apache.pulsar.common.io.SourceConfig)192 BatchSourceConfig (org.apache.pulsar.common.io.BatchSourceConfig)141 Test (org.testng.annotations.Test)129 Gson (com.google.gson.Gson)42 HashMap (java.util.HashMap)30 File (java.io.File)27 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)27 Function (org.apache.pulsar.functions.proto.Function)24 IOException (java.io.IOException)21 Response (javax.ws.rs.core.Response)18 List (java.util.List)15 Map (java.util.Map)15 RestException (org.apache.pulsar.common.util.RestException)15 IdentityFunction (org.apache.pulsar.functions.api.utils.IdentityFunction)15 FunctionMetaDataManager (org.apache.pulsar.functions.worker.FunctionMetaDataManager)15 Lists (com.google.common.collect.Lists)12 FileInputStream (java.io.FileInputStream)12 InputStream (java.io.InputStream)12 Files (java.nio.file.Files)12 PulsarAdmin (org.apache.pulsar.client.admin.PulsarAdmin)12