/** Create a populated tree, delete all records, then begin to insert again. */ private void setupWrittenByCompression(Database db) throws DatabaseException { setStepwiseStart(); DatabaseEntry key = new DatabaseEntry(); DatabaseEntry data = new DatabaseEntry(); /* Populate a tree so it grows to 2 levels, with 2 BINs. */ for (int i = 0; i < 10; i++) { IntegerBinding.intToEntry(i, key); IntegerBinding.intToEntry(i, data); assertEquals(OperationStatus.SUCCESS, db.put(null, key, data)); } Trace.trace(DbInternal.getEnvironmentImpl(env), "After inserts"); env.checkpoint(FORCE_CONFIG); if (DEBUG) { System.out.println(db.getStats(new StatsConfig())); } /* Now delete all of 1 BIN. */ for (int i = 0; i < 5; i++) { IntegerBinding.intToEntry(i, key); assertEquals(OperationStatus.SUCCESS, db.delete(null, key)); } /* Compress, removing a BIN. */ env.compress(); if (DEBUG) { System.out.println("After compress"); System.out.println(db.getStats(new StatsConfig())); } /* Checkpoint again. */ env.checkpoint(FORCE_CONFIG); }
/** * Helper to get statistics for a given database. * * @param params operation parameters * @return DatabaseStats object */ private DatabaseStats getDatabaseStats(Environment targetEnv, Object[] params) throws IllegalArgumentException, DatabaseException { if ((params == null) || (params.length < 3)) { return null; } String dbName = (String) params[2]; Database db = null; try { DatabaseConfig dbConfig = new DatabaseConfig(); dbConfig.setReadOnly(true); DbInternal.setUseExistingConfig(dbConfig, true); db = targetEnv.openDatabase(null, dbName, dbConfig); return db.getStats(getStatsConfig(params)); } finally { if (db != null) { db.close(); } } }