1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
/*-------------------------------------------------------------------------
*
* Copyright (c) 2004-2008, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/MiscTest.java,v 1.22 2008/01/08 06:56:31 jurka Exp $
*
*-------------------------------------------------------------------------
*/
package org.postgresql.test.jdbc2;
import org.postgresql.test.TestUtil;
import junit.framework.TestCase;
import java.sql.*;
import java.io.*;
/*
* Some simple tests based on problems reported by users. Hopefully these will
* help prevent previous problems from re-occuring ;-)
*
*/
public class MiscTest extends TestCase
{
public MiscTest(String name)
{
super(name);
}
/*
* Some versions of the driver would return rs as a null?
*
* Sasha <ber0806@iperbole.bologna.it> was having this problem.
*
* Added Feb 13 2001
*/
public void testDatabaseSelectNullBug() throws Exception
{
Connection con = TestUtil.openDB();
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select datname from pg_database");
assertNotNull(rs);
while (rs.next())
{
rs.getString(1);
}
rs.close();
st.close();
TestUtil.closeDB(con);
}
/**
* Ensure the cancel call does not return before it has completed.
* Previously it did which cancelled future queries.
*/
public void testSingleThreadCancel() throws Exception
{
Connection con = TestUtil.openDB();
Statement stmt = con.createStatement();
for (int i=0; i<100; i++) {
ResultSet rs = stmt.executeQuery("SELECT 1");
rs.close();
stmt.cancel();
}
TestUtil.closeDB(con);
}
public void testError() throws Exception
{
Connection con = TestUtil.openDB();
try
{
// transaction mode
con.setAutoCommit(false);
Statement stmt = con.createStatement();
stmt.execute("select 1/0");
fail( "Should not execute this, as a SQLException s/b thrown" );
con.commit();
}
catch ( SQLException ex )
{
// Verify that the SQLException is serializable.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(ex);
oos.close();
}
con.commit();
con.close();
}
public void testWarning() throws Exception
{
Connection con = TestUtil.openDB();
Statement stmt = con.createStatement();
stmt.execute("CREATE TEMP TABLE t(a int primary key)");
SQLWarning warning = stmt.getWarnings();
// We should get a warning about primary key index creation
// it's possible we won't depending on the server's
// client_min_messages setting.
while (warning != null) {
// Verify that the SQLWarning is serializable.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(warning);
oos.close();
warning = warning.getNextWarning();
}
stmt.close();
con.close();
}
public void xtestLocking() throws Exception
{
Connection con = TestUtil.openDB();
Connection con2 = TestUtil.openDB();
TestUtil.createTable(con, "test_lock", "name text");
Statement st = con.createStatement();
Statement st2 = con2.createStatement();
con.setAutoCommit(false);
st.execute("lock table test_lock");
st2.executeUpdate( "insert into test_lock ( name ) values ('hello')" );
con.commit();
TestUtil.dropTable(con, "test_lock");
con.close();
con2.close();
}
}
|