JMeter While Controller failing - while-loop

I want to be able to run multiple iterations of this test plan.
Thread Group
While ${__javaScript("${user}" != "<EOF>",)}
csv1 config
If "${user}" != "<EOF>"
Module Controller
While ${__javaScript("${user2}" != "<EOF>",)}
csv2 config
If "${user2}" != "<EOF>"
Module Controller 2
When I run the test, at the end of the 2nd while controller, it outputs the following error:
I've also tried running just 1 of the while controllers, and it has the same response. I'm not sure why it doesn't stop the current iteration and start a new one if it's able to get to the 2nd while controller.
java.lang.StackOverflowError: null
at java.lang.Class.getDeclaredFields0(Native Method) ~[?:1.8.0_231]
at java.lang.Class.privateGetDeclaredFields(Unknown Source) ~[?:1.8.0_231]
at java.lang.Class.getDeclaredField(Unknown Source) ~[?:1.8.0_231]
at jdk.nashorn.internal.runtime.Context$ContextCodeInstaller$1.run(Context.java:209) ~[nashorn.jar:?]
at jdk.nashorn.internal.runtime.Context$ContextCodeInstaller$1.run(Context.java:204) ~[nashorn.jar:?]
at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_231]
at jdk.nashorn.internal.runtime.Context$ContextCodeInstaller.initialize(Context.java:204) ~[nashorn.jar:?]
at jdk.nashorn.internal.codegen.CompilationPhase$InstallPhase.transform(CompilationPhase.java:508) ~[nashorn.jar:?]
at jdk.nashorn.internal.codegen.CompilationPhase.apply(CompilationPhase.java:624) ~[nashorn.jar:?]
at jdk.nashorn.internal.codegen.Compiler.compile(Compiler.java:655) ~[nashorn.jar:?]
at jdk.nashorn.internal.runtime.Context.compile(Context.java:1317) ~[nashorn.jar:?]
at jdk.nashorn.internal.runtime.Context.compileScript(Context.java:1251) ~[nashorn.jar:?]
at jdk.nashorn.internal.runtime.Context.compileScript(Context.java:627) ~[nashorn.jar:?]
at jdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:535) ~[nashorn.jar:?]
at jdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:524) ~[nashorn.jar:?]
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:402) ~[nashorn.jar:?]
at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:155) ~[nashorn.jar:?]
at org.apache.jmeter.functions.JavaScript.executeWithNashorn(JavaScript.java:142) ~[ApacheJMeter_functions.jar:5.1.1 r1855137]
at org.apache.jmeter.functions.JavaScript.execute(JavaScript.java:103) ~[ApacheJMeter_functions.jar:5.1.1 r1855137]
at org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:136) ~[ApacheJMeter_core.jar:5.1.1 r1855137]
at org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:111) ~[ApacheJMeter_core.jar:5.1.1 r1855137]
at org.apache.jmeter.testelement.property.FunctionProperty.getStringValue(FunctionProperty.java:101)
...
Thanks in advance.

It might be connected with the test data, check the last line(s) of your 2nd CSV file, there might be a blank line or non-printable character which is causing errors.
Since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting so consider migrating to __groovy() function in the While and If Controllers. The equivalent Groovy expression would be:
${__groovy(!vars.get("user2").equals("<EOF>"),)}
where vars is the shorthand for JMeterVariables class instance, check out Top 8 JMeter Java Classes You Should Be Using with Groovy article for more information on this and other JMeter API shortcuts
It's also recommended to always use the latest version of JMeter so consider migrating to JMeter 5.2.1 (or whatever is the most recent stable JMeter version which is available at JMeter Downloads page)

I didn't know how Loop Controllers worked, but I used them to solve this problem.
Thread Group
Throughput Controller
Loop Controller (size_of_csv)
csv config
Module Controller
Loop Controller 2(size_of_csv 2)
csv 2 config
Module Controller 2

Related

Byte Buddy 1.9.x throws `java.lang.IllegalStateException: Cannot resolve type description for java.lang.String` errors. Is it a known issue?

I am seeing Cannot resolve type description errors when trying to load classes instrumented using Byte Buddy v1.9.11 within Mule 4 (JDK 1.8). Is there a known issue with Byte Buddy, or a particular combination of isolated classloader Mule 4 is using with Byte Buddy instrumented classes? Any suggestions are appreciated.
I am using Elastic Java APM agent to instrument Mule 4 with its over-complicated classloader isolation mechanism that seems to interfere with Byte Buddy v1.9.11 used by the APM agent.
java.lang.IllegalStateException: Cannot resolve type description for java.lang.String
at co.elastic.apm.agent.shaded.bytebuddy.pool.TypePool$Resolution$Illegal.resolve(TypePool.java:159)
at co.elastic.apm.agent.shaded.bytebuddy.pool.TypePool$Default$LazyTypeDescription$TokenizedGenericType.toErasure(TypePool.java:6505)
at co.elastic.apm.agent.shaded.bytebuddy.pool.TypePool$Default$LazyTypeDescription$LazyTypeList.get(TypePool.java:6313)
at co.elastic.apm.agent.shaded.bytebuddy.pool.TypePool$Default$LazyTypeDescription$LazyTypeList.get(TypePool.java:6286)
at java.util.AbstractList$Itr.next(AbstractList.java:358)
at co.elastic.apm.agent.shaded.bytebuddy.matcher.ElementMatchers.takesArguments(ElementMatchers.java:1301)
at co.elastic.apm.agent.shaded.bytebuddy.dynamic.scaffold.inline.InliningImplementationMatcher.of(InliningImplementationMatcher.java:71)
at co.elastic.apm.agent.shaded.bytebuddy.dynamic.scaffold.inline.RedefinitionDynamicTypeBuilder.make(RedefinitionDynamicTypeBuilder.java:202)
at co.elastic.apm.agent.shaded.bytebuddy.agent.builder.AgentBuilder$Default$Transformation$Simple$Resolution.apply(AgentBuilder.java:10132)
at co.elastic.apm.agent.shaded.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.doTransform(AgentBuilder.java:10551)
at co.elastic.apm.agent.shaded.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.transform(AgentBuilder.java:10514)
at co.elastic.apm.agent.shaded.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.access$1500(AgentBuilder.java:10280)
at co.elastic.apm.agent.shaded.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer$LegacyVmDispatcher.run(AgentBuilder.java:10889)
at co.elastic.apm.agent.shaded.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer$LegacyVmDispatcher.run(AgentBuilder.java:10836)
at java.security.AccessController.doPrivileged(Native Method)
at co.elastic.apm.agent.shaded.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.transform(AgentBuilder.java:10437)
at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at org.mule.runtime.module.artifact.api.classloader.FineGrainedControlClassLoader.findLocalClass(FineGrainedControlClassLoader.java:171)
at org.mule.runtime.module.artifact.api.classloader.FineGrainedControlClassLoader.loadClass(FineGrainedControlClassLoader.java:88)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at co.elastic.apm.api.NoopTransaction.startSpan(NoopTransaction.java:132)
at co.elastic.apm.agent.utils.SpanUtils.startSpan(SpanUtils.java:34)
at co.elastic.apm.agent.internal.ApmMessageProcessorNotificationListener.onNotification(ApmMessageProcessorNotificationListener.java:27)
at co.elastic.apm.agent.internal.ApmMessageProcessorNotificationListener.onNotification(ApmMessageProcessorNotificationListener.java:10)
at org.mule.runtime.core.api.context.notification.ServerNotificationManager.lambda$fireNotification$0(ServerNotificationManager.java:193)
at org.mule.runtime.core.internal.context.notification.Sender.dispatch(Sender.java:28)
at org.mule.runtime.core.internal.context.notification.Policy.dispatchToSenders(Policy.java:146)
at org.mule.runtime.core.internal.context.notification.Policy.doDispatch(Policy.java:134)
at org.mule.runtime.core.internal.context.notification.Policy.dispatch(Policy.java:106)
at org.mule.runtime.core.api.context.notification.ServerNotificationManager.notifyListeners(ServerNotificationManager.java:211)
at org.mule.runtime.core.api.context.notification.ServerNotificationManager.fireNotification(ServerNotificationManager.java:193)
at org.mule.runtime.core.privileged.processor.chain.AbstractMessageProcessorChain.fireNotification(AbstractMessageProcessorChain.java:373)
at org.mule.runtime.core.privileged.processor.chain.AbstractMessageProcessorChain.lambda$preNotification$23(AbstractMessageProcessorChain.java:339)
at reactor.core.publisher.FluxPeekFuseable$PeekFuseableSubscriber.onNext(FluxPeekFuseable.java:190)
at org.mule.runtime.core.privileged.processor.chain.AbstractMessageProcessorChain$1.onNext(AbstractMessageProcessorChain.java:292)
at org.mule.runtime.core.privileged.processor.chain.AbstractMessageProcessorChain$1.onNext(AbstractMessageProcessorChain.java:285)
at reactor.core.publisher.FluxHide$SuppressFuseableSubscriber.onNext(FluxHide.java:127)
at reactor.core.publisher.FluxPeekFuseable$PeekFuseableSubscriber.onNext(FluxPeekFuseable.java:204)
at reactor.core.publisher.FluxPeekFuseable$PeekFuseableSubscriber.onNext(FluxPeekFuseable.java:204)
at reactor.core.publisher.FluxPeekFuseable$PeekFuseableSubscriber.onNext(FluxPeekFuseable.java:204)
at reactor.core.publisher.FluxPublishOn$PublishOnSubscriber.runAsync(FluxPublishOn.java:398)
at reactor.core.publisher.FluxPublishOn$PublishOnSubscriber.run(FluxPublishOn.java:484)
at reactor.core.scheduler.WorkerTask.call(WorkerTask.java:84)
at reactor.core.scheduler.WorkerTask.call(WorkerTask.java:37)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.mule.service.scheduler.internal.AbstractRunnableFutureDecorator.doRun(AbstractRunnableFutureDecorator.java:111)
at org.mule.service.scheduler.internal.RunnableFutureDecorator.run(RunnableFutureDecorator.java:54)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
I assume that the class file resolver used by the Elasticsearch agent is querying the class loader directly where this particular class loader is hiding the class files in question.
You can argue that this is an issue of the class loader hiding the class file or an issue of the elastic search agent not attempting other class loaders or reattempting the redefinition of the loaded class. I'd contact both entities as this can disturb different tooling.

How to Embed GEF4 MVC Logo Example in an E4 application

I want to create an Eclipse4 app that uses GEF4. More precisely I want to use the GEF4 MVC Logo Example sources into my app. I have imported the GEF4 sources, the compilation is ok. But when I want to refer to the example view, or whatever I try with my custom code ; I have runtime errors...
!ENTRY org.eclipse.e4.ui.workbench 4 0 2015-05-06 14:11:12.430
!MESSAGE Unable to create class 'org.eclipse.gef4.mvc.examples.logo.ui.view.MvcLogoExampleView' from bundle '78'
!STACK 0
org.eclipse.e4.core.di.InjectionException: com.google.inject.CreationException: Guice creation errors:
1) An exception was caught and reported. Message: Workbench has not been created yet.
at com.google.inject.util.Modules$RealOverriddenModuleBuilder$1.configure(Modules.java:172)
2) No implementation for org.eclipse.core.commands.operations.IOperationHistory was bound.
at org.eclipse.gef4.mvc.ui.MvcUiModule.configure(MvcUiModule.java:24)
2 errors
at org.eclipse.e4.core.internal.di.ConstructorRequestor.execute(ConstructorRequestor.java:55)
at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:335)
at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:258)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:162)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:104)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:73)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:55)
at org.eclipse.e4.ui.workbench.renderers.swt.ContributedPartRenderer.createWidget(ContributedPartRenderer.java:128)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createWidget(PartRenderingEngine.java:942)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:621)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:725)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:696)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:690)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:674)
at org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer.showTab(StackRenderer.java:1304)
at org.eclipse.e4.ui.workbench.renderers.swt.LazyStackRenderer$1.handleEvent(LazyStackRenderer.java:71)
at org.eclipse.e4.ui.services.internal.events.UIEventHandler$1.run(UIEventHandler.java:40)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:187)
at org.eclipse.swt.widgets.Display.syncExec(Display.java:4753)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application$1.syncExec(E4Application.java:212)
at org.eclipse.e4.ui.services.internal.events.UIEventHandler.handleEvent(UIEventHandler.java:36)
at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:197)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:197)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
at org.eclipse.equinox.internal.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java:135)
at org.eclipse.equinox.internal.event.EventAdminImpl.sendEvent(EventAdminImpl.java:78)
at org.eclipse.equinox.internal.event.EventComponent.sendEvent(EventComponent.java:39)
at org.eclipse.e4.ui.services.internal.events.EventBroker.send(EventBroker.java:85)
at org.eclipse.e4.ui.internal.workbench.UIEventPublisher.notifyChanged(UIEventPublisher.java:59)
at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:374)
at org.eclipse.e4.ui.model.application.ui.impl.ElementContainerImpl.setSelectedElement(ElementContainerImpl.java:171)
at org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer$9.widgetSelected(StackRenderer.java:1082)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4354)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1061)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1085)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1070)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:782)
at org.eclipse.swt.custom.CTabFolder.setSelection(CTabFolder.java:3111)
at org.eclipse.swt.custom.CTabFolder.onMouse(CTabFolder.java:1794)
at org.eclipse.swt.custom.CTabFolder$1.handleEvent(CTabFolder.java:283)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4354)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1061)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4172)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3761)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1112)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:993)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application.start(E4Application.java:161)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:648)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:603)
at org.eclipse.equinox.launcher.Main.run(Main.java:1465)
at org.eclipse.equinox.launcher.Main.main(Main.java:1438)
Caused by: com.google.inject.CreationException: Guice creation errors:
1) An exception was caught and reported. Message: Workbench has not been created yet.
at com.google.inject.util.Modules$RealOverriddenModuleBuilder$1.configure(Modules.java:172)
2) No implementation for org.eclipse.core.commands.operations.IOperationHistory was bound.
at org.eclipse.gef4.mvc.ui.MvcUiModule.configure(MvcUiModule.java:24)
2 errors
at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:435)
at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:154)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:106)
at com.google.inject.Guice.createInjector(Guice.java:95)
at com.google.inject.Guice.createInjector(Guice.java:72)
at com.google.inject.Guice.createInjector(Guice.java:62)
at org.eclipse.gef4.mvc.examples.logo.ui.view.MvcLogoExampleView.<init>(MvcLogoExampleView.java:30)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.eclipse.e4.core.internal.di.ConstructorRequestor.execute(ConstructorRequestor.java:41)
... 67 more
Caused by: java.lang.IllegalStateException: Workbench has not been created yet.
at org.eclipse.ui.PlatformUI.getWorkbench(PlatformUI.java:93)
at org.eclipse.gef4.mvc.ui.MvcUiModule.configure(MvcUiModule.java:25)
at org.eclipse.gef4.mvc.fx.ui.MvcFxUiModule.configure(MvcFxUiModule.java:28)
at com.google.inject.AbstractModule.configure(AbstractModule.java:59)
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:223)
at com.google.inject.spi.Elements.getElements(Elements.java:101)
at com.google.inject.spi.Elements.getElements(Elements.java:92)
at com.google.inject.util.Modules$RealOverriddenModuleBuilder$1.configure(Modules.java:172)
at com.google.inject.AbstractModule.configure(AbstractModule.java:59)
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:223)
at com.google.inject.spi.Elements.getElements(Elements.java:101)
at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:133)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:103)
... 76 more
If someone could provide me any process to integrate the GEF4 example, it'd be very nice
As stated in https://bugs.eclipse.org/bugs/show_bug.cgi?id=372171, the standalone MVC and MVC.FX bundles still have dependencies to org.eclipse.core.commands, and the integration bundles MVC.UI and MVC.FX.UI in addition introduce dependencies to org.eclipse.ui, org.eclipse.ui.views, org.eclipse.ui.workbench, etc. (which are part of the compatibility layer). The MVC logo example depends on all of them. That is, integrating the example into a pure e4 app (without compatibility layer) is currently not possible.
Replacing the dependencies from the standalone bundles to org.eclipse.core.commands with its e4 pendant (that IMHO is not available in the respective scope yet) will enable that these bundles can be used in a native e4 application (i.e. without the compatibility layer).
For the integration bundles the same would have to be done, while the current integration is intensively based on the compatibility layer, so more effort would probably be needed. This is something that will need further investigation.

Is SSLContext.createSSLEngine() thread safe?

I'm using the default JSSE provider in Java 6 (SunJSSE) like so,
SSLContext sslCtx = SSLContext.getInstance("TLS");
Can I call the method sslCtx.createSSLEngine() safely from multiple threads?
Update 1:
The code that's calling createSSLEngine() in this manner is run on the server-side only. Basically, a thread calls this method for every client that connects to the server.
The call to SSLContext.createSSLEngine() seems to be thread-safe. At least based on the fact that the application has not failed with any race-condition-related error.
In trying to find a definitive answer, I downloaded the source code of OpenJDK6 b27 and took a look at it. I’m assuming, of course, that this is the same code that is inside Oracle’s JRE 6.
When SSLContext.createSSLEngine() is called, it in its turn calls the abstract method engineCreateSSLEngine() on whatever implementation it has of the javax.net.ssl.SSLContextSpi class. In this case the implementation is sun.security.ssl.SSLContextImpl. The implementation of the engineCreateSSLEngine() method provided by SSLContextImpl simply returns a new instance of sun.security.ssl.SSLEngineImpl by calling the SSLEngineImpl(SSLContextImpl ctx) constructor.
Inspecting the code, I couldn’t find anything that suggested a possible thread-unsafe operation.
I can also agree with Elliot concerning the thread-safeness of SSLContext.createSSLEngine() in OpenJDK8 (based on analysing the code and performing simple tests).
I added this answer, because there exist situations when you HAVE to re-use SSLContexts (if you do not like wrapper classes or cannot use synchronisation): When connecting to a Wildfly application server EJB using SSL encryption, the jboss-remoting EndpointImpl decides to open a new connection based on a ConnectionKey that contains the SSLContext instance. So if you always specify a new SSLContext for each EJB call, always a new connection is used. The sad thing is, that the connection is considered "shared", so it is not closed after the call (but never re-used, due to the differing ConnectionKeys). After some time, you will only get many of those:
Caused by: java.net.SocketException: No buffer space available
at sun.nio.ch.Net.socket0(Native Method) ~[?:1.8.0_91]
at sun.nio.ch.Net.socket(Net.java:411) ~[?:1.8.0_91]
at sun.nio.ch.Net.socket(Net.java:404) ~[?:1.8.0_91]
at sun.nio.ch.SocketChannelImpl.<init>(SocketChannelImpl.java:105) ~[?:1.8.0_91]
at sun.nio.ch.SelectorProviderImpl.openSocketChannel(SelectorProviderImpl.java:60) ~[?:1.8.0_91]
at java.nio.channels.SocketChannel.open(SocketChannel.java:145) ~[?:1.8.0_91]
at org.xnio.nio.WorkerThread.openTcpStreamConnection(WorkerThread.java:250) ~[xnio-nio-3.6.2.Final.jar:3.6.2.Final]
at org.xnio.XnioIoThread.internalOpenTcpStreamConnection(XnioIoThread.java:247) ~[xnio-api-3.6.2.Final.jar:3.6.2.Final]
at org.xnio.XnioIoThread.openStreamConnection(XnioIoThread.java:226) ~[xnio-api-3.6.2.Final.jar:3.6.2.Final]
at org.xnio.XnioWorker.openStreamConnection(XnioWorker.java:398) ~[xnio-api-3.6.2.Final.jar:3.6.2.Final]
at org.jboss.remoting3.remote.RemoteConnectionProvider.createSslConnection(RemoteConnectionProvider.java:246) ~[jboss-remoting-5.0.0.
at org.jboss.remoting3.remote.HttpUpgradeConnectionProvider.createSslConnection(HttpUpgradeConnectionProvider.java:136) ~[jboss-remot
at org.jboss.remoting3.remote.RemoteConnectionProvider.connect(RemoteConnectionProvider.java:206) ~[jboss-remoting-5.0.0.Final.jar:5.
at org.jboss.remoting3.EndpointImpl.lambda$connect$6(EndpointImpl.java:618) ~[jboss-remoting-5.0.0.Final.jar:5.0.0.Final]
at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_91]
at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:617) ~[jboss-remoting-5.0.0.Final.jar:5.0.0.Final]
at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:536) ~[jboss-remoting-5.0.0.Final.jar:5.0.0.Final]
at org.jboss.remoting3.ConnectionInfo$None.getConnection(ConnectionInfo.java:83) ~[jboss-remoting-5.0.0.Final.jar:5.0.0.Final]
at org.jboss.remoting3.ConnectionInfo.getConnection(ConnectionInfo.java:56) ~[jboss-remoting-5.0.0.Final.jar:5.0.0.Final]
at org.jboss.remoting3.EndpointImpl.doGetConnection(EndpointImpl.java:487) ~[jboss-remoting-5.0.0.Final.jar:5.0.0.Final]
at org.jboss.remoting3.EndpointImpl.getConnectedIdentity(EndpointImpl.java:433) ~[jboss-remoting-5.0.0.Final.jar:5.0.0.Final]
at org.jboss.remoting3.UncloseableEndpoint.getConnectedIdentity(UncloseableEndpoint.java:51) ~[jboss-remoting-5.0.0.Final.jar:5.0.0.F
at org.jboss.remoting3.Endpoint.getConnectedIdentity(Endpoint.java:122) ~[jboss-remoting-5.0.0.Final.jar:5.0.0.Final]
at org.jboss.ejb.protocol.remote.RemoteEJBReceiver.lambda$getConnection$2(RemoteEJBReceiver.java:185) ~[jboss-ejb-client-4.0.9.Final.
at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_91]
at org.jboss.ejb.protocol.remote.RemoteEJBReceiver.getConnection(RemoteEJBReceiver.java:185) ~[jboss-ejb-client-4.0.9.Final.jar:4.0.9
at org.jboss.ejb.protocol.remote.RemoteEJBReceiver.processInvocation(RemoteEJBReceiver.java:128) ~[jboss-ejb-client-4.0.9.Final.jar:4
at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:454) ~[jboss-ejb-client-4.0.9.Final.ja
Re-using a static SSLContext fixes this.

Easy Mock - How to?

I am trying easyMock test few classes / interface methods. Methods with parameters, trying to capture the parameter, but getting one or other error. If I manage to only record one expectation, it doesn't even capture anything in the parameter pipe, where if i use the following approach, I am getting error as follows the code.
#Test
public void testFireChannelInitializer() throws Exception
{
expect(c.pipeline()).andReturn(pipeline).times(1);
channelListener.fireChannelInitializer(EasyMock.capture(pipe), serverHandler);
EasyMock.replay(c, pipeline, channelListener);
initializer.initChannel(c);
verifyAll();
assertEquals(4, pipe.getValues().size());
assertTrue(pipe.getValues().get(0) instanceof LoggingHandler);
assertTrue(pipe.getValues().get(0) instanceof ObjectEncoder);
assertTrue(pipe.getValues().get(0) instanceof ObjectDecoder);
assertTrue(pipe.getValues().get(0) instanceof ServerHandler);
}
Results in Error
testFireChannelInitializer(com.obolus.generic.impl.DefaultChannelListenerTest)
Time elapsed: 3.812 sec <<< ERROR! java.lang.IllegalStateException: 2
matchers expected, 1 recorded. This exception usually occurs when
matchers are mixed with raw values when recording a method: foo(5,
eq(6)); // wrong You need to use no matcher at all or a matcher for
every single param: foo(eq(5), eq(6)); // right foo(5, 6); // also
right at
org.easymock.internal.ExpectedInvocation.createMissingMatchers(ExpectedInvocation.java:51)
at
org.easymock.internal.ExpectedInvocation.(ExpectedInvocation.java:40)
at org.easymock.internal.RecordState.invoke(RecordState.java:78) at
org.easymock.internal.MockInvocationHandler.invoke(MockInvocationHandler.java:40)
at
org.easymock.internal.ObjectMethodsFilter.invoke(ObjectMethodsFilter.java:94)
at
org.easymock.internal.ClassProxyFactory$MockMethodInterceptor.intercept(ClassProxyFactory.java:97)
at
com.obolus.generic.impl.DefaultChannelListener$$EnhancerByCGLIB$$2da02970.fireChannelInitializer()
at
com.obolus.generic.impl.DefaultChannelListenerTest.testFireChannelInitializer(DefaultChannelListenerTest.java:63)
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:483) at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263) at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) at
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) at
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) at
org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) at
org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) at
org.junit.runners.ParentRunner.run(ParentRunner.java:300) at
org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:242)
at
org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:137)
at
org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
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:483) at
org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at
org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at
org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at
org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at
org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Any idea whats wrong or How to use easy mock? No good documentation or examples around.
The easymock website has a user guide but they redid their website recently and the guide isn't as complete as it used to be.
I think your problem might be you have to do a capture AND an argument matcher.
From the user guide:
Matches any value but captures it in the Capture parameter for later access. You can do and(someMatcher(...), capture(c)) to capture a parameter from a specific call to the method. You can also specify a CaptureType telling that a given Capture should keep the first, the last, all or no captured values.
So you might need to do an and( capture(..), paramMatcher)
Also EasyMock has an annoying API "feature" where if you use one argument matcher in a method call, then all the arguments must also be wrapped in matchers even if it's eq(). I think that's what your exception is complaining about. So I think those are your two problems.
I'm not sure what your method signature looks like so I will assume it's
void fireChannelInitializer(Object, ServerHandler);
after using static imports to import EasyMock.*
channelListener.fireChannelInitializer(
and(capture(pipe), isA(Object.class)), //captures the argument to `pipe` Capture object
eq(serverHandler));

IntelliJ NoClassDefFoundError when running IntelliJ Tests

I know this question has been asked in various forms before, but I've checked all the answers and I think we've excluded them all.
Error:
java.lang.NoClassDefFoundError: com/lgc/infra/geometry/Coord1Val
at com.lgc.infra.geometry.Coords.coord(Coords.java:89)
at com.lgc.infra.geometry.Coords.<clinit>(Coords.java:24)
at com.geoteric.lfd.eos.ReallyBasicTest.make_a_simple_coord(ReallyBasicTest.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:24)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: java.lang.ClassNotFoundException: com.lgc.infra.geometry.Coord1Val
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 37 more
Code:
package com.geoteric.lfd.eos;
import com.lgc.infra.geometry.Coord3;
import com.lgc.infra.geometry.Coords;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
/**
* Created by TClarke on 27/03/2015.
*/
public class ReallyBasicTest {
#Test
public void make_a_simple_coord()
{
Coord3 c3 = Coords.coord(1.0f, 2.0f, 3.0f);
assertThat(c3.getX(), equalTo(1.0));
}
}
Path to ClassFile:
D:\ffa_dev\link-for-decisionspace\ext\dssdk\com_lgc_dsp-core_sdk.jar!\com\lgc\infra\geometry\Coords.class
Screenshot of Module Structure:
Screenshot of Test Runner Config:
Related Code functions fine when built into real project. So, any advice on what I might have missed?
I think your .iml is not updated. Have you tried re creating your project/module .iml files. If its maven project you can recreate it by command
mvn idea:idea
After .iml is updated refresh the project and re run the test
This got upvoted, so I'll let you know what we eventually worked out.
We were writing a plugin using the API for another application. When you deploy the plugin, it gains access to all the definitions in the application. However, the unit tests are running in isolation, so the particular classes that are only defined through interfaces and factories cannot be built.
For this example:
Coord3 c3 = Coords.coord(1.0f, 2.0f, 3.0f);
Both Coord3 and Coords are defined. But com/lgc/infra/geometry/Coord1Val, which is used in Coords, is never actually defined in our library path (the API jar was clearly built with it there, but it wasn't supplied).
There are multiple potential workarounds, hopefully smart people stumbling upon this question will comment with some of them. The one we went with is to wrap Coords in a mockable factory that returns mock(Coord3.class), so that the parts that demonstrate this issue are encapsulated away.