1 8 9 package com.sleepycat.je.cleaner; 10 11 import java.io.File ; 12 import java.io.IOException ; 13 import java.util.HashMap ; 14 import java.util.HashSet ; 15 import java.util.Iterator ; 16 import java.util.Map ; 17 import java.util.Set ; 18 19 import junit.framework.TestCase; 20 21 import com.sleepycat.bind.tuple.IntegerBinding; 22 import com.sleepycat.je.CheckpointConfig; 23 import com.sleepycat.je.Cursor; 24 import com.sleepycat.je.Database; 25 import com.sleepycat.je.DatabaseConfig; 26 import com.sleepycat.je.DatabaseEntry; 27 import com.sleepycat.je.DatabaseException; 28 import com.sleepycat.je.DbInternal; 29 import com.sleepycat.je.Environment; 30 import com.sleepycat.je.EnvironmentConfig; 31 import com.sleepycat.je.EnvironmentMutableConfig; 32 import com.sleepycat.je.EnvironmentStats; 33 import com.sleepycat.je.LockMode; 34 import com.sleepycat.je.OperationStatus; 35 import com.sleepycat.je.Transaction; 36 import com.sleepycat.je.cleaner.Cleaner; 37 import com.sleepycat.je.cleaner.UtilizationProfile; 38 import com.sleepycat.je.config.EnvironmentParams; 39 import com.sleepycat.je.dbi.EnvironmentImpl; 40 import com.sleepycat.je.dbi.MemoryBudget; 41 import com.sleepycat.je.log.FileManager; 42 import com.sleepycat.je.util.StringDbt; 43 import com.sleepycat.je.util.TestUtils; 44 45 public class CleanerTest extends TestCase { 46 47 private static final int N_KEYS = 300; 48 private static final int N_KEY_BYTES = 10; 49 50 54 private static final int FILE_SIZE = 10000; 55 protected File envHome = null; 56 protected Database db = null; 57 private Environment exampleEnv; 58 private Database exampleDb; 59 private CheckpointConfig forceConfig; 60 61 public CleanerTest() { 62 envHome = new File (System.getProperty(TestUtils.DEST_DIR)); 63 forceConfig = new CheckpointConfig(); 64 forceConfig.setForce(true); 65 } 66 67 public void setUp() 68 throws IOException , DatabaseException { 69 70 TestUtils.removeLogFiles("Setup", envHome, false); 71 TestUtils.removeFiles("Setup", envHome, FileManager.DEL_SUFFIX); 72 } 73 74 private void initEnv(boolean createDb, boolean allowDups) 75 throws DatabaseException { 76 77 EnvironmentConfig envConfig = TestUtils.initEnvConfig(); 78 DbInternal.disableParameterValidation(envConfig); 79 envConfig.setTransactional(true); 80 envConfig.setAllowCreate(true); 81 envConfig.setTxnNoSync(Boolean.getBoolean(TestUtils.NO_SYNC)); 82 envConfig.setConfigParam(EnvironmentParams.LOG_FILE_MAX.getName(), 83 Integer.toString(FILE_SIZE)); 84 envConfig.setConfigParam(EnvironmentParams.ENV_CHECK_LEAKS.getName(), 85 "false"); 86 envConfig.setConfigParam(EnvironmentParams.ENV_RUN_CLEANER.getName(), 87 "false"); 88 envConfig.setConfigParam(EnvironmentParams.CLEANER_REMOVE.getName(), 89 "false"); 90 envConfig.setConfigParam 91 (EnvironmentParams.CLEANER_MIN_UTILIZATION.getName(), "80"); 92 envConfig.setConfigParam 93 (EnvironmentParams.ENV_RUN_CHECKPOINTER.getName(), "false"); 94 envConfig.setConfigParam(EnvironmentParams.NODE_MAX.getName(), "6"); 95 envConfig.setConfigParam(EnvironmentParams.BIN_DELTA_PERCENT.getName(), 96 "75"); 97 98 99 envConfig.setConfigParam 100 (EnvironmentParams.CLEANER_TRACK_DETAIL.getName(), "false"); 101 102 exampleEnv = new Environment(envHome, envConfig); 103 104 String databaseName = "cleanerDb"; 105 DatabaseConfig dbConfig = new DatabaseConfig(); 106 dbConfig.setTransactional(true); 107 dbConfig.setAllowCreate(createDb); 108 dbConfig.setSortedDuplicates(allowDups); 109 exampleDb = exampleEnv.openDatabase(null, databaseName, dbConfig); 110 } 111 112 public void tearDown() 113 throws IOException , DatabaseException { 114 115 if (exampleEnv != null) { 116 try { 117 exampleEnv.close(); 118 } catch (DatabaseException e) { 119 System.out.println("tearDown: " + e); 120 } 121 } 122 exampleDb = null; 123 exampleEnv = null; 124 125 TestUtils.removeLogFiles("TearDown", envHome, true); 127 TestUtils.removeFiles("TearDown", envHome, FileManager.DEL_SUFFIX); 128 } 130 131 private void closeEnv() 132 throws DatabaseException { 133 134 if (exampleDb != null) { 135 exampleDb.close(); 136 exampleDb = null; 137 } 138 139 if (exampleEnv != null) { 140 exampleEnv.close(); 141 exampleEnv = null; 142 } 143 } 144 145 public void testCleanerNoDupes() 146 throws Throwable { 147 148 initEnv(true, false); 149 try { 150 doCleanerTest(N_KEYS, 1); 151 } catch (Throwable t) { 152 t.printStackTrace(); 153 throw t; 154 } 155 } 156 157 public void testCleanerWithDupes() 158 throws Throwable { 159 160 initEnv(true, true); 161 try { 162 doCleanerTest(2, 500); 163 } catch (Throwable t) { 164 t.printStackTrace(); 165 throw t; 166 } 167 } 168 169 private void doCleanerTest(int nKeys, int nDupsPerKey) 170 throws DatabaseException { 171 172 EnvironmentImpl environment = 173 DbInternal.envGetEnvironmentImpl(exampleEnv); 174 FileManager fileManager = environment.getFileManager(); 175 Map expectedMap = new HashMap (); 176 doLargePut(expectedMap, nKeys, nDupsPerKey, true); 177 Long lastNum = fileManager.getLastFileNum(); 178 179 180 StringDbt foundKey = new StringDbt(); 181 StringDbt foundData = new StringDbt(); 182 183 Cursor cursor = exampleDb.openCursor(null, null); 184 185 while (cursor.getNext(foundKey, foundData, LockMode.DEFAULT) == 186 OperationStatus.SUCCESS) { 187 } 188 189 exampleEnv.checkpoint(forceConfig); 190 191 for (int i = 0; i < (int) lastNum.longValue(); i++) { 192 193 197 DbInternal.envGetEnvironmentImpl(exampleEnv). 198 getCleaner(). 199 doClean(false, true); } 202 203 EnvironmentStats stats = exampleEnv.getStats(TestUtils.FAST_STATS); 204 assertTrue(stats.getNINsCleaned() > 0); 205 206 cursor.close(); 207 closeEnv(); 208 209 initEnv(false, (nDupsPerKey > 1)); 210 211 checkData(expectedMap); 212 assertTrue(fileManager.getLastFileNum().longValue() > 213 lastNum.longValue()); 214 215 closeEnv(); 216 } 217 218 221 public void testCleanInternalNodes() 222 throws DatabaseException { 223 224 initEnv(true, true); 225 int nKeys = 200; 226 227 EnvironmentImpl environment = 228 DbInternal.envGetEnvironmentImpl(exampleEnv); 229 FileManager fileManager = environment.getFileManager(); 230 231 Map expectedMap = new HashMap (); 232 doLargePut(expectedMap, nKeys, 1, true); 233 234 235 modifyData(expectedMap, 10, true); 236 checkData(expectedMap); 237 238 239 exampleEnv.checkpoint(forceConfig); 240 checkData(expectedMap); 241 242 243 modifyData(expectedMap, 10, true); 244 checkData(expectedMap); 245 246 247 exampleEnv.checkpoint(forceConfig); 248 checkData(expectedMap); 249 250 251 Long lastNum = fileManager.getLastFileNum(); 252 exampleEnv.cleanLog(); 253 254 255 checkData(expectedMap); 256 EnvironmentStats stats = exampleEnv.getStats(TestUtils.FAST_STATS); 257 258 259 assertTrue(stats.getNINsCleaned() > 0); 260 assertTrue(stats.getNLNsCleaned() > 0); 261 262 closeEnv(); 263 initEnv(false, true); 264 checkData(expectedMap); 265 assertTrue(fileManager.getLastFileNum().longValue() > 266 lastNum.longValue()); 267 268 closeEnv(); 269 } 270 271 274 public void testCleanFileHole() 275 throws Throwable { 276 277 initEnv(true, true); 278 279 int nKeys = 20; int nDupsPerKey = 30; 281 282 EnvironmentImpl environment = 283 DbInternal.envGetEnvironmentImpl(exampleEnv); 284 FileManager fileManager = environment.getFileManager(); 285 286 287 Map expectedMap = new HashMap (); 288 doLargePut(expectedMap, nKeys, 1, true); 289 modifyData(expectedMap, 10, true); 290 doLargePut(expectedMap, nKeys, nDupsPerKey, true); 291 checkData(expectedMap); 292 293 297 deleteData(expectedMap, false, false); 298 checkData(expectedMap); 299 300 301 doLargePut(expectedMap, nKeys, nDupsPerKey, false); 302 checkData(expectedMap); 303 304 305 doLargePut(expectedMap, nKeys, nDupsPerKey, true); 306 checkData(expectedMap); 307 308 309 exampleEnv.checkpoint(forceConfig); 310 checkData(expectedMap); 311 312 313 Long lastNum = fileManager.getLastFileNum(); 314 exampleEnv.cleanLog(); 315 316 317 checkData(expectedMap); 318 EnvironmentStats stats = exampleEnv.getStats(TestUtils.FAST_STATS); 319 320 321 assertTrue(stats.getNINsCleaned() > 0); 322 assertTrue(stats.getNLNsCleaned() > 0); 323 324 closeEnv(); 325 initEnv(false, true); 326 checkData(expectedMap); 327 assertTrue(fileManager.getLastFileNum().longValue() > 328 lastNum.longValue()); 329 330 closeEnv(); 331 } 332 333 357 public void testSR13191() 358 throws Throwable { 359 360 EnvironmentConfig envConfig = TestUtils.initEnvConfig(); 361 envConfig.setAllowCreate(true); 362 envConfig.setConfigParam 363 (EnvironmentParams.ENV_RUN_CLEANER.getName(), "false"); 364 Environment env = new Environment(envHome, envConfig); 365 EnvironmentImpl envImpl = DbInternal.envGetEnvironmentImpl(env); 366 FileManager fileManager = 367 DbInternal.envGetEnvironmentImpl(env).getFileManager(); 368 369 DatabaseConfig dbConfig = new DatabaseConfig(); 370 dbConfig.setAllowCreate(true); 371 Database db1 = 372 env.openDatabase(null, "db1", dbConfig); 373 374 Database db2 = 375 env.openDatabase(null, "db2", dbConfig); 376 377 DatabaseEntry key = new DatabaseEntry(); 378 DatabaseEntry data = new DatabaseEntry(); 379 IntegerBinding.intToEntry(1, key); 380 data.setData(new byte[100000]); 381 for (int i = 0; i < 50; i++) { 382 assertEquals(OperationStatus.SUCCESS, db2.put(null, key, data)); 383 } 384 db1.close(); 385 db2.close(); 386 assertEquals("Should have 0 as current file", 0L, 387 fileManager.getCurrentFileNum()); 388 envImpl.forceLogFileFlip(); 389 env.close(); 390 391 env = new Environment(envHome, envConfig); 392 fileManager = DbInternal.envGetEnvironmentImpl(env).getFileManager(); 393 assertEquals("Should have 1 as current file", 1L, 394 fileManager.getCurrentFileNum()); 395 396 db2 = env.openDatabase(null, "db2", dbConfig); 397 398 for (int i = 0; i < 250; i++) { 399 assertEquals(OperationStatus.SUCCESS, db2.put(null, key, data)); 400 } 401 402 db2.close(); 403 env.cleanLog(); 404 db1 = env.openDatabase(null, "db1", dbConfig); 405 db1.get(null, key, data, null); 406 db1.close(); 407 env.close(); 408 } 409 410 415 public void testCleanerStop() 416 throws Throwable { 417 418 final int fileSize = 1000000; 419 EnvironmentConfig envConfig = TestUtils.initEnvConfig(); 420 envConfig.setAllowCreate(true); 421 envConfig.setConfigParam 422 (EnvironmentParams.ENV_RUN_CLEANER.getName(), "false"); 423 envConfig.setConfigParam 424 (EnvironmentParams.LOG_FILE_MAX.getName(), 425 Integer.toString(fileSize)); 426 envConfig.setConfigParam 427 (EnvironmentParams.CLEANER_MIN_UTILIZATION.getName(), "80"); 428 Environment env = new Environment(envHome, envConfig); 429 430 DatabaseConfig dbConfig = new DatabaseConfig(); 431 dbConfig.setAllowCreate(true); 432 Database db = env.openDatabase(null, "CleanerStop", dbConfig); 433 434 DatabaseEntry key = new DatabaseEntry(new byte[1]); 435 DatabaseEntry data = new DatabaseEntry(new byte[fileSize]); 436 for (int i = 0; i <= 10; i += 1) { 437 db.put(null, key, data); 438 } 439 env.checkpoint(forceConfig); 440 441 EnvironmentStats stats = env.getStats(null); 442 assertEquals(0, stats.getNCleanerRuns()); 443 444 envConfig = env.getConfig(); 445 envConfig.setConfigParam 446 (EnvironmentParams.ENV_RUN_CLEANER.getName(), "true"); 447 env.setMutableConfig(envConfig); 448 449 int iter = 0; 450 while (stats.getNCleanerRuns() == 0) { 451 iter += 1; 452 if (iter == 20) { 453 fail("Cleaner did not run after " + iter + " tries"); 454 } 455 Thread.yield(); 456 Thread.sleep(1); 457 stats = env.getStats(null); 458 } 459 460 envConfig.setConfigParam 461 (EnvironmentParams.ENV_RUN_CLEANER.getName(), "false"); 462 env.setMutableConfig(envConfig); 463 464 int prevNFiles = stats.getNCleanerRuns(); 465 stats = env.getStats(null); 466 int currNFiles = stats.getNCleanerRuns(); 467 if (currNFiles - prevNFiles > 5) { 468 fail("Expected less than 5 files cleaned," + 469 " prevNFiles=" + prevNFiles + 470 " currNFiles=" + currNFiles); 471 } 472 473 475 db.close(); 476 env.close(); 477 } 478 479 483 private void doLargePut(Map expectedMap, 484 int nKeys, 485 int nDupsPerKey, 486 boolean commit) 487 throws DatabaseException { 488 489 Transaction txn = exampleEnv.beginTransaction(null, null); 490 for (int i = 0; i < nKeys; i++) { 491 byte[] key = new byte[N_KEY_BYTES]; 492 TestUtils.generateRandomAlphaBytes(key); 493 String keyString = new String (key); 494 495 499 Set dataVals = new HashSet (); 500 if (commit) { 501 expectedMap.put(keyString, dataVals); 502 } 503 for (int j = 0; j < nDupsPerKey; j++) { 504 String dataString = Integer.toString(j); 505 exampleDb.put(txn, 506 new StringDbt(keyString), 507 new StringDbt(dataString)); 508 dataVals.add(dataString); 509 } 510 } 511 if (commit) { 512 txn.commit(); 513 } else { 514 txn.abort(); 515 } 516 } 517 518 521 private void modifyData(Map expectedMap, 522 int increment, 523 boolean commit) 524 throws DatabaseException { 525 526 Transaction txn = exampleEnv.beginTransaction(null, null); 527 528 StringDbt foundKey = new StringDbt(); 529 StringDbt foundData = new StringDbt(); 530 531 Cursor cursor = exampleDb.openCursor(txn, null); 532 OperationStatus status = cursor.getFirst(foundKey, foundData, 533 LockMode.DEFAULT); 534 535 boolean toggle = true; 536 while (status == OperationStatus.SUCCESS) { 537 if (toggle) { 538 539 String foundKeyString = foundKey.getString(); 540 String foundDataString = foundData.getString(); 541 int newValue = Integer.parseInt(foundDataString) + increment; 542 String newDataString = Integer.toString(newValue); 543 544 545 if (commit) { 546 547 Set dataVals = (Set ) expectedMap.get(foundKeyString); 548 if (dataVals == null) { 549 fail("Couldn't find " + 550 foundKeyString + "/" + foundDataString); 551 } else if (dataVals.contains(foundDataString)) { 552 dataVals.remove(foundDataString); 553 dataVals.add(newDataString); 554 } else { 555 fail("Couldn't find " + 556 foundKeyString + "/" + foundDataString); 557 } 558 } 559 560 assertEquals(OperationStatus.SUCCESS, 561 cursor.delete()); 562 assertEquals(OperationStatus.SUCCESS, 563 cursor.put(foundKey, 564 new StringDbt(newDataString))); 565 toggle = false; 566 } else { 567 toggle = true; 568 } 569 570 status = cursor.getNext(foundKey, foundData, LockMode.DEFAULT); 571 } 572 573 cursor.close(); 574 if (commit) { 575 txn.commit(); 576 } else { 577 txn.abort(); 578 } 579 } 580 583 private void deleteData(Map expectedMap, 584 boolean everyOther, 585 boolean commit) 586 throws DatabaseException { 587 588 Transaction txn = exampleEnv.beginTransaction(null, null); 589 590 StringDbt foundKey = new StringDbt(); 591 StringDbt foundData = new StringDbt(); 592 593 Cursor cursor = exampleDb.openCursor(txn, null); 594 OperationStatus status = cursor.getFirst(foundKey, foundData, 595 LockMode.DEFAULT); 596 597 boolean toggle = true; 598 while (status == OperationStatus.SUCCESS) { 599 if (toggle) { 600 601 String foundKeyString = foundKey.getString(); 602 String foundDataString = foundData.getString(); 603 604 605 if (commit) { 606 607 Set dataVals = (Set ) expectedMap.get(foundKeyString); 608 if (dataVals == null) { 609 fail("Couldn't find " + 610 foundKeyString + "/" + foundDataString); 611 } else if (dataVals.contains(foundDataString)) { 612 dataVals.remove(foundDataString); 613 if (dataVals.size() == 0) { 614 expectedMap.remove(foundKeyString); 615 } 616 } else { 617 fail("Couldn't find " + 618 foundKeyString + "/" + foundDataString); 619 } 620 } 621 622 assertEquals(OperationStatus.SUCCESS, cursor.delete()); 623 } 624 625 if (everyOther) { 626 toggle = toggle? false: true; 627 } 628 629 status = cursor.getNext(foundKey, foundData, LockMode.DEFAULT); 630 } 631 632 cursor.close(); 633 if (commit) { 634 txn.commit(); 635 } else { 636 txn.abort(); 637 } 638 } 639 640 643 private void checkData(Map expectedMap) 644 throws DatabaseException { 645 646 StringDbt foundKey = new StringDbt(); 647 StringDbt foundData = new StringDbt(); 648 Cursor cursor = exampleDb.openCursor(null, null); 649 OperationStatus status = cursor.getFirst(foundKey, foundData, 650 LockMode.DEFAULT); 651 652 657 658 Map checkMap = new HashMap (); 659 Map countMap = new HashMap (); 660 Iterator iter = expectedMap.entrySet().iterator(); 661 while (iter.hasNext()) { 662 Map.Entry entry = (Map.Entry ) iter.next(); 663 Set copySet = new HashSet (); 664 copySet.addAll((Set ) entry.getValue()); 665 checkMap.put(entry.getKey(), copySet); 666 countMap.put(entry.getKey(), new Integer (copySet.size())); 667 } 668 669 while (status == OperationStatus.SUCCESS) { 670 String foundKeyString = foundKey.getString(); 671 String foundDataString = foundData.getString(); 672 673 674 Set dataVals = (Set ) checkMap.get(foundKeyString); 675 if (dataVals == null) { 676 fail("Couldn't find " + 677 foundKeyString + "/" + foundDataString); 678 } else if (dataVals.contains(foundDataString)) { 679 dataVals.remove(foundDataString); 680 if (dataVals.size() == 0) { 681 checkMap.remove(foundKeyString); 682 } 683 } else { 684 fail("Couldn't find " + 685 foundKeyString + "/" + 686 foundDataString + 687 " in data vals"); 688 } 689 690 691 int count = cursor.count(); 692 assertEquals(((Integer )countMap.get(foundKeyString)).intValue(), 693 count); 694 695 status = cursor.getNext(foundKey, foundData, LockMode.DEFAULT); 696 } 697 698 cursor.close(); 699 700 if (checkMap.size() != 0) { 701 dumpExpected(checkMap); 702 fail("checkMapSize = " + checkMap.size()); 703 704 } 705 assertEquals(0, checkMap.size()); 706 } 707 708 private void dumpExpected(Map expectedMap) { 709 Iterator iter = expectedMap.entrySet().iterator(); 710 while (iter.hasNext()) { 711 Map.Entry entry = (Map.Entry ) iter.next(); 712 String key = (String ) entry.getKey(); 713 Iterator dataIter = ((Set ) entry.getValue()).iterator(); 714 while (dataIter.hasNext()) { 715 System.out.println("key=" + key + 716 " data=" + (String ) dataIter.next()); 717 } 718 } 719 } 720 721 725 public void testMutableConfig() 726 throws DatabaseException { 727 728 EnvironmentConfig envConfig = TestUtils.initEnvConfig(); 729 envConfig.setAllowCreate(true); 730 exampleEnv = new Environment(envHome, envConfig); 731 envConfig = exampleEnv.getConfig(); 732 EnvironmentImpl envImpl = 733 DbInternal.envGetEnvironmentImpl(exampleEnv); 734 Cleaner cleaner = envImpl.getCleaner(); 735 UtilizationProfile profile = envImpl.getUtilizationProfile(); 736 MemoryBudget budget = envImpl.getMemoryBudget(); 737 String name; 738 String val; 739 740 741 name = EnvironmentParams.CLEANER_MIN_UTILIZATION.getName(); 742 setParam(name, "33"); 743 assertEquals(33, profile.minUtilization); 744 745 746 name = EnvironmentParams.CLEANER_MIN_FILE_UTILIZATION.getName(); 747 setParam(name, "7"); 748 assertEquals(7, profile.minFileUtilization); 749 750 751 name = EnvironmentParams.CLEANER_BYTES_INTERVAL.getName(); 752 setParam(name, "1000"); 753 assertEquals(1000, cleaner.cleanerBytesInterval); 754 755 756 name = EnvironmentParams.CLEANER_DEADLOCK_RETRY.getName(); 757 setParam(name, "7"); 758 assertEquals(7, cleaner.nDeadlockRetries); 759 760 761 name = EnvironmentParams.CLEANER_LOCK_TIMEOUT.getName(); 762 setParam(name, "7000"); 763 assertEquals(7, cleaner.lockTimeout); 764 765 766 name = EnvironmentParams.CLEANER_REMOVE.getName(); 767 val = "false".equals(envConfig.getConfigParam(name)) ? 768 "true" : "false"; 769 setParam(name, val); 770 assertEquals(val.equals("true"), cleaner.expunge); 771 772 773 name = EnvironmentParams.CLEANER_MIN_AGE.getName(); 774 setParam(name, "7"); 775 assertEquals(7, profile.minAge); 776 777 778 name = EnvironmentParams.CLEANER_CLUSTER.getName(); 779 val = "false".equals(envConfig.getConfigParam(name)) ? 780 "true" : "false"; 781 setParam(name, val); 782 assertEquals(val.equals("true"), cleaner.clusterResident); 783 784 setParam(name, "false"); 785 786 787 name = EnvironmentParams.CLEANER_CLUSTER_ALL.getName(); 788 val = "false".equals(envConfig.getConfigParam(name)) ? 789 "true" : "false"; 790 setParam(name, val); 791 assertEquals(val.equals("true"), cleaner.clusterAll); 792 793 794 name = EnvironmentParams.CLEANER_MAX_BATCH_FILES.getName(); 795 setParam(name, "7"); 796 assertEquals(7, cleaner.maxBatchFiles); 797 798 799 name = EnvironmentParams.CLEANER_READ_SIZE.getName(); 800 setParam(name, "7777"); 801 assertEquals(7777, cleaner.readBufferSize); 802 803 804 name = EnvironmentParams.CLEANER_DETAIL_MAX_MEMORY_PERCENTAGE. 805 getName(); 806 setParam(name, "7"); 807 assertEquals((budget.getMaxMemory() * 7) / 100, 808 budget.getTrackerBudget()); 809 810 811 name = EnvironmentParams.CLEANER_THREADS.getName(); 812 setParam(name, "7"); 813 assertEquals((envImpl.isNoLocking() ? 0 : 7), 814 countCleanerThreads()); 815 816 exampleEnv.close(); 817 exampleEnv = null; 818 } 819 820 824 private void setParam(String name, String val) 825 throws DatabaseException { 826 827 EnvironmentMutableConfig config = exampleEnv.getMutableConfig(); 828 String myVal = config.getConfigParam(name); 829 assertTrue(!val.equals(myVal)); 830 831 config.setConfigParam(name, val); 832 exampleEnv.setMutableConfig(config); 833 834 config = exampleEnv.getMutableConfig(); 835 myVal = config.getConfigParam(name); 836 assertTrue(val.equals(myVal)); 837 } 838 839 842 private int countCleanerThreads() { 843 844 Thread [] threads = new Thread [Thread.activeCount()]; 845 Thread.enumerate(threads); 846 847 int count = 0; 848 for (int i = 0; i < threads.length; i += 1) { 849 if (threads[i] != null && 850 threads[i].getName().startsWith("Cleaner")) { 851 count += 1; 852 } 853 } 854 855 return count; 856 } 857 } 858 | Popular Tags |