Pages

Saturday, August 17, 2024

Dynamically load jndi.properties when JMeter is running

An approach to having all test configurations in one place is using the jndi.properties file of JMeter.

When maintaining many JMeter test suites, it's convenient to have the jndi.properties placed together with the JMX file, then when you need to run the test file, you copy the associated jndi.properties into the JMeter bin directory. But this becomes a pain when switching to different test suites, as you will have to replace the jndi.properties with the new one.

Here I explain how to load the jndi.properties file from the same path as the JMX file, without copying the file into the JMeter bin directory. Also opening JMeter directly by opening the JMX file.

  • Open the jmeter-t.cmd file located in the bin folder of JMeter in a text editor.
  • Find the call to the jmeter command, typically at the end of the file and looks like this:
    call "%~dp0"jmeter -j "%~n1.log" -t "%~nx1" %2 %3 %4 %5 %6 %7 %8 %9
  • Modify it to add the Juser.classpath parameter to point to the bin folder of the JMeter (%~dp0 variable) and the path of the JMX folder (%~dp1 variable):
    call "%~dp0"jmeter -j "%~n1.log" -t "%~nx1" -Juser.classpath=%~dp0;%~dp1 %2 %3 %4 %5 %6 %7 %8 %9
  • Save the changes and close the file.
  • Update the associated default application with *.jmx files:
    • Right-click any JMX file and choose Properties from the context menu.
    • From the General tab, click the Change button to change the application that opens JMX files.
    • From the dialogue, navigate to the bin folder of JMeter and select jmeter-t.cmd.

Now you can open any JMX file in JMeter by double-clicking it, supposing the jndi.properties is located in the same folder, it will be loaded with the test.

Sunday, June 30, 2024

Adding "Hard Clean" option to Visual Studio when Clean&Rebuild don't work

At some point, while we code, we need to start clean, rebuild our projects, and throw away all old irrelevant artifacts, to ensure that the version we are testing includes our most recent changes.

While Visual Studio (like any other decent IDE) provides such an option to clean the artifacts, and empty the bin and obj folders, I found it not perfect all the time, like changes made in the appsettings.json file, don't always get updated after the rebuild.
I needed a way to run my .NET projects with the confidence that they include my most recent changes, so I don't stare at the screen and wonder if what I see is really what I just changed.
The safest option to ensure that the artifacts are being rebuilt is to manually delete them. So I found a way to automate this. Bear with me...

Deleting the bin and obj folders using a PowerShell script

I don't remember how I got it, did I write it? did I ask ChatGPT to write it... I don't remember, the important thing here is that it's working exactly as I want it, you can run it on any path and be assured that it will delete any nested bin/obj folders, it's a simple script:

Get-ChildItem -Path "." .\ -include bin, obj -Recurse | ForEach-Object ($_) { remove-item $_.fullname -Force -Recurse }

Remember to set the path of the PowerShell terminal to the root path you want to scrape its bin/obj folders. Running it on the default path of the PowerShell window will probably take a hell amount of time to finish to go through all the nested bin/obj folders.

Adding the Script to Visual Studio external tools

One of the least-known features of Visual Studio is the External Tools, it allows you to plugin any external tool directly into Visual Studio, and it is such a perfect place to add the script so that we run it easily and conveniently.

From the Tools menu select> External Tools...
In the Window, click Add to add a new "external tool", fill in the fields with these values:

Title: Hard Clean (up to you)
Command: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Arguments: -ExecutionPolicy RemoteSigned -Command "&{ Get-ChildItem -Path "." .\ -include bin, obj -Recurse | ForEach-Object ($_) { remove-item $_.fullname -Force -Recurse }}
Initial directory: $(SolutionDir)
Tick the "Close on exit" option, then click OK to save.

Now, the "Hard Clean" option will appear under the tools menu and it will do the trick> recursively deleting all bin/obj folders under the current solution path.



Dynamically load jndi.properties when JMeter is running

An approach to having all test configurations in one place is using the jndi.properties file of JMeter. When maintaining many JMeter test su...