Search in sources :

Example 6 with ManagedExecutorService

use of javax.enterprise.concurrent.ManagedExecutorService in project wildfly by wildfly.

the class ManagedExecutorServiceMetricsTestCase method testManagedScheduledExecutorServiceManagement.

@Test
public void testManagedScheduledExecutorServiceManagement() throws Exception {
    final PathAddress pathAddress = EE_SUBSYSTEM_PATH_ADDRESS.append(EESubsystemModel.MANAGED_SCHEDULED_EXECUTOR_SERVICE, RESOURCE_NAME);
    // add
    final ModelNode addOperation = Util.createAddOperation(pathAddress);
    final String jndiName = "java:jboss/ee/concurrency/scheduledexecutor/" + RESOURCE_NAME;
    addOperation.get(ManagedScheduledExecutorServiceResourceDefinition.JNDI_NAME).set(jndiName);
    // note: threads will increase till CORE_THREADS config value, then reuses if has idle thread
    addOperation.get(ManagedScheduledExecutorServiceResourceDefinition.CORE_THREADS).set(2);
    // task will be considered hung if duration > 1s
    addOperation.get(ManagedScheduledExecutorServiceResourceDefinition.HUNG_TASK_THRESHOLD).set(1000);
    final ModelNode addResult = managementClient.getControllerClient().execute(addOperation);
    Assert.assertFalse(addResult.get(FAILURE_DESCRIPTION).toString(), addResult.get(FAILURE_DESCRIPTION).isDefined());
    try {
        // lookup the executor
        final ManagedExecutorService executorService = InitialContext.doLookup(jndiName);
        Assert.assertNotNull(executorService);
        testRuntimeStats(pathAddress, executorService);
    } finally {
        // remove
        final ModelNode removeOperation = Util.createRemoveOperation(pathAddress);
        removeOperation.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
        final ModelNode removeResult = managementClient.getControllerClient().execute(removeOperation);
        Assert.assertFalse(removeResult.get(FAILURE_DESCRIPTION).toString(), removeResult.get(FAILURE_DESCRIPTION).isDefined());
    }
}
Also used : ManagedExecutorService(javax.enterprise.concurrent.ManagedExecutorService) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test)

Example 7 with ManagedExecutorService

use of javax.enterprise.concurrent.ManagedExecutorService in project wildfly by wildfly.

the class ManagedExecutorServiceMetricsTestCase method testMaxRequests.

/**
 * WFLY-13177 - this tests another edge-case when executor is busy, but a new task is rejected due to a max-requests counter achieved.
 * In that case RequestController will reject any other tasks which should not decrease/increase active request counter in RequestController.
 *
 * @throws Exception
 */
@Test
public void testMaxRequests() throws Exception {
    final PathAddress pathAddress = EE_SUBSYSTEM_PATH_ADDRESS.append(EESubsystemModel.MANAGED_EXECUTOR_SERVICE, RESOURCE_NAME);
    // add
    final ModelNode addOperation = Util.createAddOperation(pathAddress);
    final String jndiName = "java:jboss/ee/concurrency/maxrequests/" + RESOURCE_NAME;
    addOperation.get(ManagedExecutorServiceResourceDefinition.JNDI_NAME).set(jndiName);
    // note: threads will increase till CORE_THREADS config value, then reuses if has idle thread
    addOperation.get(ManagedExecutorServiceResourceDefinition.CORE_THREADS).set(2);
    addOperation.get(ManagedExecutorServiceResourceDefinition.QUEUE_LENGTH).set(1);
    final ModelNode addResult = managementClient.getControllerClient().execute(addOperation);
    Assert.assertFalse(addResult.get(FAILURE_DESCRIPTION).toString(), addResult.get(FAILURE_DESCRIPTION).isDefined());
    writeAttribute(REQUEST_CONTROLLER_PATH_ADDRESS, MAX_REQUEST_ATTRIBUTE_NAME, 3, true);
    try {
        final ManagedExecutorService executorService = InitialContext.doLookup(jndiName);
        Assert.assertNotNull(executorService);
        testActiveRequestStats(pathAddress, executorService);
    } finally {
        try {
            // remove
            final ModelNode removeOperation = Util.createRemoveOperation(pathAddress);
            removeOperation.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
            final ModelNode removeResult = managementClient.getControllerClient().execute(removeOperation);
            Assert.assertFalse(removeResult.get(FAILURE_DESCRIPTION).toString(), removeResult.get(FAILURE_DESCRIPTION).isDefined());
        } finally {
            undefineAttribute(REQUEST_CONTROLLER_PATH_ADDRESS, MAX_REQUEST_ATTRIBUTE_NAME, true);
        }
    }
}
Also used : ManagedExecutorService(javax.enterprise.concurrent.ManagedExecutorService) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test)

Example 8 with ManagedExecutorService

use of javax.enterprise.concurrent.ManagedExecutorService in project Payara by payara.

the class FaultToleranceService method getManagedExecutorService.

/**
 * Gets the configured ManagedExecutorService.
 * @return The configured ManagedExecutorService, or the default ManagedExecutorService if the configured one
 * couldn't be found
 * @throws NamingException If the default ManagedExecutorService couldn't be found
 */
public ManagedExecutorService getManagedExecutorService() throws NamingException {
    String managedExecutorServiceName = faultToleranceServiceConfiguration.getManagedExecutorService();
    InitialContext ctx = new InitialContext();
    ManagedExecutorService managedExecutorService;
    // If no name has been set, just get the default
    if (managedExecutorServiceName == null || managedExecutorServiceName.isEmpty()) {
        managedExecutorService = (ManagedExecutorService) ctx.lookup("java:comp/DefaultManagedExecutorService");
    } else {
        try {
            managedExecutorService = (ManagedExecutorService) ctx.lookup(managedExecutorServiceName);
        } catch (NamingException ex) {
            logger.log(Level.INFO, "Could not find configured ManagedExecutorService, " + managedExecutorServiceName + ", so resorting to default", ex);
            managedExecutorService = (ManagedExecutorService) ctx.lookup("java:comp/DefaultManagedExecutorService");
        }
    }
    return managedExecutorService;
}
Also used : ManagedExecutorService(javax.enterprise.concurrent.ManagedExecutorService) NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext)

Example 9 with ManagedExecutorService

use of javax.enterprise.concurrent.ManagedExecutorService in project wildfly by wildfly.

the class ManagedExecutorServiceMetricsTestCase method testManagedExecutorServiceManagement.

@Test
public void testManagedExecutorServiceManagement() throws Exception {
    final PathAddress pathAddress = EE_SUBSYSTEM_PATH_ADDRESS.append(EESubsystemModel.MANAGED_EXECUTOR_SERVICE, RESOURCE_NAME);
    // add
    final ModelNode addOperation = Util.createAddOperation(pathAddress);
    final String jndiName = "java:jboss/ee/concurrency/executor/" + RESOURCE_NAME;
    addOperation.get(ManagedExecutorServiceResourceDefinition.JNDI_NAME).set(jndiName);
    // note: threads will increase till CORE_THREADS config value, then reuses if has idle thread
    addOperation.get(ManagedExecutorServiceResourceDefinition.CORE_THREADS).set(2);
    // task will be considered hung if duration > 1s
    addOperation.get(ManagedExecutorServiceResourceDefinition.HUNG_TASK_THRESHOLD).set(1000);
    final ModelNode addResult = managementClient.getControllerClient().execute(addOperation);
    Assert.assertFalse(addResult.get(FAILURE_DESCRIPTION).toString(), addResult.get(FAILURE_DESCRIPTION).isDefined());
    try {
        final ManagedExecutorService executorService = InitialContext.doLookup(jndiName);
        Assert.assertNotNull(executorService);
        testRuntimeStats(pathAddress, executorService);
    } finally {
        // remove
        final ModelNode removeOperation = Util.createRemoveOperation(pathAddress);
        removeOperation.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
        final ModelNode removeResult = managementClient.getControllerClient().execute(removeOperation);
        Assert.assertFalse(removeResult.get(FAILURE_DESCRIPTION).toString(), removeResult.get(FAILURE_DESCRIPTION).isDefined());
    }
}
Also used : ManagedExecutorService(javax.enterprise.concurrent.ManagedExecutorService) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test)

Example 10 with ManagedExecutorService

use of javax.enterprise.concurrent.ManagedExecutorService in project wildfly by wildfly.

the class ManagedExecutorServiceMetricsTestCase method testActiveRequests.

/**
 * WFLY-13177 - this tests an edge-case when executor threads are all busy and even queue is at its maximum. In that case
 * the executor will reject any other tasks which should not increase active request counter in RequestController.
 *
 * @throws Exception
 */
@Test
public void testActiveRequests() throws Exception {
    final PathAddress pathAddress = EE_SUBSYSTEM_PATH_ADDRESS.append(EESubsystemModel.MANAGED_EXECUTOR_SERVICE, RESOURCE_NAME);
    // add
    final ModelNode addOperation = Util.createAddOperation(pathAddress);
    final String jndiName = "java:jboss/ee/concurrency/activerequests/" + RESOURCE_NAME;
    addOperation.get(ManagedExecutorServiceResourceDefinition.JNDI_NAME).set(jndiName);
    // note: threads will increase till CORE_THREADS config value, then reuses if has idle thread
    addOperation.get(ManagedExecutorServiceResourceDefinition.CORE_THREADS).set(2);
    addOperation.get(ManagedExecutorServiceResourceDefinition.QUEUE_LENGTH).set(1);
    final ModelNode addResult = managementClient.getControllerClient().execute(addOperation);
    Assert.assertFalse(addResult.get(FAILURE_DESCRIPTION).toString(), addResult.get(FAILURE_DESCRIPTION).isDefined());
    try {
        final ManagedExecutorService executorService = InitialContext.doLookup(jndiName);
        Assert.assertNotNull(executorService);
        testActiveRequestStats(pathAddress, executorService);
    } finally {
        // remove
        final ModelNode removeOperation = Util.createRemoveOperation(pathAddress);
        removeOperation.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
        final ModelNode removeResult = managementClient.getControllerClient().execute(removeOperation);
        Assert.assertFalse(removeResult.get(FAILURE_DESCRIPTION).toString(), removeResult.get(FAILURE_DESCRIPTION).isDefined());
    }
}
Also used : ManagedExecutorService(javax.enterprise.concurrent.ManagedExecutorService) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test)

Aggregations

ManagedExecutorService (javax.enterprise.concurrent.ManagedExecutorService)10 PathAddress (org.jboss.as.controller.PathAddress)8 ModelNode (org.jboss.dmr.ModelNode)8 Test (org.junit.Test)8 FaultToleranceService (fish.payara.microprofile.faulttolerance.FaultToleranceService)1 FallbackPolicy (fish.payara.microprofile.faulttolerance.interceptors.fallback.FallbackPolicy)1 Callable (java.util.concurrent.Callable)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 AroundInvoke (javax.interceptor.AroundInvoke)1 InitialContext (javax.naming.InitialContext)1 NamingException (javax.naming.NamingException)1 Config (org.eclipse.microprofile.config.Config)1 Fallback (org.eclipse.microprofile.faulttolerance.Fallback)1 FaultToleranceException (org.eclipse.microprofile.faulttolerance.exceptions.FaultToleranceException)1 InvocationManager (org.glassfish.api.invocation.InvocationManager)1