Salil Surendran

Ranch Hand
+ Follow
since Jan 16, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Salil Surendran

`mvn dependency:build-classpath -DincludeScope=test`

doesn't show test jars that have been added to the pom.xml

   <dependency>
         <groupId>org.apache.spark</groupId>
         <artifactId>spark-streaming_${scala.binary.version}</artifactId>
         <version>${project.version}</version>
       </dependency>
       <dependency>
         <groupId>org.apache.spark</groupId>
         <artifactId>spark-streaming_${scala.binary.version}</artifactId>
         <version>${project.version}</version>
         <type>test-jar</type>
         <scope>test</scope>
       </dependency>

However, `mvn -f pom.xml dependency:tree|grep tests` does show these test jars. Is this some kind of a bug in maven?

   Using `mvn` from path: /usr/bin/mvn
   [INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ java8-tests_2.10 ---
   [INFO] org.apache.spark:java8-tests_2.10:pom:1.6.0-cdh5.11.0-SNAPSHOT
   [INFO] |  |  +- org.apache.avro:avro-ipc:jar:tests:1.7.6-cdh5.11.0-SNAPSHOT:compile
   [INFO] +- org.apache.spark:spark-core_2.10:test-jar:tests:1.6.0-cdh5.11.0-SNAPSHOT:test
   [INFO] +- org.apache.spark:spark-streaming_2.10:test-jar:tests:1.6.0-cdh5.11.0-SNAPSHOT:test

I am trying the above in a more complicated project mixing scala and java code. On a simpler sample project this does work.
4 years ago

Tim Cooke wrote:Assuming you've used "mvn clean install" to build the jar then by default test cases are not included in the jar. And why would they be? The tests have been run successfully before packaging up in the jar so you don't need to run it again. Right?


Yes I see your point. I have generated the tests jar. the reason I want to execute the tests in this jar is because as part of a integration test suite I have to execute the tests related to a particular module. So given that I will not have a pom file is there a way to just execute the test purely via a python script just by putting all the arguments like dependencies and dependencies to scan in a command line?
4 years ago
I have a jar installed in my local ~/.m2 repo and I would like to execute a single test using the '-Dtest' option via a python script. I tried using this command on the command line ' mvn surefire:test -DdependenciesToScan=groupId:artifactId -Dtest=NameOfTest' on the command line however it doesn't seem like maven is not finding the NameOfTest in the groupId:artifactId dependency and returning back with no tests executed? Any way to execute a single test in an already installed maven artifact?
4 years ago

0
down vote
favorite

I have a constructor that takes a couple of arguments for eg. new Reporter(host,port). I want to verify that this constructor is called with the expected params. I get the configuration parameters from a Config object and then call the business method StartUp.startReporter(); and I expect that new Reporter(host,port) gets called with the parameters from the config object. Here is the code:

5 years ago
Recently I had a discussion with a friend about concurrency in java and he asked me as to why is the synchronized keyword either around a block of code or method slow. I answered back saying that it is slow because it contends for an object monitor. Also it gives a happens before guarantee and it has to synchronize all the variables in it's cache with main memory and at the end of the block it has to flush the cache back. It also prevents compiler as well as cpu reordering of instructions. However he said that these do lead to a slowdown but this is not the main reason for performance degradation. Essentially even if there is no contention when a thread hits a synchronized block it switches from user mode to kernel mode and the thread has to save state and then when it leaves the block it has to once again reload the state. I am trying to find literature on the web that describes this but I am unable to find any. I am wondering if anyone can confirm this is correct? Why should java threads enter kernel mode when it hits synchronized and why not before that? I am asking about the explicit switch from user mode to kernel mode and it this causes a performance degradation?
I wrote this simple Java program:

This generate the following disassembled code for i++ and j++ (remaining disassembled code removed):

This is what I understand about the following assembly code:

mov r10,7d5d0e898h : Moves the pointer to the IncrementClass.class to register r10
inc dword ptr [r10+74h] : Increments the 4 byte value at the address at [r10 + 74h],(i.e. i)
mov r11d,dword ptr [r10+70h] :Moves the 4 value value at the address [r10 + 70h] to register r11d (i.e move value of j to r11d)
inc r11d : Increment r11d
mov dword ptr [r10+70h],r11d : write value of r11d to [r10 + 70h] so it is visible to other threads -lock add dword ptr [rsp],0h : lock the memory address represented by the stack pointer rsp and add 0 to it.
JMM states that before each volatile read there must be a load memory barrier and after every volatile write there must be a store barrier. My question is:

Why isn't there a load barrier before the read of j into r11d?
How does the lock and add to rsp ensure the value of j in r11d is propogated back to main memory. All I read from the intel specs is that lock provides the cpu with an exclusive lock on the specified memory address for the duration of the operation. Why is i++ not atomic or thread safe. If you look at the instruction incrementing i "inc dword ptr [r10+74h]" this should directly write to memory and every other thread should be able to see this value. From what I understand when the CPU writes to memory as above this value is cached in the cache line and doesn't go all the way to memory and so an explicit instruction is needed for it to write to memory. Which I believe is the LOCK statement but how does a LOCK on the stack pointer ensure the value in the cache gets written to memory
Hello,
We have a requirement where certain tests are required to run in a seperate jvm. Using reuseForks=false in maven will run each test class in a seperate jvm but this will slow down the whole test run significantly. Is it possible to annotate a testng test with a particular annotation so that maven runs it in a seperate jvm.
6 years ago
Hello,
Due to legacy reasons we have forkMode set to 'pertest' in our pom. This configuration can't be changed. However when I remote debug in eclipse(or command line) I use `"-Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -Xnoagent -Djava.compiler=NONE" test -DforkMode=never"`. I then connect to port 8000 from eclipse. However since forkMode is set to pertest each time a jvm is spawned to run a test which means that I have to remote connect every time to keep the test running and I have over 3000 tests. The -DforkMode=never never takes effect and is overridden with what is the in the pom. Is this the right behavior? What can I do to have the remote debugger reconnect even if the jvm forks?
6 years ago
Hello,
I am trying to run cobertura in maven so that it generates a file in a seperate location than target/cobertura/cobertura.ser. However, I find no way to configure cobertura. I tried this

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.6</version>
<configuration>
<dataFile>C:\\Salil\\Work\\cobertura-datafiles\\corbertura.ser</dataFile>
<outputDirectory>C:\\Salil\\Work\\cobertura-report</outputDirectory>
</configuration>
</plugin>

and also tried `mvn clean cobertura:cobertura -Dcobertura.datafile=C:\\Salil\\Work\\cobertura-datafiles\\corbertura.ser` and that doesn't work either. I have tried ${project.build.directory} instead of a fixed path too. Tried java 6 and 7 and maven 3.0.2 and 3.2. None of it worked. What worked was
`mvn clean cobertura:cobertura -Dnet.sourceforge.cobertura.datafile=C:\\Salil\\Work\\cobertura-datafiles\\corbertura.ser`
which generates the given file but also creates another file in the default directory target/cobertura. I looked at the source code of cobertura maven plugin and I can see it has the old style of @parameter annotation which is in javadocs. So is it even configurable. In the end what I am trying to do is run cobertura in a specific configuration and generate a cobertura.ser file and then again in a different configuration to update the cobertura.ser file and then generate a report. What is the best way to do this? Run cobertura on the command line? Run cobertura via the ant maven task? Any other ideas?
6 years ago
Hello,
Is it possible to execute TestNg tests in a JUnit TestSuite. I see a lot of web pages describing how to use TestNg to run JUnit but none the other way around.
7 years ago
From what I understand, synchronized keyword syncs local thread cache with main memory. volatile keyword basically always reads the variable from the main memory at every access. Of course accessing main memory is much more expensive than local thread cache so these operations are expensive. However, a CAS operation use low level hardware operations but still has to access main memory. So how is a CAS operation any faster?
Hello Friends,
I have a class that I am partially mocking using NonStrictExpectations



The problem is that when I use Deencapsulation.invoke() to mock a private method it messes up the source code of the CampaignSelector class and hence when I debug into the getMessageFromCampaign() method the source code is misaligned in Eclipse. I understand that JMockit redefines classes but this only happens when private methods are mocked and not public. Any way to get around this problem?
7 years ago
Hello,
Was wondering if one of the requests to a web server results in StackOverflow error is the whole server shutdown or just the thread dies or an error is thrown back to the client?
7 years ago
Hello Friends,
I am facing a particular problem where I have to test a method that reads a list of objects from a cache and then sorts them based upon priority. The list of objects as well as the cache has to be mock objects. However, once the method returns I have to test that these mock objects that are returned back by this method is sorted correctly based upon expected priority. Here is a very very simplified code sample which mimics what I am trying to do. In this code sample I have 3 Priority Beans which are mocked and I am trying to sort and return it back in ArrayComparator.sortBeans() method. However, the problems are obvious. The call to pb.getPriority() is not instance based but invocation count based and hence when the comparator calls getPriority on the bean for more than 3 times I get an UnexpectedInvocation error. Even I get through that in the assertEquals() method call pbArray[x].getPriority() method still calls the mock object. What I need are real stubs which are unique objects which can later on be compared. How do I do that in JMockit?

package com.salil.jmockit.mockarray;

import java.util.Arrays;
import java.util.Comparator;

public class ArrayComparator {

public PriorityBean[] sortBeans(PriorityBean[] beans){
Arrays.sort(beans,new Comparator<PriorityBean>() {

public int compare(PriorityBean o1, PriorityBean o2) {
return o2.getPriority() - o1.getPriority();
}
});
return beans;
}

}

package com.salil.jmockit.mockarray;

public class PriorityBean {

private int priority;

PriorityBean(int priority){
this.priority = priority;
}

public int getPriority(){
return priority;
}

}


package com.salil.jmockit.mockarray;

import static org.junit.Assert.assertEquals;
import mockit.Expectations;

import org.junit.Test;

public class MockArrayComparatorTest {

@Test
public void testSortBeans(final PriorityBean pb) {
new Expectations(){

{
pb.getPriority();
returns(5,10,0);
}
};

ArrayComparator ac = new ArrayComparator();
PriorityBean[] pbArray = ac.sortBeans(new PriorityBean[]{pb,pb,pb});
assertEquals(3,pbArray.length);
assertEquals(10,pbArray[0].getPriority());
assertEquals(5,pbArray[1].getPriority());
assertEquals(0,pbArray[2].getPriority());
}

}


8 years ago

James Boswell wrote:Could you show the POM you are using for the code?


Not using a pom. This is a simple java application. Yes, the maven.repo might have thrown you off.
8 years ago