How do GWT tests on Gerrit plugins ?

104 views
Skip to first unread message

Damien Chesneau

unread,
Jul 29, 2016, 8:49:31 AM7/29/16
to Repo and Gerrit Discussion
Hello,

I'm actually trying to do tests for GWT module present in my Gerrit plugin. 
I have succeseed to create simple Java tests using junit but, I want to uses java classes in the client package.

Did you know how to do that using buck ? 

Thank's per advance.

Damien Chesneau

unread,
Aug 16, 2016, 7:02:35 AM8/16/16
to Repo and Gerrit Discussion
Here is the result of a empty test :

FAILURE com.nokia.zebre.client.data.CommentTest testCommentCreation: org/eclipse/jetty/util/log/Logger
java
.lang.NoClassDefFoundError: org/eclipse/jetty/util/log/Logger
        at com
.google.gwt.junit.JUnitShell$ArgProcessor.<init>(JUnitShell.java:244)
        at com
.google.gwt.junit.JUnitShell.getUnitTestShell(JUnitShell.java:690)
        at com
.google.gwt.junit.JUnitShell.runTest(JUnitShell.java:678)
        at com
.google.gwt.junit.client.GWTTestCase.runTest(GWTTestCase.java:421)
        at junit
.framework.TestCase.runBare(TestCase.java:141)
        at junit
.framework.TestResult$1.protect(TestResult.java:122)
        at junit
.framework.TestResult.runProtected(TestResult.java:142)
        at junit
.framework.TestResult.run(TestResult.java:125)
        at junit
.framework.TestCase.run(TestCase.java:129)
        at com
.google.gwt.junit.client.GWTTestCase.run(GWTTestCase.java:247)
        at junit
.framework.TestSuite.runTest(TestSuite.java:255)
        at junit
.framework.TestSuite.run(TestSuite.java:250)
        at org
.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)
        at org
.junit.runners.Suite.runChild(Suite.java:127)
        at org
.junit.runners.Suite.runChild(Suite.java:26)
        at org
.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
        at org
.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
        at org
.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
        at org
.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
        at org
.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
        at org
.junit.runners.ParentRunner.run(ParentRunner.java:309)
        at org
.junit.runner.JUnitCore.run(JUnitCore.java:160)
        at org
.junit.runner.JUnitCore.run(JUnitCore.java:138)
        at com
.facebook.buck.testrunner.JUnitRunner.run(JUnitRunner.java:132)
        at com
.facebook.buck.testrunner.BaseRunner.runAndExit(BaseRunner.java:219)
        at com
.facebook.buck.testrunner.JUnitMain.main(JUnitMain.java:47)
        at sun
.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun
.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun
.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java
.lang.reflect.Method.invoke(Method.java:497)
        at com
.facebook.buck.jvm.java.runner.FileClassPathRunner.main(FileClassPathRunner.java:87)
Caused by: java.lang.ClassNotFoundException: org.eclipse.jetty.util.log.Logger
        at java
.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java
.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun
.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
        at java
.lang.ClassLoader.loadClass(ClassLoader.java:357)
       
... 31 more


Anyone have an idea ? 

Sven Selberg

unread,
Aug 16, 2016, 8:27:02 AM8/16/16
to Repo and Gerrit Discussion
A stab in the dark... Have you tried adding jetty-utils to your BUCK test rule?

deps = [
...
   '//lib/jetty:utils',
...

/Sven

Damien Chesneau

unread,
Aug 16, 2016, 8:32:57 AM8/16/16
to Repo and Gerrit Discussion
We can't add this as you can see bellow : 
but //lib/jetty:utils was not found

Sven Selberg

unread,
Aug 16, 2016, 9:34:03 AM8/16/16
to Repo and Gerrit Discussion
Are you running tests in-tree or stand-alone?

/Sven

Sven Selberg

unread,
Aug 16, 2016, 9:35:59 AM8/16/16
to Repo and Gerrit Discussion
If you could share the BUCK file of the plugin that could perhaps clarify the problem.

/Sven

Damien Chesneau

unread,
Aug 16, 2016, 9:38:56 AM8/16/16
to Repo and Gerrit Discussion
For sure : 
include_defs(
  '//bucklets/gerrit_plugin.bucklet',
)
include_defs(
  '//lib/maven.defs'
)

MODULE = 'com.nokia.zebre.ZebreForm'
VERSION = '9.2.13.v20150730'
EXCLUDE = ['about.html']

gerrit_plugin(
  name = 'zebre',
  srcs = glob(['src/main/java/**/*.xml','src/main/java/**/*.java','src/main/java/**/*.css']),
  resources = glob(['src/main/resources/**/*']),
  gwt_module = MODULE,
  manifest_entries = [
    'Gerrit-ApiType: plugin',
    'Gerrit-PluginName: zebre-plugin',
    'Gerrit-Module: com.nokia.zebre.Module',
    'Gerrit-HttpModule: com.nokia.zebre.HttpModule',
    'Implementation-Version: 2.0.0',
    'Implementation-Vendor: Nokia',
    'Implementation-Title: HIDE'
  ],
  provided_deps = [
    '//lib/log:log4j'
  ]
)

maven_jar(
  name = 'servlet',
  id = 'org.eclipse.jetty:jetty-servlet:' + VERSION,
  license = 'Apache2.0',
  deps = [':security'],
  exclude = EXCLUDE,
)

maven_jar(
  name = 'security',
  id = 'org.eclipse.jetty:jetty-security:' + VERSION,
  license = 'Apache2.0',
  deps = [':server'],
  exclude = EXCLUDE,
  visibility = [],
)

maven_jar(
  name = 'client',
  id = 'javax.servlet:javax.servlet-api:3.1.0' ,
  license = 'Apache2.0',
  visibility = [],
)

maven_jar(
  name = 'servlets',
  id = 'org.eclipse.jetty:jetty-servlets:' + VERSION,
  license = 'Apache2.0',
  exclude = EXCLUDE,
  visibility = [
    '//tools/eclipse:classpath',
    '//gerrit-gwtdebug:gwtdebug',
  ],
)

maven_jar(
  name = 'server',
  id = 'org.eclipse.jetty:jetty-server:' + VERSION,
  license = 'Apache2.0',
  exported_deps = [
    ':continuation',
    ':http',
  ],
  exclude = EXCLUDE,
)

maven_jar(
  name = 'jmx',
  id = 'org.eclipse.jetty:jetty-jmx:' + VERSION,
  license = 'Apache2.0',
  exported_deps = [
    ':continuation',
    ':http',
  ],
  exclude = EXCLUDE,
)

maven_jar(
  name = 'continuation',
  id = 'org.eclipse.jetty:jetty-continuation:' + VERSION,
  license = 'Apache2.0',
  exclude = EXCLUDE,
)

maven_jar(
  name = 'http',
  id = 'org.eclipse.jetty:jetty-http:' + VERSION,
  license = 'Apache2.0',
  exported_deps = [':io'],
  exclude = EXCLUDE,
)

maven_jar(
  name = 'io',
  id = 'org.eclipse.jetty:jetty-io:' + VERSION,
  license = 'Apache2.0',
  exported_deps = [':util'],
  exclude = EXCLUDE,
  visibility = [],
)

maven_jar(
  name = 'util',
  id = 'org.eclipse.jetty:jetty-util:' + VERSION,
  license = 'Apache2.0',
  exclude = EXCLUDE,
  visibility = [],
)
maven_jar(
  name = 'webapp',
  id = 'org.eclipse.jetty:jetty-webapp:' + VERSION,
  license = 'Apache2.0',
  exclude = EXCLUDE,
  visibility = [],
)

java_test(
  name = 'zebre_tests',
  srcs = glob(['src/test/java/**/*.java']),
  labels = [
    'zebre'
  ],
  source_under_test = [
    ':zebre__plugin'
  ],
  deps = GWT_PLUGIN_DEPS + GERRIT_PLUGIN_API + GERRIT_TESTS + [
    ':servlet',
    ':security',
    ':servlets',
    ':client',
    ':server',
    ':webapp',
    ':jmx',
    ':continuation',
    ':http',
    ':io',
    ':util',
    ':zebre',
    ':zebre-static-jar',
    ':zebre__gwt_application',
    ':zebre__manifest',
    ':zebre__plugin',
    '//lib:gson',
    '//lib:gwtorm',
    '//lib:gwtorm_client',
    '//lib:junit',
    '//lib:truth__jar',
    '//lib/guice:guice-assistedinject',
    '//lib/guice:guice-servlet',
    '//lib/guice:guice_library',
    '//lib/guice:javax-inject',
    '//lib/gwt:dev',
    '//lib/gwt:gwt-test-utils',
    '//lib/jgit:jgit',
    '//lib/log:log4j',
  ]
)

Damien Chesneau

unread,
Aug 16, 2016, 9:40:09 AM8/16/16
to Repo and Gerrit Discussion
I run just plugin tests not all gerrit tests 
For sure : 

        at java
.lang<span

Björn Pedersen

unread,
Aug 16, 2016, 11:44:30 AM8/16/16
to Repo and Gerrit Discussion

Looking at the BUCK file:
you define util as jetty-util, did you intend to define utils as jetty-utils ?

Björn

Sven Selberg

unread,
Aug 17, 2016, 2:33:08 AM8/17/16
to Repo and Gerrit Discussion
Can't see how it could be related but I can't find these:
    ':zebre',
    ':zebre-static-jar',
    ':zebre__gwt_application',
    ':zebre__manifest',
Where are they defined?

BUCK is usually very helpful in suggesting what should be added to the BUCK file in order for it to work. Are you seeing no such hints at the bottom of the output.

/Sven

Damien Chesneau

unread,
Aug 17, 2016, 3:42:18 AM8/17/16
to Repo and Gerrit Discussion
Yes, util is just a short version of jetty-util but i must update to jetty-util as well.

Damien Chesneau

unread,
Aug 17, 2016, 3:45:09 AM8/17/16
to Repo and Gerrit Discussion
This is build buy buck with the buck build command as you can see bellow :
BUILT //plugins/zebre:zebre__manifest (143/377 JOBS)
BUILT
//plugins/zebre:zebre__gwt_module#gwt_module (144/377 JOBS)
BUILT
//plugins/zebre:zebre__plugin (145/377 JOBS)
BUILT
//plugins/zebre:zebre__gwt_application (146/377 JOBS)
BUILT
//plugins/zebre:zebre-static (147/377 JOBS)
BUILT
//plugins/zebre:zebre-static-jar (148/377 JOBS)
BUILT
//plugins/zebre:zebre (149/377 JOBS)
[-] BUILDING...FINISHED 27.0s [100%]


I haven't any hints sadly :(

Sven Selberg

unread,
Aug 17, 2016, 4:53:53 AM8/17/16
to Repo and Gerrit Discussion
The way I did it was to start out with something like:
java_test(
  name = 'my-plugin_tests',
  srcs = glob(
    ['src/test/java/**/*.java'],
  ),
  labels = ['my-plugin'],
  source_under_test = [':my-plugin__plugin'],
  deps = [
    ':my-plugin__plugin',
 ]

* Try and run tests
* Add BUCK's suggested dependencies
* add dependencies depending on compilation errors (where BUCK couldn't help)
* iterate until it worked
(this procedure was remarkably pain free in my case).

The only noticeable difference between my BUCK file and yours is that:
1. The plugin artifact is the first in the deps list (which shouldn't matter since it's not ordered IIUC)
2. The plugin artifact was the only artifact I listed as a dependency. (but then again it wasn't a gwt plugin, so what do I know?)

So I'm obviously missing something obvious. Perhaps someone else can see what's wrong?

/Sven
Reply all
Reply to author
Forward
0 new messages