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

embed bug fix triade and internal cleanup #2456

Closed
wants to merge 24 commits into from

Conversation

kares
Copy link
Member

@kares kares commented Jan 13, 2015

while using JRuby's embed APIs in a slightly more advanced scenarios I run into several issues :

  • BiVariableMap is not behaving as a valid Map instance (throwing NPEs on methods)
  • ARGV was mean to be kept (as the map is cleared) but not correctly

added some tests covering intended (existing and fixed) functionality. trying to understand the details of context providers (and related embed variable impls) was a bit hard to read thus the did clean-up some (helped my brain to process the code).

let me know if smt needs more work, targeted jruby-1_7 - there are no (existing) API incompatibilities ...

@kares
Copy link
Member Author

@kares kares commented Jan 13, 2015

oh heavens, OSGi is at me ... @mkristian could I maybe get any hints from you, please :

     [exec] [INFO] org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.swissbox.extender.BundleWatcher] : Releasing bundle [org.ops4j.pax.exam.inject]
     [exec] [INFO] org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.swissbox.extender.BundleWatcher] : Releasing bundle [org.ops4j.pax.exam.extender.service]
     [exec] [INFO] 10:46:40.149 [main] DEBUG org.ops4j.exec.DefaultJavaRunner - Shutdown in progress...
     [exec] [INFO] 
     [exec] [INFO] 10:46:40.149 [main] DEBUG org.ops4j.exec.DefaultJavaRunner - Unwrapping stream I/O.
     [exec] [INFO] 10:46:40.149 [main] INFO  org.ops4j.exec.DefaultJavaRunner - Platform has been shutdown.
     [exec] [INFO] 10:46:40.155 [main] INFO  o.o.p.e.spi.reactors.ReactorManager - suite finished
     [exec] [INFO] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.629 sec <<< FAILURE!
     [exec] [INFO] testJRubyCreate(org.jruby.embed.osgi.test.JRubyOsgiEmbedTest)  Time elapsed: 2.429 sec  <<< ERROR!
     [exec] [INFO] java.io.IOException: No thread-local org.jruby.Ruby available; can't deserialize Ruby object. Set with Ruby#setThreadLocalRuntime.
     [exec] [INFO]  at org.jruby.RubyBasicObject.readObject(RubyBasicObject.java:2866)
     [exec] [INFO]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     [exec] [INFO]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
     [exec] [INFO]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     [exec] [INFO]  at java.lang.reflect.Method.invoke(Method.java:622)
     [exec] [INFO]  at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1001)
     [exec] [INFO]  at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1892)
     [exec] [INFO]  at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1797)
     [exec] [INFO]  at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1349)
     [exec] [INFO]  at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1989)
     [exec] [INFO]  at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1914)
     [exec] [INFO]  at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1797)
     [exec] [INFO]  at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1349)
     [exec] [INFO]  at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1989)
     [exec] [INFO]  at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1914)
     [exec] [INFO]  at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1797)
     [exec] [INFO]  at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1349)
     [exec] [INFO]  at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1989)
     [exec] [INFO]  at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1914)
     [exec] [INFO]  at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1797)
     [exec] [INFO]  at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1349)
     [exec] [INFO]  at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1989)
     [exec] [INFO]  at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1914)
     [exec] [INFO]  at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1797)
     [exec] [INFO]  at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1349)
     [exec] [INFO]  at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1989)
     [exec] [INFO]  at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1914)
     [exec] [INFO]  at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1797)
     [exec] [INFO]  at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1349)
     [exec] [INFO]  at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
     [exec] [INFO]  at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:243)
     [exec] [INFO]  at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:160)
     [exec] [INFO]  at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:194)
     [exec] [INFO]  at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:148)
     [exec] [INFO]  at com.sun.proxy.$Proxy7.callService(Unknown Source)
     [exec] [INFO]  at org.ops4j.pax.exam.forked.ForkedTestContainer.call(ForkedTestContainer.java:98)
     [exec] [INFO]  at org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactor.invoke(AllConfinedStagedReactor.java:84)
     [exec] [INFO]  at org.ops4j.pax.exam.junit.PaxExam$2.evaluate(PaxExam.java:294)
     [exec] [INFO]  at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
     [exec] [INFO]  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
     [exec] [INFO]  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
     [exec] [INFO]  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
     [exec] [INFO]  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
     [exec] [INFO]  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
     [exec] [INFO]  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
     [exec] [INFO]  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
     [exec] [INFO]  at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
     [exec] [INFO]  at org.ops4j.pax.exam.junit.PaxExam.run(PaxExam.java:111)
     [exec] [INFO]  at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
     [exec] [INFO]  at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
     [exec] [INFO]  at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
     [exec] [INFO]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     [exec] [INFO]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
     [exec] [INFO]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     [exec] [INFO]  at java.lang.reflect.Method.invoke(Method.java:622)
     [exec] [INFO]  at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
     [exec] [INFO]  at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
     [exec] [INFO]  at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
     [exec] [INFO]  at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
     [exec] [INFO]  at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
     [exec] [INFO] 
     [exec] [INFO] 
     [exec] [INFO] Results :
     [exec] [INFO] 
     [exec] [INFO] Tests in error: 
     [exec] [INFO]   testJRubyCreate(org.jruby.embed.osgi.test.JRubyOsgiEmbedTest): No thread-local org.jruby.Ruby available; can't deserialize Ruby object. Set with Ruby#setThreadLocalRuntime.
     [exec] [INFO] 
     [exec] [INFO] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0

@mkristian
Copy link
Member

@mkristian mkristian commented Jan 13, 2015

@kares this is quite something: the test-method "testJRubyCreate" first prints out two empty lines before it creates the IsolatedScriptingContainer. these lines are not there and the log goes immediately to releases the OSGi container. not sure what fails here - will have a look myself.

@mkristian
Copy link
Member

@mkristian mkristian commented Jan 13, 2015

@kares the problem is that all those settings:
https://github.com/jruby/jruby/blob/jruby-1_7/core/src/main/java/org/jruby/embed/IsolatedScriptingContainer.java#L70

like the classlaoder, loadPAth, HomeDirectory have no effect and the test runs more a vanilla ScriptingContainer which can not load the jruby/java.rb from jruby-core.jar

actually the OSGi problems is

  • the classloader which loads jruby is NOT Thread.currentThread
  • jruby-home with classpath://META-INF/jruby.home does not find default gems
  • embedded gems work only with GEM_PATH set to uri:classloader://

the test fails hard with an exception which the PAX runner does not handle nicely. the exception is:

2015-01-13T15:39:08.603Z: LoadService: trying fileInClasspath: jruby/java.jar.rb
java.lang.RuntimeException: org.jruby.exceptions.RaiseException: (LoadError) no such file to load -- jruby/java
    at org.jruby.embed.ScriptingContainer.<init>(ScriptingContainer.java:232)
    at org.jruby.embed.IsolatedScriptingContainer.<init>(IsolatedScriptingContainer.java:65)
    at org.jruby.embed.IsolatedScriptingContainer.<init>(IsolatedScriptingContainer.java:48)
    at org.jruby.embed.IsolatedScriptingContainer.<init>(IsolatedScriptingContainer.java:53)
    at org.jruby.embed.IsolatedScriptingContainer.<init>(IsolatedScriptingContainer.java:42)
    at org.jruby.embed.osgi.test.JRubyOsgiEmbedTest.testJRubyCreate(JRubyOsgiEmbedTest.java:71)

to simulate OSGi in a unit test in core/src/test/java is to use the classloader trick like:
https://github.com/jruby/jruby/blob/master/core/src/test/java/org/jruby/embed/ParentClassLoaderTest.java#L26
in
https://github.com/jruby/jruby/blob/master/core/src/test/java/org/jruby/embed/ParentClassLoaderTest.java#L45
but for IsolatedSCriptingContainer

@kares
Copy link
Member Author

@kares kares commented Jan 13, 2015

@mkristian seems that I will have to try running that locally ... I'm quite surprised the changes affected the OSGi container - as far as I looked into it. this one kares@969db40f034 mostly affected the singlethread provider, but there seems to be no direct relation to the container. anyways, thanks for the feedback!

@mkristian
Copy link
Member

@mkristian mkristian commented Jan 13, 2015

I added a testcase which simulates OSGi a bit and which fails on your branch with the same error as the OSGi test:

https://github.com/jruby/jruby/blob/jruby-1_7/core/src/test/java/org/jruby/embed/IsolatedScriptingContainerTest.java

kares added 24 commits Jan 22, 2015
… implementations :

- share the logic of obtaining a global runtime
- when global runtime is used make sure we always return the correct instance config!
- introduce & use LocalContext's internal getRuntime for lazy runtime initialization
- support contructors for all providers without the lazy argument
correctly synchronize local context setup/teardown (on our class)!
@kares kares force-pushed the embed-internal-cleanup branch from 03de97c to a5b938e Compare Jan 22, 2015
@kares
Copy link
Member Author

@kares kares commented Jan 22, 2015

@mkristian thanks, that turned very valuable ... avoided the regression and added some more related tests

@kares
Copy link
Member Author

@kares kares commented Feb 27, 2015

going to re-open this one

@kares kares closed this Feb 27, 2015
@headius
Copy link
Member

@headius headius commented May 4, 2015

Whatever happened with this? The comment trail is confusing.

@kares kares added this to the Invalid or Duplicate milestone May 4, 2015
@headius headius removed this from the Invalid or Duplicate milestone May 4, 2015
@headius headius added this to the Invalid or Duplicate milestone May 4, 2015
@kares
Copy link
Member Author

@kares kares commented May 4, 2015

sorry about that ... duplicate of #2630

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants