Search in sources :

Example 46 with CollectionProperty

use of org.apache.jmeter.testelement.property.CollectionProperty in project jmeter by apache.

the class UserParametersGui method modifyTestElement.

/**
 * Modifies a given TestElement to mirror the data in the gui components.
 *
 * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
 */
@Override
public void modifyTestElement(TestElement params) {
    GuiUtils.stopTableEditing(paramTable);
    UserParameters userParams = (UserParameters) params;
    userParams.setNames(new CollectionProperty(UserParameters.NAMES, tableModel.getColumnData(NAME_COL_RESOURCE)));
    CollectionProperty threadLists = new CollectionProperty(UserParameters.THREAD_VALUES, new ArrayList<>());
    log.debug("making threadlists from gui");
    for (int col = 1; col < tableModel.getColumnCount(); col++) {
        threadLists.addItem(tableModel.getColumnData(getUserColName(col)));
        if (log.isDebugEnabled()) {
            log.debug("Adding column to threadlist: {}", tableModel.getColumnData(getUserColName(col)));
            log.debug("Threadlists now = {}", threadLists);
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("In the end, threadlists = {}", threadLists);
    }
    userParams.setThreadLists(threadLists);
    userParams.setPerIteration(perIterationCheck.isSelected());
    super.configureTestElement(params);
}
Also used : UserParameters(org.apache.jmeter.modifiers.UserParameters) CollectionProperty(org.apache.jmeter.testelement.property.CollectionProperty)

Example 47 with CollectionProperty

use of org.apache.jmeter.testelement.property.CollectionProperty in project jmeter by apache.

the class TestTreeCloner method testCloning.

@Test
public void testCloning() throws Exception {
    ListedHashTree original = new ListedHashTree();
    GenericController controller = new GenericController();
    controller.setName("controller");
    Arguments args = new Arguments();
    args.setName("args");
    TestPlan plan = new TestPlan();
    plan.addParameter("server", "jakarta");
    original.add(controller, args);
    original.add(plan);
    ResultCollector listener = new ResultCollector();
    listener.setName("Collector");
    original.add(controller, listener);
    TreeCloner cloner = new TreeCloner();
    original.traverse(cloner);
    ListedHashTree newTree = cloner.getClonedTree();
    assertTrue(original != newTree);
    assertEquals(original.size(), newTree.size());
    assertEquals(original.getTree(original.getArray()[0]).size(), newTree.getTree(newTree.getArray()[0]).size());
    assertTrue(original.getArray()[0] != newTree.getArray()[0]);
    assertEquals(((GenericController) original.getArray()[0]).getName(), ((GenericController) newTree.getArray()[0]).getName());
    assertSame(original.getTree(original.getArray()[0]).getArray()[1], newTree.getTree(newTree.getArray()[0]).getArray()[1]);
    TestPlan clonedTestPlan = (TestPlan) newTree.getArray()[1];
    clonedTestPlan.setRunningVersion(true);
    clonedTestPlan.recoverRunningVersion();
    assertTrue(!plan.getUserDefinedVariablesAsProperty().isRunningVersion());
    assertTrue(clonedTestPlan.getUserDefinedVariablesAsProperty().isRunningVersion());
    Arguments vars = (Arguments) plan.getUserDefinedVariablesAsProperty().getObjectValue();
    PropertyIterator iter = ((CollectionProperty) vars.getProperty(Arguments.ARGUMENTS)).iterator();
    while (iter.hasNext()) {
        JMeterProperty argProp = iter.next();
        assertTrue(!argProp.isRunningVersion());
        assertTrue(argProp.getObjectValue() instanceof Argument);
        Argument arg = (Argument) argProp.getObjectValue();
        arg.setValue("yahoo");
        assertEquals("yahoo", arg.getValue());
    }
    vars = (Arguments) clonedTestPlan.getUserDefinedVariablesAsProperty().getObjectValue();
    iter = vars.propertyIterator();
    while (iter.hasNext()) {
        assertTrue(iter.next().isRunningVersion());
    }
}
Also used : ListedHashTree(org.apache.jorphan.collections.ListedHashTree) CollectionProperty(org.apache.jmeter.testelement.property.CollectionProperty) JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) Argument(org.apache.jmeter.config.Argument) TestPlan(org.apache.jmeter.testelement.TestPlan) Arguments(org.apache.jmeter.config.Arguments) PropertyIterator(org.apache.jmeter.testelement.property.PropertyIterator) GenericController(org.apache.jmeter.control.GenericController) ResultCollector(org.apache.jmeter.reporters.ResultCollector) Test(org.junit.jupiter.api.Test)

Example 48 with CollectionProperty

use of org.apache.jmeter.testelement.property.CollectionProperty in project jmeter by apache.

the class DNSCacheManager method isStaticHost.

private boolean isStaticHost(String host) {
    JMeterProperty p = getProperty(HOSTS);
    if (p instanceof NullProperty) {
        removeProperty(HOSTS);
        return false;
    }
    CollectionProperty property = (CollectionProperty) p;
    for (JMeterProperty jMeterProperty : property) {
        TestElementProperty possibleEntry = (TestElementProperty) jMeterProperty;
        if (log.isDebugEnabled()) {
            log.debug("Look for {} at {}: {}", host, possibleEntry.getObjectValue(), possibleEntry.getObjectValue().getClass());
        }
        StaticHost entry = (StaticHost) possibleEntry.getObjectValue();
        if (entry.getName().equalsIgnoreCase(host)) {
            if (log.isDebugEnabled()) {
                log.debug("Found static host: {} => {}", host, entry.getAddress());
            }
            return true;
        }
    }
    log.debug("No static host found for {}", host);
    return false;
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) CollectionProperty(org.apache.jmeter.testelement.property.CollectionProperty) NullProperty(org.apache.jmeter.testelement.property.NullProperty) TestElementProperty(org.apache.jmeter.testelement.property.TestElementProperty)

Example 49 with CollectionProperty

use of org.apache.jmeter.testelement.property.CollectionProperty in project jmeter by apache.

the class DNSCacheManager method fromStaticHost.

private InetAddress[] fromStaticHost(String host) {
    JMeterProperty p = getProperty(HOSTS);
    if (p instanceof NullProperty) {
        removeProperty(HOSTS);
        return new InetAddress[0];
    }
    CollectionProperty property = (CollectionProperty) p;
    for (JMeterProperty jMeterProperty : property) {
        StaticHost entry = (StaticHost) jMeterProperty.getObjectValue();
        if (!entry.getName().equals(host)) {
            // try the next property
            continue;
        }
        List<InetAddress> addresses = new ArrayList<>();
        for (String address : entry.getAddress().split("\\s*,\\s*")) {
            try {
                final InetAddress[] requestLookup = requestLookup(address);
                if (requestLookup == null) {
                    addAsLiteralAddress(addresses, address);
                } else {
                    addresses.addAll(Arrays.asList(requestLookup));
                }
            } catch (UnknownHostException e) {
                addAsLiteralAddress(addresses, address);
                log.warn("Couldn't resolve static address {} for host {}", address, host, e);
            }
        }
        return addresses.toArray(new InetAddress[addresses.size()]);
    }
    return new InetAddress[0];
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) CollectionProperty(org.apache.jmeter.testelement.property.CollectionProperty) NullProperty(org.apache.jmeter.testelement.property.NullProperty) UnknownHostException(java.net.UnknownHostException) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress)

Example 50 with CollectionProperty

use of org.apache.jmeter.testelement.property.CollectionProperty in project jmeter by apache.

the class DNSCacheManager method createResolver.

private Resolver createResolver() {
    CollectionProperty dnsServers = getServers();
    try {
        String[] serverNames = new String[dnsServers.size()];
        int index = 0;
        for (JMeterProperty jMeterProperty : dnsServers) {
            serverNames[index] = jMeterProperty.getStringValue();
            index++;
        }
        ExtendedResolver result = new ExtendedResolver(serverNames);
        if (log.isDebugEnabled()) {
            log.debug("Using DNS Resolvers: {}", Arrays.asList(result.getResolvers()));
        }
        // resolvers will be chosen via round-robin
        result.setLoadBalance(true);
        return result;
    } catch (UnknownHostException uhe) {
        this.initFailed = true;
        log.warn("Failed to create Extended resolver: {}", uhe.getMessage(), uhe);
        return null;
    }
}
Also used : ExtendedResolver(org.xbill.DNS.ExtendedResolver) CollectionProperty(org.apache.jmeter.testelement.property.CollectionProperty) JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) UnknownHostException(java.net.UnknownHostException)

Aggregations

CollectionProperty (org.apache.jmeter.testelement.property.CollectionProperty)91 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)29 ArrayList (java.util.ArrayList)19 NullProperty (org.apache.jmeter.testelement.property.NullProperty)13 Test (org.junit.Test)11 PropertyIterator (org.apache.jmeter.testelement.property.PropertyIterator)8 Test (org.junit.jupiter.api.Test)7 IOException (java.io.IOException)5 List (java.util.List)4 StringProperty (org.apache.jmeter.testelement.property.StringProperty)4 File (java.io.File)3 Argument (org.apache.jmeter.config.Argument)3 PowerTableModel (org.apache.jmeter.gui.util.PowerTableModel)3 TestPlan (org.apache.jmeter.testelement.TestPlan)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Field (java.lang.reflect.Field)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 UnknownHostException (java.net.UnknownHostException)2 LinkedList (java.util.LinkedList)2