use of alma.acs.util.StopWatch in project ACS by ACS-Community.
the class ContainerServicesTesterImpl method testGetReferenceWithCustomClientSideTimeout.
/**
* @see alma.jconttest.ContainerServicesTesterOperations#testGetReferenceWithCustomClientSideTimeout(String)
*/
public boolean testGetReferenceWithCustomClientSideTimeout() {
boolean ret = true;
try {
String compName = "DefaultDummyComp";
org.omg.CORBA.Object compObj = m_containerServices.getComponent(compName);
DummyComponent comp = alma.jconttest.DummyComponentHelper.narrow(compObj);
//secs. (should be at most 10 s longer than 'timeout'
int waitTime = 18;
// because component deactivation blocks only 10 seconds on a still running operation.
// secs.
int timeout = 10;
// first let's try to call the IF without a timeout
try {
comp.callThatTakesSomeTime(waitTime * 1000);
} catch (org.omg.CORBA.TIMEOUT e) {
m_logger.log(Level.WARNING, "No TIMEOUT exception expected for a 20 second call, without applying a special client-side timeout.");
ret = false;
}
// then we call the ContainerServices to assign a timeout of 10 seconds
org.omg.CORBA.Object compObjWithTimeout = m_containerServices.getReferenceWithCustomClientSideTimeout(compObj, timeout);
DummyComponent compWithTimeout = alma.jconttest.DummyComponentHelper.narrow(compObjWithTimeout);
// we call again the IF
StopWatch sw = new StopWatch(m_logger);
try {
compWithTimeout.callThatTakesSomeTime(waitTime * 1000);
m_logger.log(Level.WARNING, "TIMEOUT exception expected after " + timeout + " seconds.");
ret = false;
} catch (org.omg.CORBA.TIMEOUT e) {
m_logger.info("Good: got a TIMEOUT exception from DefaultDummyComp#callThatTakesSomeTime");
}
int elapsedTime = (int) sw.getLapTimeMillis() / 1000;
if (Math.abs(elapsedTime - timeout) > 2) {
ret = false;
m_logger.log(Level.WARNING, "TIMEOUT exception caught as expected, but after " + elapsedTime + " seconds instead of the expected " + timeout + " seconds.");
}
// the release call should block for the remaining 8 s that 'callThatTakesSomeTime' keeps running after our client timeout.
m_containerServices.releaseComponent(compName);
} catch (Exception ex) {
m_logger.log(Level.WARNING, "Failure in testGetReferenceWithCustomClientSideTimeout, will return 'false'.", ex);
ret = false;
}
return ret;
}
use of alma.acs.util.StopWatch in project ACS by ACS-Community.
the class ContainerClientPendingReplyTimeoutTest method testOrbLevelTimeout.
/**
* Tests the client-side relative roundtrip ORB timeout for Java containers "frodoContainerWithTimeoutX".
* Here the values in the CDB are supposed to override the general ORB timeout setting from orb.properties.
*/
public void testOrbLevelTimeout() throws Exception {
assertEquals(syslevelOrbTimeoutSecDefined, syslevelOrbTimeoutSec);
//seconds defined in CDB
String container = "frodoContainerWithTimeout";
String component = "DummyCompWrapper_ContainerTimeout";
String container1, component1;
int[] timeout = { 30, 10, 20 };
//Change this value from 1 to 2 or 3 if you want to test other configurations by hand. This is set to 1 to avoid a timeout from NRI tests.
int n = 1;
for (int i = 0; i < n; i++) {
container1 = container + (i + 1);
component1 = component + (i + 1);
DummyComponentWrapper wrapper1 = DummyComponentWrapperHelper.narrow(getContainerServices().getComponent(component1));
int timeout1Sec = (int) jconttestUtil.getContainerLevelOrbTimeout(container1);
assertEquals("Unexpected CDB timeout for container " + container1, timeout[i], timeout1Sec);
//because this test is run several times with different values of syslevelOrbTimeoutSec
if (syslevelOrbTimeoutSec <= timeout1Sec)
break;
assertTrue(container1 + "'s timeout should be shorter than the system-level timeout", syslevelOrbTimeoutSec - timeout1Sec >= 5);
try {
assertFalse(wrapper1.callDummyComponentWithTime((timeout1Sec - 5) * 1000));
//Here we will check that the timeout is similar (+- 5 s) to the timeout defined in CDB
StopWatch sw = new StopWatch(m_logger);
boolean gotTimeoutException = wrapper1.callDummyComponentWithTime((timeout1Sec + 5) * 1000);
int actualTimeout1Sec = (int) sw.getLapTimeMillis() / 1000;
assertTrue("timeout exception expected", gotTimeoutException);
int deviationSec = Math.abs(actualTimeout1Sec - timeout1Sec);
assertTrue("Expected timeout exception was thrown, but after unexpected " + actualTimeout1Sec + " ms.", deviationSec < 2);
} catch (CouldntPerformActionEx ex) {
// so that junit can display the exception trace
throw AcsJCouldntPerformActionEx.fromCouldntPerformActionEx(ex);
}
}
// @TODO: use also DummyCompWrapper_ContainerTimeout2 and DummyCompWrapper_ContainerTimeout3
// to check different container timeout settings.
// This should also check the effect of variations of the system-level timeout, as described in COMP-1063/19/Jun/08 10:03 AM
// (The magic 3 minutes even if system level is at 7 minutes. To be verified usign command line override of
// property jacorb.connection.client.pending_reply_timeout)
//This test will be run 2 times with different values of the system level timeout timeout using the prologue of TAT
}
use of alma.acs.util.StopWatch in project ACS by ACS-Community.
the class AcsLoggingHandler method publish.
/**
* @see java.util.logging.Handler#publish(java.util.logging.LogRecord)
* Writes a single log into an array of strings.
* @param logRecord
*/
public void publish(LogRecord logRecord) {
if (isClosed) {
if (DEBUG) {
System.out.println("AcsLoggingHandler: ignoring record with msg='" + logRecord.getMessage() + "' because this logging handler is already closed.");
}
// or throw an exc.
return;
}
if (!isLoggable(logRecord) || logRecord.getLevel().intValue() == Level.OFF.intValue()) {
// abusing Level.OFF for a log call is not caught by the JDK!
if (DEBUG) {
System.out.println("AcsLoggingHandler: ignoring record with msg='" + logRecord.getMessage() + "' because isLoggable() was false.");
}
return;
}
StopWatch sw_local = null;
if (PROFILE) {
LogParameterUtil logParamUtil = new LogParameterUtil(logRecord);
StopWatch sw_parent = logParamUtil.getStopWatch();
if (sw_parent != null) {
sw_local = sw_parent.createStopWatchForSubtask("AcsLoggingHandler");
}
}
if (logThrottle == null || logThrottle.checkPublishLogRecordRemote()) {
// must trigger a call to LogRecord#inferCaller before the log record gets processed by a different thread
logRecord.getSourceClassName();
logQueue.log(logRecord);
if (AcsLogLevel.getNativeLevel(logRecord.getLevel()).getAcsLevel().compareTo(immediateDispatchLevel) >= 0) {
if (DEBUG) {
System.out.println("flushing log queue because of log record with level " + logRecord.getLevel().getName());
}
logQueue.flush();
}
} else {
// System.out.println("Suppressed remote log!");
}
if (PROFILE && sw_local != null) {
sw_local.stop();
}
}
use of alma.acs.util.StopWatch in project ACS by ACS-Community.
the class StdOutConsoleHandler method publish.
/**
* Publish a <tt>LogRecord</tt>.
* <p>
* The logging request was made initially to a <tt>Logger</tt> object,
* which initialized the <tt>LogRecord</tt> and forwarded it here.
* <p>
*
* @param record
* description of the log event. A null record is silently
* ignored and is not published
*/
public synchronized void publish(LogRecord record) {
StopWatch sw_local = null;
if (PROFILE) {
LogParameterUtil logParamUtil = new LogParameterUtil(record);
StopWatch sw_parent = logParamUtil.getStopWatch();
if (sw_parent != null) {
sw_local = sw_parent.createStopWatchForSubtask("StdOutConsoleHandler");
}
}
if (logThrottle == null || logThrottle.checkPublishLogRecordLocal()) {
super.publish(record);
flush();
}
if (PROFILE && sw_local != null) {
sw_local.stop();
}
}
use of alma.acs.util.StopWatch in project ACS by ACS-Community.
the class ServicesDaemonTest method testNamingSrvStartStopCheckCallback.
/////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////// Test methods //////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
/**
* Starts and stops the naming service via the daemon,
* checking the callbacks.
*/
public void testNamingSrvStartStopCheckCallback() throws Exception {
assertNamingService(false);
DaemonCallbackImpl daemonCallbackImpl = new DaemonCallbackImpl(logger);
DaemonCallback dcb = activateDaemonCallback(daemonCallbackImpl);
// start naming service
daemonCallbackImpl.prepareWaitForDone("naming");
StopWatch sw = new StopWatch(logger);
daemon.start_naming_service(dcb, instanceNumber);
assertTrue("Failed to start naming service in 10 s", daemonCallbackImpl.waitForDone(10, TimeUnit.SECONDS));
sw.logLapTime("call start_naming_service");
assertFalse(AcsJCompletion.fromCorbaCompletion(daemonCallbackImpl.getLastDoneCompletion()).isError());
assertNamingService(true);
// stop naming service
daemonCallbackImpl.prepareWaitForDone("naming");
sw.reset();
daemon.stop_naming_service(dcb, instanceNumber);
assertTrue("Failed to stop naming service in 5 s", daemonCallbackImpl.waitForDone(5, TimeUnit.SECONDS));
sw.logLapTime("call stop_naming_service");
}
Aggregations