///////////////////////////////////////////////////////////////////////////////// //This is a simple scheme how a test program should be. //1. We have implemented all methods defined in interface like "openAccount", "buyStock" etc. //For simplicity, I omitted all paremeters for each function. //2. We create equal number of threads which do the opposite direction operations like buy vs. sell //3. If our server is properly synchronized against these two operations, namely buy and sell, the //final balance should remain the same before testing. //4. The barrier is used to make sure threads starts at the same time. //5. And you can implement your new testing functions like this style, for example, do a transfer testing. // i.e. 50 threads call tradeStock(cust1, stock1, quan1, cust2,stock2,quan2) // and 50 threads call tradeStock(cust2, stock2, quan2, cust1, stock1, quan1) at the same time. // Then the only thing you need to modify this testing template is to create another "Thread" // class which call "tradeStock" instead of "buyStock" and "sellStock". ////////////////////////////////////////////////////////////////////////////////// package Client; import java.io.*; import java.util.*; import java.util.concurrent.*; import org.omg.CosNaming.NamingContextPackage.*; import org.omg.CosNaming.*; import org.omg.CORBA.ORB.*; import org.omg.CORBA.*; public class Client { protected static int RunningThreadNumber=10; protected static RunningThread deposits[]; protected static RunningThread withdraws[]; protected static CyclicBarrier doubleBarrier=new CyclicBarrier(RunningThreadNumber*2); protected static NamingContextExt ncRef; protected static ORB orb; public static int openAccount()throws java.rmi.RemoteException { //implement your method here } public static float login()throws java.rmi.RemoteException { //implement your method here } public static float buyStock()throws java.rmi.RemoteException { //implement your method here } public static float sellStock()throws java.rmi.RemoteException { //implement your method here } public static float logOut()throws java.rmi.RemoteException { //implement here } public static float tradeStock()throws java.rmi.RemoteException { //implement your method here } public static void init() { //implement the initialization } public static void main(String args[]) { try { //do whatever initialization job here, like retrieve orb, namingcontext, etc. init(); threadTester(); } catch(Exception er) { System.out.println(er.getMessage()); } } //a helper class of thread to test mutual exclusion in server static class RunningThread extends Thread { protected float amount; protected int account; public RunningThread(int acnt, float amt) { amount=amt; account=acnt; } public void run() { try { doubleBarrier.await(); if (amount>0) { sellStock(); } else { buyStock(); } } catch (Exception er) { System.out.println(er.getMessage()); } } } protected static void threadTester() { int account; float amount; try { account=openAccount();//open a new account; login(account); amount=buyStock(account, 3000);//you probably need stock symbol here, deposits=new RunningThread[RunningThreadNumber]; withdraws=new RunningThread[RunningThreadNumber]; System.out.println("thread test begins and we buy 3000.0 to account " + Integer.toString(account) + " and we are going to run equal number of buy and sell actions," + "if server is not properly synchronized, the balance will not be the same probably"); System.out.println("the balance of account "+ Integer.toString(account) + " is " + Float.toString(amount)); for (int i=0; i