This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 75204 - Some tests of the db module fail
Summary: Some tests of the db module fail
Status: RESOLVED FIXED
Alias: None
Product: db
Classification: Unclassified
Component: Code (show other bugs)
Version: 5.x
Hardware: All All
: P3 blocker (vote)
Assignee: Andrei Badea
URL:
Keywords: RANDOM, TEST
Depends on:
Blocks: 76922 117894
  Show dependency tree
 
Reported: 2006-04-19 10:12 UTC by Andrei Badea
Modified: 2008-09-20 05:31 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Log (8.93 KB, text/plain)
2006-04-19 10:19 UTC, Andrei Badea
Details
New log (6.20 KB, text/html)
2006-07-10 09:25 UTC, Andrei Badea
Details
Stack trace for first thread calling JDBCDriverConverter.getEnvironment() (2.45 KB, text/plain)
2008-01-15 22:57 UTC, David Vancouvering
Details
Second thread calling JDBCDriverConverter.getEnvironment() (1.78 KB, text/plain)
2008-01-15 22:57 UTC, David Vancouvering
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrei Badea 2006-04-19 10:12:30 UTC
In the 200604180200 daily run.
Comment 1 Andrei Badea 2006-04-19 10:19:59 UTC
Created attachment 29921 [details]
Log
Comment 2 Andrei Badea 2006-04-19 10:33:37 UTC
I don't understand why this happens, the tests pass on my machine.
Comment 3 Andrei Badea 2006-04-19 15:29:13 UTC
The cause of the fail is that the DataObject-s for the JDBCDriver instances are
garbage-collected. FolderLookup does not even send resultChanged events for the
new drivers unless allInstances() has been called on the result. Even after
obtaining a collection containing the newly added drivers by calling
allInstances() on the result in the resultChanged() event, it seems the
DataObject-s can still be garbage-collected afterwards. When newInstance() is
called again, new DataObject-s and new JDBCDriver-s are created, thus this fail.

Disabling the failing test and downgrading to P3, since this has no user impact.

Checking in cfg-unit.xml;
/cvs/db/test/cfg-unit.xml,v  <--  cfg-unit.xml
new revision: 1.2.22.1; previous revision: 1.2
done
Comment 4 Andrei Badea 2006-04-19 15:34:00 UTC
Adding a (failing for now) test to assert that the same instances are retrieved
from JDBCDriverManager that were added to it.

Checking in cfg-unit.xml;
/cvs/db/test/cfg-unit.xml,v  <--  cfg-unit.xml
new revision: 1.2.22.2; previous revision: 1.2.22.1
done
RCS file:
/cvs/db/test/unit/src/org/netbeans/api/db/explorer/Attic/JDBCDriverManagerTest.java,v
done
Checking in unit/src/org/netbeans/api/db/explorer/JDBCDriverManagerTest.java;
/cvs/db/test/unit/src/org/netbeans/api/db/explorer/Attic/JDBCDriverManagerTest.java,v
 <--  JDBCDriverManagerTest.java
new revision: 1.1.2.1; previous revision: 1.1
done
Comment 5 Andrei Badea 2006-06-23 18:07:17 UTC
Simplifying the test and showing the driver's data object can indeed be GC'd.

Checking in test/unit/src/org/netbeans/api/db/explorer/JDBCDriverManagerTest.java;
/cvs/db/test/unit/src/org/netbeans/api/db/explorer/Attic/JDBCDriverManagerTest.java,v
 <--  JDBCDriverManagerTest.java
new revision: 1.1.2.2; previous revision: 1.1.2.1
done
Comment 6 Andrei Badea 2006-06-26 17:23:48 UTC
Hopefully fixed.

Checking in src/org/netbeans/api/db/explorer/JDBCDriverManager.java;
/cvs/db/src/org/netbeans/api/db/explorer/JDBCDriverManager.java,v  <-- 
JDBCDriverManager.java
new revision: 1.2.22.1; previous revision: 1.2
done
Checking in test/cfg-unit.xml;
/cvs/db/test/cfg-unit.xml,v  <--  cfg-unit.xml
new revision: 1.2.22.3; previous revision: 1.2.22.2
done
Checking in test/unit/src/org/netbeans/api/db/explorer/JDBCDriverManagerTest.java;
/cvs/db/test/unit/src/org/netbeans/api/db/explorer/Attic/JDBCDriverManagerTest.java,v
 <--  JDBCDriverManagerTest.java
new revision: 1.1.2.3; previous revision: 1.1.2.2
done
Comment 7 Andrei Badea 2006-07-10 09:24:10 UTC
Happened again.
Comment 8 Andrei Badea 2006-07-10 09:25:15 UTC
Created attachment 31699 [details]
New log
Comment 9 Andrei Badea 2007-02-14 12:00:59 UTC
Still failing randomly on my machine.
Comment 10 Andrei Badea 2007-07-30 15:47:19 UTC
When adding the following line to JDBCDriverConvertor

System.out.println("Getting environment for DataObject " + System.identityHashCode(obj));

when the test fails this line is printed twice, each time with a different identity hash code. When the test passes it
is only printed once.
Comment 11 Andrei Badea 2007-07-30 17:11:31 UTC
Making a change that causes the test to fail more often, if not always.

Checking in JDBCDriverManagerTest.java;
/cvs/db/test/unit/src/org/netbeans/api/db/explorer/JDBCDriverManagerTest.java,v  <--  JDBCDriverManagerTest.java
new revision: 1.4; previous revision: 1.3
done
Comment 12 Andrei Badea 2007-07-30 17:13:48 UTC
Yarda promised to look at it.
Comment 13 Andrei Badea 2007-07-30 17:23:02 UTC
BTW the line mentioned in desc11 is added to JDBCDriverConvertor.getEnvironment().
Comment 14 Jaroslav Tulach 2007-08-29 12:21:51 UTC
I have rewritten the tests to use core/startup



IDE:-------------------------------------------------
IDE: [29.8.07 13:20] Committing started
Checking in test/unit/src/org/netbeans/api/db/explorer/JDBCDriverManagerTest.java;
/shared/data/ccvs/repository/db/test/unit/src/org/netbeans/api/db/explorer/JDBCDriverManagerTest.java,v  <--  
JDBCDriverManagerTest.java
new revision: 1.5; previous revision: 1.4
done
Checking in test/unit/src/org/netbeans/api/db/explorer/DatabaseConnectionTest.java;
/shared/data/ccvs/repository/db/test/unit/src/org/netbeans/api/db/explorer/DatabaseConnectionTest.java,v  <--  
DatabaseConnectionTest.java
new revision: 1.3; previous revision: 1.2
done
Checking in nbproject/project.xml;
/shared/data/ccvs/repository/db/nbproject/project.xml,v  <--  project.xml
new revision: 1.22; previous revision: 1.21
done
Checking in test/unit/src/org/netbeans/modules/db/test/TestBase.java;
/shared/data/ccvs/repository/db/test/unit/src/org/netbeans/modules/db/test/TestBase.java,v  <--  TestBase.java
new revision: 1.7; previous revision: 1.6
done
Checking in test/unit/src/org/netbeans/modules/db/test/Util.java;
/shared/data/ccvs/repository/db/test/unit/src/org/netbeans/modules/db/test/Util.java,v  <--  Util.java
new revision: 1.3; previous revision: 1.2
done
Checking in test/unit/src/org/netbeans/modules/db/explorer/driver/JDBCDriverConvertorTest.java;
/shared/data/ccvs/repository/db/test/unit/src/org/netbeans/modules/db/explorer/driver/JDBCDriverConvertorTest.java,v  
<--  JDBCDriverConvertorTest.java
new revision: 1.9; previous revision: 1.8
done
Checking in test/unit/src/org/netbeans/modules/db/explorer/DatabaseConnectionConvertorTest.java;
/shared/data/ccvs/repository/db/test/unit/src/org/netbeans/modules/db/explorer/DatabaseConnectionConvertorTest.java,v  
<--  DatabaseConnectionConvertorTest.java
new revision: 1.8; previous revision: 1.7
done
Checking in src/org/netbeans/modules/db/explorer/driver/JDBCDriverConvertor.java;
/shared/data/ccvs/repository/db/src/org/netbeans/modules/db/explorer/driver/JDBCDriverConvertor.java,v  <--  
JDBCDriverConvertor.java
new revision: 1.19; previous revision: 1.18
done
IDE: [29.8.07 13:21] Committing finished
Comment 15 Andrei Badea 2007-10-05 12:51:11 UTC
Seems it the DataObject of the new driver can still be garbage-collected before someone calls allInstances() on the
respective Lookup.Result.

Checking in JDBCDriverManagerTest.java;
/cvs/db/test/unit/src/org/netbeans/api/db/explorer/JDBCDriverManagerTest.java,v  <--  JDBCDriverManagerTest.java
new revision: 1.8; previous revision: 1.7
done
Comment 16 Andrei Badea 2007-10-05 13:44:18 UTC
Added the same tests for connections too.

Checking in test/unit/src/org/netbeans/modules/db/explorer/ConnectionListTest.java;
/cvs/db/test/unit/src/org/netbeans/modules/db/explorer/ConnectionListTest.java,v  <--  ConnectionListTest.java
initial revision: 1.1
done
Comment 17 David Vancouvering 2008-01-09 22:52:11 UTC
This doesn't appear to be happening any more.  Marking as fixed.  Andrei, please reopen if this is still an issue.
Comment 18 Andrei Badea 2008-01-14 16:17:41 UTC
JDBCDriverManagerTest just failed on my computer.
Comment 19 David Vancouvering 2008-01-15 22:52:57 UTC
When I run this in the debugger, I see two threads running pretty much simultaneously, and it appears they are both
creating a DataObject for the JDBCDriver.  I put a breakpoint in JDBCDriverConverter.getEnvironment() and I hit it twice.

Each time I hit it, I copied the stack trace.  I am including both stack traces as attachments.  In one case the source
is  JDBCDriverConverter$AtomicWriter.run() which calls XMLDataObject.getCookie().  In the other case the source is
FolderList$ListTask which is running postCreationTask(), which calls
defaultProcessObjects->acceptDataObject->XMLDataObject.getCookie().

So what we end up with are two different data objects, one after the other.  This causes the JDBCDriverManagerTest to
fail at assertSame() because the driver it created is not the same one that ends up being ultimately stored in the
FileObject tree.  The same thing is happening with the ConnectionListTest.

I'm not sure how this is related to garbage collection.  I don't quite understand the test, because is does assertGC()
which shows that the data object *can* be garbage collected, which would imply to me that it's possible for a new
instance to be created and thus assertSame() will fail.  Perhaps Andrei can shed some light on this?

It doesn't help that I have no idea what getEnvironment() does or how it's used.  The FileObject system is still a bit
like black magic to me.  
Comment 20 David Vancouvering 2008-01-15 22:55:41 UTC
I consider failing unit tests a P2.
Comment 21 David Vancouvering 2008-01-15 22:57:25 UTC
Created attachment 55100 [details]
Stack trace for first thread calling JDBCDriverConverter.getEnvironment()
Comment 22 David Vancouvering 2008-01-15 22:57:55 UTC
Created attachment 55101 [details]
Second thread calling JDBCDriverConverter.getEnvironment()
Comment 23 David Vancouvering 2008-01-15 22:59:08 UTC
I want to add a note that when I tried Thread.dumpStack() in the code, the two stack traces from the two threads
overlayed each other in the output.  I'm not sure if that's relevant...
Comment 24 David Vancouvering 2008-01-16 01:37:59 UTC
It looks like the second thread is called by a task that is run when a property change event is filed on the folder
containing the JDBC driver.  

Further investigation seems to indicate that the DataObject has been changed, but I'm not sure why.

One odd other note: the last debug run, the assertGC() failed.  Every other time it has passed.  I'm a bit flummoxed.
Comment 25 David Vancouvering 2008-01-16 01:41:32 UTC
My *suspicion*, although I don't have data to confirm it yet, is the performance improvements being made for 6.1 in the
FileSystem code have invalidated the assumption that allInstances() creates strong references to the DataObjects, and so
the fix to this bug no longer works.
Comment 26 David Vancouvering 2008-01-17 01:23:20 UTC
I talked with Andrei about this.  He believes this issue has always been there, but I didn't used to see it when I ran
tests, so I think something has changed since 6.0.

Our discussion also convinced me that it's a P3 since it's not user-visible and covers a timing edge case.  But the
issue ultimately is in openide, so I'm moving it over to that component too.
Comment 27 David Vancouvering 2008-01-17 04:35:04 UTC
Commented out assertSame() test in ConnectionListTest and JDBCDriverManagerTest.  When this is fixed, these lines should
be put back in.  Hopefully this won't get missed.
Comment 28 Lukas Hasik 2008-04-10 21:15:15 UTC
moving opened issues from TM <= 6.1 to TM=Dev
Comment 29 Jaroslav Tulach 2008-08-05 11:00:54 UTC
Does the test still fails? Do you have some machine where they are executed daily? Thanks.
Comment 30 David Vancouvering 2008-08-05 16:58:13 UTC
Hey, Jarda.  The test that gets this failure was commented out because it was causing distractions for us and this issue
had been on your queue for some time.

If you want to see if the test still fails, uncomment the code that was commented out with the label 75204

in db/test/src/org/netbeans/api/db/explorer/JDBCDriverManagerTest.java and
db/test/src/org/netbeans/modules/db/explorer/ConnectionListTest.java

They still fail for me
Comment 31 David Vancouvering 2008-08-05 22:14:14 UTC
Still fails for me
Comment 32 Andrei Badea 2008-09-19 16:54:24 UTC
The problem is that although the convertor was trying to recognize the DataObject inside the writer atomic action, the
DataObject was not noticed by the recognized thread until the respective file change event was sent. This could cause
the DO to be garbage-collected and recognized again by the recognized thread, but that was too late to match the DO with
the original instance.
Comment 33 Andrei Badea 2008-09-19 16:55:49 UTC
#a0b670a984b7
Comment 34 Quality Engineering 2008-09-20 05:31:56 UTC
Integrated into 'main-golden', will be available in build *200809200201* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/a0b670a984b7
User: Andrei Badea <abadea@netbeans.org>
Log: #75204: Some tests of the db module fail