java - glassfish embedded v4.1.1 and lambda -
i have junit test (integration test) embedded glassfish server. test failed if use lambda in stateless ejb. without lambda expression test works fine.
is there fix or snapshot version of embedded glassfish server? have not found info snapshot version of glassfish-embedded-all :(
used dependency:
<dependency> <groupid>org.glassfish.main.extras</groupid> <artifactid>glassfish-embedded-all</artifactid> <version>4.1.1</version> <scope>test</scope> </dependency>
if uncomment line (1) or (2) reference of example bean null in junit test (lookup failed exception appears) :(
bean/ejb:
@stateless @localbean public class examplebean { @persistencecontext private entitymanager em; public person get(long id) { optional<person> p = optional.ofnullable(em.find(person.class, id)); list<person> persons = new arraylist<>(); persons.add(p.get()); // (1) properties.foreach(person -> system.out.println(person)); // (2) string name = person.map(person::getname).orelse(null); //system.out.println(name"); return p; } }
test class:
public class examplebeantest { @ejb private static examplebean examplebean; private static context context; private static ejbcontainer container; @beforeclass public static void init() { map<string, object> props = new hashmap<string,object>(); props.put(ejbcontainer.modules, new file[]{new file("target/test-classes"), new file("target/classes")}); try { container = ejbcontainer.createejbcontainer(props); context = container.getcontext(); examplebean = (examplebean) context.lookup("java:global/classes/examplebean"); } catch (exception e) { e.printstacktrace(); } } @afterclass public static void teardown() throws exception { if (container != null) { container.close(); } } @test public void testget() throws namingexception { assertnotnull(examplebean); person p = examplebean.get(1); assertnotnull(p); assertequals("text", p.getname()); } }
is there embedded ee container juint test + java 8 able execute java lambda expressions?
edit1: have created test lambda , classic iteration. bean classic iteration runs fine foreach got "lookup failed" exception. going on here?
public person get(long id) { optional<person> person = optional.ofnullable(em.find(person.class, id)); list<person> persons = new arraylist<>(); persons.add(person.get()); long l = persons.stream().count(); system.out.println("length: " + l); // <- ok, result: 1 (person p : persons) { // <- ok, 1 result: "text" string name = p.getname(); system.out.println("name: " + name); } // if keep following line in code lookup failed exception // if comment these lines code works fine persons.foreach(pp -> { system.out.println(pp.getname()); }); return person.get(); }
exeption:
feb 05, 2016 10:36:17 pm org.glassfish.ejb.embedded.ejbcontainerproviderimpl createejbcontainer severe: ejb6005:no ejb modules found javax.naming.namingexception: lookup failed 'java:global/classes/examplebean' in serialcontext[myenv={java.naming.factory.initial=com.sun.enterprise.naming.impl.serialinitcontextfactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.jndistatefactoryimpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [root exception javax.naming.namenotfoundexception: classes] @ com.sun.enterprise.naming.impl.serialcontext.lookup(serialcontext.java:491) @ com.sun.enterprise.naming.impl.serialcontext.lookup(serialcontext.java:438) @ javax.naming.initialcontext.lookup(initialcontext.java:417) @ javax.naming.initialcontext.lookup(initialcontext.java:417) @ a.b.examplebeantest.init(examplebeantest.java:39) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:498) @ org.junit.runners.model.frameworkmethod$1.runreflectivecall(frameworkmethod.java:50) @ org.junit.internal.runners.model.reflectivecallable.run(reflectivecallable.java:12) @ org.junit.runners.model.frameworkmethod.invokeexplosively(frameworkmethod.java:47) @ org.junit.internal.runners.statements.runbefores.evaluate(runbefores.java:24) @ org.junit.internal.runners.statements.runafters.evaluate(runafters.java:27) @ org.junit.runners.parentrunner.run(parentrunner.java:363) @ org.junit.runner.junitcore.run(junitcore.java:137) @ com.intellij.junit4.junit4ideatestrunner.startrunnerwithargs(junit4ideatestrunner.java:69) @ com.intellij.rt.execution.junit.junitstarter.preparestreamsandstart(junitstarter.java:234) @ com.intellij.rt.execution.junit.junitstarter.main(junitstarter.java:74) caused by: javax.naming.namenotfoundexception: classes @ com.sun.enterprise.naming.impl.transientcontext.resolvecontext(transientcontext.java:299) @ com.sun.enterprise.naming.impl.transientcontext.lookup(transientcontext.java:207) @ com.sun.enterprise.naming.impl.transientcontext.lookup(transientcontext.java:208) @ com.sun.enterprise.naming.impl.serialcontextproviderimpl.lookup(serialcontextproviderimpl.java:66) @ com.sun.enterprise.naming.impl.localserialcontextproviderimpl.lookup(localserialcontextproviderimpl.java:114) @ com.sun.enterprise.naming.impl.serialcontext.lookup(serialcontext.java:478) ... 18 more
edit2: can see ncls-deployment-00009 warning message in maven log file. 1 related forum topic have found: glassfish deploy error “archive type of myproject.jar not recognized”. here remove lambda expressions suggested.
maven log
feb 06, 2016 8:49:37 org.glassfish.deployment.common.genericannotationdetector scanarchive warning: ncls-deployment-00009 feb 06, 2016 8:49:37 org.glassfish.ejb.embedded.ejbcontainerproviderimpl createejbcontainer severe: ejb6005:no ejb modules found javax.naming.namingexception: lookup failed 'java:global/classes/examplebean' in serialcontext[myenv={java.naming.factory.initial=com.sun.enterprise.naming.impl.serialinitcontextfactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.jndistatefactoryimpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [root exception javax.naming.namenotfoundexception: classes] @ com.sun.enterprise.naming.impl.serialcontext.lookup(serialcontext.java:491) @ com.sun.enterprise.naming.impl.serialcontext.lookup(serialcontext.java:438) @ javax.naming.initialcontext.lookup(initialcontext.java:417) @ javax.naming.initialcontext.lookup(initialcontext.java:417) @ a.b.examplebeantest.init(examplebeantest.java:39) ... caused by: javax.naming.namenotfoundexception: classes ...
is bug?
is there working, embedded ee container execute junit/integration tests java 8 + ejb/bean + lambda?
where can report glassfish-embedded-all module related bug? found glassfish server related jira.
the lambda bug fixed couple of days ago: https://github.com/payara/payara/issues/647
Comments
Post a Comment