FileDocCategorySizeDatePackage
TestAppFrame.javaAPI DocExample8529Thu Nov 08 00:22:48 GMT 2001com.ora.rmibook.chapter13.bank.applications

TestAppFrame

public class TestAppFrame extends ExitingFrame

Fields Summary
private static String
ALL_ACCOUNTS
private TestResultHolder
_testResultHolder
private NameRepository
_nameRepository
private JTextField
_numberOfThreadsField
private JTextField
_numberOfOperationsField
private JButton
_testButton
private JTextArea
_resultsArea
private JComboBox
_accountChooser
private int
_numberOfFinishedThreads
private int
_numberOfThreads
private ChooserListener
_chooserListener
private Rectangle
_upperLeftCorner
Constructors Summary
public TestAppFrame(int numberOfServers)

       
        _nameRepository = new NameRepository(numberOfServers);
        _chooserListener = new ChooserListener();
        _upperLeftCorner = new Rectangle (0, 0, 1, 1);
    
Methods Summary
private javax.swing.JComponentbuildConfigurationPanel()

        JPanel returnValue = new JPanel(new GridLayout(1, 5));

        _numberOfThreadsField = new JTextField();
        _numberOfOperationsField = new JTextField();
        _testButton = new JButton("Perform Test");
        _testButton.addActionListener(new TestLauncher());
        returnValue.add(new JLabel("Number of Clients"));
        returnValue.add(_numberOfThreadsField);
        returnValue.add(new JLabel("Number of Operations"));
        returnValue.add(_numberOfOperationsField);
        returnValue.add(_testButton);
        returnValue.setBorder(BorderFactory.createEtchedBorder());
        return returnValue;
    
protected voidbuildGUI()

        setTitle("Chapter 12 Testing Application");
        JPanel mainPanel = new JPanel(new BorderLayout());

        mainPanel.add(buildConfigurationPanel(), BorderLayout.NORTH);
        mainPanel.add(buildResultsWindow(), BorderLayout.CENTER);
        setSize(600, 400);
        setContentPane(mainPanel);
    
private javax.swing.JComponentbuildResultsWindow()

        JPanel returnValue = new JPanel(new BorderLayout());

        _resultsArea = new JTextArea();
        _accountChooser = new JComboBox();
        returnValue.add(_accountChooser, BorderLayout.NORTH);
        returnValue.add(new JScrollPane(_resultsArea), BorderLayout.CENTER);
        return returnValue;
    
private voidcomputeSummaryForChosenAccount(java.lang.String accountName)

        ResultsSummary summaryObject = new ResultsSummary();

        summarize(summaryObject, _testResultHolder.getResultsForAccount(accountName), true);
        displaySummary(summaryObject);
    
private voidcomputeSummaryforAllAccounts()

        ResultsSummary summaryObject = new ResultsSummary();
        Iterator i = (_testResultHolder.getAccountNames()).iterator();

        while (i.hasNext()) {
            String nextAccountName = (String) i.next();

            summarize(summaryObject, _testResultHolder.getResultsForAccount(nextAccountName), false);
        }
        displaySummary(summaryObject);
    
private voiddisplaySummary(com.ora.rmibook.chapter13.bank.applications.TestAppFrame$ResultsSummary summaryObject)

        String partialString = "Number of operations : " + summaryObject.numberOfTests + "\n"
            + "\tAverage operation time: " + (summaryObject.totalTime / summaryObject.numberOfTests) + " milliseconds.\n"
            + "\tLongest operation time: " + summaryObject.longestTime + " milliseconds.\n"
            + "\tNumber of successes : " + summaryObject.numberOfSuccesses + ".\n"
            + "\tNumber of failures : " + summaryObject.numberOfFailures + ".\n"
            + "\tNumber of locks : " + summaryObject.numberOfLocks + ".\n"
            + "\tNumber of remote exceptions : " + summaryObject.numberOfRemoteExceptions + ".\n"
            + "\tNumber of unable to connects : " + summaryObject.numberOfUnableToConnects + ".\n";

        if (summaryObject.resultsString.equals("")) {
            summaryObject.resultsString = partialString;
        } else {
            summaryObject.resultsString = partialString
                    + "\n\n" + "Detailed Results \n ==================\n\n"
                    + summaryObject.resultsString;
        }
        _resultsArea.setText(summaryObject.resultsString);
        _resultsArea.scrollRectToVisible(_upperLeftCorner);
    
private voidreset()

        _testResultHolder = new TestResultHolder();
        _numberOfFinishedThreads = 0;
    
private voidresetGUI()

        _testResultHolder.sortResults();
        _accountChooser.removeActionListener(_chooserListener);
        _accountChooser.removeAllItems();
        _accountChooser.addItem(ALL_ACCOUNTS);
        Iterator i = (_testResultHolder.getAccountNames()).iterator();

        while (i.hasNext()) {
            _accountChooser.addItem(i.next());
        }
        _resultsArea.setText("");
        _accountChooser.addActionListener(_chooserListener);
        computeSummaryforAllAccounts();
    
protected synchronized booleansomeThreadsNotFinished()

        return _numberOfFinishedThreads < _numberOfThreads;
    
private voidsummarize(com.ora.rmibook.chapter13.bank.applications.TestAppFrame$ResultsSummary summaryObject, java.util.Collection tests, boolean addDescriptions)

        Iterator i = tests.iterator();

        while (i.hasNext()) {
            Test nextTest = (Test) i.next();

            summaryObject.totalTime += nextTest.duration;
            summaryObject.numberOfTests++;
            if (addDescriptions) {
                summaryObject.resultsString += nextTest.describeOutcome();
            }
            if (summaryObject.longestTime < nextTest.duration) {
                summaryObject.longestTime = nextTest.duration;
            }
            if (nextTest.status == Test.FAILURE) {
                summaryObject.numberOfFailures++;
            }
            if (nextTest.status == Test.ACCOUNT_WAS_LOCKED) {
                summaryObject.numberOfLocks++;
            }
            if (nextTest.status == Test.REMOTE_EXCEPTION_THROWN) {
                summaryObject.numberOfRemoteExceptions++;
            }
            if (nextTest.status == Test.UNABLE_TO_CONNECT) {
                summaryObject.numberOfUnableToConnects++;
            }
            if (nextTest.status == Test.SUCCESS) {
                summaryObject.numberOfSuccesses++;
            }
        }
    
protected synchronized voidtestThreadFinished(TestThread testThread)

        _numberOfFinishedThreads++;