User: danch
Date: 01/06/29 21:38:05
Added: src/main/org/jboss/test/readahead/ejb Address.java
CMPFindTestEntity.java CMPFindTestSession.java
Log:
Added tests for readahead functionality. Note that this only checks to see if they
work: it doesn't verify that it's actually performing well
Revision Changes Path
1.1 jbosstest/src/main/org/jboss/test/readahead/ejb/Address.java
Index: Address.java
===================================================================
package org.jboss.test.readahead.ejb;
import javax.ejb.EntityBean;
import javax.ejb.CreateException;
import javax.ejb.RemoveException;
import javax.ejb.EntityContext;
import org.jboss.test.readahead.interfaces.AddressPK;
/**
* Implementation class for one of the entities used in read-ahead finder
* tests
*
* @author <a href="mailto:[EMAIL PROTECTED]">danch (Dan Christopherson</a>
* @version $Id: Address.java,v 1.1 2001/06/30 04:38:05 danch Exp $
*
* Revision:
*/
public class Address implements EntityBean {
EntityContext entityContext;
public String key;
public String addressId;
public String address;
public String city;
public String state;
public String zip;
public AddressPK ejbCreate(String key, String addressId, String address,
String city, String state, String zip)
throws CreateException
{
this.key = key;
this.addressId = addressId;
this.address = address;
this.city = city;
this.state = state;
this.zip = zip;
return new AddressPK(key, addressId);
}
public void ejbPostCreate(String key, String addressId, String address,
String city, String state, String zip) throws
CreateException {
}
public void ejbRemove() throws RemoveException {
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void ejbLoad() {
}
public void ejbStore() {
}
public void setEntityContext(EntityContext entityContext) {
this.entityContext = entityContext;
}
public void unsetEntityContext() {
entityContext = null;
}
public void setKey(String newKey) {
key = newKey;
}
public String getKey() {
return key;
}
public void setAddressId(String newAddressId) {
addressId = newAddressId;
}
public String getAddressId() {
return addressId;
}
public void setAddress(String newAddress) {
address = newAddress;
}
public String getAddress() {
return address;
}
public void setCity(String newCity) {
city = newCity;
}
public String getCity() {
return city;
}
public void setState(String newState) {
state = newState;
}
public String getState() {
return state;
}
public void setZip(String newZip) {
zip = newZip;
}
public String getZip() {
return zip;
}
}
1.1
jbosstest/src/main/org/jboss/test/readahead/ejb/CMPFindTestEntity.java
Index: CMPFindTestEntity.java
===================================================================
package org.jboss.test.readahead.ejb;
import javax.ejb.EntityBean;
import javax.ejb.CreateException;
import javax.ejb.RemoveException;
import javax.ejb.EntityContext;
/**
* Implementation class for one of the entities used in read-ahead finder
* tests
*
* @author <a href="mailto:[EMAIL PROTECTED]">danch (Dan Christopherson</a>
* @version $Id: CMPFindTestEntity.java,v 1.1 2001/06/30 04:38:05 danch Exp $
*
* Revision:
*/
public class CMPFindTestEntity implements EntityBean {
EntityContext entityContext;
public String key;
public String name;
public String rank;
public String serialNumber;
private boolean modified;
public String ejbCreate(String key) throws CreateException {
this.key = key;
return key;
}
public boolean isModified() {
return modified;
}
public void ejbPostCreate(String key) throws CreateException {
}
public void ejbRemove() throws RemoveException {
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void ejbLoad() {
modified = false;
}
public void ejbStore() {
modified = false;
}
public void setEntityContext(EntityContext entityContext) {
this.entityContext = entityContext;
}
public void unsetEntityContext() {
entityContext = null;
}
public String getKey() {
return key;
}
public void setName(String newName) {
name = newName;
}
public String getName() {
return name;
}
public void setRank(String newRank) {
rank = newRank;
modified = true;
}
public String getRank() {
return rank;
}
public void setSerialNumber(String newSerialNumber) {
serialNumber = newSerialNumber;
modified = true;
}
public String getSerialNumber() {
return serialNumber;
}
}
1.1
jbosstest/src/main/org/jboss/test/readahead/ejb/CMPFindTestSession.java
Index: CMPFindTestSession.java
===================================================================
package org.jboss.test.readahead.ejb;
import java.util.Iterator;
import java.util.Collection;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import org.jboss.test.readahead.interfaces.AddressHome;
import org.jboss.test.readahead.interfaces.AddressRemote;
import org.jboss.test.readahead.interfaces.CMPFindTestEntityHome;
import org.jboss.test.readahead.interfaces.CMPFindTestEntityRemote;
/**
* Implementation class for session bean used in read-ahead finder
* tests
*
* @author <a href="mailto:[EMAIL PROTECTED]">danch (Dan Christopherson</a>
* @version $Id: CMPFindTestSession.java,v 1.1 2001/06/30 04:38:05 danch Exp $
*
* Revision:
*/
public class CMPFindTestSession implements SessionBean {
private static final int DATASET_SIZE = 100;
private SessionContext sessionContext;
public void ejbCreate() {
}
public void ejbRemove() {
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void setSessionContext(SessionContext context) {
sessionContext = context;
}
public void removeTestData() {
try {
InitialContext ctx = new InitialContext();
CMPFindTestEntityHome home =
(CMPFindTestEntityHome)ctx.lookup("CMPFindTestEntity");
Collection coll = home.findAll();
Iterator iter = coll.iterator();
while (iter.hasNext()) {
CMPFindTestEntityRemote rem = (CMPFindTestEntityRemote)iter.next();
rem.remove();
}
} catch (Exception e) {
}
}
public void createTestData() {
try {
InitialContext ctx = new InitialContext();
CMPFindTestEntityHome home =
(CMPFindTestEntityHome)ctx.lookup("CMPFindTestEntity");
AddressHome addrHome = (AddressHome)ctx.lookup("Address");
for (int i=0;i<DATASET_SIZE;i++) {
String key = Long.toString(System.currentTimeMillis());
CMPFindTestEntityRemote rem = home.create(key);
rem.setName("Name");
rem.setRank("Rank");
rem.setSerialNumber("123456789");
//give him an address
if ((i % 2) ==0) {
addrHome.create(rem.getKey(), "1", "123 east st.", "Eau Claire",
"WI", "54701");
} else {
addrHome.create(rem.getKey(), "1", "123 east st.", "Milwaukee", "WI",
"54201");
}
}
} catch (Exception e) {
System.out.println("Exception caught: "+e);
e.printStackTrace();
throw new EJBException(e.getMessage());
}
}
public void addressByCity() {
try {
InitialContext ctx = new InitialContext();
AddressHome home = (AddressHome)ctx.lookup("Address");
long startTime = System.currentTimeMillis();
Collection coll = home.findByCity("Eau Claire");
int count = 0;
Iterator iter = coll.iterator();
while (iter.hasNext()) {
AddressRemote rem = (AddressRemote)iter.next();
rem.getCity();
// System.out.println("Name: "+rem.getName()+" Rank: "+rem.getRank());
count++;
}
long endTime = System.currentTimeMillis();
System.out.println("called "+count+" beans in "+(endTime-startTime)+" ms.");
} catch (Exception e) {
System.out.println("Caught "+e);
}
}
public void testByCity() {
try {
InitialContext ctx = new InitialContext();
CMPFindTestEntityHome home =
(CMPFindTestEntityHome)ctx.lookup("CMPFindTestEntity");
long startTime = System.currentTimeMillis();
Collection coll = home.findByCity("Eau Claire");
int count = 0;
Iterator iter = coll.iterator();
while (iter.hasNext()) {
CMPFindTestEntityRemote rem = (CMPFindTestEntityRemote)iter.next();
rem.getName();
// System.out.println("Name: "+rem.getName()+" Rank: "+rem.getRank());
count++;
}
long endTime = System.currentTimeMillis();
System.out.println("called "+count+" beans in "+(endTime-startTime)+" ms.");
} catch (Exception e) {
}
}
public void testFinder() {
try {
InitialContext ctx = new InitialContext();
CMPFindTestEntityHome home =
(CMPFindTestEntityHome)ctx.lookup("CMPFindTestEntity");
long startTime = System.currentTimeMillis();
Collection coll = home.findAll();
int count = 0;
Iterator iter = coll.iterator();
while (iter.hasNext()) {
CMPFindTestEntityRemote rem = (CMPFindTestEntityRemote)iter.next();
rem.getName();
// System.out.println("Name: "+rem.getName()+" Rank: "+rem.getRank());
count++;
}
long endTime = System.currentTimeMillis();
System.out.println("called "+count+" beans in "+(endTime-startTime)+" ms.");
} catch (Exception e) {
}
}
public void testUpdates() {
try {
InitialContext ctx = new InitialContext();
CMPFindTestEntityHome home =
(CMPFindTestEntityHome)ctx.lookup("CMPFindTestEntity");
long startTime = System.currentTimeMillis();
Collection coll = home.findAll();
int count = 0;
Iterator iter = coll.iterator();
while (iter.hasNext()) {
CMPFindTestEntityRemote rem = (CMPFindTestEntityRemote)iter.next();
rem.getName();
rem.setRank("Very");
count++;
}
long endTime = System.currentTimeMillis();
System.out.println("called "+count+" beans in "+(endTime-startTime)+" ms.");
} catch (Exception e) {
}
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development