sobota 25. února 2017

Maven - Jak spustit testy na všech modulech i když některé testy padají.

Maven buildi jednotlive moduly. A ihned jak v některém spadne test, tak build skončí, protože všechny ostatní moduly přeskočí.

  • mvn test
    - Build běží jen k modulu s prvním padajícím testem. A zbytek modulů přeskočí.
  • mvn test --fail-at-end
    - Pokud modul spadne, tak přeskočí jen moduly, které na tomto modulu zavísí.
  • mvn test --fail-never
    - Spouští všechny moduly - žádné nepřeskočí. I když některé popadají.

mvn test

Příklad:

[INFO] Reactor Summary:
[INFO] 
[INFO] smpl ................................................ SUCCESS [  1.166 s]
[INFO] smpl-test ........................................... SUCCESS [  4.077 s]
[INFO] smpl-common ......................................... SUCCESS [ 29.367 s]
[INFO] smpl-data ........................................... SUCCESS [  9.442 s]
[INFO] smpl-persistence .................................... SUCCESS [ 27.131 s]
[INFO] smpl-core ........................................... FAILURE [01:24 min]
[INFO] smpl-icm-persistence ................................ SKIPPED
[INFO] smpl-ips ............................................ SKIPPED
[INFO] smpl-sys-info ....................................... SKIPPED
[INFO] smpl-gmc-cloud ...................................... SKIPPED
[INFO] smpl-workflow ....................................... SKIPPED
[INFO] smpl-cluster ........................................ SKIPPED
[INFO] smpl-engine ......................................... SKIPPED
[INFO] smpl-definitions .................................... SKIPPED
[INFO] smpl-statistics-report-creator ...................... SKIPPED
[INFO] smpl-upgrade ........................................ SKIPPED
[INFO] smpl-monitoring ..................................... SKIPPED
[INFO] smpl-webserver ...................................... SKIPPED
[INFO] smpl-webserver-core ................................. SKIPPED
[INFO] smpl-node ........................................... SKIPPED
[INFO] smpl-icm-package-creator ............................ SKIPPED
[INFO] smpl-doc-exporter ................................... SKIPPED
[INFO] smpl-i18n-converter ................................. SKIPPED
[INFO] smpl-stopper ........................................ SKIPPED
[INFO] smpl-bobril ......................................... SKIPPED
[INFO] smpl-frontend ....................................... SKIPPED
[INFO] smpl-webserver-app .................................. SKIPPED
[INFO] smpl-sample-app ..................................... SKIPPED
[INFO] smpl-installer ...................................... SKIPPED
[INFO] smpl-incubator ...................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:35 min
[INFO] Finished at: 2017-01-19T09:38:42+01:00
[INFO] Final Memory: 54M/1044M
[INFO] ------------------------------------------------------------------------

mvn test --fail-at-end

Příklad:

[INFO] Reactor Summary:
[INFO] 
[INFO] smpl ................................................ SUCCESS [  1.443 s]
[INFO] smpl-test ........................................... SUCCESS [  5.906 s]
[INFO] smpl-common ......................................... SUCCESS [ 32.095 s]
[INFO] smpl-data ........................................... SUCCESS [ 13.179 s]
[INFO] smpl-persistence .................................... SUCCESS [ 28.213 s]
[INFO] smpl-core ........................................... FAILURE [01:27 min]
[INFO] smpl-icm-persistence ................................ SKIPPED
[INFO] smpl-ips ............................................ SKIPPED
[INFO] smpl-sys-info ....................................... SKIPPED
[INFO] smpl-gmc-cloud ...................................... SUCCESS [  1.289 s]
[INFO] smpl-workflow ....................................... SKIPPED
[INFO] smpl-cluster ........................................ SKIPPED
[INFO] smpl-engine ......................................... SKIPPED
[INFO] smpl-definitions .................................... SUCCESS [  0.693 s]
[INFO] smpl-statistics-report-creator ...................... SUCCESS [  1.108 s]
[INFO] smpl-upgrade ........................................ FAILURE [ 18.500 s]
[INFO] smpl-monitoring ..................................... SKIPPED
[INFO] smpl-webserver ...................................... SUCCESS [  0.630 s]
[INFO] smpl-webserver-core ................................. SKIPPED
[INFO] smpl-node ........................................... SKIPPED
[INFO] smpl-icm-package-creator ............................ SUCCESS [  1.222 s]
[INFO] smpl-doc-exporter ................................... SUCCESS [  1.074 s]
[INFO] smpl-i18n-converter ................................. SUCCESS [  1.342 s]
[INFO] smpl-stopper ........................................ SUCCESS [  0.833 s]
[INFO] smpl-bobril ......................................... SUCCESS [ 30.465 s]
[INFO] smpl-frontend ....................................... SUCCESS [01:42 min]
[INFO] smpl-webserver-app .................................. SKIPPED
[INFO] smpl-sample-app ..................................... SUCCESS [ 14.232 s]
[INFO] smpl-installer ...................................... SKIPPED
[INFO] smpl-incubator ...................................... SUCCESS [  0.620 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 05:42 min
[INFO] Finished at: 2017-01-19T09:27:37+01:00
[INFO] Final Memory: 65M/1149M

mvn test --fail-never

Příklad:

[INFO] Reactor Summary:
[INFO] 
[INFO] smpl ................................................ SUCCESS [  1.272 s]
[INFO] smpl-test ........................................... SUCCESS [  5.089 s]
[INFO] smpl-common ......................................... SUCCESS [ 32.105 s]
[INFO] smpl-data ........................................... SUCCESS [  9.521 s]
[INFO] smpl-persistence .................................... SUCCESS [ 27.626 s]
[INFO] smpl-core ........................................... FAILURE [01:25 min]
[INFO] smpl-icm-persistence ................................ FAILURE [ 10.546 s]
[INFO] smpl-ips ............................................ SUCCESS [ 13.612 s]
[INFO] smpl-sys-info ....................................... SUCCESS [  5.811 s]
[INFO] smpl-gmc-cloud ...................................... SUCCESS [  1.094 s]
[INFO] smpl-workflow ....................................... SUCCESS [ 31.439 s]
[INFO] smpl-cluster ........................................ SUCCESS [ 13.137 s]
[INFO] smpl-engine ......................................... FAILURE [01:31 min]
[INFO] smpl-definitions .................................... SUCCESS [  0.560 s]
[INFO] smpl-statistics-report-creator ...................... SUCCESS [  1.038 s]
[INFO] smpl-upgrade ........................................ FAILURE [ 16.010 s]
[INFO] smpl-monitoring ..................................... FAILURE [ 30.710 s]
[INFO] smpl-webserver ...................................... SUCCESS [  0.580 s]
[INFO] smpl-webserver-core ................................. SUCCESS [ 46.682 s]
[INFO] smpl-node ........................................... FAILURE [  6.602 s]
[INFO] smpl-icm-package-creator ............................ SUCCESS [  1.033 s]
[INFO] smpl-doc-exporter ................................... SUCCESS [  1.010 s]
[INFO] smpl-i18n-converter ................................. SUCCESS [  1.097 s]
[INFO] smpl-stopper ........................................ SUCCESS [  0.570 s]
[INFO] smpl-bobril ......................................... SUCCESS [ 14.878 s]
[INFO] smpl-frontend ....................................... SUCCESS [01:38 min]
[INFO] smpl-webserver-app .................................. SUCCESS [  2.341 s]
[INFO] smpl-sample-app ..................................... SUCCESS [ 13.023 s]
[INFO] smpl-installer ...................................... SUCCESS [ 17.248 s]
[INFO] smpl-incubator ...................................... SUCCESS [  0.557 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 09:41 min
[INFO] Finished at: 2017-01-19T09:50:06+01:00
[INFO] Final Memory: 77M/1483M
[INFO] ------------------------------------------------------------------------

pondělí 20. února 2017

Jak nadefinovat vlastní MBean ve Springu

Do svého aplikačního contextu přidat

    
    <context:mbean-export/>
(context je tento namespace xmlns:context="http://www.springframework.org/schema/context")

Pak již lze nadefinovat vlastní Mbean. (Příklad je v Kotlinu)

import org.springframework.jmx.export.annotation.ManagedOperation
import org.springframework.jmx.export.annotation.ManagedResource
import org.springframework.stereotype.Component

@Component
@ManagedResource(objectName = "MyApplicationName" + ":name=HelloMBeanWorld")
class HelloMBeanWorld {

    //Its component - you can simply autowire anything
    //@Autowired
    //private MyBean myBean

    @ManagedOperation(description = "My hello world MBean")
    fun getHelloMBeanWorld(): String {
        return "Hello MBean world!!!"
    }

}

A pak stačí spustit aplikaci a přistupovat ke své MBean třeba pomocí JConsole. Spring už pořeší, registrovaní a hlavně taky odregistrování bean a vše. Díky Springu!

Další možnosti jsou krásně popsané v dokumentaci springu: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/jmx.html

pondělí 12. září 2016

Run Groovy Project Without Compilation Using Gradle

Run Groovy Project Without Compilation Using Gradle

To be honest it is automatically compiled by Gradle. All changes made into "buildSrc/src/main/groovy" are automatically compiled during startup.

Key feature of Gradle is how nicely it manages "buildSrc" directory.

Here is sample project https://bitbucket.org/bugs_/samples/src/default/RunGroovyProjectWithoutCompilationUsingGradle/

sobota 30. července 2016

čtvrtek 28. července 2016

Count number bytes in UTF-8 for Java String

https://bitbucket.org/bugs_/utils/src/default/CoreUtils/src/main/java/cz/vondr/coreutils/utf/Utf8LengthUtil.java

  • Problem 1: You have Java String variable. And you need get number of bytes in UTF-8
  • Problem 2: You need split String into multiple Strings, in the way that each of them have exact number of bytes. (expect last part of course :) )

Thanks to stackoverflow.com

úterý 15. března 2016

MXBeans ovládání z command line

MX Beany jsem vždy ovládal pomoci JConsole. To ale nejde bez grafického prostředí

Tady je jeden ze způsobů, jak něco spustit z command line
http://wiki.cyclopsgroup.org/jmxterm/download.html

stáhnout jmxterm-1.0-alpha-4-uber.jar

java.exe -jar jmxterm-1.0-alpha-4-uber.jar    (potřebuje to JDK ne jen JRE)

prikaz "jvms"
  (vylistuje jvm procesy)

prikaz "open "
  (se pripoji k procesu)

prikaz "run -d MyApp -b MyApp:name=MyBean nameOfMethod"
  (se spustí danou metodu na dane beane)

pondělí 19. října 2015

Gradle - Get Hg Mercurial revision

Here is part of build.gradle file, which get mercurial revision and define task "revision", which print it to output.

It uses javahg to get revision number and that's why it needs Mercurial installation. We could use hg4j to remove this requirement. Anyway this script can be improved a lot, but for me it did it's work.