Search in sources :

Example 1 with ListDataConfig

use of com.axway.ats.agent.core.threading.data.config.ListDataConfig in project ats-framework by Axway.

the class Test_QueueCanceling method allAtOnce_OneThreadReallyRunning_OneThreadPaused.

/**
     * All(or most of) the tests in this class let the actions do SLEEP (the internal thread state is TIMED_WAITING) while mean running.
     * In this test, the threads are really running(the internal thread state is RUNNABLE).
     * When we cancel the queue, one of the is RUNNING its first iteration, the other thread is sleeping between its first and second iterations.
     */
@Test
public void allAtOnce_OneThreadReallyRunning_OneThreadPaused() throws Exception {
    expectedNumExecutions = 2;
    ListDataConfig parameterData = new ListDataConfig("runTime", Arrays.asList(new String[] { "500", "2000" }), ParameterProviderLevel.PER_THREAD_STATIC);
    LoaderDataConfig loaderDataConfig = new LoaderDataConfig();
    loaderDataConfig.addParameterConfig(parameterData);
    actionRequests.add(new ActionRequest(TEST_COMPONENT_NAME, ACTION_RUNNING, new Object[] { "runTime" }));
    AllAtOncePattern pattern = new AllAtOncePattern(2, false, 2, 1000);
    QueueExecutionStatistics.getInstance().initActionExecutionResults(QUEUE_NAME);
    actionHandler.scheduleActions(HOST, QUEUE_NAME, -1, actionRequests, pattern, loaderDataConfig, false);
    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 2 with ListDataConfig

use of com.axway.ats.agent.core.threading.data.config.ListDataConfig 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 3 with ListDataConfig

use of com.axway.ats.agent.core.threading.data.config.ListDataConfig in project ats-framework by Axway.

the class Test_ParameterDataProviderFactory method createListProvider.

@Test
public void createListProvider() throws AgentException, URISyntaxException {
    ListDataConfig listDataConfig = new ListDataConfig("param1", new String[] { "test1", "test2" }, ParameterProviderLevel.PER_INVOCATION);
    ParameterDataProvider dataProvider = ParameterDataProviderFactory.createDataProvider(listDataConfig);
    assertEquals(ListParameterDataProvider.class, dataProvider.getClass());
    ArgumentValue generatedValue = dataProvider.getValue(new ArrayList<ArgumentValue>());
    assertEquals("param1", generatedValue.getName());
    assertEquals("test1", generatedValue.getValue());
}
Also used : ListDataConfig(com.axway.ats.agent.core.threading.data.config.ListDataConfig) ArgumentValue(com.axway.ats.agent.core.action.ArgumentValue) Test(org.junit.Test) BaseTest(com.axway.ats.agent.core.BaseTest)

Example 4 with ListDataConfig

use of com.axway.ats.agent.core.threading.data.config.ListDataConfig in project ats-framework by Axway.

the class ParameterDataProviderFactory method createDataProvider.

/**
     * Create a data provider based on a configuration provider
     *
     * @param parameterConfig the configuration based on which to create the provider
     * @return the newly created provider
     * @throws ParameterDataProviderNotSupportedException if the provider is not supported
     * @throws ParameterDataProviderInitalizationException if there is an error during provider initialization
     */
public static ParameterDataProvider createDataProvider(ParameterDataConfig parameterConfig) throws ParameterDataProviderNotSupportedException, ParameterDataProviderInitalizationException {
    ParameterDataProvider parameterDataProvider;
    Class<?> parameterConfigClass = parameterConfig.getClass();
    if (parameterConfigClass == RangeDataConfig.class) {
        RangeDataConfig rangeDataConfig = (RangeDataConfig) parameterConfig;
        //choose the right one, based on the arguments
        if (rangeDataConfig.getStaticValue() != null) {
            parameterDataProvider = new StringRangeParameterDataProvider(rangeDataConfig.getParameterName(), rangeDataConfig.getStaticValue(), (Integer) rangeDataConfig.getRangeStart(), (Integer) rangeDataConfig.getRangeEnd(), parameterConfig.getParameterProviderLevel());
        } else {
            parameterDataProvider = new IntegerRangeParameterDataProvider(rangeDataConfig.getParameterName(), (Integer) rangeDataConfig.getRangeStart(), (Integer) rangeDataConfig.getRangeEnd(), parameterConfig.getParameterProviderLevel());
        }
    } else if (parameterConfigClass == ListDataConfig.class) {
        ListDataConfig listDataConfig = (ListDataConfig) parameterConfig;
        parameterDataProvider = new ListParameterDataProvider(listDataConfig.getParameterName(), listDataConfig.getValues(), listDataConfig.getParameterProviderLevel());
    } else if (parameterConfigClass == FileNamesDataConfig.class) {
        FileNamesDataConfig fileNamesDataConfig = (FileNamesDataConfig) parameterConfig;
        parameterDataProvider = new FileNamesParameterDataProvider(fileNamesDataConfig.getParameterName(), fileNamesDataConfig.getFileContainers(), fileNamesDataConfig.getRecursiveSearch(), fileNamesDataConfig.getReturnFullPath(), fileNamesDataConfig.getParameterProviderLevel());
    } else if (parameterConfigClass == UsernameDataConfig.class) {
        UsernameDataConfig nameDataConfig = (UsernameDataConfig) parameterConfig;
        if (nameDataConfig.getValues() != null) {
            parameterDataProvider = new ListParameterDataProvider(nameDataConfig.getParameterName(), nameDataConfig.getValues(), nameDataConfig.getParameterProviderLevel(), UsernameDataConfig.class);
        } else {
            parameterDataProvider = new StringRangeParameterDataProvider(nameDataConfig.getParameterName(), nameDataConfig.getStaticValue(), (Integer) nameDataConfig.getRangeStart(), (Integer) nameDataConfig.getRangeEnd(), parameterConfig.getParameterProviderLevel(), UsernameDataConfig.class);
        }
    } else if (parameterConfigClass.getGenericSuperclass() == CustomParameterDataConfig.class) {
        // custom data provider
        CustomParameterDataConfig customDataConfig = (CustomParameterDataConfig) parameterConfig;
        try {
            // find the constructor of the custom data provider
            Constructor<? extends CustomParameterDataProvider> constructor = customDataConfig.getDataProviderClass().getDeclaredConstructor(String.class, Map.class, ParameterProviderLevel.class);
            // call the constructor of the custom data provider
            parameterDataProvider = (CustomParameterDataProvider) constructor.newInstance(customDataConfig.getParameterName(), customDataConfig.getControlTokens(), customDataConfig.getParameterProviderLevel());
        } catch (Exception e) {
            throw new ParameterDataProviderNotSupportedException(parameterConfigClass);
        }
    } else {
        throw new ParameterDataProviderNotSupportedException(parameterConfigClass);
    }
    //initialize the newly created provider
    parameterDataProvider.initialize();
    //and return it back to the caller
    return parameterDataProvider;
}
Also used : RangeDataConfig(com.axway.ats.agent.core.threading.data.config.RangeDataConfig) FileNamesDataConfig(com.axway.ats.agent.core.threading.data.config.FileNamesDataConfig) UsernameDataConfig(com.axway.ats.agent.core.threading.data.config.UsernameDataConfig) ParameterDataProviderNotSupportedException(com.axway.ats.agent.core.threading.exceptions.ParameterDataProviderNotSupportedException) ParameterDataProviderInitalizationException(com.axway.ats.agent.core.threading.exceptions.ParameterDataProviderInitalizationException) CustomParameterDataConfig(com.axway.ats.agent.core.threading.data.config.CustomParameterDataConfig) ParameterDataProviderNotSupportedException(com.axway.ats.agent.core.threading.exceptions.ParameterDataProviderNotSupportedException) ListDataConfig(com.axway.ats.agent.core.threading.data.config.ListDataConfig)

Example 5 with ListDataConfig

use of com.axway.ats.agent.core.threading.data.config.ListDataConfig in project ats-framework by Axway.

the class DisabledTest_MultiThreadedActionHandlerWithParameterizedInputData method setUpTest_ActionInvoker.

@BeforeClass
public static void setUpTest_ActionInvoker() throws AgentException {
    Component component = new Component(TEST_COMPONENT_NAME);
    ComponentActionMap actionMap = new ComponentActionMap(TEST_COMPONENT_NAME);
    actionMap.registerActionClass(ParameterizedInputActionClass.class);
    component.setActionMap(actionMap);
    ComponentRepository componentRepository = ComponentRepository.getInstance();
    componentRepository.clear();
    componentRepository.putComponent(component);
    ActionRequest actionRequest1 = new ActionRequest(TEST_COMPONENT_NAME, "create file", new Object[] { "test" });
    ActionRequest actionRequest2 = new ActionRequest(TEST_COMPONENT_NAME, "upload file", new Object[] { "test" });
    ActionRequest actionRequest3 = new ActionRequest(TEST_COMPONENT_NAME, "action long", new Object[] { -120 });
    actionRequests = new ArrayList<ActionRequest>();
    actionRequests.add(actionRequest1);
    actionRequests.add(actionRequest2);
    actionRequests.add(actionRequest3);
    fileUploadActionRequest = new ActionRequest(TEST_COMPONENT_NAME, "upload file", new Object[] { "fileName" });
    parameterDataProviders = new ListDataConfig[] { new ListDataConfig("fileName", new String[] { "X1.txt", "X2.txt", "X3.txt" }, ParameterProviderLevel.PER_INVOCATION), new ListDataConfig("fileName", new String[] { "Y1.txt", "Y2.txt" }, ParameterProviderLevel.PER_INVOCATION), new ListDataConfig("fileName", new String[] { "Z1.txt", "Z2.txt", "Z3.txt", "Z4.txt" }, ParameterProviderLevel.PER_INVOCATION) };
}
Also used : ActionRequest(com.axway.ats.agent.core.action.ActionRequest) ListDataConfig(com.axway.ats.agent.core.threading.data.config.ListDataConfig) BeforeClass(org.junit.BeforeClass)

Aggregations

ListDataConfig (com.axway.ats.agent.core.threading.data.config.ListDataConfig)6 ActionRequest (com.axway.ats.agent.core.action.ActionRequest)4 Test (org.junit.Test)4 LoaderDataConfig (com.axway.ats.agent.core.threading.data.config.LoaderDataConfig)3 AllAtOncePattern (com.axway.ats.agent.core.threading.patterns.AllAtOncePattern)3 BaseTest (com.axway.ats.agent.core.BaseTest)1 ArgumentValue (com.axway.ats.agent.core.action.ArgumentValue)1 CustomParameterDataConfig (com.axway.ats.agent.core.threading.data.config.CustomParameterDataConfig)1 FileNamesDataConfig (com.axway.ats.agent.core.threading.data.config.FileNamesDataConfig)1 RangeDataConfig (com.axway.ats.agent.core.threading.data.config.RangeDataConfig)1 UsernameDataConfig (com.axway.ats.agent.core.threading.data.config.UsernameDataConfig)1 ParameterDataProviderInitalizationException (com.axway.ats.agent.core.threading.exceptions.ParameterDataProviderInitalizationException)1 ParameterDataProviderNotSupportedException (com.axway.ats.agent.core.threading.exceptions.ParameterDataProviderNotSupportedException)1 BeforeClass (org.junit.BeforeClass)1