Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 327604

Summary: Legacy fails in CDOWorkspace test cases
Product: [Modeling] EMF Reporter: Martin Fluegge <martin.fluegge>
Component: cdo.legacyAssignee: Martin Fluegge <martin.fluegge>
Status: CLOSED FIXED QA Contact: Eike Stepper <stepper>
Severity: normal    
Priority: P3 Flags: stepper: review+
Version: 4.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Test v1
none
Patch v1 none

Description Martin Fluegge CLA 2010-10-12 15:26:41 EDT
Some legacy tests are failing while executing org.eclipse.emf.cdo.tests.WorkspaceTest.java. 

10 tests are failing because the number of converted objects is wrong. The legacy wrapper doesn not seem to read out all objects.

Two tests are failing with an ObjectNotFoundException

org.eclipse.emf.cdo.tests.config.impl.ConfigTestException: Error in WorkspaceTest.testLocalChangesAfterDetach2 [Combined, MEM, JVM, Legacy]
	at org.eclipse.emf.cdo.tests.config.impl.ConfigTest.runBare(ConfigTest.java:466)
	at junit.framework.TestResult$1.protect(TestResult.java:110)
	at junit.framework.TestResult.runProtected(TestResult.java:128)
	at junit.framework.TestResult.run(TestResult.java:113)
	at junit.framework.TestCase.run(TestCase.java:124)
	at org.eclipse.net4j.util.tests.AbstractOMTest.run(AbstractOMTest.java:196)
	at junit.framework.TestSuite.runTest(TestSuite.java:232)
	at junit.framework.TestSuite.run(TestSuite.java:227)
	at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.eclipse.emf.cdo.util.ObjectNotFoundException: Object OID13 not found in branch 0 at *
	at org.eclipse.emf.internal.cdo.view.AbstractCDOView.createObject(AbstractCDOView.java:826)
	at org.eclipse.emf.internal.cdo.view.AbstractCDOView.getObject(AbstractCDOView.java:709)
	at org.eclipse.emf.internal.cdo.transaction.CDOTransactionImpl.getObject(CDOTransactionImpl.java:996)
	at org.eclipse.emf.internal.cdo.view.AbstractCDOView.getObject(AbstractCDOView.java:658)
	at org.eclipse.emf.internal.cdo.view.AbstractCDOView.getObject(AbstractCDOView.java:1)
	at org.eclipse.emf.internal.cdo.CDOLegacyWrapper.getValueFromRevision(CDOLegacyWrapper.java:683)
	at org.eclipse.emf.internal.cdo.CDOLegacyWrapper.cdoInternalPostDetach(CDOLegacyWrapper.java:204)
	at org.eclipse.emf.internal.cdo.CDOStateMachine.detach(CDOStateMachine.java:280)
	at org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl.detached(CDOResourceImpl.java:1037)
	at org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl$ContentsCDOList.inverseRemove(CDOResourceImpl.java:1281)
	at org.eclipse.emf.common.notify.impl.DelegatingNotifyingListImpl.remove(DelegatingNotifyingListImpl.java:731)
	at org.eclipse.emf.common.util.AbstractEList$EIterator.remove(AbstractEList.java:740)
	at org.eclipse.emf.cdo.tests.WorkspaceTest.testLocalChangesAfterDetach2(WorkspaceTest.java:588)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at junit.framework.TestCase.runTest(TestCase.java:168)
	at org.eclipse.net4j.util.tests.AbstractOMTest.runBare(AbstractOMTest.java:150)
	at org.eclipse.emf.cdo.tests.config.impl.ConfigTest.runBare(ConfigTest.java:457)
	... 14 more
Comment 1 Martin Fluegge CLA 2010-10-13 14:10:23 EDT
Created attachment 180809 [details]
Test v1

I had a quick look and found out two interesting things:

1.) If the OrderDetail is not attached to the Product the test passes
2.) If the products are added to the resource after all other objects the test passes (even if the Product is attached to the OrderDetail)

So it seems that there is something wrong in the relationship between SalesOrder, Product and OderDetail.

I attached a smaller version of the WorkSpaceTest to make debugging easier. 

Investigation is ongoing...
Comment 2 Martin Fluegge CLA 2010-10-13 15:28:23 EDT
Created attachment 180816 [details]
Patch v1

O.k. Here?s the answer:

First, the resource created a Product. This led to the creation of an OrderDetail while the "oderdetails" feature was processed. This again created a SalesOrder (always talking about *.Impl) while setting the OrderDetails container feature. During the process of the SalesOrder the OrderDetails was set to the related containment feature. Everything is correct now, but remember that the OrderDetail is not yet finished. After creating a customer on the SalesOrder the SalesOrder was finished and returned to the OrderDetail and the container set. Still no problem. 

Now comes the fun part. 

When the OrderDetail set the "order" containment reference (our SalesOrder) by calling inverseAdd(?) the method call simply removed the OrderDetail from it?s container

So the answer is: Do not add the container if it is already attached.

I attached a patch to fix the problem.
Comment 3 Eike Stepper CLA 2010-10-16 02:13:59 EDT
You fixed it ;-)
Comment 4 Martin Fluegge CLA 2010-10-16 06:02:11 EDT
Committed to HEAD.
Comment 5 Eike Stepper CLA 2011-06-23 03:37:29 EDT
Available in R20110608-1407