View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.impl.wsdl.actions.loadtest;
14  
15  import com.eviware.soapui.impl.wsdl.loadtest.WsdlLoadTest;
16  import com.eviware.soapui.impl.wsdl.support.HelpUrls;
17  import com.eviware.soapui.model.settings.Settings;
18  import com.eviware.soapui.settings.HttpSettings;
19  import com.eviware.soapui.support.UISupport;
20  import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
21  import com.eviware.x.form.XFormDialog;
22  import com.eviware.x.form.XFormField;
23  import com.eviware.x.form.XFormFieldListener;
24  import com.eviware.x.form.support.ADialogBuilder;
25  import com.eviware.x.form.support.AField;
26  import com.eviware.x.form.support.AField.AFieldType;
27  import com.eviware.x.form.support.AForm;
28  import com.eviware.x.form.support.APage;
29  
30  /***
31   * Displays the LoadTest Options dialog
32   * 
33   * @author Ole.Matzura
34   */
35  
36  public class LoadTestOptionsAction extends AbstractSoapUIAction<WsdlLoadTest>
37  {
38  	public static final String SOAPUI_ACTION_ID = "LoadTestOptionsAction";
39  	private XFormDialog dialog;
40  
41  	public LoadTestOptionsAction()
42  	{
43  		super( "Options", "Sets options for this LoadTest" );
44  	}
45  
46  	public void perform( WsdlLoadTest loadTest, Object param )
47  	{
48  		if( dialog == null )
49  			buildDialog();
50  
51  		dialog.setIntValue( SettingsForm.THREAD_STARTUP_DELAY, loadTest.getStartDelay() );
52  		dialog.setBooleanValue( SettingsForm.RESET_STATISTICS, loadTest.getResetStatisticsOnThreadCountChange() );
53  		dialog.setBooleanValue( SettingsForm.CALC_TPS, loadTest.getCalculateTPSOnTimePassed() );
54  		dialog.setIntValue( SettingsForm.SAMPLE_INTERVAL, ( int ) loadTest.getSampleInterval() );
55  		dialog.setBooleanValue( SettingsForm.DISABLE_HISTORY, loadTest.getHistoryLimit() == 0 );
56  		dialog.setIntValue( SettingsForm.MAX_ASSERTIONS, ( int ) loadTest.getMaxAssertionErrors() );
57  		dialog.setBooleanValue( SettingsForm.CANCEL_RUNNING, loadTest.getCancelOnReachedLimit() );
58  		dialog.setIntValue( SettingsForm.STRATEGY_INTERVAL, ( int ) loadTest.getStrategyInterval() );
59  		dialog.setBooleanValue( SettingsForm.CANCEL_EXCESSIVE, loadTest.getCancelExcessiveThreads() );
60  		dialog.setBooleanValue( SettingsForm.TESTSTEP_STATISTICS, loadTest.getUpdateStatisticsPerTestStep() );
61  
62  		Settings settings = loadTest.getSettings();
63  
64  		dialog.setBooleanValue( SettingsForm.INCLUDE_REQUEST, settings.getBoolean( HttpSettings.INCLUDE_REQUEST_IN_TIME_TAKEN ) );
65  		dialog.setBooleanValue( SettingsForm.INCLUDE_RESPONSE, settings.getBoolean( HttpSettings.INCLUDE_RESPONSE_IN_TIME_TAKEN ) );
66  		dialog.setBooleanValue( SettingsForm.CLOSE_CONNECTIONS, settings.getBoolean( HttpSettings.CLOSE_CONNECTIONS ) );
67  		
68  		dialog.setValue( LogForm.LOG_FOLDER, loadTest.getStatisticsLogFolder() );
69  		dialog.setIntValue( LogForm.LOG_INTERVAL, ( int ) loadTest.getStatisticsLogInterval() );
70  		dialog.setBooleanValue( LogForm.LOG_ON_THREADCOUNT_CHANGE, loadTest.getLogStatisticsOnThreadChange() );
71  
72  		if( dialog.show() && !loadTest.isRunning() )
73  		{
74  			try
75  			{
76  				loadTest.setStartDelay( dialog.getIntValue( SettingsForm.THREAD_STARTUP_DELAY, loadTest.getStartDelay() ) );
77  				loadTest.setResetStatisticsOnThreadCountChange( dialog.getBooleanValue( SettingsForm.RESET_STATISTICS ) );
78  				loadTest.setCalculateTPSOnTimePassed( dialog.getBooleanValue( SettingsForm.CALC_TPS ) );
79  				loadTest.setSampleInterval( dialog.getIntValue( SettingsForm.SAMPLE_INTERVAL, ( int ) loadTest.getSampleInterval() ) );
80  				loadTest.setHistoryLimit( dialog.getBooleanValue( SettingsForm.DISABLE_HISTORY ) ? 0 : -1 );
81  				loadTest.setMaxAssertionErrors( dialog.getIntValue( SettingsForm.MAX_ASSERTIONS, 1000 ) );
82  				loadTest.setCancelOnReachedLimit( dialog.getBooleanValue( SettingsForm.CANCEL_RUNNING ) );
83  				loadTest.setStrategyInterval( dialog.getIntValue( SettingsForm.STRATEGY_INTERVAL, WsdlLoadTest.DEFAULT_STRATEGY_INTERVAL ) );
84  				loadTest.setCancelExcessiveThreads( dialog.getBooleanValue( SettingsForm.CANCEL_EXCESSIVE ) );
85  				loadTest.setUpdateStatisticsPerTestStep( dialog.getBooleanValue(SettingsForm.TESTSTEP_STATISTICS));
86  
87  				settings.setBoolean( HttpSettings.INCLUDE_REQUEST_IN_TIME_TAKEN, dialog
88  							.getBooleanValue( SettingsForm.INCLUDE_REQUEST ) );
89  				settings.setBoolean( HttpSettings.INCLUDE_RESPONSE_IN_TIME_TAKEN, dialog
90  							.getBooleanValue( SettingsForm.INCLUDE_RESPONSE ) );
91  				settings.setBoolean( HttpSettings.CLOSE_CONNECTIONS, dialog.getBooleanValue( SettingsForm.CLOSE_CONNECTIONS ) );
92  				
93  				loadTest.setLogStatisticsOnThreadChange( dialog.getBooleanValue( LogForm.LOG_ON_THREADCOUNT_CHANGE ) );
94  				loadTest.setStatisticsLogFolder( dialog.getValue( LogForm.LOG_FOLDER ) );
95  				loadTest.setStatisticsLogInterval( dialog.getIntValue( LogForm.LOG_INTERVAL, ( int ) loadTest.getStatisticsLogInterval() ) );
96  			}
97  			catch( NumberFormatException ex )
98  			{
99  				ex.printStackTrace();
100 			}
101 		}
102 	}
103 
104 	private void buildDialog()
105 	{
106 		dialog = ADialogBuilder.buildTabbedDialog( WizardForm.class, null );
107 		dialog.getFormField( SettingsForm.DISABLE_HISTORY ).addFormFieldListener( new XFormFieldListener()
108 		{
109 			public void valueChanged( XFormField sourceField, String newValue, String oldValue )
110 			{
111 				dialog.getFormField( SettingsForm.SAMPLE_INTERVAL ).setEnabled( !Boolean.parseBoolean( newValue ) );
112 			}
113 		} );
114 	}
115 
116 	@AForm( description = "Set options for this LoadTest", name = "LoadTest Options", helpUrl = HelpUrls.LOADTESTOPTIONS_HELP_URL, icon = UISupport.TOOL_ICON_PATH )
117 	private interface WizardForm
118 	{
119 		@APage( name = "Settings" )
120 		public final static SettingsForm INPUT = null;
121 
122 		@APage( name = "Statistics Log" )
123 		public final static LogForm LogForm = null;
124 	}
125 
126 	@AForm( name = "LoadTest Options", description = "", helpUrl = HelpUrls.LOADTESTOPTIONS_HELP_URL, icon = UISupport.OPTIONS_ICON_PATH )
127 	private interface SettingsForm
128 	{
129 		@AField( name = "Thread Startup Delay", description = "The delay before starting a thread in ms", type = AFieldType.INT )
130 		public final static String THREAD_STARTUP_DELAY = "Thread Startup Delay";
131 
132 		@AField( name = "Reset Statistics", description = "when the number of threads changes", type = AFieldType.BOOLEAN )
133 		public final static String RESET_STATISTICS = "Reset Statistics";
134 
135 		@AField( name = "Calculate TPS/BPS", description = "based on actual time passed", type = AFieldType.BOOLEAN )
136 		public final static String CALC_TPS = "Calculate TPS/BPS";
137 
138 		@AField( name = "TestStep Statistics", description = "update statistics every TestStep", type = AFieldType.BOOLEAN )
139 		public final static String TESTSTEP_STATISTICS = "TestStep Statistics";
140 
141 		@AField( name = "Include Request Write", description = "in calculated time", type = AFieldType.BOOLEAN )
142 		public final static String INCLUDE_REQUEST = "Include Request Write";
143 
144 		@AField( name = "Include Response Read", description = "in calculated time", type = AFieldType.BOOLEAN )
145 		public final static String INCLUDE_RESPONSE = "Include Response Read";
146 
147 		@AField( name = "Close Connections", description = "between each request", type = AFieldType.BOOLEAN )
148 		public final static String CLOSE_CONNECTIONS = "Close Connections";
149 
150 		@AField( name = "Sample Interval", description = "statistics sample interval in milliseconds", type = AFieldType.INT )
151 		public final static String SAMPLE_INTERVAL = "Sample Interval";
152 
153 		@AField( name = "Disable History", description = "to preserve memory (will disable diagrams)", type = AFieldType.BOOLEAN )
154 		public final static String DISABLE_HISTORY = "Disable History";
155 
156 		@AField( name = "Max Assertions in Log", description = "the maximum number of assertion errors to keep in log (to preserve memory)", type = AFieldType.INT )
157 		public final static String MAX_ASSERTIONS = "Max Assertions in Log";
158 
159 		@AField( name = "Cancel Running", description = "Cancel running TestCases when Limit has been reached", type = AFieldType.BOOLEAN )
160 		public final static String CANCEL_RUNNING = "Cancel Running";
161 
162 		@AField( name = "Cancel Excessive", description = "Cancel excessive threads when ThreadCount decreases", type = AFieldType.BOOLEAN )
163 		public final static String CANCEL_EXCESSIVE = "Cancel Excessive";
164 
165 		@AField( name = "Strategy Interval", description = "LoadTest Strategy application interval in milliseconds", type = AFieldType.INT )
166 		public final static String STRATEGY_INTERVAL = "Strategy Interval";
167 		
168 	}
169 	
170 	@AForm( name = "Logging", description = "", helpUrl = HelpUrls.LOADTESTOPTIONS_HELP_URL, icon = UISupport.OPTIONS_ICON_PATH )
171 	private interface LogForm
172 	{
173 		@AField( name = "Log Folder", description = "The folder in which to create log files", type = AFieldType.FOLDER )
174 		public final static String LOG_FOLDER = "Log Folder";
175 
176 		@AField( name = "Log Interval", description = "The log interval in milliseconds, 0 only logs at end", type = AFieldType.INT )
177 		public final static String LOG_INTERVAL = "Log Interval";
178 
179 		@AField( name = "Log on ThreadCount change", description = "Log every time the number of threads changes", type = AFieldType.BOOLEAN )
180 		public final static String LOG_ON_THREADCOUNT_CHANGE = "Log on ThreadCount change";
181 	}
182 }