1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2002,2010 Oracle. All rights reserved.
*
* $Id: EnvironmentConfigTest.java,v 1.14.2.2 2010/01/04 15:30:42 cwl Exp $
*/
package com.sleepycat.je;
import java.io.File;
import java.util.Properties;
import junit.framework.TestCase;
import com.sleepycat.je.Environment;
import com.sleepycat.je.config.EnvironmentParams;
import com.sleepycat.je.util.TestUtils;
public class EnvironmentConfigTest extends TestCase {
/**
* Try out the validation in EnvironmentConfig.
*/
public void testValidation()
throws DatabaseException {
/*
* This validation should be successfull
*/
Properties props = new Properties();
props.setProperty("java.util.logging.FileHandler.limit", "2000");
props.setProperty("java.util.logging.FileHandler.on", "false");
new EnvironmentConfig(props); // Just instantiate a config object.
/*
* Should fail: we should throw because leftover.param is not
* a valid parameter.
*/
props.clear();
props.setProperty("leftover.param", "foo");
checkEnvironmentConfigValidation(props);
/*
* Should fail: we should throw because FileHandlerLimit
* is less than its minimum
*/
props.clear();
props.setProperty("java.util.logging.FileHandler.limit", "1");
checkEnvironmentConfigValidation(props);
/*
* Should fail: we should throw because FileHandler.on is not
* a valid value.
*/
props.clear();
props.setProperty("java.util.logging.FileHandler.on", "xxx");
checkEnvironmentConfigValidation(props);
}
/**
* Test single parameter setting.
*/
public void testSingleParam()
throws Exception {
try {
EnvironmentConfig config = new EnvironmentConfig();
config.setConfigParam("foo", "7");
fail("Should fail because of invalid param name");
} catch (IllegalArgumentException e) {
// expected.
}
EnvironmentConfig config = new EnvironmentConfig();
config.setConfigParam(EnvironmentParams.MAX_MEMORY_PERCENT.getName(),
"81");
assertEquals(81, config.getCachePercent());
}
public void testInconsistentParams()
throws Exception {
try {
EnvironmentConfig config = new EnvironmentConfig();
config.setAllowCreate(true);
config.setLocking(false);
config.setTransactional(true);
File envHome = new File(System.getProperty(TestUtils.DEST_DIR));
new Environment(envHome, config);
fail("Should fail because of inconsistent param values");
} catch (IllegalArgumentException e) {
// expected.
}
}
/* Helper to catch expected exceptions. */
private void checkEnvironmentConfigValidation(Properties props) {
try {
new EnvironmentConfig(props);
fail("Should fail because of a parameter validation problem");
} catch (IllegalArgumentException e) {
// expected.
}
}
}
|