I am redefining classes with ByteBuddy within a unit test. I am resetting the class after each test to ensure no cross-talk between tests.
ByteBuddy works as expected when simply running the tests in the Eclipse IDE or when running with maven command line. But if it run in Eclipse with coverage, resetting the class results in the following exception:
java.lang.UnsupportedOperationException: class redefinition failed: attempted to change the schema (add/remove fields)
Bellow is a sample test which passes in the default JUnit runner but fails when run with Code Coverage in Eclipse. Below that is the full stack trace of the failure.
I am using ByteBuddy version 1.8.22 and the EclEmma Java Code Coverage Package version 3.1.0.201804041601.
I am assuming this issue is due to a conflict between ByteBuddy class modifications and EclEmma code instrumentation. It there an alternate approach to restoring class definitions that would work around this issue?
Fails under Coverage:
import static net.bytebuddy.matcher.ElementMatchers.named;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import net.bytebuddy.ByteBuddy;
import net.bytebuddy.agent.ByteBuddyAgent;
import net.bytebuddy.dynamic.loading.ClassReloadingStrategy;
import net.bytebuddy.implementation.FixedValue;
public class ByteBuddyEclEmmaTest {
#Test
public void recreateEclEmmaByteBuddyResetIssue() throws Exception {
ByteBuddyAgent.install();
ByteBuddy byteBuddy = new ByteBuddy();
ClassReloadingStrategy classReloadingStrategy = ClassReloadingStrategy.fromInstalledAgent();
byteBuddy
.redefine(X.class)
.method(named("getValue")).intercept(FixedValue.value("faked value"))
.make()
.load(X.class.getClassLoader(), classReloadingStrategy);
X x = new X();
assertThat(x.getValue()).isEqualTo("faked value");
classReloadingStrategy.reset(X.class);
assertThat(x.getValue()).isEqualTo("real value");
}
public class X {
public String getValue() {
return "real value";
}
}
}
Stack Trace:
java.lang.UnsupportedOperationException: class redefinition failed: attempted to change the schema (add/remove fields)
at sun.instrument.InstrumentationImpl.redefineClasses0(Native Method)
at sun.instrument.InstrumentationImpl.redefineClasses(InstrumentationImpl.java:170)
at net.bytebuddy.dynamic.loading.ClassReloadingStrategy$Strategy$1.apply(ClassReloadingStrategy.java:261)
at net.bytebuddy.dynamic.loading.ClassReloadingStrategy$Strategy$1.reset(ClassReloadingStrategy.java:279)
at net.bytebuddy.dynamic.loading.ClassReloadingStrategy.reset(ClassReloadingStrategy.java:209)
at net.bytebuddy.dynamic.loading.ClassReloadingStrategy.reset(ClassReloadingStrategy.java:195)
at ByteBuddyEclEmmaTest.recreateEclEmmaByteBuddyResetIssue(ByteBuddyEclEmmaTest.java:30)
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:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
I figured out my issue was caused by an older version of ByteBuddy. I was getting version 1.6.14 pulled into my project from Mockito. When I explicitly brought in ByteBuddy version 1.8.22, the test runs successfully, both with and without Coverage.
Related
I'm trying to run a cucumber test using selenium / java. Based on the console output , I can say for sure that the step definiton file has been found by the feature file , but still , the moment the code enters the #Given block , it errors out with below. I tried my best to know why this error occurs , tried adding xstream jar and many other things , but just cant figure out the exact jar file that I need to add / remove or update.
My Feature File is Below:
#Author: your.email#your.domain.com
#Keywords Summary :
#Feature: List of scenarios.
#Scenario: Business rule through list of steps with arguments.
#Given: Some precondition step
#When: Some key actions
#Then: To observe outcomes or validation
#And,But: To enumerate more Given,When,Then steps
#Scenario Outline: List of steps for data-driven as an Examples and <placeholder>
#Examples: Container for s table
#Background: List of steps run before each of the scenarios
#""" (Doc Strings)
#| (Data Tables)
## (Tags/Labels):To group Scenarios
#<> (placeholder)
#""
## (Comments)
#Sample Feature Definition Template
Feature: Title of your feature
I want to use this template for my feature file
Scenario: Launch the Browser
Given I initialize the driver
When I launch the url
Then I land on the page
Console Output Below:
Feature: Title of your feature
I want to use this template for my feature file
Scenario: Launch the Browser # src/features/browser.feature:22
Given I initialize the driver # browser.i_initialize_the_driver()
java.lang.ExceptionInInitializerError
at cucumber.deps.com.thoughtworks.xstream.XStream.setupConverters(XStream.java:807)
at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:574)
at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:530)
at cucumber.runtime.xstream.LocalizedXStreams$LocalizedXStream.<init>(LocalizedXStreams.java:76)
at cucumber.runtime.xstream.LocalizedXStreams.newXStream(LocalizedXStreams.java:48)
at cucumber.runtime.xstream.LocalizedXStreams.get(LocalizedXStreams.java:39)
at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:40)
at cucumber.api.TestStep.executeStep(TestStep.java:102)
at cucumber.api.TestStep.run(TestStep.java:83)
at cucumber.api.TestCase.run(TestCase.java:58)
at cucumber.runner.Runner.runPickle(Runner.java:80)
at cucumber.runtime.junit.PickleRunners$NoStepDescriptions.run(PickleRunners.java:140)
at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:68)
at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:23)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:73)
at cucumber.api.junit.Cucumber.runChild(Cucumber.java:117)
at cucumber.api.junit.Cucumber.runChild(Cucumber.java:55)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at cucumber.api.junit.Cucumber$1.evaluate(Cucumber.java:126)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at org.junit.vintage.engine.execution.RunnerExecutor.execute(RunnerExecutor.java:43)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
at org.junit.vintage.engine.VintageTestEngine.executeAllChildren(VintageTestEngine.java:82)
at org.junit.vintage.engine.VintageTestEngine.execute(VintageTestEngine.java:73)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:108)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:96)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:84)
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:98)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:40)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:529)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:756)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
at ?.I initialize the driver(src/features/browser.feature:23)
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.util.Comparator java.util.TreeMap.comparator accessible: module java.base does not "opens java.util" to unnamed module #43bd930a
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:357)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:177)
at java.base/java.lang.reflect.Field.setAccessible(Field.java:171)
at cucumber.deps.com.thoughtworks.xstream.core.util.Fields.locate(Fields.java:39)
at cucumber.deps.com.thoughtworks.xstream.converters.collections.TreeMapConverter.<clinit>(TreeMapConverter.java:50)
at cucumber.deps.com.thoughtworks.xstream.XStream.setupConverters(XStream.java:807)
at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:574)
at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:530)
at cucumber.runtime.xstream.LocalizedXStreams$LocalizedXStream.<init>(LocalizedXStreams.java:76)
at cucumber.runtime.xstream.LocalizedXStreams.newXStream(LocalizedXStreams.java:48)
at cucumber.runtime.xstream.LocalizedXStreams.get(LocalizedXStreams.java:39)
at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:40)
at cucumber.api.TestStep.executeStep(TestStep.java:102)
at cucumber.api.TestStep.run(TestStep.java:83)
at cucumber.api.TestCase.run(TestCase.java:58)
at cucumber.runner.Runner.runPickle(Runner.java:80)
at cucumber.runtime.junit.PickleRunners$NoStepDescriptions.run(PickleRunners.java:140)
at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:68)
at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:23)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:73)
at cucumber.api.junit.Cucumber.runChild(Cucumber.java:117)
at cucumber.api.junit.Cucumber.runChild(Cucumber.java:55)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at cucumber.api.junit.Cucumber$1.evaluate(Cucumber.java:126)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at org.junit.vintage.engine.execution.RunnerExecutor.execute(RunnerExecutor.java:43)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
at org.junit.vintage.engine.VintageTestEngine.executeAllChildren(VintageTestEngine.java:82)
at org.junit.vintage.engine.VintageTestEngine.execute(VintageTestEngine.java:73)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:108)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:96)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:84)
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:98)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:40)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:529)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:756)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
When I launch the url # browser.i_launch_the_url()
Then I land on the page # browser.i_land_on_the_page()
My Code Structure:
My Test Runner Class is below:
package cucumbertest;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(
features="src/features",
glue="stepdefinition",
plugin= {"pretty","html:target/Cucumber.html"},
monochrome=true
)
public class TestRunner {
}
My Step Definition Class is below:
package stepdefinition;
import org.junit.Assert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class browser {
WebDriver driver;
#Given("^I initialize the driver$")
public void i_initialize_the_driver() throws Exception {
// Write code here that turns the phrase above into concrete actions
//throw new PendingException();
System.setProperty("webdriver.gecko.driver", "C:\\Users\\ttmanner\\Downloads\\geckodriver-v0.29.1-win64\\geckodriver.exe");
driver = new FirefoxDriver();
System.out.println("Iam in Given");
}
#When("^I launch the url$")
public void i_launch_the_url() throws Exception {
// Write code here that turns the phrase above into concrete actions
//throw new PendingException();
driver.get("http://idrw.org/");
}
#Then("^I land on the page$")
public void i_land_on_the_page() throws Exception {
// Write code here that turns the phrase above into concrete actions
//throw new PendingException();
Assert.assertTrue(driver.getTitle().equals("Defence"));
}
}
My Jar Files are below (Not using Maven , Unfortunately I'm in a specific scenario where I cant use Maven)
You are using a combination of Cucumber and Java that are not compatible together. You can either downgrade your Java or upgrade your Cucumber version. The latter is probably the better choice.
When using Mockito in JUnit4, I encounter the error in the title.
My code is shown below
package cn.patest.judgerAutoscalerKotlin
import org.junit.Test
import org.mockito.*
import java.lang.RuntimeException
class CalculateScaleToTest {
#Mock
private lateinit var test: cn.patest.judgerAutoscalerKotlin.Test
private fun mockTest() {
test = cn.patest.judgerAutoscalerKotlin.Test()
Mockito.doAnswer { 1 }.`when`(test).test()
}
#Test
fun z() {
mockTest()
}
}
package cn.patest.judgerAutoscalerKotlin
class Test() {
fun test(): Int {
return 1
}
}
Error details are shown below:
org.mockito.exceptions.misusing.NotAMockException:
Argument passed to when() is not a mock!
Example of correct stubbing:
doThrow(new RuntimeException()).when(mock).someMethod();
at cn.patest.judgerAutoscalerKotlin.CalculateScaleToTest.mockTest(CalculateScaleToTest.kt:53)
at cn.patest.judgerAutoscalerKotlin.CalculateScaleToTest.z(CalculateScaleToTest.kt:61)
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:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
I searched with google and found some similar issues but they have different situations from mine.
With:
test = cn.patest.judgerAutoscalerKotlin.Test()
you create a real object, not a mocked one.
Remove the above line and add:
#Before
fun before() {
MockitoAnnotations.initMocks( this )
}
Reference:
Mock
MockitoAnnotations
MockitoAnnotations.initMocks(this) method has to be called to initialize annotated fields.
Note also that mocking the class under test in a real environment doesn't make any sense (in contrast to a MCVE like here).
I have a cluster with 2 nodes. Then I tried to run the CacheJdbcStoreExample in apache-ignite-fabric-2.1.0-bin/examples.But I got following exception:
visor> [06:51:41,113][SEVERE][tcp-disco-msg-worker-#13%null%][TcpDiscoverySpi] Failed to unmarshal discovery custom message.
class org.apache.ignite.IgniteCheckedException: Failed to find class with given class loader for unmarshalling (make sure same versions of all classes are available on all nodes or enable pee
r-class-loading) [clsLdr=sun.misc.Launcher$AppClassLoader#4aa4ceeb, cls=org.apache.ignite.examples.datagrid.store.jdbc.CacheJdbcStoreExample$1] at org.apache.ignite.marshaller.jdk.JdkMarshaller.unmarshal0(JdkMarshaller.java:124)
at org.apache.ignite.marshaller.AbstractNodeNameAwareMarshaller.unmarshal(AbstractNodeNameAwareMarshaller.java:94)
at org.apache.ignite.marshaller.jdk.JdkMarshaller.unmarshal0(JdkMarshaller.java:143)
at org.apache.ignite.marshaller.AbstractNodeNameAwareMarshaller.unmarshal(AbstractNodeNameAwareMarshaller.java:82)
at org.apache.ignite.internal.util.IgniteUtils.unmarshal(IgniteUtils.java:9733)
at org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryCustomEventMessage.message(TcpDiscoveryCustomEventMessage.java:81)
at org.apache.ignite.spi.discovery.tcp.ServerImpl$RingMessageWorker.notifyDiscoveryListener(ServerImpl.java:5436)
at org.apache.ignite.spi.discovery.tcp.ServerImpl$RingMessageWorker.processCustomMessage(ServerImpl.java:5321)
at org.apache.ignite.spi.discovery.tcp.ServerImpl$RingMessageWorker.processMessage(ServerImpl.java:2629)
at org.apache.ignite.spi.discovery.tcp.ServerImpl$RingMessageWorker.processMessage(ServerImpl.java:2420)
at org.apache.ignite.spi.discovery.tcp.ServerImpl$MessageWorkerAdapter.body(ServerImpl.java:6576)
at org.apache.ignite.spi.discovery.tcp.ServerImpl$RingMessageWorker.body(ServerImpl.java:2506)
at org.apache.ignite.spi.IgniteSpiThread.run(IgniteSpiThread.java:62)
Caused by: java.lang.ClassNotFoundException: org.apache.ignite.examples.datagrid.store.jdbc.CacheJdbcStoreExample$1
at java.net.URLClassLoader$1.run(URLClassLoader.java:359)
at java.net.URLClassLoader$1.run(URLClassLoader.java:348)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:347)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:278)
at org.apache.ignite.internal.util.IgniteUtils.forName(IgniteUtils.java:8465)
at org.apache.ignite.marshaller.jdk.JdkMarshallerObjectInputStream.resolveClass(JdkMarshallerObjectInputStream.java:54)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1817)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1711)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1982)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1533)
at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1917)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1527)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2227)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2151)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2009)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1533)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2227)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2151)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2009)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1533)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:420)
at java.util.ArrayList.readObject(ArrayList.java:771)
at sun.reflect.GeneratedMethodAccessor16.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1058)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2118)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2009)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1533)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2227)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2151)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2009)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1533)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2227)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2151)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2009)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1533)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:420)
at org.apache.ignite.marshaller.jdk.JdkMarshaller.unmarshal0(JdkMarshaller.java:121)
... 12 more
I decompiled CacheJdbcStoreExample$1.class and got following code:
CacheJdbcStoreExample$1
package org.apache.ignite.examples.datagrid.store.jdbc;
import javax.cache.configuration.Factory;
import org.apache.ignite.cache.store.CacheStoreSessionListener;
import org.apache.ignite.cache.store.jdbc.CacheJdbcStoreSessionListener;
import org.h2.jdbcx.JdbcConnectionPool;
class CacheJdbcStoreExample$1
implements Factory<CacheStoreSessionListener>
{
public CacheStoreSessionListener create()
{
CacheJdbcStoreSessionListener lsnr = new CacheJdbcStoreSessionListener();
lsnr.setDataSource(JdbcConnectionPool.create("jdbc:h2:tcp://localhost/mem:ExampleDb", "sa", ""));
return lsnr;
}
}
SO I think there is something wrong at row 90 in CacheJdbcStoreExample source code:
// Configure JDBC session listener.
cacheCfg.setCacheStoreSessionListenerFactories(new Factory<CacheStoreSessionListener>() {
#Override public CacheStoreSessionListener create() {
CacheJdbcStoreSessionListener lsnr = new CacheJdbcStoreSessionListener();
lsnr.setDataSource(JdbcConnectionPool.create("jdbc:h2:tcp://localhost/mem:ExampleDb", "sa", ""));
return lsnr;
}
});
If I run the example on only one node not a cluster, it's OK.
What should I do to fix it?
The problem is that you configured a cache with a factory of CacheStoreSessionListener-s, but this factory is not visible from other nodes as they don't have it in their classpath.
You should start additional remote nodes with org.apache.ignite.examples.ExampleNodeStartup class from examples module or add examples module to the classpath of other nodes.
I have issues running my unit tests with a specific version of Robolectric and Facebook. My test scripts work when I have the following
testCompile "org.robolectric:robolectric:3.3.2"
testCompile "org.robolectric:shadows-multidex:3.3.2"
testCompile 'org.robolectric:shadows-support-v4:3.3.2'
and
compile 'com.facebook.android:facebook-android-sdk:4.2.0'
But, when I upgrade to
compile 'com.facebook.android:facebook-android-sdk:4.22.0'
I get the following issues:
WARNING: unknown service appops
WARNING: no system properties value for persist.radio.multisim.config
The Facebook sdk must be initialized before calling activateApp
at com.facebook.appevents.AppEventsLogger.activateApp(AppEventsLogger.java:226)
at com.facebook.appevents.AppEventsLogger.activateApp(AppEventsLogger.java:208)
at ladenzeile.android.services.tracking.TrackingService.trackActivateApp(TrackingService.java:129)
at ladenzeile.android.new_app.NewHome.activity.AppCompatAbstractBaseActivity.onResume(AppCompatAbstractBaseActivity.java:328)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1257)
at android.app.Activity.performResume(Activity.java:6076)
at org.robolectric.util.ReflectionHelpers$6.run(ReflectionHelpers.java:198)
at org.robolectric.util.ReflectionHelpers.traverseClassHierarchy(ReflectionHelpers.java:341)
at org.robolectric.util.ReflectionHelpers.callInstanceMethod(ReflectionHelpers.java:192)
at org.robolectric.android.controller.ComponentController$1.run(ComponentController.java:75)
at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:362)
at org.robolectric.shadows.CoreShadowsAdapter$2.runPaused(CoreShadowsAdapter.java:40)
at org.robolectric.android.controller.ComponentController.invokeWhilePaused(ComponentController.java:72)
at org.robolectric.android.controller.ActivityController.resume(ActivityController.java:171)
at org.robolectric.android.controller.ActivityController.setup(ActivityController.java:245)
at org.robolectric.Robolectric.setupActivity(Robolectric.java:97)
at ladenzeile.android.new_app.newPreference.RegionPreferenceInteractorTest.saveLanguageAndCountryCode(RegionPreferenceInteractorTest.java:38)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.robolectric.RobolectricTestRunner$HelperTestRunner$1.evaluate(RobolectricTestRunner.java:488)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.robolectric.internal.SandboxTestRunner$2.evaluate(SandboxTestRunner.java:209)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:109)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:36)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.robolectric.internal.SandboxTestRunner$1.evaluate(SandboxTestRunner.java:63)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Process finished with exit code 255
Any idea how to fix the issue?
Since 4.19, Facebook SDK does an automatic init process. Robolectric doesn't start it properly, hence the crash.
If you don't need Facebook SDK initialized, a perfectly valid solution is shadowing activateApp call. Create this class:
#Implements(AppEventsLogger.class)
public class ShadowAppEventsLogger {
#Implementation
public static void activateApp(Application application) {
// Do nothing, just shadow
}
}
and attach it to your test:
#Config(shadows = {ShadowAppEventsLogger.class, ...}, ... )
#Test public void fooTest() {...}
Ref: http://robolectric.org/extending/
I'm trying to do a marshal dump and load in Scala...
import scala.util.Marshal
case class Test(test: String)
val t = Test("hello")
val bytes = Marshal.dump(t)
Marshal.load[Test](bytes)
...but the call to Marshal.load is throwing a ClassNotFoundException...
java.lang.ClassNotFoundException: Test
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:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:603)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1574)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1495)
at java.io.ObjectInputStream.readClass(ObjectInputStream.java:1461)
at java.io.Ob...
I've also tried using the fully qualified class name but with no luck. What am I missing?
Which version of SBT are you using? I had similar problems with SBT 0.7.7 and resolved them by adding the following to my build:
// cause the SBT "run" action to fork
override def fork = Some(new ForkScalaRun() {
override def scalaJars = Seq(buildLibraryJar.asFile, buildCompilerJar.asFile)
})
Causing the "run" action to fork seems to resolve class loader problems, and problems with trapping System.exit calls:
http://code.google.com/p/simple-build-tool/wiki/Forking
http://code.google.com/p/simple-build-tool/wiki/RunningProjectCode