[
https://issues.jboss.org/browse/AS7-3884?page=com.atlassian.jira.plugin.s...
]
Prasad Deshpande commented on AS7-3884:
---------------------------------------
I'm just posting code relevant to InitialContext creation & lookup
{code}
//protected Hashtable<String, Object> mApplicationServerProperties; defined
in parent class
public RemoteClientAPI() throws CaseWareException {
super();
searchAndLoadJndiProperties(null);
initialiseAppServerSettings(null);
}
private void searchAndLoadJndiProperties(Hashtable<String, String>
applicationServerProperties) throws CaseWareException {
InputStream is =
getClass().getClassLoader().getResourceAsStream("jndi.properties");
Properties p = new Properties();
try {
if (is != null) {
p.load(is);
}
if (mApplicationServerProperties == null) {
mApplicationServerProperties = new Hashtable<String, Object>();
}
Set<Object> keys = p.keySet();
for (Object key : keys) {
if (key != null) {
if("jboss.naming.client.ejb.context".equalsIgnoreCase(key.toString())){
mApplicationServerProperties.put(key.toString(),
Boolean.parseBoolean(p.getProperty(key.toString())));
}else{
mApplicationServerProperties.put(key.toString(), p.getProperty(key.toString()));
}
}
}
if (applicationServerProperties != null) {
// Set<String> sup = applicationServerProperties.keySet();
for (Entry<String, String> entry : applicationServerProperties.entrySet()) {
if (!Util.isEmpty(entry.getKey()) && !Util.isEmpty(entry.getValue())) {
mApplicationServerProperties.put(entry.getKey(), entry.getValue());
}
}
}
} catch (IOException e) {
//e.printStackTrace();
}
}
private void initialiseAppServerSettings(String remoteUrl){
try {
String appServer = System.getProperty("caseware.server.Appserver");
if(Util.isEmpty(appServer) ||
ConfigConstants.JBOSS_APP_SERVER.equalsIgnoreCase(appServer)){
try {
//purposely loading class using forName, don't want jboss specific class to be
loaded
//for other app servers.
Class<?> jbossClass =
Class.forName("com.banctec.caseware.client.api.JBossRemoteClientSetting");
RemoteClientSetting jboss = (RemoteClientSetting)jbossClass.newInstance();
jboss.initialiseClientSettings(remoteUrl);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
} catch (CaseWareException e) {
e.printStackTrace();
}
}
// This is where remote EJB is looked up
protected RemoteEJB createRemoteEJB() throws javax.naming.NamingException {
if (var!= null) {
return var;
}
if (mContext == null) {
mContext = new InitialContext(mApplicationServerProperties);
}
var= (RemoteEJB) mContext.lookup("ejb:<some name here>");
return var;
}
& code from com.banctec.caseware.client.api.JBossRemoteClientSetting class
public void initialiseClientSettings(String remoteUrl) throws CaseWareException{
Properties props = loadJbossEjbClientProperties(remoteUrl); // here I'm loading
properties specified in
// jboss-ejb-client.properties & overriding host & port if
necessary
//override only if url is different that default
if(props != null){
final EJBClientConfiguration ejbClientConfiguration = new
PropertiesBasedEJBClientConfiguration(props);
final ContextSelector<EJBClientContext> ejbClientContextSelector = new
ConfigBasedEJBClientContextSelector(ejbClientConfiguration);
if(jBossDefaultSelector == null){
jBossDefaultSelector = EJBClientContext.setSelector(ejbClientContextSelector);
}else{
EJBClientContext.setSelector(ejbClientContextSelector);
}
}else if(jBossDefaultSelector != null){
EJBClientContext.setSelector(jBossDefaultSelector);
}
}
{code}
Once RemoteClientAPI instance is ready, I'm calling business methods...
Load testing application with Jmeter & jboss remoting throws
exception saying "Too many channels open"
------------------------------------------------------------------------------------------------------
Key: AS7-3884
URL:
https://issues.jboss.org/browse/AS7-3884
Project: Application Server 7
Issue Type: Bug
Components: EJB, Naming
Affects Versions: 7.1.0.Final
Environment: windows 64 bit
Reporter: Prasad Deshpande
Assignee: jaikiran pai
I've created a sampler for JMeter for load testing application. When I ran that with
say around 30 threads with rampup time 80 seconds, after a while I kept getting exception
specified in
https://community.jboss.org/thread/195709?tstart=0. I later tried to close
InitialContext in teardown methods, but wasn't really helpful. I looked at no. of
InitialContext intances present in the VM using visualvm heapdump & found that just
before throwing exception, it was 24 & after throwing exception for all threads, it
did reach to 30, but it wasn't useful..
Please note that, I'm creating InitialContext with passing following parameters to
it:
java.naming.factory.url.pkgs=org.jboss.ejb.client.naming
java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory
java.naming.provider.url=remote://localhost:4447
jboss.naming.client.ejb.context=true
Here is the code for Java Sampler
{code}
package com;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient;
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
import org.apache.jmeter.samplers.SampleResult;
import com.banctec.caseware.client.api.API;
import com.banctec.caseware.client.api.RemoteClientAPI;
import com.banctec.caseware.resources.CaseResource;
import com.banctec.caseware.resources.LoginResource;
import com.banctec.caseware.resources.Resource;
public class EJBTest extends AbstractJavaSamplerClient {
private API api = null;
private Long typeId;
private int setupTestCalled = 0;
private int teardownTestCalled = 0;
private int runTestCalled = 0;
public Arguments getDefaultParameters() {
Arguments defaultParameters = new Arguments();
defaultParameters.addArgument("typeId", "1");
defaultParameters.addArgument("RunLoop", "200");
defaultParameters.addArgument("username", "abc");
defaultParameters.addArgument("password", "abc");
return defaultParameters;
}
public void setupTest(JavaSamplerContext context) {
try {
typeId = context.getLongParameter("typeId");
api = new RemoteClientAPI();//this is where InitialContext gets created
LoginResource loginResource = new
LoginResource(context.getParameter("username"),
context.getParameter("password"));
loginResource.setUseDefaultRole(Boolean.valueOf(true));
api.login(new Resource[] { loginResource });
}catch (Exception e) {
e.printStackTrace();
}
System.out.println(" Number of times setupTest called
"+(++setupTestCalled));
}
public void teardownTest(JavaSamplerContext context) {
try{
if (api != null) {
api.logout();//In this method InitialContext.close() get's called
}
}catch (Exception e) {
e.printStackTrace();
}
System.out.println(" Number of times teardownTest called
"+(++teardownTestCalled));
}
public SampleResult runTest(JavaSamplerContext context) {
SampleResult result = new SampleResult();
boolean success = true;
int loopCount = context.getIntParameter("RunLoop");
result.sampleStart();
//Here goes the code that will call few business methods on remote EJB's
in application
// I've purposely removed this bit here..
System.out.println(" Number of times runTest called "+(++runTestCalled));
result.sampleEnd();
result.setSuccessful(success);
return result;
}
}
{code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see:
http://www.atlassian.com/software/jira