aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Test Client For FBN Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Test Client For FBN " Watch "Test Client For FBN " New topic
Author

Test Client For FBN

Ramesh kumaar
Ranch Hand

Joined: Mar 19, 2002
Posts: 146
I Have a configuration file Lock.txt which contains recNo,NoOfSeats as follows
10,10
10,20
10,10
10,1
10,1
Lets assume there are 41 seats are there for RecNo 10
Now write a Thread based TestClient which will read the above conf and span that much threads by having the recNo, seatNo. Inside the run method call lock(recNo), modify(seatNo), unLock(recNo) dont forget to use yeild() inside ur run().
In ur DataImpl's modifyRec() have a sleep(2000) as the first statement(For testing purpose alone).
Once the above program is compleated start the client program.
Here my modifyRec will return true(boolean var)
once the seat is booked else false. So for the above test case only the last should return false. if it happen u can be sure about ur locking procedure.
Guys & Girls please give ur valid feedback about my test case.

regards,
-rameshkumar
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
I can't make sense out of your test plan. All you have to do is to write a non-GUI client that will simulate multiple conections to the database. Your test cace would create say 20 threads, each connecting to database, and each booking a number of seats (one at a time) on the same airline. So if you have 20 threads, and each books 100 seats (again, one at a time), run your test and make sure that your seat count is reduced by exactly 2000. That's all there is to it to test record locks.
Eugene
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
Ramesh,
I had a main line code and two Thread inner classes to my testing. It worked out great. The two threads simulate two different clients. In order to do this, you need to get two seperate remote instances from the RMI server. I also simulated more than two clients by spawning instances of these threads in a for loop in the main() method. In any case you need to check the following:
1) Available seats are getting reduced based on the book request
2) You don't allow over booking of flights.
3) Block clients who are trying to book the seats in the same flight.
4) Unreferenced locks are getting removed
You can achieve the above by including sleep() statements in the run() method of thread classes and Sytem.out.println() in both client and server side classes.
[ June 23, 2002: Message edited by: Sai Prasad ]
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
Here is a snippet of my test code:
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
Sorry, forgot to post another important part of the testing code:

Eugene.
Ramesh kumaar
Ranch Hand

Joined: Mar 19, 2002
Posts: 146
Thanks a lot Sai and Eugene,
I am trying to write a testclient based on ur ideas and get back to u for u valid comments.
regards,
-rameshkumar
Ramesh kumaar
Ranch Hand

Joined: Mar 19, 2002
Posts: 146
Thanks a lot Sai and Eugene,
I am trying to write a testclient based on ur ideas and get back to u for u valid comments.
regards,
-rameshkumar
Ramesh kumaar
Ranch Hand

Joined: Mar 19, 2002
Posts: 146
Hi sai and Eugene,

Please go through the testprogram which i have written and give me ur valid feed back. Tell me that is it enought to be sure that my FBN program works fine.
Here in the following iam sure first three are working.
1) Available seats are getting reduced based on the book request
2) You don't allow over booking of flights.
3) Block clients who are trying to book the seats in the same flight.
4) Unreferenced locks are getting removed
package test.db;
import java.io.*;
import java.util.*;
import test.db.DataInterface;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.net.MalformedURLException;
/**
* TestClient --
*
* @author Rameshkumar.km
* @version$Name$
* @see
* @bugs
*/
public class TestClient
{
public TestClient()
{
}
private static class ThreadOne implements Runnable
{
static DataInterface dataInterfaceOne;
public int recNo,seatNo;
public ThreadOne(String str)
{
StringTokenizer st=new StringTokenizer(str,",");
this.recNo=Integer.parseInt((String)st.nextToken());
this.seatNo=Integer.parseInt((String)st.nextToken());
}
static
{
try
{
dataInterfaceOne=(DataInterface) Naming.lookup("rmi://localhost:2099/FBNServer");
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
public void run()
{
try
{
{
Thread.yield();
dataInterfaceOne.lock(recNo);
boolean bool=dataInterfaceOne.modifyRec(recNo,seatNo);
dataInterfaceOne.unlock(recNo);
System.out.println("Thread one Seat booked----For "+recNo+" Seats :"+seatNo+"Status :"+bool);

}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

private static class ThreadTwo implements Runnable
{
static DataInterface dataInterfaceTwo;
public int recNo,seatNo;
public ThreadTwo(String str)
{
StringTokenizer st=new StringTokenizer(str,",");
this.recNo=Integer.parseInt((String)st.nextToken());
this.seatNo=Integer.parseInt((String)st.nextToken());
}

static{
try
{
dataInterfaceTwo=(DataInterface) Naming.lookup("rmi://localhost:2099/FBNServer");
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
public void run()
{
try
{
//while(true)
{
Thread.yield();
dataInterfaceTwo.lock(recNo);
boolean bool=dataInterfaceTwo.modifyRec(recNo,seatNo);
dataInterfaceTwo.unlock(recNo);
System.out.println("Thread Two Seat booked----For "+recNo+" Seats :"+seatNo+"Status :"+bool);

}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}


public Vector readConf(String str) throws Exception
{
FileReader fr=new FileReader(str);
BufferedReader br=new BufferedReader(fr);
Vector vec=new Vector();
String tempStr="";
while((tempStr=br.readLine())!=null)
{
vec.addElement(tempStr);
tempStr="";
}
return vec;
}
public void displayValues(DataInfo[] dInfo)
{
for(int i=0;i<dInfo.length;i++)
{
DataInfo dataInfo=dInfo[i];
String []values=dataInfo.getValues();
StringBuffer sb=new StringBuffer();
for(int j=0;j<values.length; j++)
{
sb.append(values[j]+" : ");
}
System.out.println(sb);
}
}
//}
public static void main(String args[])
{
try
{
TestClient tc= new TestClient();
Vector vec=tc.readConf("Lock.txt");
for(int i=0;i<vec.size();i++)
{
String lock=(String)vec.elementAt(i);
ThreadOne tClient=(new TestClient()).new ThreadOne(lock);
ThreadTwo tClient1=(new TestClient()).new ThreadTwo(lock);
new Thread(tClient,new Integer(i).toString()).start();
new Thread(tClient1,new Integer(i).toString()).start();
}
}
catch(Exception e)
{
e.printStackTrace();
}

}

}
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
I didn't use yield() but sleep(delay). The quality of this code depends on how you have implemented client/server/db classes. If you think they are good enough, test it. Take your time to satisfy yourself and then ship'm to Sun.
Ramesh kumaar
Ranch Hand

Joined: Mar 19, 2002
Posts: 146
Thanks Sai,
Ramesh kumaar
Ranch Hand

Joined: Mar 19, 2002
Posts: 146
Thanks a lot Sai,
For the service u are doing here. Here me too have a sleep() in the DataImpls modify() method. I guess that is not a bad idea.
-rameshkumar
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
I would test not the lock/unlock code, but the book() method. Just call your book method that reserves 1 seat for a given flight in a loop, and do it from multiple threads.
Next time you post code, use Codes, it would be much easier to read your code.
Eugene.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Test Client For FBN