1 8 9 package com.sleepycat.je; 10 11 import java.io.File ; 12 import java.util.Properties ; 13 14 import junit.framework.TestCase; 15 16 import com.sleepycat.je.Environment; 17 import com.sleepycat.je.config.EnvironmentParams; 18 import com.sleepycat.je.util.TestUtils; 19 20 public class EnvironmentConfigTest extends TestCase { 21 22 25 public void testValidation() 26 throws DatabaseException { 27 28 31 Properties props = new Properties (); 32 props.setProperty("java.util.logging.FileHandler.limit", "2000"); 33 props.setProperty("java.util.logging.FileHandler.on", "false"); 34 new EnvironmentConfig(props); 36 40 props.clear(); 41 props.setProperty("leftover.param", "foo"); 42 checkEnvironmentConfigValidation(props); 43 44 48 props.clear(); 49 props.setProperty("java.util.logging.FileHandler.limit", "1"); 50 checkEnvironmentConfigValidation(props); 51 52 56 props.clear(); 57 props.setProperty("java.util.logging.FileHandler.on", "xxx"); 58 checkEnvironmentConfigValidation(props); 59 } 60 61 64 public void testSingleParam() 65 throws Exception { 66 67 try { 68 EnvironmentConfig config = new EnvironmentConfig(); 69 config.setConfigParam("foo", "7"); 70 fail("Should fail because of invalid param name"); 71 } catch (IllegalArgumentException e) { 72 } 74 75 EnvironmentConfig config = new EnvironmentConfig(); 76 config.setConfigParam(EnvironmentParams.MAX_MEMORY_PERCENT.getName(), 77 "81"); 78 assertEquals(81, config.getCachePercent()); 79 } 80 81 public void testInconsistentParams() 82 throws Exception { 83 84 try { 85 EnvironmentConfig config = new EnvironmentConfig(); 86 config.setAllowCreate(true); 87 config.setLocking(false); 88 config.setTransactional(true); 89 File envHome = new File (System.getProperty(TestUtils.DEST_DIR)); 90 Environment env = new Environment(envHome, config); 91 fail("Should fail because of inconsistent param values"); 92 } catch (IllegalArgumentException e) { 93 } 95 } 96 97 98 private void checkEnvironmentConfigValidation(Properties props) { 99 try { 100 new EnvironmentConfig(props); 101 fail("Should fail because of a parameter validation problem"); 102 } catch (IllegalArgumentException e) { 103 } 105 } 106 } 107 108 | Popular Tags |