Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DSpot/Pit on Lutece core #704

Closed
assadOW2 opened this issue Feb 11, 2019 · 20 comments
Closed

DSpot/Pit on Lutece core #704

assadOW2 opened this issue Feb 11, 2019 · 20 comments
Assignees
Labels
feature high priority This issue has the highest priority and should be fixed as soon as possible

Comments

@assadOW2
Copy link

Characteristics

  • Reproducibility: [always]
  • Execution Environment: [Ubuntu 16.04]
  • Reporter: [Assad Montasser, am@ow2.org]

Description

Unit tests on Lutece core (https://github.com/lutece-platform/lutece-core) require special configuration in order to be executed successfully. Command line argument used is:

mvn clean lutece:exploded antrun:run test -Dlutece-antrun-db-host=localhost -Dlutece-antrun-db-name=lutece -Dlutece-antrun-db-user=lutece -Dlutece-antrun-db-password=motdepasse -Dlutece-test-mysql

More information on automatic tests can be found on official Lutece wiki: https://fr.lutece.paris.fr/fr/wiki/maven.html

If unit tests are run with standard mvn test command, they fail. And this is why pit is not running when executing DSpot, it says it requires a green test suite.

My question is how can we run DSpot in order to pass the same configuration as above, regarding database.
Thanks for your help.

Steps to reproduce

Properties file
project=.
targetModule=
filter=fr.paris.lutece.*
src=src/java
testSrc=src/test/java
javaVersion=8
outputDirectory=dspot-out/
timeoutConstInMillis=10000
jvmArgs=-Xmx2048m,-Xms1024m
excludedClasses=
Command Line / Options
java -jar  /home/assadm/STAMP-project/dspot/dspot/target/dspot-2.0.1-SNAPSHOT-jar-with-dependencies.jar --path-to-properties dspot.properties --verbose

Other files and URLs

Relationships

Help on issue template

Preview to follow the link or open file .github/ISSUE_DOC.md

@danglotb
Copy link
Member

Hello @assadOW2

Are you able to execute PIT and descartes? Could you please provide the command line?

I guess executing the test with JUnit won't work also?

I'll look to have a solution to this problem.

@assadOW2
Copy link
Author

hello @danglotb

JUnit tests work only if you use the command line I gave in the description (and of course a mysql running on localhost for that configuration).
I didn't try PIT/Descartes yet, I am working on it right now.
Thanks for your help.

@danglotb
Copy link
Member

Okay, so to be able to amplify the test suite of Lutece, we need to implement/fix the maven execution in the STAMP-project/testrunner.

I'm gonna try to do that ASAP.

@nicolabertazzo
Copy link
Contributor

Hi @danglotb,

I tryed to fix the execution of the tests.
My solution is:

  • Modify the pom and add the dependency:
		<dependency>
			<groupId>org.hsqldb</groupId>
			<artifactId>hsqldb</artifactId>
			<version>2.3.4</version>
		</dependency>

  • Execute the command:
    mvn lutece:exploded antrun:run test -Dlutece-test-hsql

  • After that mvn test command will work

@danglotb
Copy link
Member

But DSpot uses a java command line to execute the test and not mvn test.

I'm currently working on this.

@danglotb
Copy link
Member

For now, the major problem is that when we run a mvn test, it recompiles the tests classes while in DSpot, we have a compilation phase for specific classes, e.g. instrumented test classes.

There are two potential solutions:

  1. prevent maven to execute maven-compiler-plugin:3.1:testCompile (default-testCompile).
  2. output a temporary .java in the source tree of the project under amplification and let maven compiling it.

The first solution would be better for me, since we won't mess the source tree of the user.

Do you have any idea how to do it?

@danglotb
Copy link
Member

danglotb commented Feb 15, 2019

I found a workaround but it requires to modify the pom.xml of the client project.

One must add:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <executions>
        <execution>
            <id>default-testCompile</id>
            <phase>none</phase>
        </execution>
    </executions>
</plugin>

This can be implemented in DSpot, since we have already the mechanism of using a custom pom to execute pit/descartes.

@danglotb danglotb self-assigned this Feb 15, 2019
@danglotb danglotb added feature high priority This issue has the highest priority and should be fixed as soon as possible labels Feb 15, 2019
@danglotb
Copy link
Member

Hello, #714 should allow executing DSpot on Lutece.

For now, I cannot merge the changes because the new release of STAMP-project/testrunner is not yet available. (need some time to be on maven central).

But, I propose you to pull the branch feat-use-maven-exec-test and build DSpot with it:

git remote add danglotb https://github.com/danglotb/dspot.git
git fetch danglotb feat-use-maven-exec-test
git checkout feat-use-maven-exec-test
mvn clean package -DskipTests

Then, you must do two things:

  • add to your properties files the new property maven.pre.goals with the correct values. In your case you must add the following line:
maven.pre.goals=lutece:exploded,antrun:run,-Dlutece-antrun-db-host=localhost,-Dlutece-antrun-db-name=lutece,-Dlutece-antrun-db-user=lutece,-Dlutece-antrun-db-password=motdepasse,-Dlutece-test-mysql

Which is the concatenation of all your pre goals separated with a comma ,.

  • use the --use-maven-to-exe-test flag on the command line to use maven and configured pre goals for tests' execution.

Please, keep me update.

@gibello
Copy link

gibello commented Feb 18, 2019

Hi @danglotb,

Same error occurs:
java.lang.RuntimeException: java.io.FileNotFoundException: /home/gibello/STAMP/STAMP-project/lutece-core/target/dspot/observations.ser (Aucun fichier ou dossier de ce type).

Works better if I use the maven plugin in a <build> section of the pom, then mvn dspot:amplify-unit-tests (tested without the pre.goals trick).

@danglotb
Copy link
Member

Hi @gibello

Same error occurs:
java.lang.RuntimeException: java.io.FileNotFoundException: /home/gibello/STAMP/STAMP-project/lutece-core/target/dspot/observations.ser (Aucun fichier ou dossier de ce type).

Okay, I'll reproduce and fix this.

Works better if I use the maven plugin in a <build> section of the pom, then mvn dspot:amplify-unit-tests (tested without the pre.goals trick).

What did you do? Could give me the whole procedure? Could it be generalizable?

@gibello
Copy link

gibello commented Feb 19, 2019

Hi @danglotb , thanks a lot :)

Added that in the pom (note I recompiled the Mojo and added the missing "excludedClasses" property):
`

  <plugins>
    <plugin>
      <groupId>eu.stamp-project</groupId>
      <artifactId>dspot-maven</artifactId>
      <version>2.0.1-SNAPSHOT</version>
      <configuration>
        <src>src/java</src>
        <testSrc>src/test/java</testSrc>
        <!--testCriterion>JacocoCoverageSelector</testCriterion-->
        <excludedClasses>fr.paris.lutece.portal.*</excludedClasses>
        <outputDirectory>target/trash</outputDirectory>
        <verbose>true</verbose>
        <generate-new-test-class>true</generate-new-test-class>
        <with-comment>true</with-comment>
        <use-maven-to-exe-test>true</use-maven-to-exe-test>
      </configuration>
    </plugin>
  </plugins>
</build>`

mvn dspot:amplify-unit-tests

Works (well, I'm not sure the reports are relevant... but discovering, dspot, maybe I don't find them, it's not really documented what is generated ansd where...). Takes 15 minutes and no failure, at least.

If I uncomment the Jacoco testCriterion, it fails because of "CoveragePerTest.ser" not found (after a kind of class version mismatch in asm, I think...). So, it works only with default testCriterion (and only with the maven plugin, not the command line).

generate-new-test-class, with-comment and use-maven-to-exe-test do not change anything in the fact that it works (it does if I comment them out).

@danglotb
Copy link
Member

Hello,

I'm not able to execute the Lutece's tests.

I obtain the following errors:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.8:run (default-cli) on project lutece-core: An Ant BuildException has occured: The following error occurred while executing this line:
[ERROR] /home/bdanglot/workspace/lutece-core/target/lutece/WEB-INF/sql/build.xml:240: The following error occurred while executing this line:
[ERROR] /home/bdanglot/workspace/lutece-core/target/lutece/WEB-INF/sql/build.xml:47: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
[ERROR] 
[ERROR] The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
[ERROR] around Ant part ...<ant antfile="/home/bdanglot/workspace/lutece-core/target/lutece/WEB-INF/sql/build.xml" dir="/home/bdanglot/workspace/lutece-core/target/lutece/WEB-INF/sql/">... @ 14:161 in /home/bdanglot/workspace/lutece-core/target/antrun/build-main.xml: Connection refused (Connection refused)

With the following command line:

mvn clean lutece:exploded antrun:run test -Dlutece-antrun-db-host=localhost -Dlutece-antrun-db-name=lutece -Dlutece-antrun-db-user=lutece -Dlutece-antrun-db-password=motdepasse -Dlutece-test-mysql

Lutece-core version: da9efa1737ed47a004c6fe2dfac94f5b3b232a76

Thank you.

@danglotb
Copy link
Member

ping @assadOW2 @gibello

@assadOW2
Copy link
Author

hi @danglotb :

Is mysql runnning and reachable on localhost ?

@nicolabertazzo
Copy link
Contributor

nicolabertazzo commented Feb 22, 2019 via email

@danglotb
Copy link
Member

I did manage to build and test lutece-core. I had to create a special user, called Lutece in my mysql.

I can now look if we can amplify the tests.

@danglotb
Copy link
Member

@assadOW2 were you able to run pit or descartes on lutece? If so, could you explain to me how?

And obviously, the JacocoCoverageSelector won't work, since we need to execute the test through a maven command line, and test runner uses a java command line to compute the coverage.

I'm gonna work on test-runner to make it able to compute the coverage with a maven command.

@danglotb
Copy link
Member

danglotb commented Apr 5, 2019

Hi, should we keep this issue open?

@gibello
Copy link

gibello commented Apr 5, 2019

@danglotb Concerning Lutece itself, a reminder of how to run tests (not sure you were aware of the last tip, at the end of this comment):

Install MySQL ("sudo apt-get install mysql-server")
Create a user in mysql, or set "root" user password to "motdepasse".
If using your own db user, change "root" and "motdepasse" (put your own user/passwd instead) in lutece-core/webapp/WEB-INF/conf/db.properties

Build lutece:
mvn clean lutece:exploded

Initialize the database (with the script attached - it is an aggregate of multiple db scripts found in the lutece codebase): create_mysql_lutece_test_db.sql
mysql -u Username -pPassword < create_mysql_lutece_test_db.sql
(Username and Password are your mysql user/pwd, default lutece config uses root/motdepasse).

Now you should be able to run "mvn test" .
Everytime you run it again, repeat the database init above (with the script). A lutece rebuild should not be necessary.

Note that you may still encounter another issue: fr.paris.lutece.portal.service.plugin.PluginFileTest contains a hard-coded path… with a TODO comment (!), that may require to hard-copy target/test-classes/ dir in ../ so that everything goes fine (better do it, it is safer).

@danglotb
Copy link
Member

Closing this issue. Please reopen it or open a new one. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature high priority This issue has the highest priority and should be fixed as soon as possible
Projects
None yet
Development

No branches or pull requests

4 participants