ClassCast exception of a Groovy Verticle class to Java Verticle in an Integration Test

439 views
Skip to first unread message

bytor99999

unread,
Aug 7, 2013, 1:21:13 AM8/7/13
to ve...@googlegroups.com
So, this is my latest error

org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'com.company.data.verticle.DataServerVerticle@112eae9c' with class 'com.company.data.verticle.DataServerVerticle' to class 'org.vertx.java.platform.Verticle'

DataServiceVerticle extends Verticle, but the Groovy version. 

This is occurring in a test verticle

class DataServerBaseTestVerticle extends TestVerticle {

Can you not test a Groovy class Verticle?

Thanks

Mark

bytor99999

unread,
Aug 7, 2013, 1:42:15 AM8/7/13
to ve...@googlegroups.com
I actually think this is a bug in the testtools project. In core we just prefix the Groovy class in deploy() method with "groovy:" and I think there is parsing code to handle that, but that that same parsing code is not in TestVerticle in testtools.

Thanks

Mark

Norman Maurer

unread,
Aug 7, 2013, 1:46:36 AM8/7/13
to ve...@googlegroups.com
Thanks Mark,

I will have a look shortly.

Bye,
Norman

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Tim Fox

unread,
Aug 7, 2013, 4:32:13 AM8/7/13
to ve...@googlegroups.com
I'm not sure what you're trying to achieve here.. the TestVerticle is
just a stub Java class - you shouldn't normally edit it.

The standard build contains examples of Groovy tests - can't you just
take a look at those?

bytor99999

unread,
Aug 7, 2013, 12:11:21 PM8/7/13
to ve...@googlegroups.com
I am not editing. I am extending it, then deploying a Groovy Verticle and it throws a ClassCastException. It is not allowing me to deployVerticle(GroovyVerticleHere)

Thanks

Mark

Tim Fox

unread,
Aug 7, 2013, 12:21:00 PM8/7/13
to ve...@googlegroups.com
But... what are you trying to achieve? If you just want to write tests
in Groovy, that's easy, just take a look at the Groovy test examples
already there...

Tim Fox

unread,
Aug 7, 2013, 12:30:13 PM8/7/13
to ve...@googlegroups.com
Can you provide the *exact* line of code that you are using to deploy
the verticle that fails?

On 07/08/13 17:11, bytor99999 wrote:

bytor99999

unread,
Aug 7, 2013, 1:22:16 PM8/7/13
to ve...@googlegroups.com
container.deployVerticle("groovy:com.company.data.verticle.DataServerVerticle", 1,
      new Handler<AsyncResult<String>>() {
        @Override
        public void handle(AsyncResult<String> deployed) {
          callBackWhenDone.call()
        }
      }
    )

Thanks

Mark

bytor99999

unread,
Aug 7, 2013, 7:57:34 PM8/7/13
to ve...@googlegroups.com
OK, I have a better example to use. And it uses the example tests in the Gradle Template.

1) Got to com.mycompany.myproject.test.integration.java.SomeVerticle class in the tests. Refactor the file name to be .groovy instead of .java. And change the import of Verticle to be the Groovy version 

import org.vertx.groovy.platform.Verticle;

2) Now run this test in BasicIntegrationTest
public void testDeployArbitraryVerticle() 

You will get the ClassCastException

Starting test: testDeployArbitraryVerticle
Aug 07, 2013 4:52:43 PM org.vertx.java.core.logging.impl.JULLogDelegate error
SEVERE: Exception in Java verticle
java.lang.ClassCastException: com.mycompany.myproject.test.integration.java.SomeVerticle cannot be cast to org.vertx.java.platform.Verticle
at org.vertx.java.platform.impl.java.JavaVerticleFactory.createVerticle(JavaVerticleFactory.java:57)
at org.vertx.java.platform.impl.DefaultPlatformManager$18.run(DefaultPlatformManager.java:1262)
at org.vertx.java.core.impl.DefaultContext$3.run(DefaultContext.java:171)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:353)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:365)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
at java.lang.Thread.run(Thread.java:722)


Simple enough to demonstrate that you cannot test a Groovy Verticle in a Unit test using a Test class that extends TestVerticle. It looks like the only way you can test a Groovy Verticle is with a test script and not class. However, we have removed all our Groovy scripts to be Groovy classes because the team has voted to use classes instead of scripts. They find it easier to read as classes.

I will create an Issue and link back to this thread.

Thanks

Mark

bytor99999

unread,
Aug 7, 2013, 8:04:07 PM8/7/13
to ve...@googlegroups.com
OK, now I actually don't get ClassCastException, but it can't seem to call initialize. 

In my first attempt where I got the ClassCastException I forgot to put "groovy:" in front of the classname.

Mark

bytor99999

unread,
Aug 7, 2013, 9:24:27 PM8/7/13
to ve...@googlegroups.com
Still using the example in the Gradle Template with the instructions I posted before, and I changed the test code to look like this

  public void testDeployArbitraryVerticle() {
    initialize();
    assertEquals("bar", "bar");
    container.deployVerticle("groovy:"+SomeVerticle.class.getName(), new Handler<AsyncResult<String>>() {
            @Override
            public void handle(AsyncResult<String> deployed) {
              System.out.println(deployed);
            }
          } );
  }


If you set a break point on System.out.println(deployed);

Then looked at the values of deployed, you will see that failed == true and in this test's case has the 

groovy.lang.MissingMethodException: No signature of method: static org.vertx.testtools.VertxAssert.initialize() is applicable for argument types: (org.vertx.groovy.core.Vertx) values: [org.vertx.groovy.core.Vertx@7b14cc93]
Possible solutions: initialize(org.vertx.java.core.Vertx)

Exception thrown.

Different than the ClassCastException In see in my module, where I set a break point inside a handler just like that. In my module it shows failed == true, but the exception is ClassCastException. 

Basically, I just think that the testtools does not have the facility to deploy a Groovy compiled class Verticle. that it has to be deployed in tests via a Groovy Script instead.

Mark
Reply all
Reply to author
Forward
0 new messages