/*- * See the file LICENSE for redistribution information. * * Copyright (c) 2000 * Sleepycat Software. All rights reserved. * * $Id: TestConstruct02.java,v 1.3 2001/10/05 02:36:09 bostic Exp $ */ /* * Do some regression tests for constructors. * Run normally (without arguments) it is a simple regression test. * Run with a numeric argument, it repeats the regression a number * of times, to try to determine if there are memory leaks. */ package com.sleepycat.test; import com.sleepycat.db.*; import java.io.File; import java.io.IOException; import java.io.FileNotFoundException; public class TestConstruct02 { public static final String CONSTRUCT02_DBNAME = "construct02.db"; public static final String CONSTRUCT02_DBDIR = "./"; public static final String CONSTRUCT02_DBFULLPATH = CONSTRUCT02_DBDIR + "/" + CONSTRUCT02_DBNAME; private int itemcount; // count the number of items in the database public static boolean verbose_flag = false; private DbEnv dbenv = new DbEnv(0); public TestConstruct02() throws DbException, FileNotFoundException { dbenv.open(CONSTRUCT02_DBDIR, Db.DB_CREATE | Db.DB_INIT_MPOOL, 0666); } public void close() { try { dbenv.close(0); removeall(true, true); } catch (DbException dbe) { ERR("DbException: " + dbe); } } public static void ERR(String a) { System.out.println("FAIL: " + a); sysexit(1); } public static void DEBUGOUT(String s) { System.out.println(s); } public static void VERBOSEOUT(String s) { if (verbose_flag) System.out.println(s); } public static void sysexit(int code) { System.exit(code); } private static void check_file_removed(String name, boolean fatal, boolean force_remove_first) { File f = new File(name); if (force_remove_first) { f.delete(); } if (f.exists()) { if (fatal) System.out.print("FAIL: "); System.out.print("File \"" + name + "\" still exists after run\n"); if (fatal) sysexit(1); } } // Check that key/data for 0 - count-1 are already present, // and write a key/data for count. The key and data are // both "0123...N" where N == count-1. // void rundb(Db db, int count) throws DbException, FileNotFoundException { // The bit map of keys we've seen long bitmap = 0; // The bit map of keys we expect to see long expected = (1 << (count+1)) - 1; byte outbuf[] = new byte[count+1]; int i; for (i=0; i count) { ERR("reread length is bad: expect " + count + " got "+ len + " (" + key_string + ")" ); } else if (!data_string.equals(key_string)) { ERR("key/data don't match"); } else if ((bitmap & bit) != 0) { ERR("key already seen"); } else if ((expected & bit) == 0) { ERR("key was not expected"); } else { bitmap |= bit; expected &= ~(bit); for (i=0; i= '0' && ch <= '9') { mask |= (1 << (ch - '0')); } else if (ch == 'v') { verbose_flag = true; } else { ERR("Usage: construct02 [-testdigits] count"); } } System.out.println("mask = " + mask); } else { try { iterations = Integer.parseInt(arg); if (iterations < 0) { ERR("Usage: construct02 [-testdigits] count"); } } catch (NumberFormatException nfe) { ERR("EXCEPTION RECEIVED: " + nfe); } } } System.gc(); System.runFinalization(); VERBOSEOUT("gc complete"); long starttotal = Runtime.getRuntime().totalMemory(); long startfree = Runtime.getRuntime().freeMemory(); TestConstruct02 con = null; try { con = new TestConstruct02(); } catch (DbException dbe) { System.err.println("Exception: " + dbe); System.exit(1); } catch (java.io.FileNotFoundException fnfe) { System.err.println("Exception: " + fnfe); System.exit(1); } for (int i=0; i -scale) return "<" + scale; } return ">" + max; } }