Search in sources :

Example 1 with StandardControllerServiceNode

use of org.apache.nifi.controller.service.StandardControllerServiceNode in project nifi by apache.

the class TestStandardProcessScheduler method validateEnabledDisableMultiThread.

/**
 * Validates that in multi threaded environment enabling service can still
 * be disabled. This test is set up in such way that disabling of the
 * service could be initiated by both disable and enable methods. In other
 * words it tests two conditions in
 * {@link StandardControllerServiceNode#disable(java.util.concurrent.ScheduledExecutorService, Heartbeater)}
 * where the disabling of the service can be initiated right there (if
 * ENABLED), or if service is still enabling its disabling will be deferred
 * to the logic in
 * {@link StandardControllerServiceNode#enable(java.util.concurrent.ScheduledExecutorService, long, Heartbeater)}
 * IN any even the resulting state of the service is DISABLED
 */
@Test
@Ignore
public void validateEnabledDisableMultiThread() throws Exception {
    final StandardProcessScheduler scheduler = createScheduler();
    final StandardControllerServiceProvider provider = new StandardControllerServiceProvider(controller, scheduler, null, stateMgrProvider, variableRegistry, nifiProperties);
    final ExecutorService executor = Executors.newCachedThreadPool();
    for (int i = 0; i < 200; i++) {
        final ControllerServiceNode serviceNode = provider.createControllerService(RandomShortDelayEnablingService.class.getName(), "1", systemBundle.getBundleDetails().getCoordinate(), null, false);
        executor.execute(new Runnable() {

            @Override
            public void run() {
                scheduler.enableControllerService(serviceNode);
            }
        });
        // ensure that enable gets initiated before disable
        Thread.sleep(10);
        executor.execute(new Runnable() {

            @Override
            public void run() {
                scheduler.disableControllerService(serviceNode);
            }
        });
        Thread.sleep(100);
        assertFalse(serviceNode.isActive());
        assertTrue(serviceNode.getState() == ControllerServiceState.DISABLED);
    }
    // need to sleep a while since we are emulating async invocations on
    // method that is also internally async
    Thread.sleep(500);
    executor.shutdown();
    executor.awaitTermination(5000, TimeUnit.MILLISECONDS);
}
Also used : ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) StandardControllerServiceNode(org.apache.nifi.controller.service.StandardControllerServiceNode) StandardControllerServiceProvider(org.apache.nifi.controller.service.StandardControllerServiceProvider) ExecutorService(java.util.concurrent.ExecutorService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

ExecutorService (java.util.concurrent.ExecutorService)1 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)1 StandardControllerServiceNode (org.apache.nifi.controller.service.StandardControllerServiceNode)1 StandardControllerServiceProvider (org.apache.nifi.controller.service.StandardControllerServiceProvider)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1