//
//==============================================================================
//
-// Author: John Alex
-//
-// Modified By:
-//
//%/////////////////////////////////////////////////////////////////////////////
#include <iostream>
//
// Set up tables for client properties.
//
- _clientTable = new Table[Total_Clients];
-
- //
- // Allocate one table to collect all the common properties Thy use AutoPtr
- //
- _propertyTable = new Table;
-
- //
- // Client Information
- //
- _clientCommands = 0;
- _clientDurations = 0;
- _clientDelays = 0;
+ _clientTable.reset(new Table[Total_Clients]);
//
// Get environment variables:
}
_hostName = getOpts [i].Value ();
_hostNameSpecified = true;
- if (!_propertyTable->insert("hostname", _hostName))
+ if (!_propertyTable.insert("hostname", _hostName))
{
// shouldn't get here
if(verboseEnabled)
throw e;
}
_portNumberSpecified = true;
- if (!_propertyTable->insert("port", _portNumberStr))
+ if (!_propertyTable.insert("port", _portNumberStr))
{
if(verboseEnabled)
{
{
_portNumber = 5989;
_portNumberStr = "5989";
- if (!_propertyTable->insert("port", _portNumberStr))
+ if (!_propertyTable.insert("port", _portNumberStr))
{
if(verboseEnabled)
{
}
}
}
- if (!_propertyTable->insert("ssl", ""))
+ if (!_propertyTable.insert("ssl", ""))
{
if(verboseEnabled)
{
}
_userName = getOpts[i].Value();
_userNameSpecified = true;
- if (!_propertyTable->insert("username", _userName))
+ if (!_propertyTable.insert("username", _userName))
{
if(verboseEnabled)
{
}
_password = getOpts[i].Value();
_passwordSpecified = true;
- if (!_propertyTable->insert("password", _password))
+ if (!_propertyTable.insert("password", _password))
{
if(verboseEnabled)
{
//
// Array's to store client specific information
//
- _clientCommands = new String[_clientCount];
- _clientDurations = new Uint64[_clientCount];
- _clientDelays = new Uint64[_clientCount];
+ _clientCommands.reset(new String[_clientCount]);
+ _clientDurations.reset(new Uint64[_clientCount]);
+ _clientDelays.reset(new Uint64[_clientCount]);
//
// Retrieve all the client options from the client table
//
// Stress Client Name must exist for each client/client table
//
- if (!_clientTable[j].lookup(NAME, clientName))
+ if (!_clientTable.get()[j].lookup(NAME, clientName))
{
log_file<<StressTestControllerCommand::COMMAND_NAME<<
"::Required property NAME not found."<<endl;
//
// Generate the commands for each client from each client table.
//
- for (Table::Iterator i = _clientTable[j].start(); i; i++)
+ for (Table::Iterator i = _clientTable.get()[j].start(); i; i++)
{
if (String::equalNoCase(i.key(),HOSTNAME))
{
// from config file and include it as part of the client command
// as required.
//
- for (Table::Iterator k = _propertyTable->start(); k; k++)
+ for (Table::Iterator k = _propertyTable.start(); k; k++)
{
String propertyValue = String::EMPTY;
//
// Only include the common properties that are not already
// listed for the clients.
//
- if (!_clientTable[j].lookup(k.key(), propertyValue))
+ if (!_clientTable.get()[j].lookup(k.key(), propertyValue))
{
//
// Include options other than ToleranceLevel
{
duration = _duration;
}
- } /* for (Table::Iterator k = _propertyTable->start(); k; k++) */
+ } /* for (Table::Iterator k = _propertyTable.start(); k; k++) */
//
// Looking up table while ignoring cases for Client Duration/Wait.
//
- for (Table::Iterator k = _clientTable[j].start(); k; k++)
+ for (Table::Iterator k = _clientTable.get()[j].start(); k; k++)
{
//
// Overwrite duration if client duration set
// Save the generated command to corresponding element in the
// clientCommand array.
//
- _clientCommands[j] = client_command;
+ _clientCommands.get()[j] = client_command;
//
// Converting minutes to milliseconds
//
- _clientDurations[j] = (Uint64)convertmin2millisecs(duration);
- _clientDelays[j] = (Uint64)convertmin2millisecs(delay);
+ _clientDurations.get()[j] = (Uint64)convertmin2millisecs(duration);
+ _clientDelays.get()[j] = (Uint64)convertmin2millisecs(delay);
//
// Saving logs
//
- log_file<<StressTestControllerCommand::COMMAND_NAME<<
- "::Client Command[";
- log_file<<j<<"]"<<endl;
- log_file<<" "<<_clientCommands[j]<<endl;
- log_file<<" Client Duration: "<<
- convertUint64toString(_clientDurations[j])<<endl;
- log_file<<
- " Client Delay: "<<convertUint64toString(_clientDelays[j])<<endl;
+ log_file << StressTestControllerCommand::COMMAND_NAME <<
+ "::Client Command[" << j << "]" << endl;
+ log_file << " " << _clientCommands.get()[j] << endl;
+ log_file << " Client Duration: " <<
+ convertUint64toString(_clientDurations.get()[j]) << endl;
+ log_file << " Client Delay: " <<
+ convertUint64toString(_clientDelays.get()[j]) << endl;
//
// Verbose
//
if (verboseEnabled)
{
- cout<<
- StressTestControllerCommand::COMMAND_NAME<<"::Client Command[";
- cout<<j<<"]"<<endl;
- cout<<" "<<_clientCommands[j]<<endl;
- cout<<" Client Duration: "<<
- convertUint64toString(_clientDurations[j])<<endl;
- cout<<" Client Delay: "<<convertUint64toString(_clientDelays[j])<<
- endl;
+ cout << StressTestControllerCommand::COMMAND_NAME <<
+ "::Client Command[" << j << "]" << endl;
+ cout << " " << _clientCommands.get()[j] << endl;
+ cout << " Client Duration: " <<
+ convertUint64toString(_clientDurations.get()[j]) << endl;
+ cout << " Client Delay: " <<
+ convertUint64toString(_clientDelays.get()[j]) << endl;
}
} /* for(Uint32 j=0; j< _clientCount; j++) */
return true;
ostream& outPrintWriter,
ostream& errPrintWriter)
{
-
int actual_client = 0;
Uint64 startMilliseconds = 0;
Uint64 nowMilliseconds = 0;
Uint64 stopMilliseconds = 0;
Uint64 timeoutMilliseconds = 0;
- Uint64 *clientStartMilliseconds = 0;
- Uint64 *clientStopMilliseconds = 0;
- Uint64 *clientDelayMilliseconds = 0;
- Boolean *clientStopped = 0;
- Boolean *clientDelayed = 0;
- String act_command = String::EMPTY;
+ AutoArrayPtr<Uint64> clientStartMilliseconds;
+ AutoArrayPtr<Uint64> clientStopMilliseconds;
+ AutoArrayPtr<Uint64> clientDelayMilliseconds;
+ AutoArrayPtr<Boolean> clientStopped;
+ AutoArrayPtr<Boolean> clientDelayed;
+ String act_command;
Boolean TestFailed = false;
char str[15];
char strTime[256];
struct tm tmTime;
-
-
//
// log file
//
if(_clientCount > 0)
{
clientInstance = new int[_clientCount];
- clientStartMilliseconds = new Uint64[_clientCount];
- clientStopMilliseconds = new Uint64[_clientCount];
- clientDelayMilliseconds = new Uint64[_clientCount];
- clientStopped = new Boolean[_clientCount];
- clientDelayed = new Boolean[_clientCount];
+ clientStartMilliseconds.reset(new Uint64[_clientCount]);
+ clientStopMilliseconds.reset(new Uint64[_clientCount]);
+ clientDelayMilliseconds.reset(new Uint64[_clientCount]);
+ clientStopped.reset(new Boolean[_clientCount]);
+ clientDelayed.reset(new Boolean[_clientCount]);
}
else
{
//
for (Uint32 i=0;i<_clientCount;i++)
{
- clientStopped[i] = false;
- clientDelayed[i] = false;
+ clientStopped.get()[i] = false;
+ clientDelayed.get()[i] = false;
}
//
// Set up duration of the tests
//
// Acquire the client Instance for each clients
//
- if (!_clientTable[j].lookup(INSTANCE, clientInst))
+ if (!_clientTable.get()[j].lookup(INSTANCE, clientInst))
{
String ErrReport = String("Invalid Property Value: ");
ErrReport.append(INSTANCE);
//
// Acquire and set client specific duration
//
- clientStartMilliseconds[j] =
+ clientStartMilliseconds.get()[j] =
TimeValue::getCurrentTime().toMilliseconds();
- clientStopMilliseconds[j] =
- clientStartMilliseconds[j] + _clientDurations[j];
+ clientStopMilliseconds.get()[j] =
+ clientStartMilliseconds.get()[j] +
+ _clientDurations.get()[j];
//
// for verbose only
//
if (verboseEnabled)
{
- outPrintWriter<<"Client:"<<"["<<j<<"]"<<endl;
- log_file<<"Client:"<<"["<<j<<"]"<<endl;
- outPrintWriter<<"ClientStart:"<<
- convertUint64toString(clientStartMilliseconds[j])<<
+ outPrintWriter << "Client:" << "[" << j<< "]" << endl;
+ log_file << "Client:" << "[" << j << "]" << endl;
+ outPrintWriter << "ClientStart:" <<
+ convertUint64toString(
+ clientStartMilliseconds.get()[j]) <<
endl;
- outPrintWriter<<"ClientStop:"<<
- convertUint64toString(clientStopMilliseconds[j])<<
+ outPrintWriter << "ClientStop:" <<
+ convertUint64toString(
+ clientStopMilliseconds.get()[j]) <<
endl;
- outPrintWriter<<"ClientDuration:"<<
- convertUint64toString(_clientDurations[j])<<endl;
- log_file<<"ClientStart:"<<
- convertUint64toString(clientStartMilliseconds[j])<<
+ outPrintWriter << "ClientDuration:" <<
+ convertUint64toString(_clientDurations.get()[j]) <<
endl;
- log_file<<"ClientStop:"<<
- convertUint64toString(clientStopMilliseconds[j])<<
+ log_file << "ClientStart:" <<
+ convertUint64toString(
+ clientStartMilliseconds.get()[j]) <<
+ endl;
+ log_file << "ClientStop:" <<
+ convertUint64toString(
+ clientStopMilliseconds.get()[j]) <<
+ endl;
+ log_file << "ClientDuration:" <<
+ convertUint64toString(_clientDurations.get()[j]) <<
endl;
- log_file<<
- "ClientDuration:"<<
- convertUint64toString(_clientDurations[j])<<endl;
}
log_file<<
"Number of instances of this client: "<<
//
// Adding all the required parameters for the command.
//
- act_command.append(_clientCommands[j].getCString());
+ act_command.append(_clientCommands.get()[j]);
act_command.append(" -clientid ");
sprintf(str,"%d",actual_client);
act_command.append(str);
//
// Stop only running clients as required.
//
- if (!clientStopped[clientID])
+ if (!clientStopped.get()[clientID])
{
//
// If Client's duration is up
//
- if (clientStopMilliseconds[clientID]<= nowMilliseconds)
+ if (clientStopMilliseconds.get()[clientID] <=
+ nowMilliseconds)
{
//
// Stop all the instances of this client
//
// indicate that the client was stopped.
//
- clientStopped[clientID] = true;
+ clientStopped.get()[clientID] = true;
//
// If the Client has a Wait time
//
- if (_clientDelays[clientID] !=0)
+ if (_clientDelays.get()[clientID] !=0)
{
- clientDelayMilliseconds[clientID] =
- nowMilliseconds + _clientDelays[clientID];
- clientDelayed[clientID] = true;
+ clientDelayMilliseconds.get()[clientID] =
+ nowMilliseconds +
+ _clientDelays.get()[clientID];
+ clientDelayed.get()[clientID] = true;
}
} /* if (clientStopMilliseconds[clientID]<= nowMilli..*/
- } /* if (!clientStopped[clientID]) */
+ } /* if (!clientStopped.get()[clientID]) */
else
{
//
// Only restart clients that are waiting.
//
- if (clientDelayed[clientID])
+ if (clientDelayed.get()[clientID])
{
//
// When waiting period is consumed.
//
- if (clientDelayMilliseconds[clientID]<=
+ if (clientDelayMilliseconds.get()[clientID] <=
nowMilliseconds)
{
//
act_command.append("start ");
#endif
act_command.append(
- _clientCommands[clientID].getCString());
+ _clientCommands.get()[clientID]);
act_command.append(" -clientid ");
sprintf(str,"%d",clientID+instanceID);
act_command.append(str);
act_command.append(" -pidfile ");
act_command.append(" \"");
- act_command.append(_stressTestClientPIDFile);
+ act_command.append(
+ _stressTestClientPIDFile);
act_command.append("\"");
act_command.append(" -clientlog");
act_command.append(" \"");
- act_command.append(_stressTestClientLogFile);
+ act_command.append(
+ _stressTestClientLogFile);
act_command.append("\"");
act_command.append("&");
log_file<<"Restarting client:("<<
}
clientActive[clientID+instanceID] = true;
} /* for (int instanceID =0;instanceID .. */
- clientStopMilliseconds[clientID] =
+ clientStopMilliseconds.get()[clientID] =
nowMilliseconds +
- _clientDurations[clientID];
- clientStopped[clientID] = false;
- clientDelayed[clientID] = false;
+ _clientDurations.get()[clientID];
+ clientStopped.get()[clientID] = false;
+ clientDelayed.get()[clientID] = false;
}/* if(clientDelayMilliseconds[clientID]<=nowMi.. */
- } /* if(clientDelayed[clientID]) */
+ } /* if(clientDelayed.get()[clientID]) */
} /* else ..*/
} /* for(Uint32 clientID=0;clientID < _clientCount;clientID++)*/
} /* else for if(!actual_client) */
{
cout<<" "<<name<<"\t= "<<value<<endl;
}
- if (!_propertyTable->insert(name, value))
+ if (!_propertyTable.insert(name, value))
{
//
// Duplicate property, ignore the new property value.
cout<<StressTestControllerCommand::COMMAND_NAME<<
"::Common Properties:"<<endl;
}
- for (Table::Iterator i = _propertyTable->start(); i; i++)
+ for (Table::Iterator i = _propertyTable.start(); i; i++)
{
log_file<<" "<<i.key()<<"\t= "<<i.value()<<endl;
if (verboseEnabled)
{
cout<<"Client("<<j<<")"<<endl;
}
- for (Table::Iterator i = _clientTable[j].start(); i; i++)
+ for (Table::Iterator i = _clientTable.get()[j].start(); i; i++)
{
log_file<<" "<<i.key()<<" = "<<i.value()<<endl;
if (verboseEnabled)
}
if (!(isalpha(*p) || *p == '_'))
{
- throw StressTestControllerException(StressTestControllerException::INVALID_OPTION);
+ throw StressTestControllerException(
+ StressTestControllerException::INVALID_OPTION);
}
name.append(*p++);
//
if (*p != '=')
{
- throw StressTestControllerException(StressTestControllerException::INVALID_OPERATOR);
+ throw StressTestControllerException(
+ StressTestControllerException::INVALID_OPERATOR);
}
p++;
if(*p !=']' && *p != ',')
{
- throw StressTestControllerException(StressTestControllerException::MISSING_BRACE);
+ throw StressTestControllerException(
+ StressTestControllerException::MISSING_BRACE);
}
if(value == String::EMPTY)
{
- throw StressTestControllerException(StressTestControllerException::MISSING_VALUE);
+ throw StressTestControllerException(
+ StressTestControllerException::MISSING_VALUE);
}
#ifdef STRESSTEST_DEBUG
//
// Save client property in client table if valid.
//
- if (!_clientTable[_currClientCount].insert(name,value))
+ if (!_clientTable.get()[_currClientCount].insert(name,value))
{
//
// Duplicate property, ignore the new property value.
{
Total_Clients += NEW_CLIENTS;
Table* tempClientTable = new Table[Total_Clients];
- for (Uint32 i =0;i<_clientCount;i++)
+ for (Uint32 i = 0; i < _clientCount; i++)
{
- tempClientTable[i] = _clientTable[i];
+ tempClientTable[i] = _clientTable.get()[i];
}
- delete [] _clientTable;
- _clientTable = tempClientTable;
- }
+ _clientTable.reset(tempClientTable);
+ }
//
// Store the client Name in the table
//
- if (!_clientTable[_clientCount].insert(NAME, name))
+ if (!_clientTable.get()[_clientCount].insert(NAME, name))
{
//
// Duplicate property, ignore the new property value.
//
// Store the number of instances for the client in the table
//
- if (!_clientTable[_clientCount].insert(INSTANCE, value))
+ if (!_clientTable.get()[_clientCount].insert(INSTANCE, value))
{
//
//
// Adding the default instance value to each client table
//
- if (!_clientTable[i].insert(INSTANCE, DEFAULT_INSTANCE))
+ if (!_clientTable.get()[i].insert(INSTANCE, DEFAULT_INSTANCE))
{
log_file << "Duplicate name already saved: "<<INSTANCE<<endl;
if (verboseEnabled)
{
case 0:
{
- if (!_clientTable[i].insert(NAME, MODELWALK_CLIENT))
+ if (!_clientTable.get()[i].insert(NAME, MODELWALK_CLIENT))
{
log_file << "Duplicate name already saved: "<<NAME<<endl;
if (verboseEnabled)
cout<< "Duplicate name already saved: "<<NAME<<endl;
}
}
- log_file << "Stress Test Client Name:"<<MODELWALK_CLIENT<< endl;
+ log_file << "Stress Test Client Name:" << MODELWALK_CLIENT <<
+ endl;
if (verboseEnabled)
{
cout<< "Stress Test Client Name:"<<MODELWALK_CLIENT<< endl;
}
case 1:
{
- if (!_clientTable[i].insert(NAME, WRAPPER_CLIENT))
+ if (!_clientTable.get()[i].insert(NAME, WRAPPER_CLIENT))
{
log_file << "Duplicate name already saved: "<<NAME<<endl;
if (verboseEnabled)
{
cout << "Stress Test Client Name:" <<WRAPPER_CLIENT<< endl;
}
- if (!_clientTable[i].insert(CLIENTNAME, "CLI"))
+ if (!_clientTable.get()[i].insert(CLIENTNAME, "CLI"))
{
log_file<< "Duplicate name already saved: "<<
CLIENTNAME<<endl;
CLIENTNAME<<endl;
}
}
- if (!_clientTable[i].insert(OPTIONS, "niall"))
+ if (!_clientTable.get()[i].insert(OPTIONS, "niall"))
{
log_file<< "Duplicate name already saved: "<<OPTIONS<<endl;
if (verboseEnabled)