Search in sources :

Example 21 with ActionRequest

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);
}
Also used : ActionRequest(com.axway.ats.agent.core.action.ActionRequest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ArgumentWrapper(com.axway.ats.agent.webapp.client.ArgumentWrapper) ObjectOutputStream(java.io.ObjectOutputStream) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 22 with ActionRequest

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();
    }
}
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 ActionRequest

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) {
            }
        }
    }
}
Also used : ActionRequest(com.axway.ats.agent.core.action.ActionRequest) RemoteExecutor(com.axway.ats.agent.webapp.client.executors.RemoteExecutor) AbstractClientExecutor(com.axway.ats.agent.webapp.client.executors.AbstractClientExecutor) LocalExecutor(com.axway.ats.agent.webapp.client.executors.LocalExecutor) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 24 with ActionRequest

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;
}
Also used : ActionRequest(com.axway.ats.agent.core.action.ActionRequest) RemoteExecutor(com.axway.ats.agent.webapp.client.executors.RemoteExecutor) LocalExecutor(com.axway.ats.agent.webapp.client.executors.LocalExecutor)

Example 25 with ActionRequest

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"));
}
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)

Aggregations

ActionRequest (com.axway.ats.agent.core.action.ActionRequest)44 Test (org.junit.Test)36 LoaderDataConfig (com.axway.ats.agent.core.threading.data.config.LoaderDataConfig)26 AllAtOncePattern (com.axway.ats.agent.core.threading.patterns.AllAtOncePattern)24 ArrayList (java.util.ArrayList)20 BaseTest (com.axway.ats.agent.core.BaseTest)6 ParameterDataProvider (com.axway.ats.agent.core.threading.data.ParameterDataProvider)6 FixedDurationAllAtOncePattern (com.axway.ats.agent.core.threading.patterns.FixedDurationAllAtOncePattern)5 RampUpPattern (com.axway.ats.agent.core.threading.patterns.RampUpPattern)5 ListDataConfig (com.axway.ats.agent.core.threading.data.config.ListDataConfig)4 FixedDurationRampUpPattern (com.axway.ats.agent.core.threading.patterns.FixedDurationRampUpPattern)3 LocalExecutor (com.axway.ats.agent.webapp.client.executors.LocalExecutor)3 BeforeClass (org.junit.BeforeClass)3 AgentException (com.axway.ats.agent.core.exceptions.AgentException)2 ThreadingPattern (com.axway.ats.agent.core.threading.patterns.ThreadingPattern)2 RemoteExecutor (com.axway.ats.agent.webapp.client.executors.RemoteExecutor)2 IOException (java.io.IOException)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Component (com.axway.ats.agent.core.Component)1 ComponentActionMap (com.axway.ats.agent.core.ComponentActionMap)1