use of com.axway.ats.agent.core.threading.data.config.LoaderDataConfig in project ats-framework by Axway.
the class Test_QueueCanceling method allAtOnce_SynchronizedActions.
/**
* 2 threads are run synchronized, 1 thread will do its iteration and will be put in sleep by
* the Thread Manager waiting until the 2 (slower) finish its iteration.
* This is the moment we will cancel the queue.
*/
@Test
public void allAtOnce_SynchronizedActions() throws Exception {
expectedNumExecutions = 2;
final String paramName = "sleepTime";
ListDataConfig parameterData = new ListDataConfig(paramName, Arrays.asList(new String[] { "500", "1500" }), ParameterProviderLevel.PER_THREAD_STATIC);
LoaderDataConfig loaderDataConfig = new LoaderDataConfig();
loaderDataConfig.addParameterConfig(parameterData);
actionRequests.add(new ActionRequest(TEST_COMPONENT_NAME, ACTION_SLEEP, new Object[] { paramName }));
AllAtOncePattern pattern = new AllAtOncePattern(2, false, 2, 0);
pattern.setUseSynchronizedIterations(true);
QueueExecutionStatistics.getInstance().initActionExecutionResults(QUEUE_NAME);
actionHandler.scheduleActions(HOST, QUEUE_NAME, -1, actionRequests, pattern, loaderDataConfig, true);
actionHandler.startQueue(QUEUE_NAME);
Thread.sleep(1000);
}
use of com.axway.ats.agent.core.threading.data.config.LoaderDataConfig 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.threading.data.config.LoaderDataConfig in project ats-framework by Axway.
the class ActionQueue method executeQueuedActions.
/**
* Execute all queued actions in multiple threads
*
* @param atsAgents the hosts to execute to
* @param threadingPattern the multithreading pattern
* @param loaderDataConfig the loader variable data configuration
* @throws AgentException on error
*/
public void executeQueuedActions(List<String> atsAgents, ThreadingPattern threadingPattern, LoaderDataConfig loaderDataConfig) throws AgentException {
if (threadingPattern == null) {
throw new AgentException("Threading pattern is not specified. You must specify one");
}
isQueueFinished = false;
//create an empty instance of the config
if (loaderDataConfig == null) {
loaderDataConfig = new LoaderDataConfig();
}
if (atsAgents == null || atsAgents.size() == 0) {
//local execution
LocalLoadExecutor localLoadExecutor = new LocalLoadExecutor(name, sequence, threadingPattern, loaderDataConfig);
localLoadExecutor.executeActions(queuedActions);
} else {
if (threadingPattern.getThreadCount() < atsAgents.size()) {
String firstHost = atsAgents.get(0);
log.warn("The total number of threads [" + threadingPattern.getThreadCount() + "] is less than the number of remote execution hosts [" + atsAgents.size() + "], so all threads will be run on just one host [" + firstHost + "]");
atsAgents = new ArrayList<String>();
atsAgents.add(firstHost);
}
//distributed remote execution
DistributedLoadExecutor distributedLoadExecutor = new DistributedLoadExecutor(name, sequence, atsAgents, threadingPattern, loaderDataConfig);
distributedLoadExecutor.executeActions(queuedActions);
}
if (threadingPattern.isBlockUntilCompletion()) {
isQueueFinished = true;
}
inQueueMode = false;
}
use of com.axway.ats.agent.core.threading.data.config.LoaderDataConfig 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"));
}
use of com.axway.ats.agent.core.threading.data.config.LoaderDataConfig in project ats-framework by Axway.
the class DisabledTest_MultiThreadedActionHandlerWithParameterizedInputData method paremterizedIntegerDataPositive.
@Test
public void paremterizedIntegerDataPositive() throws Exception {
LoaderDataConfig loaderDataConfig = new LoaderDataConfig();
loaderDataConfig.addParameterConfig(new RangeDataConfig("milliseconds", 1, 300));
AllAtOncePattern pattern = new AllAtOncePattern(5, true);
QueueExecutionStatistics.getInstance().initActionExecutionResults("test 1");
actionHandler.executeActions("IP", "test 1", -1, actionRequests, pattern, loaderDataConfig);
assertEquals(5, ParameterizedInputActionClass.addedLongs.size());
for (int i = 1; i < 6; i++) {
assertTrue(ParameterizedInputActionClass.addedLongs.contains(new Long(i)));
}
}
Aggregations