/*- * See the file LICENSE for redistribution information. * * Copyright (c) 2000-2003 * Sleepycat Software. All rights reserved. * * $Id: TestConstruct01.java,v 1.2 2004/03/30 01:24:39 jtownsen 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 TestConstruct01 { public static final String CONSTRUCT01_DBNAME = "construct01.db"; public static final String CONSTRUCT01_DBDIR = "/tmp"; public static final String CONSTRUCT01_DBFULLPATH = CONSTRUCT01_DBDIR + "/" + CONSTRUCT01_DBNAME; private int itemcount; // count the number of items in the database public static boolean verbose_flag = false; public static void ERR(String a) { System.out.println("FAIL: " + a); System.err.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. // // For some reason on Windows, we need to open using the full pathname // of the file when there is no environment, thus the 'has_env' // variable. // void rundb(Db db, int count, boolean has_env, TestOptions options) throws DbException, FileNotFoundException { String name; if (has_env) name = CONSTRUCT01_DBNAME; else name = CONSTRUCT01_DBFULLPATH; db.set_error_stream(System.err); // We don't really care about the pagesize, but we do want // to make sure adjusting Db specific variables works before // opening the db. // db.set_pagesize(1024); db.open(null, name, null, Db.DB_BTREE, (count != 0) ? 0 : Db.DB_CREATE, 0664); // 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: construct01 [-testdigits] count"); } } VERBOSEOUT("mask = " + mask); } else { try { iterations = Integer.parseInt(arg); if (iterations < 0) { ERR("Usage: construct01 [-testdigits] count"); } } catch (NumberFormatException nfe) { ERR("EXCEPTION RECEIVED: " + nfe); } } } // Run GC before and after the test to give // a baseline for any Java memory used. // System.gc(); System.runFinalization(); VERBOSEOUT("gc complete"); long starttotal = Runtime.getRuntime().totalMemory(); long startfree = Runtime.getRuntime().freeMemory(); TestConstruct01 con = new TestConstruct01(); int[] dbt_flags = { 0, Db.DB_DBT_MALLOC, Db.DB_DBT_REALLOC }; String[] dbt_flags_name = { "default", "malloc", "realloc" }; TestOptions options = new TestOptions(); options.testmask = mask; for (int flagiter = 0; flagiter < dbt_flags.length; flagiter++) { options.dbt_alloc_flags = dbt_flags[flagiter]; VERBOSEOUT("Running with DBT alloc flags: " + dbt_flags_name[flagiter]); for (int i=0; i -scale) return "<" + scale; } return ">" + max; } } class TestOptions { int testmask = 0; // which tests to run int dbt_alloc_flags = 0; // DB_DBT_* flags to use int successcounter =0; }