• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Test Client For FBN

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is a snippet of my test code:
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, forgot to post another important part of the testing code:

Eugene.
 
Ramesh kumaar
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 560
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Sai,
 
Ramesh kumaar
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic