You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "Julius.Stroffek" <Ju...@Sun.COM> on 2006/11/13 11:26:34 UTC

openConnection dissapeared from BaseJDBCTestCase.java

Hi All,

I prepared a patch for DERBY-1434 with a test. I wanted to submit it 
today, however when updated a trunk to the most recent version, the method

openConnection(String databaseName)

disaperead from the BaseJDBCTestCase.java.

I need to create two connections to different databases in a test so the 
openDefaultConnection() method is notsufficient. I think that probably 
no tests used this method. How should I create these connections today? 
Should I create the missing openConnection method?

Cheers

Julo

Re: openConnection dissapeared from BaseJDBCTestCase.java

Posted by "Julius.Stroffek" <Ju...@Sun.COM>.
Just posting the corresponding test function:
---

    public void testMultipleConnections() throws Exception {
        Connection conn1 = openConnection("FIRSTDB1");
        conn1.setAutoCommit(false);
        Statement st = conn1.createStatement();
        st.execute("create table FIRSTDB_T1 (i int, j int, k int)");
        st.execute("insert into FIRSTDB_T1 values (1, 3, 5)");
        PreparedStatement pSt1 =
                conn1.prepareStatement("select * from FIRSTDB_T1");
        ResultSet rs1 = pSt1.executeQuery();
        rs1.next();
        rs1.close();
       
        Connection conn2 = openConnection("SECONDDB2");
        conn2.setAutoCommit(false);
        Statement st2 = conn2.createStatement();
        st2.execute("create table SECONDDB_T1 (i int, j int, k int)");
        st2.execute("insert into SECONDDB_T1 values (2, 4, 6)");
        PreparedStatement pSt2 =
                conn2.prepareStatement("select * from SECONDDB_T1");
       
        rs1 = pSt2.executeQuery();
        rs1.next();
        rs1.close();
       
        conn1.rollback();
        conn1.close();
        conn2.rollback();
        conn2.close();
    }
 
Julius.Stroffek wrote:
> Hi All,
>
> I prepared a patch for DERBY-1434 with a test. I wanted to submit it 
> today, however when updated a trunk to the most recent version, the 
> method
>
> openConnection(String databaseName)
>
> disaperead from the BaseJDBCTestCase.java.
>
> I need to create two connections to different databases in a test so 
> the openDefaultConnection() method is notsufficient. I think that 
> probably no tests used this method. How should I create these 
> connections today? Should I create the missing openConnection method?
>
> Cheers
>
> Julo


Re: openConnection dissapeared from BaseJDBCTestCase.java

Posted by "Julius.Stroffek" <Ju...@Sun.COM>.
Daniel John Debrunner wrote:
> Julius.Stroffek wrote:
>
>> I have created a patch for DERBY-1434 where the test does not clean 
>> the databases. Would it be alright to add the patch to trunk and 
>> resolve database cleaning issue as a part of DERBY-2087?
>
> I think that's fine.
>
> I looked at the issue but it wasn't obvious to me what your change was 
> doing, I didn't see any description in the Jira comments. But then I 
> don't know that code area.
>
> Dan.
>
The relevant change is only that I removed static modifier from fields 
noHoldPKGNAMCBytes and holdPKGNAMCBytes of the 
org.apache.derby.client.am.SectionManager class. The reasons for doing 
this are discussed in comments of DERBY-1434. This change itself should 
not affect behavior of derby because the database name in PKGNAMCSN is 
only used for hashing. It makes the server traces only more readable.

All other changes deal with tests only (discussed in 
http://www.nabble.com/DERBY-1434---Client-can-send-incorrect-database-name-to-server-after-having-made-multiple-connections-to-different-databases.-tf2389323.html#a6705919). 
I added a test to parsePKGNAMCSN function that the database specified in 
RDBNAM of PKGNAMCSN was specified correctly (used only when the client 
version is >= 10.3.0, because the clients lower than this will send 
wrong RDBNAM).

I added two tests:

1.) A check that the error of wrong RDBNAM of PKGNAMCSN is handled 
correctly. This was added to "protocol.tests" file.
2.) A check that two connections to different databases on the same 
derby instance are handled correctly. The derbynet/DRDAProtocolTest.java.

Then I have to change the RDBNAM codepoint of PKGNAMCSN term in most 
places in "protocol.tests" because it was not specified correctly. I 
changed it from 'test' to 'wombat'. This caused the patch to grow in size.

Thank you for reviewing a change.

Julo


Re: openConnection dissapeared from BaseJDBCTestCase.java

Posted by Daniel John Debrunner <dj...@apache.org>.
Julius.Stroffek wrote:

> I have created a patch for DERBY-1434 where the test does not clean the 
> databases. Would it be alright to add the patch to trunk and resolve 
> database cleaning issue as a part of DERBY-2087?

I think that's fine.

I looked at the issue but it wasn't obvious to me what your change was 
doing, I didn't see any description in the Jira comments. But then I 
don't know that code area.

Dan.


Re: openConnection dissapeared from BaseJDBCTestCase.java

Posted by "Julius.Stroffek" <Ju...@Sun.COM>.
Daniel John Debrunner wrote:
> Julius.Stroffek wrote:
>> Daniel John Debrunner wrote:
>>> I just added a utility method
>>>
>>> JDBCDataSource.getDataSource(String dbName)
>>>
>>> to obtain a connection to a different database, eg.
>>>
>>> ds = JDBCDataSource.getDataSource("otherdb");
>>> conn = ds.getConnection();
>
>> Would it be possible to create a test which passes some attributes to 
>> JDBC connection? I have not found anything related to this.
>
> Once you have the DataSource for the database then you can set any 
> attributes or DataSource properties you need.
>
> JDBCDataSource.getDataSource(); // default database
> JDBCDataSource.getDataSource("otherdb"); // specific database
>
>
> Dan.
>
I have created a patch for DERBY-1434 where the test does not clean the 
databases. Would it be alright to add the patch to trunk and resolve 
database cleaning issue as a part of DERBY-2087?

Cheers

Julo

Re: openConnection dissapeared from BaseJDBCTestCase.java

Posted by Daniel John Debrunner <dj...@apache.org>.
Julius.Stroffek wrote:
> Daniel John Debrunner wrote:
>> I just added a utility method
>>
>> JDBCDataSource.getDataSource(String dbName)
>>
>> to obtain a connection to a different database, eg.
>>
>> ds = JDBCDataSource.getDataSource("otherdb");
>> conn = ds.getConnection();

> Would it be possible to create a test which passes some attributes to 
> JDBC connection? I have not found anything related to this.

Once you have the DataSource for the database then you can set any 
attributes or DataSource properties you need.

JDBCDataSource.getDataSource(); // default database
JDBCDataSource.getDataSource("otherdb"); // specific database


Dan.


Re: openConnection dissapeared from BaseJDBCTestCase.java

Posted by "Julius.Stroffek" <Ju...@Sun.COM>.
Daniel John Debrunner wrote:
> I just added a utility method
>
> JDBCDataSource.getDataSource(String dbName)
>
> to obtain a connection to a different database, eg.
>
> ds = JDBCDataSource.getDataSource("otherdb");
> conn = ds.getConnection();
Thanks, Dan.

> With a test that needs concurrent multiple open databases some thought 
> on the setup is needed to ensure the extra databases are created 
> and/or cleaned and shutdown at the end of the test. If multiple tests 
> simply created their own databases and left them lying around then it 
> would cause issues eventually.
How this should by done?

Would it be possible to create a test which passes some attributes to 
JDBC connection? I have not found anything related to this.

Cheers

Julo

Re: openConnection dissapeared from BaseJDBCTestCase.java

Posted by Daniel John Debrunner <dj...@apache.org>.
Julius.Stroffek wrote:
> Hi All,
> 
> I prepared a patch for DERBY-1434 with a test. I wanted to submit it 
> today, however when updated a trunk to the most recent version, the method
> 
> openConnection(String databaseName)
> 
> disaperead from the BaseJDBCTestCase.java.
> 
> I need to create two connections to different databases in a test so the 
> openDefaultConnection() method is notsufficient. I think that probably 
> no tests used this method. How should I create these connections today? 
> Should I create the missing openConnection method?

I just added a utility method

JDBCDataSource.getDataSource(String dbName)

to obtain a connection to a different database, eg.

ds = JDBCDataSource.getDataSource("otherdb");
conn = ds.getConnection();

I'm using it for the database class loading test to obtain a connection 
to a database contained in a jar file.

The current setup is focused on a single database, I did a while back 
add a decorator to switch the default database & connection to a 
different "single use" database 
(TestConfiguration.singleUseDatabaseDecorator).

With a test that needs concurrent multiple open databases some thought 
on the setup is needed to ensure the extra databases are created and/or 
cleaned and shutdown at the end of the test. If multiple tests simply 
created their own databases and left them lying around then it would 
cause issues eventually.

Dan.