use of com.axway.ats.agent.core.action.ActionRequest in project ats-framework by Axway.
the class Test_RemoteExecutor method executeActionPositive.
@SuppressWarnings("unchecked")
@Test
public void executeActionPositive() throws Exception {
Object resultToReturn = new Integer(4);
ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
ObjectOutputStream objectOutStream = new ObjectOutputStream(byteOutStream);
objectOutStream.writeObject(resultToReturn);
expect(AgentServicePool.getInstance()).andReturn(mockAgentServicePool);
expect(mockAgentServicePool.getClient("10.1.1.3")).andReturn(mockAgentService);
expect(mockAgentService.executeAction(eq(TEST_COMPONENT_NAME), eq("action 1"), (List<ArgumentWrapper>) notNull())).andReturn(byteOutStream.toByteArray());
replayAll();
RemoteExecutor remoteExecutor = new RemoteExecutor("10.1.1.3");
Object actualResult = remoteExecutor.executeAction(new ActionRequest(TEST_COMPONENT_NAME, "action 1", new Object[] { 1 }));
verifyAll();
assertEquals(resultToReturn, actualResult);
}
use of com.axway.ats.agent.core.action.ActionRequest in project ats-framework by Axway.
the class AgentWsImpl method scheduleActionsInMultipleThreads.
/**
* Schedule a set of actions (queue) in multiple threads. The actions
* will not be executed until a call to startQueue is made
*
* @param queueName the name of the action queue
* @param actions the actions in that queue
* @param serializedThreadingPattern the serialized threading pattern to be used
* @param testCaseState the test case state
* @throws AgentException on error
* @throws InternalComponentException if an exception is thrown while the actions are executed
*/
@WebMethod
public void scheduleActionsInMultipleThreads(@WebParam(name = "name") String queueName, @WebParam(name = "queueId") int queueId, @WebParam(name = "actions") ActionWrapper[] actions, @WebParam(name = "serializedThreadingPattern") byte[] serializedThreadingPattern, @WebParam(name = "serializedLoaderDataConfig") byte[] serializedLoaderDataConfig, boolean isUseSynchronizedIterations) throws AgentException, InternalComponentException {
final String caller = getCaller();
ThreadsPerCaller.registerThread(caller);
try {
ArrayList<ActionRequest> actionRequests = new ArrayList<ActionRequest>();
for (ActionWrapper actionWrapper : actions) {
List<ArgumentWrapper> args = actionWrapper.getArgs();
int numArguments = args.size();
Object[] arguments = new Object[numArguments];
// unwrap the action arguments
for (int i = 0; i < numArguments; i++) {
ArgumentWrapper argWrapper = args.get(i);
ByteArrayInputStream byteInStream = new ByteArrayInputStream(argWrapper.getArgumentValue());
ObjectInputStream objectInStream = new ObjectInputStream(byteInStream);
arguments[i] = objectInStream.readObject();
}
// construct the action request
ActionRequest actionRequest = new ActionRequest(actionWrapper.getComponentName(), actionWrapper.getActionName(), arguments);
actionRequests.add(actionRequest);
}
ByteArrayInputStream byteInStream;
ObjectInputStream objectInStream;
// de-serialize the threading configuration
byteInStream = new ByteArrayInputStream(serializedThreadingPattern);
objectInStream = new ObjectInputStream(byteInStream);
ThreadingPattern threadingPattern = (ThreadingPattern) objectInStream.readObject();
// de-serialize the loader data configuration
byteInStream = new ByteArrayInputStream(serializedLoaderDataConfig);
objectInStream = new ObjectInputStream(byteInStream);
LoaderDataConfig loaderDataConfig = (LoaderDataConfig) objectInStream.readObject();
MultiThreadedActionHandler.getInstance(caller).scheduleActions(caller, queueName, queueId, actionRequests, threadingPattern, loaderDataConfig, isUseSynchronizedIterations);
} catch (Exception e) {
handleExceptions(e);
} finally {
ThreadsPerCaller.unregisterThread();
}
}
use of com.axway.ats.agent.core.action.ActionRequest in project ats-framework by Axway.
the class AgentConfigurationClient method isComponentLoaded.
/**
* Tells if an Agent component is loaded, so its actions can be called.
* This method will wait for the specified timeout period until the wanted condition is met.
*
* @param componentName the name of the component
* @param timeout maximum timeout (in seconds) to wait for the component to be loaded.
* @return whether it is available
*/
@PublicAtsApi
public boolean isComponentLoaded(String componentName, int timeout) throws AgentException {
// construct an action request
ActionRequest actionRequest = new ActionRequest(componentName, "fake action name", new Object[] {});
AbstractClientExecutor executor;
if (atsAgent.equals(LOCAL_JVM)) {
executor = new LocalExecutor();
} else {
executor = new RemoteExecutor(atsAgent, false);
}
long startTimestamp = System.currentTimeMillis();
while (true) {
if (executor.isComponentLoaded(actionRequest)) {
// it is loaded
return true;
} else if (System.currentTimeMillis() - startTimestamp > timeout * 1000) {
// not loaded for the whole timeout
return false;
} else {
// not loaded, but we will check again
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
}
}
use of com.axway.ats.agent.core.action.ActionRequest in project ats-framework by Axway.
the class ActionClient method executeAction.
/**
* Execute the given action
*
* @param actionName
* name of the action
* @param arguments
* arguments for the action
* @return result of the action execution
* @throws AgentException
* if exception occurs during action execution
*/
protected Object executeAction(String actionName, Object[] arguments) throws AgentException {
// construct an action request
ActionRequest actionRequest = new ActionRequest(component, actionName, arguments);
// the returned result
Object result = null;
// Check if we are queuing - in this case all actions will be routed to the queue
// The exception is when we are sending command to the Monitoring Service
ActionQueue actionQueue = ActionQueue.getCurrentInstance();
if (!actionQueue.isInQueueMode() || component.equals(SystemMonitorDefinitions.ATS_SYSTEM_MONITORING_COMPONENT_NAME)) {
if (atsAgent.equals(LOCAL_JVM)) {
LocalExecutor localExecutor = new LocalExecutor();
result = localExecutor.executeAction(actionRequest);
} else {
RemoteExecutor remoteExecutor = new RemoteExecutor(atsAgent);
result = remoteExecutor.executeAction(actionRequest);
}
} else {
actionQueue.addActionRequest(actionRequest);
}
return result;
}
use of com.axway.ats.agent.core.action.ActionRequest in project ats-framework by Axway.
the class DisabledTest_MultiThreadedActionHandlerWithParameterizedInputData method paramPresentInDataProvidersMoreTimeThanInTheInvokers.
@Test
public void paramPresentInDataProvidersMoreTimeThanInTheInvokers() throws Exception {
// A warning message should be logged saying a parameter is provided more time then it is used in the actions
int nThreads = 1;
int nInvocations = 2;
List<ActionRequest> actions = new ArrayList<ActionRequest>();
LoaderDataConfig loaderDataConfig = new LoaderDataConfig();
for (int i = 0; i < nInvocations; i++) {
actions.add(fileUploadActionRequest);
}
loaderDataConfig.addParameterConfig(parameterDataProviders[0]);
loaderDataConfig.addParameterConfig(parameterDataProviders[1]);
loaderDataConfig.addParameterConfig(parameterDataProviders[2]);
AllAtOncePattern pattern = new AllAtOncePattern(nThreads, true);
QueueExecutionStatistics.getInstance().initActionExecutionResults("test 1");
actionHandler.executeActions("IP", "test 1", -1, actions, pattern, loaderDataConfig);
assertEquals(nInvocations * nThreads, ParameterizedInputActionClass.getAddedStringsCount());
assertEquals(1, (int) ParameterizedInputActionClass.addedStrings.get("X1.txt"));
assertNull(ParameterizedInputActionClass.addedStrings.get("X2.txt"));
assertNull(ParameterizedInputActionClass.addedStrings.get("X3.txt"));
assertNull(ParameterizedInputActionClass.addedStrings.get("Y2.txt"));
}
Aggregations