problems unit testing my code

"Jay D. Askren" <[email protected]> Thu, 17 Nov 2005 16:57:15 -0500
Newsgroups gmane.comp.db.mckoi
Message-ID <[email protected]>
I'm trying to unit test some code I wrote which works with Mckoi in
embedded mode.  My setup method for the junit testcase is almost
straight from the Database Control Api page:

 

        DefaultDBConfig config = new DefaultDBConfig();

        config.setDatabasePath("dbTest\\");

        config.setLogPath("dbTest\\logs\\");

        DBController control = DBController.getDefault();

        DBSystem session;

        if (control.databaseExists(config)) {

          session = control.startDatabase(config);

        }

        else {

          session = control.createDatabase(config, username, password);

        }

        Connection connection = session.getConnection(username,
password);

        connection.setAutoCommit(false);

       

        // I havev code which creates tables here:

        connection.createStatement().executeUpdate("CREATE TABLE ...");

        .......

 

        // the following works just fine and shows my tables that I
created

        try{

            Statement stmt = connection.createStatement();

            ResultSet results = stmt.executeQuery("SHOW TABLES");

            if(!results.next()){

                System.out.println("Table not created");

            }

            while(results.next()){

                System.out.println(results.getString(1));

            }

        } catch (Exception e){

            

        }

        

        // Close the JDBC connection.

        connection.close();

        

        // Close the database session (frees up the resources)

        session.close();

 

 

Then in my test method, I try to access the tables I created and the
tables have disappeared.

 

My log file looks like this:

 

**** Debug log started: Thu Nov 17 16:38:46 EST 2005 ****

% Storage System: v1 file storage mode.

% Internal Data Cache size:          4194304

% Internal Data Cache max cell size: 8192

% lookup_comparison_list = false

% read_only = false

% transaction_error_on_dirty_select = true

% ignore_case_for_identifiers = false

% Java NIO API is available.

% io_safety_level = 10

% Using stardard IO API for heap buffered file access.

% [Buffer Manager] Using IO API: Java IO

% [Buffer Manager] Page Size: 8192

% [Buffer Manager] Max pages: 256

% Using regex bridge: gnu.regexp

% No 'function_factories' config property found.

% statement_cache = true

% Max worker threads set to: 4

% Starting Database Server

**** Debug log started: Thu Nov 17 16:38:46 EST 2005 ****

% Storage System: v1 file storage mode.

% Internal Data Cache size:          4194304

% Internal Data Cache max cell size: 8192

% lookup_comparison_list = false

% read_only = false

% transaction_error_on_dirty_select = true

% ignore_case_for_identifiers = false

% Java NIO API is available.

% io_safety_level = 10

% Using stardard IO API for heap buffered file access.

% [Buffer Manager] Using IO API: Java IO

% [Buffer Manager] Page Size: 8192

% [Buffer Manager] Max pages: 256

% Using regex bridge: gnu.regexp

% No 'function_factories' config property found.

% statement_cache = true

% Max worker threads set to: 4

% Starting Database Server

> com.mckoi.database.jdbcserver.JDBCDatabaseInterface ( lvl: 20 )

  Couldn't change to 'test_user' schema.

% Dropped: 032APP_url_t

% Dropped: 031APP_consumer_t

% Dropped: 030APP_monitor_t

% Dropped: 029APP_publication_t

% Dropped: 028APP_agent_t

% Dropped: 027APP_document_t

 

 

It seems curious to me that the tables are dropped in the log even
though I never dropped them programmatically.  Any idea what is going on
here?  Why are the tables being dropped, and how do I get them to stay
around long enough to do my unit testing. 

 

Also, where can I find the javadoc for Mckoi?   

 

Finally, if I have more than one test method in my testcase, I get the
following error:

 

> com.mckoi.database.DatabaseSystem ( lvl: 40 )

  Error starting buffer manager

[com.mckoi.debug.Debug - Exception thrown: 'Journal file already
exists.']

java.io.IOException: Journal file already exists.

 

 

How do people usually handle unit tests with Mckoi?

 

 

Jay Askren

Software Developer

Quantum Leap Innovations