Search in sources :

Example 1 with ServiceA

use of org.apache.nifi.controller.service.mock.ServiceA in project nifi by apache.

the class TestFlowController method testReloadControllerService.

@Test
public void testReloadControllerService() {
    final String id = "ServiceA" + System.currentTimeMillis();
    final BundleCoordinate coordinate = systemBundle.getBundleDetails().getCoordinate();
    final ControllerServiceNode controllerServiceNode = controller.createControllerService(ServiceA.class.getName(), id, coordinate, null, true);
    final String originalName = controllerServiceNode.getName();
    assertEquals(id, controllerServiceNode.getIdentifier());
    assertEquals(id, controllerServiceNode.getComponent().getIdentifier());
    assertEquals(coordinate.getCoordinate(), controllerServiceNode.getBundleCoordinate().getCoordinate());
    assertEquals(ServiceA.class.getCanonicalName(), controllerServiceNode.getCanonicalClassName());
    assertEquals(ServiceA.class.getSimpleName(), controllerServiceNode.getComponentType());
    assertEquals(ServiceA.class.getCanonicalName(), controllerServiceNode.getComponent().getClass().getCanonicalName());
    controller.reload(controllerServiceNode, ServiceB.class.getName(), coordinate, Collections.emptySet());
    // ids and coordinate should stay the same
    assertEquals(id, controllerServiceNode.getIdentifier());
    assertEquals(id, controllerServiceNode.getComponent().getIdentifier());
    assertEquals(coordinate.getCoordinate(), controllerServiceNode.getBundleCoordinate().getCoordinate());
    // in this test we happened to change between two services that have different canonical class names
    // but in the running application the DAO layer would call verifyCanUpdateBundle and would prevent this so
    // for the sake of this test it is ok that the canonical class name hasn't changed
    assertEquals(originalName, controllerServiceNode.getName());
    assertEquals(ServiceA.class.getCanonicalName(), controllerServiceNode.getCanonicalClassName());
    assertEquals(ServiceA.class.getSimpleName(), controllerServiceNode.getComponentType());
    assertEquals(ServiceB.class.getCanonicalName(), controllerServiceNode.getComponent().getClass().getCanonicalName());
}
Also used : ServiceB(org.apache.nifi.controller.service.mock.ServiceB) ServiceA(org.apache.nifi.controller.service.mock.ServiceA) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) Test(org.junit.Test)

Example 2 with ServiceA

use of org.apache.nifi.controller.service.mock.ServiceA in project nifi by apache.

the class TestFlowController method testReloadControllerServiceWithAdditionalResources.

@Test
public void testReloadControllerServiceWithAdditionalResources() throws MalformedURLException {
    final URL resource1 = new File("src/test/resources/TestClasspathResources/resource1.txt").toURI().toURL();
    final URL resource2 = new File("src/test/resources/TestClasspathResources/resource2.txt").toURI().toURL();
    final URL resource3 = new File("src/test/resources/TestClasspathResources/resource3.txt").toURI().toURL();
    final Set<URL> additionalUrls = new LinkedHashSet<>(Arrays.asList(resource1, resource2, resource3));
    final String id = "ServiceA" + System.currentTimeMillis();
    final BundleCoordinate coordinate = systemBundle.getBundleDetails().getCoordinate();
    final ControllerServiceNode controllerServiceNode = controller.createControllerService(ServiceA.class.getName(), id, coordinate, null, true);
    final String originalName = controllerServiceNode.getName();
    // the instance class loader shouldn't have any of the resources yet
    InstanceClassLoader instanceClassLoader = ExtensionManager.getInstanceClassLoader(id);
    assertNotNull(instanceClassLoader);
    assertFalse(containsResource(instanceClassLoader.getURLs(), resource1));
    assertFalse(containsResource(instanceClassLoader.getURLs(), resource2));
    assertFalse(containsResource(instanceClassLoader.getURLs(), resource3));
    assertTrue(instanceClassLoader.getAdditionalResourceUrls().isEmpty());
    controller.reload(controllerServiceNode, ServiceB.class.getName(), coordinate, additionalUrls);
    // the instance class loader shouldn't have any of the resources yet
    instanceClassLoader = ExtensionManager.getInstanceClassLoader(id);
    assertNotNull(instanceClassLoader);
    assertTrue(containsResource(instanceClassLoader.getURLs(), resource1));
    assertTrue(containsResource(instanceClassLoader.getURLs(), resource2));
    assertTrue(containsResource(instanceClassLoader.getURLs(), resource3));
    assertEquals(3, instanceClassLoader.getAdditionalResourceUrls().size());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ServiceB(org.apache.nifi.controller.service.mock.ServiceB) ServiceA(org.apache.nifi.controller.service.mock.ServiceA) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) InstanceClassLoader(org.apache.nifi.nar.InstanceClassLoader) File(java.io.File) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) URL(java.net.URL) Test(org.junit.Test)

Aggregations

BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)2 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)2 ServiceA (org.apache.nifi.controller.service.mock.ServiceA)2 ServiceB (org.apache.nifi.controller.service.mock.ServiceB)2 Test (org.junit.Test)2 File (java.io.File)1 URL (java.net.URL)1 LinkedHashSet (java.util.LinkedHashSet)1 InstanceClassLoader (org.apache.nifi.nar.InstanceClassLoader)1