Search in sources :

Example 1 with ContextServiceImpl

use of org.glassfish.enterprise.concurrent.ContextServiceImpl in project Payara by payara.

the class ConcurrentRuntimeTest method testParseContextInfo_null.

@Test
public void testParseContextInfo_null() throws Exception {
    expect(contextServiceConfig.getJndiName()).andReturn("concurrent/ctxSrv").anyTimes();
    expect(contextServiceConfig.getContextInfo()).andReturn(null).anyTimes();
    expect(contextServiceConfig.getContextInfoEnabled()).andReturn("true");
    replay(contextServiceConfig);
    ConcurrentRuntime concurrentRuntime = new ConcurrentRuntime();
    ResourceInfo resource = new ResourceInfo("test");
    ContextServiceImpl contextService = concurrentRuntime.getContextService(resource, contextServiceConfig);
    ContextSetupProviderImpl contextSetupProvider = (ContextSetupProviderImpl) contextService.getContextSetupProvider();
    assertTrue((Boolean) Util.getdFieldValue(contextSetupProvider, "classloading"));
    assertTrue((Boolean) Util.getdFieldValue(contextSetupProvider, "naming"));
    assertTrue((Boolean) Util.getdFieldValue(contextSetupProvider, "security"));
    assertTrue((Boolean) Util.getdFieldValue(contextSetupProvider, "workArea"));
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) ContextServiceImpl(org.glassfish.enterprise.concurrent.ContextServiceImpl) Test(org.junit.Test)

Example 2 with ContextServiceImpl

use of org.glassfish.enterprise.concurrent.ContextServiceImpl in project Payara by payara.

the class ConcurrentRuntimeTest method testCreateManagedThreadFactory.

// re-enable when API added to ManagedThreadFactoryImpl to retrieve ContextService and threadPriority
@Ignore
@Test
public void testCreateManagedThreadFactory() throws Exception {
    final int THREAD_PRIORITY = 8;
    expect(managedThreadFactoryConfig.getJndiName()).andReturn("concurrent/mtf").anyTimes();
    expect(managedThreadFactoryConfig.getContextInfo()).andReturn("Classloader, JNDI, Security").anyTimes();
    expect(managedThreadFactoryConfig.getContextInfoEnabled()).andReturn("true").anyTimes();
    expect(managedThreadFactoryConfig.getThreadPriority()).andReturn(THREAD_PRIORITY).anyTimes();
    replay(managedThreadFactoryConfig);
    ConcurrentRuntime concurrentRuntime = new ConcurrentRuntime();
    ResourceInfo resource = new ResourceInfo("test");
    ManagedThreadFactoryImpl managedThreadFactory = concurrentRuntime.getManagedThreadFactory(resource, managedThreadFactoryConfig);
    ContextServiceImpl contextService = (ContextServiceImpl) Util.getdFieldValue(managedThreadFactory, "contextService");
    ContextSetupProviderImpl contextSetupProvider = (ContextSetupProviderImpl) contextService.getContextSetupProvider();
    assertTrue((Boolean) Util.getdFieldValue(contextSetupProvider, "classloading"));
    assertTrue((Boolean) Util.getdFieldValue(contextSetupProvider, "naming"));
    assertTrue((Boolean) Util.getdFieldValue(contextSetupProvider, "security"));
    assertFalse((Boolean) Util.getdFieldValue(contextSetupProvider, "workArea"));
    int threadPriority = (Integer) Util.getdFieldValue(managedThreadFactory, "priority");
    assertEquals(THREAD_PRIORITY, threadPriority);
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) ManagedThreadFactoryImpl(org.glassfish.enterprise.concurrent.ManagedThreadFactoryImpl) ContextServiceImpl(org.glassfish.enterprise.concurrent.ContextServiceImpl) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with ContextServiceImpl

use of org.glassfish.enterprise.concurrent.ContextServiceImpl in project Payara by payara.

the class ConcurrentRuntimeTest method testParseContextInfo_empty.

@Test
public void testParseContextInfo_empty() throws Exception {
    expect(contextServiceConfig.getJndiName()).andReturn("concurrent/ctxSrv").anyTimes();
    expect(contextServiceConfig.getContextInfo()).andReturn("").anyTimes();
    expect(contextServiceConfig.getContextInfoEnabled()).andReturn("true");
    replay(contextServiceConfig);
    ConcurrentRuntime concurrentRuntime = new ConcurrentRuntime();
    ResourceInfo resource = new ResourceInfo("test");
    ContextServiceImpl contextService = concurrentRuntime.getContextService(resource, contextServiceConfig);
    ContextSetupProviderImpl contextSetupProvider = (ContextSetupProviderImpl) contextService.getContextSetupProvider();
    assertFalse((Boolean) Util.getdFieldValue(contextSetupProvider, "classloading"));
    assertFalse((Boolean) Util.getdFieldValue(contextSetupProvider, "naming"));
    assertFalse((Boolean) Util.getdFieldValue(contextSetupProvider, "security"));
    assertFalse((Boolean) Util.getdFieldValue(contextSetupProvider, "workArea"));
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) ContextServiceImpl(org.glassfish.enterprise.concurrent.ContextServiceImpl) Test(org.junit.Test)

Example 4 with ContextServiceImpl

use of org.glassfish.enterprise.concurrent.ContextServiceImpl in project Payara by payara.

the class ConcurrentRuntimeTest method testParseContextInfo_disabled.

@Test
public void testParseContextInfo_disabled() throws Exception {
    expect(contextServiceConfig.getJndiName()).andReturn("concurrent/ctxSrv").anyTimes();
    expect(contextServiceConfig.getContextInfo()).andReturn("Classloader, JNDI, Security, WorkArea").anyTimes();
    expect(contextServiceConfig.getContextInfoEnabled()).andReturn("false");
    replay(contextServiceConfig);
    ConcurrentRuntime concurrentRuntime = new ConcurrentRuntime();
    ResourceInfo resource = new ResourceInfo("test");
    ContextServiceImpl contextService = concurrentRuntime.getContextService(resource, contextServiceConfig);
    ContextSetupProviderImpl contextSetupProvider = (ContextSetupProviderImpl) contextService.getContextSetupProvider();
    assertFalse((Boolean) Util.getdFieldValue(contextSetupProvider, "classloading"));
    assertFalse((Boolean) Util.getdFieldValue(contextSetupProvider, "naming"));
    assertFalse((Boolean) Util.getdFieldValue(contextSetupProvider, "security"));
    assertFalse((Boolean) Util.getdFieldValue(contextSetupProvider, "workArea"));
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) ContextServiceImpl(org.glassfish.enterprise.concurrent.ContextServiceImpl) Test(org.junit.Test)

Example 5 with ContextServiceImpl

use of org.glassfish.enterprise.concurrent.ContextServiceImpl in project Payara by payara.

the class ConcurrentRuntimeTest method testParseContextInfo_lowerCase.

@Test
public void testParseContextInfo_lowerCase() throws Exception {
    expect(contextServiceConfig.getJndiName()).andReturn("concurrent/ctxSrv").anyTimes();
    expect(contextServiceConfig.getContextInfo()).andReturn("classloader, jndi, security, workarea").anyTimes();
    expect(contextServiceConfig.getContextInfoEnabled()).andReturn("true");
    replay(contextServiceConfig);
    ConcurrentRuntime concurrentRuntime = new ConcurrentRuntime();
    ResourceInfo resource = new ResourceInfo("test");
    ContextServiceImpl contextService = concurrentRuntime.getContextService(resource, contextServiceConfig);
    ContextSetupProviderImpl contextSetupProvider = (ContextSetupProviderImpl) contextService.getContextSetupProvider();
    assertTrue((Boolean) Util.getdFieldValue(contextSetupProvider, "classloading"));
    assertTrue((Boolean) Util.getdFieldValue(contextSetupProvider, "naming"));
    assertTrue((Boolean) Util.getdFieldValue(contextSetupProvider, "security"));
    assertTrue((Boolean) Util.getdFieldValue(contextSetupProvider, "workArea"));
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) ContextServiceImpl(org.glassfish.enterprise.concurrent.ContextServiceImpl) Test(org.junit.Test)

Aggregations

ContextServiceImpl (org.glassfish.enterprise.concurrent.ContextServiceImpl)8 ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)8 Test (org.junit.Test)8 ManagedThreadFactoryImpl (org.glassfish.enterprise.concurrent.ManagedThreadFactoryImpl)1 Ignore (org.junit.Ignore)1