~ubuntu-branches/ubuntu/maverick/libpgjava/maverick

« back to all changes in this revision

Viewing changes to src/interfaces/jdbc/org/postgresql/test/jdbc2/optional/PoolingDataSourceTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Vandyck
  • Date: 2006-04-25 00:07:07 UTC
  • mfrom: (1.3.1 upstream) (3.1.1 dapper)
  • Revision ID: james.westby@ubuntu.com-20060425000707-6lr2s0awuz4z48hm
* Drop support for the old jdbc2 driver (can be reverted if wanted)
  (closes: #358345).
* New upstream (thanks to Wolfgang Baer).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.postgresql.test.jdbc2.optional;
2
 
 
3
 
import java.sql.SQLException;
4
 
import java.sql.Statement;
5
 
import org.postgresql.test.TestUtil;
6
 
import org.postgresql.jdbc2.optional.PoolingDataSource;
7
 
import org.postgresql.jdbc2.optional.BaseDataSource;
8
 
 
9
 
/**
10
 
 * Minimal tests for pooling DataSource.  Needs many more.
11
 
 *
12
 
 * @author Aaron Mulder (ammulder@chariotsolutions.com)
13
 
 * @version $Revision: 1.1.6.2 $
14
 
 */
15
 
public class PoolingDataSourceTest extends BaseDataSourceTest
16
 
{
17
 
    private final static String DS_NAME = "JDBC 2 SE Test DataSource";
18
 
 
19
 
    /**
20
 
     * Constructor required by JUnit
21
 
     */
22
 
    public PoolingDataSourceTest(String name)
23
 
    {
24
 
        super(name);
25
 
    }
26
 
 
27
 
    protected void tearDown() throws Exception
28
 
    {
29
 
        super.tearDown();
30
 
        if (bds instanceof PoolingDataSource)
31
 
        {
32
 
            ((PoolingDataSource) bds).close();
33
 
        }
34
 
    }
35
 
 
36
 
    /**
37
 
     * Creates and configures a new SimpleDataSource.
38
 
     */
39
 
    protected void initializeDataSource()
40
 
    {
41
 
        if (bds == null)
42
 
        {
43
 
            bds = new PoolingDataSource();
44
 
            bds.setServerName(TestUtil.getServer());
45
 
            bds.setPortNumber(TestUtil.getPort());
46
 
            bds.setDatabaseName(TestUtil.getDatabase());
47
 
            bds.setUser(TestUtil.getUser());
48
 
            bds.setPassword(TestUtil.getPassword());
49
 
            ((PoolingDataSource) bds).setDataSourceName(DS_NAME);
50
 
            ((PoolingDataSource) bds).setInitialConnections(2);
51
 
            ((PoolingDataSource) bds).setMaxConnections(10);
52
 
        }
53
 
    }
54
 
 
55
 
    /**
56
 
     * In this case, we *do* want it to be pooled.
57
 
     */
58
 
    public void testNotPooledConnection()
59
 
    {
60
 
        try
61
 
        {
62
 
            con = getDataSourceConnection();
63
 
            String name = con.toString();
64
 
            con.close();
65
 
            con = getDataSourceConnection();
66
 
            String name2 = con.toString();
67
 
            con.close();
68
 
            assertTrue("Pooled DS doesn't appear to be pooling connections!", name.equals(name2));
69
 
        }
70
 
        catch (SQLException e)
71
 
        {
72
 
            fail(e.getMessage());
73
 
        }
74
 
    }
75
 
 
76
 
    /**
77
 
     * In this case, the desired behavior is dereferencing.
78
 
     */
79
 
    protected void compareJndiDataSource(BaseDataSource oldbds, BaseDataSource bds)
80
 
    {
81
 
        assertTrue("DataSource was serialized or recreated, should have been dereferenced", bds == oldbds);
82
 
    }
83
 
 
84
 
    /**
85
 
     * Check that 2 DS instances can't use the same name.
86
 
     */
87
 
    public void testCantReuseName()
88
 
    {
89
 
        initializeDataSource();
90
 
        PoolingDataSource pds = new PoolingDataSource();
91
 
        try
92
 
        {
93
 
            pds.setDataSourceName(DS_NAME);
94
 
            fail("Should have denied 2nd DataSource with same name");
95
 
        }
96
 
        catch (IllegalArgumentException e)
97
 
        {
98
 
        }
99
 
    }
100
 
 
101
 
    /**
102
 
     * Closing a Connection twice is not an error.
103
 
     */
104
 
    public void testDoubleConnectionClose() throws SQLException
105
 
    {
106
 
        con = getDataSourceConnection();
107
 
        con.close();
108
 
        con.close();
109
 
    }
110
 
 
111
 
    /**
112
 
     * Closing a Statement twice is not an error.
113
 
     */
114
 
    public void testDoubleStatementClose() throws SQLException
115
 
    {
116
 
        con = getDataSourceConnection();
117
 
        Statement stmt = con.createStatement();
118
 
        stmt.close();
119
 
        stmt.close();
120
 
        con.close();
121
 
    }
122
 
}