Search in sources :

Example 1 with WorkerUtils

use of org.apache.pulsar.functions.worker.WorkerUtils in project pulsar by apache.

the class SinkApiV3ResourceTest method testDeregisterSinkBKPackageCleanup.

@Test
public void testDeregisterSinkBKPackageCleanup() throws IOException {
    mockInstanceUtils();
    try (final MockedStatic<WorkerUtils> ctx = Mockito.mockStatic(WorkerUtils.class)) {
        when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(sink))).thenReturn(true);
        String packagePath = "public/default/test/591541f0-c7c5-40c0-983b-610c722f90b0-pulsar-io-batch-data-generator-2.7.0.nar";
        when(mockedManager.getFunctionMetaData(eq(tenant), eq(namespace), eq(sink))).thenReturn(FunctionMetaData.newBuilder().setPackageLocation(Function.PackageLocationMetaData.newBuilder().setPackagePath(packagePath).build()).build());
        deregisterDefaultSink();
        ctx.verify(() -> {
            WorkerUtils.deleteFromBookkeeper(any(), eq(packagePath));
        }, times(1));
    }
}
Also used : WorkerUtils(org.apache.pulsar.functions.worker.WorkerUtils) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.testng.annotations.Test)

Example 2 with WorkerUtils

use of org.apache.pulsar.functions.worker.WorkerUtils in project pulsar by apache.

the class SourceApiV3ResourceTest method testDeregisterFileSourceBKPackageCleanup.

@Test
public void testDeregisterFileSourceBKPackageCleanup() throws IOException {
    String packagePath = "file://foo/connector.jar";
    try (final MockedStatic<WorkerUtils> ctx = Mockito.mockStatic(WorkerUtils.class)) {
        when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(source))).thenReturn(true);
        when(mockedManager.getFunctionMetaData(eq(tenant), eq(namespace), eq(source))).thenReturn(FunctionMetaData.newBuilder().setPackageLocation(PackageLocationMetaData.newBuilder().setPackagePath(packagePath).build()).build());
        deregisterDefaultSource();
        // if the source has a file url, we shouldn't try to clean it up
        ctx.verify(() -> {
            WorkerUtils.deleteFromBookkeeper(any(), eq(packagePath));
        }, times(0));
    }
}
Also used : WorkerUtils(org.apache.pulsar.functions.worker.WorkerUtils) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

Example 3 with WorkerUtils

use of org.apache.pulsar.functions.worker.WorkerUtils in project pulsar by apache.

the class SinkApiV3ResourceTest method testDeregisterBuiltinSinkBKPackageCleanup.

@Test
public void testDeregisterBuiltinSinkBKPackageCleanup() {
    mockInstanceUtils();
    try (final MockedStatic<WorkerUtils> ctx = Mockito.mockStatic(WorkerUtils.class)) {
        when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(sink))).thenReturn(true);
        String packagePath = String.format("%s://data-generator", Utils.BUILTIN);
        when(mockedManager.getFunctionMetaData(eq(tenant), eq(namespace), eq(sink))).thenReturn(FunctionMetaData.newBuilder().setPackageLocation(Function.PackageLocationMetaData.newBuilder().setPackagePath(packagePath).build()).build());
        deregisterDefaultSink();
        // if the sink is a builtin sink we shouldn't try to clean it up
        ctx.verify(() -> {
            WorkerUtils.deleteFromBookkeeper(any(), eq(packagePath));
        }, times(0));
    }
}
Also used : WorkerUtils(org.apache.pulsar.functions.worker.WorkerUtils) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.testng.annotations.Test)

Example 4 with WorkerUtils

use of org.apache.pulsar.functions.worker.WorkerUtils in project pulsar by yahoo.

the class SinkApiV3ResourceTest method testDeregisterBuiltinSinkBKPackageCleanup.

@Test
public void testDeregisterBuiltinSinkBKPackageCleanup() {
    mockInstanceUtils();
    try (final MockedStatic<WorkerUtils> ctx = Mockito.mockStatic(WorkerUtils.class)) {
        when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(sink))).thenReturn(true);
        String packagePath = String.format("%s://data-generator", Utils.BUILTIN);
        when(mockedManager.getFunctionMetaData(eq(tenant), eq(namespace), eq(sink))).thenReturn(FunctionMetaData.newBuilder().setPackageLocation(Function.PackageLocationMetaData.newBuilder().setPackagePath(packagePath).build()).build());
        deregisterDefaultSink();
        // if the sink is a builtin sink we shouldn't try to clean it up
        ctx.verify(() -> {
            WorkerUtils.deleteFromBookkeeper(any(), eq(packagePath));
        }, times(0));
    }
}
Also used : WorkerUtils(org.apache.pulsar.functions.worker.WorkerUtils) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.testng.annotations.Test)

Example 5 with WorkerUtils

use of org.apache.pulsar.functions.worker.WorkerUtils in project pulsar by yahoo.

the class SinkApiV3ResourceTest method testDeregisterSinkBKPackageCleanup.

@Test
public void testDeregisterSinkBKPackageCleanup() throws IOException {
    mockInstanceUtils();
    try (final MockedStatic<WorkerUtils> ctx = Mockito.mockStatic(WorkerUtils.class)) {
        when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(sink))).thenReturn(true);
        String packagePath = "public/default/test/591541f0-c7c5-40c0-983b-610c722f90b0-pulsar-io-batch-data-generator-2.7.0.nar";
        when(mockedManager.getFunctionMetaData(eq(tenant), eq(namespace), eq(sink))).thenReturn(FunctionMetaData.newBuilder().setPackageLocation(Function.PackageLocationMetaData.newBuilder().setPackagePath(packagePath).build()).build());
        deregisterDefaultSink();
        ctx.verify(() -> {
            WorkerUtils.deleteFromBookkeeper(any(), eq(packagePath));
        }, times(1));
    }
}
Also used : WorkerUtils(org.apache.pulsar.functions.worker.WorkerUtils) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.testng.annotations.Test)

Aggregations

WorkerUtils (org.apache.pulsar.functions.worker.WorkerUtils)24 Test (org.testng.annotations.Test)24 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 Mockito.anyString (org.mockito.Mockito.anyString)12