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