User: starksm
Date: 01/07/14 00:34:44
Added: src/main/org/jboss/test/perf/test Setup.java
Log:
Add security overhead performance tests
Revision Changes Path
1.1 jbosstest/src/main/org/jboss/test/perf/test/Setup.java
Index: Setup.java
===================================================================
package org.jboss.test.perf.test;
import java.io.IOException;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import javax.security.auth.login.LoginContext;
import junit.extensions.TestSetup;
import junit.framework.TestSuite;
import org.jboss.test.perf.interfaces.Entity;
import org.jboss.test.perf.interfaces.EntityPK;
import org.jboss.test.perf.interfaces.Entity2PK;
import org.jboss.test.perf.interfaces.EntityHome;
import org.jboss.test.perf.interfaces.Entity2Home;
import org.jboss.test.util.Deploy;
/** Setup utility class.
@author [EMAIL PROTECTED]
@version $Revision: 1.1 $
*/
public class Setup extends TestSetup
{
LoginContext lc = null;
String filename;
boolean isSecure;
Setup(TestSuite suite, String filename, boolean isSecure)
{
super(suite);
this.filename = filename;
this.isSecure = isSecure;
}
protected void setUp() throws Exception
{
System.out.println("+++ Performing the TestSuite setup");
if( isSecure )
login();
Deploy.deploy(filename);
createEntityBeans(1000);
createEntity2Beans(1000);
}
protected void tearDown() throws Exception
{
System.out.println("+++ Performing the TestSuite tear down");
removeEntityBeans(1000);
removeEntity2Beans(1000);
Deploy.undeploy(filename);
if( isSecure )
logout();
}
private void createEntityBeans(int max) throws Exception
{
InitialContext jndiContext = new InitialContext();
String jndiName = isSecure ? "secure/perf/Entity" : "Entity";
Object obj = jndiContext.lookup(jndiName);
obj = PortableRemoteObject.narrow(obj, EntityHome.class);
EntityHome home = (EntityHome) obj;
System.out.println("Creating "+max+" Entity beans");
for(int n = 0; n < max; n ++)
home.create(n, n);
}
private void removeEntityBeans(int max) throws Exception
{
InitialContext jndiContext = new InitialContext();
String jndiName = isSecure ? "secure/perf/Entity" : "Entity";
Object obj = jndiContext.lookup(jndiName);
obj = PortableRemoteObject.narrow(obj, EntityHome.class);
EntityHome home = (EntityHome) obj;
System.out.println("Removing "+max+" Entity beans");
for(int n = 0; n < max; n ++)
home.remove(new EntityPK(n));
}
private void createEntity2Beans(int max) throws Exception
{
InitialContext jndiContext = new InitialContext();
String jndiName = isSecure ? "secure/perf/Entity2" : "Entity2";
Object obj = jndiContext.lookup(jndiName);
obj = PortableRemoteObject.narrow(obj, Entity2Home.class);
Entity2Home home = (Entity2Home) obj;
System.out.println("Creating "+max+" Entity2 beans");
for(int n = 0; n < max; n ++)
home.create(n, "String"+n, new Double(n), n);
}
private void removeEntity2Beans(int max) throws Exception
{
InitialContext jndiContext = new InitialContext();
String jndiName = isSecure ? "secure/perf/Entity2" : "Entity2";
Object obj = jndiContext.lookup(jndiName);
obj = PortableRemoteObject.narrow(obj, Entity2Home.class);
Entity2Home home = (Entity2Home) obj;
System.out.println("Removing "+max+" Entity2 beans");
for(int n = 0; n < max; n ++)
home.remove(new Entity2PK(n, "String"+n, new Double(n)));
}
private void login() throws Exception
{
String username = "jduke";
char[] password = "theduke".toCharArray();
AppCallbackHandler handler = new AppCallbackHandler(username, password);
System.out.println("Creating LoginContext(other)");
lc = new LoginContext("spec-test", handler);
lc.login();
System.out.println("Created LoginContext, subject="+lc.getSubject());
}
private void logout()
{
try
{
lc.logout();
}
catch(Exception e)
{
}
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development