Search in sources :

Example 21 with LoaderDataConfig

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);
}
Also used : AllAtOncePattern(com.axway.ats.agent.core.threading.patterns.AllAtOncePattern) ActionRequest(com.axway.ats.agent.core.action.ActionRequest) ListDataConfig(com.axway.ats.agent.core.threading.data.config.ListDataConfig) LoaderDataConfig(com.axway.ats.agent.core.threading.data.config.LoaderDataConfig) Test(org.junit.Test)

Example 22 with LoaderDataConfig

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();
    }
}
Also used : ArrayList(java.util.ArrayList) InternalComponentException(com.axway.ats.agent.core.exceptions.InternalComponentException) AgentException(com.axway.ats.agent.core.exceptions.AgentException) NoSuchActionException(com.axway.ats.agent.core.exceptions.NoSuchActionException) NoCompatibleMethodFoundException(com.axway.ats.agent.core.exceptions.NoCompatibleMethodFoundException) NoSuchComponentException(com.axway.ats.agent.core.exceptions.NoSuchComponentException) IOException(java.io.IOException) ActionExecutionException(com.axway.ats.agent.core.exceptions.ActionExecutionException) LoaderDataConfig(com.axway.ats.agent.core.threading.data.config.LoaderDataConfig) ThreadingPattern(com.axway.ats.agent.core.threading.patterns.ThreadingPattern) ActionRequest(com.axway.ats.agent.core.action.ActionRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInputStream(java.io.ObjectInputStream) WebMethod(javax.jws.WebMethod)

Example 23 with LoaderDataConfig

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;
}
Also used : DistributedLoadExecutor(com.axway.ats.agent.webapp.client.executors.DistributedLoadExecutor) AgentException(com.axway.ats.agent.core.exceptions.AgentException) LocalLoadExecutor(com.axway.ats.agent.webapp.client.executors.LocalLoadExecutor) LoaderDataConfig(com.axway.ats.agent.core.threading.data.config.LoaderDataConfig)

Example 24 with LoaderDataConfig

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"));
}
Also used : AllAtOncePattern(com.axway.ats.agent.core.threading.patterns.AllAtOncePattern) ActionRequest(com.axway.ats.agent.core.action.ActionRequest) ArrayList(java.util.ArrayList) LoaderDataConfig(com.axway.ats.agent.core.threading.data.config.LoaderDataConfig) Test(org.junit.Test)

Example 25 with LoaderDataConfig

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)));
    }
}
Also used : RangeDataConfig(com.axway.ats.agent.core.threading.data.config.RangeDataConfig) AllAtOncePattern(com.axway.ats.agent.core.threading.patterns.AllAtOncePattern) LoaderDataConfig(com.axway.ats.agent.core.threading.data.config.LoaderDataConfig) Test(org.junit.Test)

Aggregations

LoaderDataConfig (com.axway.ats.agent.core.threading.data.config.LoaderDataConfig)50 Test (org.junit.Test)47 AllAtOncePattern (com.axway.ats.agent.core.threading.patterns.AllAtOncePattern)30 ActionRequest (com.axway.ats.agent.core.action.ActionRequest)26 RampUpPattern (com.axway.ats.agent.core.threading.patterns.RampUpPattern)18 ArrayList (java.util.ArrayList)16 RangeDataConfig (com.axway.ats.agent.core.threading.data.config.RangeDataConfig)5 AgentException (com.axway.ats.agent.core.exceptions.AgentException)3 ListDataConfig (com.axway.ats.agent.core.threading.data.config.ListDataConfig)3 ThreadingPattern (com.axway.ats.agent.core.threading.patterns.ThreadingPattern)2 IOException (java.io.IOException)2 ActionExecutionException (com.axway.ats.agent.core.exceptions.ActionExecutionException)1 InternalComponentException (com.axway.ats.agent.core.exceptions.InternalComponentException)1 NoCompatibleMethodFoundException (com.axway.ats.agent.core.exceptions.NoCompatibleMethodFoundException)1 NoSuchActionException (com.axway.ats.agent.core.exceptions.NoSuchActionException)1 NoSuchComponentException (com.axway.ats.agent.core.exceptions.NoSuchComponentException)1 ImportantThread (com.axway.ats.agent.core.threading.ImportantThread)1 ActionWrapper (com.axway.ats.agent.webapp.client.ActionWrapper)1 AgentException_Exception (com.axway.ats.agent.webapp.client.AgentException_Exception)1 AgentService (com.axway.ats.agent.webapp.client.AgentService)1