Q: I want to fail Beanshell sampler when my script is not conditions not satisfied I am using Beanshell sampler with java code  to compare the two files line by line. I want to fail the Beanshell sampler if comparison failed at any line. I see always my beanshell sampler is sucess in view results treee even the comparison failed or passed. So any one please give me a idea how to fail the sampler.
Note: I used Beanshell Assertion as well but its not worked.
View Results Tree Image
Beanshell Sampler with Beanshell Assertion

A: boolean differenceInFile = false;
SampleResult.setSuccessful(differenceInFile);
IsSuccess=differenceInFile;

line #2 and line #3 is what you need in your bean shell sampler to pass / fail depending on your file comparasion
Sample JMX File
It will show you as an xml, try to download it


A: There is SampleResult pre-defined variable which you can use for setting the sampler passed or failed, define response code, response message, response body, etc.
So something like:
if (there_are_differences) {
    SampleResult.setSuccessful(false)
    SampleResult.setResponseCode("500")
    SampleResult.setResponseMessage("Files are different")
}

In the assertion you have AssertionResult for the same.
Also be aware that you should be using JSR223 Test Elements and Groovy language for scripting since JMeter 3.1 so it might be a good option for migration.
More information on JMeter API shorthands available for the JSR223 Test Elements - Top 8 JMeter Java Classes You Should Be Using with Groovy
