use of org.apache.pulsar.functions.auth.FunctionAuthProvider in project incubator-pulsar by apache.
the class FunctionActionerTest method testFunctionAuthDisabled.
@Test
public void testFunctionAuthDisabled() 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://localhost:6650");
workerConfig.setStateStorageServiceUrl("foo");
workerConfig.setFunctionAssignmentTopicName("assignments");
String downloadDir = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
workerConfig.setDownloadDirectory(downloadDir);
RuntimeFactory factory = mock(RuntimeFactory.class);
Runtime runtime = mock(Runtime.class);
doReturn(runtime).when(factory).createContainer(any(), any(), any(), any());
doNothing().when(runtime).start();
Namespace dlogNamespace = mock(Namespace.class);
final String exceptionMsg = "dl namespace not-found";
doThrow(new IllegalArgumentException(exceptionMsg)).when(dlogNamespace).openLog(any());
@SuppressWarnings("resource") FunctionActioner actioner = new FunctionActioner(workerConfig, factory, dlogNamespace, new ConnectorsManager(workerConfig), new FunctionsManager(workerConfig), mock(PulsarAdmin.class));
String pkgPathLocation = "http://invalid/my-file.jar";
Function.FunctionMetaData functionMeta = Function.FunctionMetaData.newBuilder().setFunctionDetails(Function.FunctionDetails.newBuilder().setTenant("test-tenant").setNamespace("test-namespace").setName("func-1")).setPackageLocation(PackageLocationMetaData.newBuilder().setPackagePath(pkgPathLocation).build()).build();
Function.Instance instance = Function.Instance.newBuilder().setFunctionMetaData(functionMeta).build();
RuntimeSpawner runtimeSpawner = spy(actioner.getRuntimeSpawner(instance, "foo"));
assertNull(runtimeSpawner.getInstanceConfig().getFunctionAuthenticationSpec());
FunctionRuntimeInfo functionRuntimeInfo = mock(FunctionRuntimeInfo.class);
RuntimeFactory runtimeFactory = mock(RuntimeFactory.class);
Optional<FunctionAuthProvider> functionAuthProvider = Optional.of(mock(FunctionAuthProvider.class));
doReturn(functionAuthProvider).when(runtimeFactory).getAuthProvider();
doReturn(runtimeFactory).when(runtimeSpawner).getRuntimeFactory();
doReturn(instance).when(functionRuntimeInfo).getFunctionInstance();
doReturn(runtimeSpawner).when(functionRuntimeInfo).getRuntimeSpawner();
actioner.terminateFunction(functionRuntimeInfo);
// make sure cache
verify(functionAuthProvider.get(), times(0)).cleanUpAuthData(any(), any());
}
use of org.apache.pulsar.functions.auth.FunctionAuthProvider in project pulsar by yahoo.
the class FunctionActionerTest method testFunctionAuthDisabled.
@Test
public void testFunctionAuthDisabled() 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://localhost:6650");
workerConfig.setStateStorageServiceUrl("foo");
workerConfig.setFunctionAssignmentTopicName("assignments");
String downloadDir = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
workerConfig.setDownloadDirectory(downloadDir);
RuntimeFactory factory = mock(RuntimeFactory.class);
Runtime runtime = mock(Runtime.class);
doReturn(runtime).when(factory).createContainer(any(), any(), any(), any());
doNothing().when(runtime).start();
Namespace dlogNamespace = mock(Namespace.class);
final String exceptionMsg = "dl namespace not-found";
doThrow(new IllegalArgumentException(exceptionMsg)).when(dlogNamespace).openLog(any());
@SuppressWarnings("resource") FunctionActioner actioner = new FunctionActioner(workerConfig, factory, dlogNamespace, new ConnectorsManager(workerConfig), new FunctionsManager(workerConfig), mock(PulsarAdmin.class));
String pkgPathLocation = "http://invalid/my-file.jar";
Function.FunctionMetaData functionMeta = Function.FunctionMetaData.newBuilder().setFunctionDetails(Function.FunctionDetails.newBuilder().setTenant("test-tenant").setNamespace("test-namespace").setName("func-1")).setPackageLocation(PackageLocationMetaData.newBuilder().setPackagePath(pkgPathLocation).build()).build();
Function.Instance instance = Function.Instance.newBuilder().setFunctionMetaData(functionMeta).build();
RuntimeSpawner runtimeSpawner = spy(actioner.getRuntimeSpawner(instance, "foo"));
assertNull(runtimeSpawner.getInstanceConfig().getFunctionAuthenticationSpec());
FunctionRuntimeInfo functionRuntimeInfo = mock(FunctionRuntimeInfo.class);
RuntimeFactory runtimeFactory = mock(RuntimeFactory.class);
Optional<FunctionAuthProvider> functionAuthProvider = Optional.of(mock(FunctionAuthProvider.class));
doReturn(functionAuthProvider).when(runtimeFactory).getAuthProvider();
doReturn(runtimeFactory).when(runtimeSpawner).getRuntimeFactory();
doReturn(instance).when(functionRuntimeInfo).getFunctionInstance();
doReturn(runtimeSpawner).when(functionRuntimeInfo).getRuntimeSpawner();
actioner.terminateFunction(functionRuntimeInfo);
// make sure cache
verify(functionAuthProvider.get(), times(0)).cleanUpAuthData(any(), any());
}
use of org.apache.pulsar.functions.auth.FunctionAuthProvider in project pulsar by apache.
the class FunctionActionerTest method testFunctionAuthDisabled.
@Test
public void testFunctionAuthDisabled() 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://localhost:6650");
workerConfig.setStateStorageServiceUrl("foo");
workerConfig.setFunctionAssignmentTopicName("assignments");
String downloadDir = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
workerConfig.setDownloadDirectory(downloadDir);
RuntimeFactory factory = mock(RuntimeFactory.class);
Runtime runtime = mock(Runtime.class);
doReturn(runtime).when(factory).createContainer(any(), any(), any(), any());
doNothing().when(runtime).start();
Namespace dlogNamespace = mock(Namespace.class);
final String exceptionMsg = "dl namespace not-found";
doThrow(new IllegalArgumentException(exceptionMsg)).when(dlogNamespace).openLog(any());
@SuppressWarnings("resource") FunctionActioner actioner = new FunctionActioner(workerConfig, factory, dlogNamespace, new ConnectorsManager(workerConfig), new FunctionsManager(workerConfig), mock(PulsarAdmin.class));
String pkgPathLocation = "http://invalid/my-file.jar";
Function.FunctionMetaData functionMeta = Function.FunctionMetaData.newBuilder().setFunctionDetails(Function.FunctionDetails.newBuilder().setTenant("test-tenant").setNamespace("test-namespace").setName("func-1")).setPackageLocation(PackageLocationMetaData.newBuilder().setPackagePath(pkgPathLocation).build()).build();
Function.Instance instance = Function.Instance.newBuilder().setFunctionMetaData(functionMeta).build();
RuntimeSpawner runtimeSpawner = spy(actioner.getRuntimeSpawner(instance, "foo"));
assertNull(runtimeSpawner.getInstanceConfig().getFunctionAuthenticationSpec());
FunctionRuntimeInfo functionRuntimeInfo = mock(FunctionRuntimeInfo.class);
RuntimeFactory runtimeFactory = mock(RuntimeFactory.class);
Optional<FunctionAuthProvider> functionAuthProvider = Optional.of(mock(FunctionAuthProvider.class));
doReturn(functionAuthProvider).when(runtimeFactory).getAuthProvider();
doReturn(runtimeFactory).when(runtimeSpawner).getRuntimeFactory();
doReturn(instance).when(functionRuntimeInfo).getFunctionInstance();
doReturn(runtimeSpawner).when(functionRuntimeInfo).getRuntimeSpawner();
actioner.terminateFunction(functionRuntimeInfo);
// make sure cache
verify(functionAuthProvider.get(), times(0)).cleanUpAuthData(any(), any());
}
Aggregations