本文整理匯總了Java中com.sleepycat.je.Environment.close方法的典型用法代碼示例。如果您正苦於以下問題:Java Environment.close方法的具體用法?Java Environment.close怎麽用?Java Environment.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.sleepycat.je.Environment
的用法示例。
在下文中一共展示了Environment.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: UpdateGroundhogScript
import com.sleepycat.je.Environment; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public UpdateGroundhogScript(File datadir) throws DatabaseException {
environmentConfig = new EnvironmentConfig();
environmentConfig.setAllowCreate(true);
environmentConfig.setTransactional(true);
environmentConfig.setCacheSize(302400000);
// perform other environment configurations
environment = new Environment(datadir, environmentConfig);
List<String> names = environment.getDatabaseNames();
if (names.contains(datadir.getName())) {
environment.renameDatabase(null, datadir.getName(), databaseName);
}
environment.close();
}
示例2: testLesserVersionNotUpdated
import com.sleepycat.je.Environment; //導入方法依賴的package包/類
/**
* Tests that when a file is opened with a lesser version than the current
* version, a new log file is started for writing new log entries. This is
* important so that the new header version is written even if no new log
* file is needed. If the new version were not written, an older version
* of JE would not recognize that there had been a version change.
*/
public void testLesserVersionNotUpdated()
throws DatabaseException, IOException {
TestUtils.loadLog(getClass(), Utils.MIN_VERSION_NAME, envHome);
File logFile = new File(envHome, TestUtils.LOG_FILE_NAME);
long origFileSize = logFile.length();
EnvironmentConfig envConfig = TestUtils.initEnvConfig();
envConfig.setAllowCreate(false);
envConfig.setTransactional(true);
Environment env = new Environment(envHome, envConfig);
env.sync();
env.close();
assertEquals(origFileSize, logFile.length());
}
示例3: testEmptyDatabaseSR14744
import com.sleepycat.je.Environment; //導入方法依賴的package包/類
public void testEmptyDatabaseSR14744()
throws Throwable {
Database db = null;
try {
EnvironmentConfig envConfig = getEnvConfig(true);
env = new Environment(envHome, envConfig);
db = createDb(true);
db.sync();
} finally {
if (db != null) {
db.close();
}
env.sync();
env.close();
env = null;
}
}
示例4: testGreaterVersionNotAllowed
import com.sleepycat.je.Environment; //導入方法依賴的package包/類
/**
* Tests that an exception is thrown when a log header is read with a newer
* version than the current version. The maxversion.jdb log file is loaded
* as a resource by this test and written as a regular log file. When the
* environment is opened, we expect a LogException.
*/
public void testGreaterVersionNotAllowed()
throws DatabaseException, IOException {
TestUtils.loadLog(getClass(), Utils.MAX_VERSION_NAME, envHome);
EnvironmentConfig envConfig = TestUtils.initEnvConfig();
envConfig.setAllowCreate(false);
envConfig.setTransactional(true);
try {
Environment env = new Environment(envHome, envConfig);
try {
env.close();
} catch (Exception ignore) {}
} catch (DatabaseException e) {
if (e.getCause() instanceof LogException) {
/* Got LogException as expected. */
return;
}
}
fail("Expected LogException");
}
示例5: testBadLog
import com.sleepycat.je.Environment; //導入方法依賴的package包/類
/**
* Tests that we can load a log file containing offsets that correspond to
* non-obsolete LNs. The bad log file was created using testBasic run
* against JE 2.0.54. It contains version 1 FSLNs, one of which has an
* offset which is not obsolete.
*/
public void testBadLog()
throws DatabaseException, IOException {
/* Copy a log file with bad offsets to log file zero. */
String resName = "rmw_bad_offsets.jdb";
TestUtils.loadLog(getClass(), resName, envHome);
/* Open the log we just copied. */
EnvironmentConfig envConfig = TestUtils.initEnvConfig();
envConfig.setAllowCreate(false);
envConfig.setReadOnly(true);
env = new Environment(envHome, envConfig);
/*
* Verify the UP of the bad log. Prior to adding the code in
* FileSummaryLN.postFetchInit that discards version 1 offsets, this
* assertion failed.
*/
UtilizationProfile up =
DbInternal.envGetEnvironmentImpl(env).getUtilizationProfile();
assertTrue(up.verifyFileSummaryDatabase());
env.close();
env = null;
}
示例6: putPerformanceTest
import com.sleepycat.je.Environment; //導入方法依賴的package包/類
public void putPerformanceTest() {
final int numEntries = 5000;
final int minEntrySize = 50;
final int maxEntrySize = 1000;
final Random random = new Random();
File dbDir = createDbDir("putPerformanceTest");
Environment dbEnvironment = BerkeleyDBViewComputationCacheSource.constructDatabaseEnvironment(dbDir, false);
BerkeleyDBBinaryDataStore dataStore = new BerkeleyDBBinaryDataStore(dbEnvironment, "putPerformanceTest");
dataStore.start();
OperationTimer timer = new OperationTimer(s_logger, "Writing {} entries", numEntries);
int randRange = maxEntrySize - minEntrySize;
for (int i = 0; i < numEntries; i++) {
int nBytes = minEntrySize + random.nextInt(randRange);
byte[] bytes = new byte[nBytes];
random.nextBytes(bytes);
dataStore.put(i, bytes);
}
long numMillis = timer.finished();
double msPerPut = ((double) numMillis) / ((double) numEntries);
double putsPerSecond = 1000.0 / msPerPut;
s_logger.info("for {} entries, {} ms/put, {} puts/sec", new Object[] {numEntries, msPerPut, putsPerSecond});
dataStore.delete();
dataStore.stop();
dbEnvironment.close();
}
開發者ID:DevStreet,項目名稱:FinanceAnalytics,代碼行數:34,代碼來源:BerkeleyDBValueSpecificationIdentifierBinaryDataStoreTest.java
示例7: reloadPreservesMaxValue
import com.sleepycat.je.Environment; //導入方法依賴的package包/類
@Test
public void reloadPreservesMaxValue() throws IOException {
File dbDir = createDbDir("reloadPreservesMaxValue");
Environment dbEnvironment = createDbEnvironment(dbDir);
FudgeContext fudgeContext = OpenGammaFudgeContext.getInstance();
BerkeleyDBIdentifierMap idSource = new BerkeleyDBIdentifierMap(dbEnvironment, fudgeContext);
idSource.start();
String valueName = "value-5";
ValueSpecification valueSpec = getValueSpec(valueName);
long initialIdentifier = idSource.getIdentifier(valueSpec);
// Cycle everything to simulate a clean shutdown and restart.
idSource.stop();
dbEnvironment.close();
dbEnvironment = createDbEnvironment(dbDir);
idSource = new BerkeleyDBIdentifierMap(dbEnvironment, fudgeContext);
idSource.start();
// Check we get the same thing back.
valueName = "value-5";
valueSpec = getValueSpec(valueName);
long identifier = idSource.getIdentifier(valueSpec);
assertEquals(initialIdentifier, identifier);
// Check that the next one is the previous max + 1
valueName = "value-99999";
valueSpec = getValueSpec(valueName);
identifier = idSource.getIdentifier(valueSpec);
assertEquals(initialIdentifier + 1, identifier);
}
示例8: UpdataIntegerSetStoreScript
import com.sleepycat.je.Environment; //導入方法依賴的package包/類
public UpdataIntegerSetStoreScript(File datadir) throws DatabaseException {
environmentConfig = new EnvironmentConfig();
environmentConfig.setAllowCreate(true);
environmentConfig.setTransactional(true);
environmentConfig.setCacheSize(302400000);
// perform other environment configurations
environment = new Environment(datadir, environmentConfig);
List<String> names = environment.getDatabaseNames();
if (names.contains(datadir.getName())) {
environment.renameDatabase(null, datadir.getName(), databaseName);
}
environment.close();
}
示例9: testRemoveNonPersistentDbSR15317
import com.sleepycat.je.Environment; //導入方法依賴的package包/類
/**
* Check that all INs are removed from the INList for a DB that is removed
* before it is sync'ed (or checkpointed). Before the bug fix, INs were
* not removed if the DB root IN was never logged (was still null). This
* caused a DatabaseException when evicting, because the evictor expects no
* INs for deleted DBs on the INList.
*/
public void testRemoveNonPersistentDbSR15317()
throws Throwable {
Database db = null;
try {
EnvironmentConfig envConfig = getEnvConfig(true);
/* Disable compressor for test predictability. */
envConfig.setConfigParam("je.env.runINCompressor", "false");
env = new Environment(envHome, envConfig);
db = createDb(true);
/* Insert some data to cause eviction later. */
insert(db,
null, // txn
1, // start
30000, // end
new HashSet(), // expected
false); // useRandom
db.close();
env.removeDatabase(null, DBNAME);
envConfig = env.getConfig();
/* Switch to a small cache to force eviction. */
envConfig.setCacheSize(96 * 1024);
env.setMutableConfig(envConfig);
for (int i = 0; i < 10; i += 1) {
env.evictMemory();
}
} finally {
if (env != null) {
try {
env.close();
} catch (Throwable e) {
System.out.println("Ignored: " + e);
}
env = null;
}
}
}
示例10: xtestReadOnly
import com.sleepycat.je.Environment; //導入方法依賴的package包/類
public void xtestReadOnly()
throws Exception {
/* Make a read-only handle on a read-write environment directory.*/
Environment env = createEnv(true, envHome);
try {
DbBackup backup = new DbBackup(env);
fail("Should fail because env is read/only.");
} catch (DatabaseException expected) {
}
env.close();
/*
* Make a read-only handle on a read-only environment directory. Use a
* new environment directory because we're going to set it read0nly and
* there doesn't seem to be a way of undoing that.
*/
File tempEnvDir = new File(envHome, SAVE1);
assertTrue(tempEnvDir.mkdirs());
env = createEnv(false, tempEnvDir);
growFiles("db1", env, 8);
env.close();
//assertTrue(tempEnvDir.setReadOnly());
env = createEnv(true, tempEnvDir);
DbBackup backupHelper = new DbBackup(env);
backupHelper.startBackup();
FileManager fileManager =
DbInternal.envGetEnvironmentImpl(env).getFileManager();
long lastFile = fileManager.getLastFileNum().longValue();
assertEquals(lastFile, backupHelper.getLastFileInBackupSet());
backupHelper.endBackup();
env.close();
assertTrue(tempEnvDir.delete());
}
示例11: run
import com.sleepycat.je.Environment; //導入方法依賴的package包/類
public void run(File envHomeDirectory)
throws DatabaseException, IOException {
/* Create the environment object. */
EnvironmentConfig envConfig = new EnvironmentConfig();
envConfig.setAllowCreate(true);
Environment env = new Environment(envHomeDirectory, envConfig);
/* Create the database object. */
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setAllowCreate(true);
Database db = env.openDatabase(null, DB_NAME, dbConfig);
/* Create the sequence oject. */
SequenceConfig config = new SequenceConfig();
config.setAllowCreate(true);
DatabaseEntry key =
new DatabaseEntry(KEY_NAME.getBytes("UTF-8"));
Sequence seq = db.openSequence(null, key, config);
/* Allocate a few sequence numbers. */
for (int i = 0; i < 10; i++) {
long seqnum = seq.get(null, 1);
System.out.println("Got sequence number: " + seqnum);
}
/* Close all. */
seq.close();
db.close();
env.close();
}
示例12: testDefaults
import com.sleepycat.je.Environment; //導入方法依賴的package包/類
public void testDefaults()
throws Exception {
EnvironmentConfig envConfig = TestUtils.initEnvConfig();
envConfig.setAllowCreate(true);
Environment env = new Environment(envHome, envConfig);
EnvironmentImpl envImpl = DbInternal.envGetEnvironmentImpl(env);
MemoryBudget testBudget = envImpl.getMemoryBudget();
/*
System.out.println("max= " + testBudget.getMaxMemory());
System.out.println("tree= " + testBudget.getCacheBudget());
System.out.println("log= " + testBudget.getLogBufferBudget());
System.out.println("thresh= " + testBudget.getEvictorCheckThreshold());
*/
assertTrue(testBudget.getMaxMemory() > 0);
assertTrue(testBudget.getCacheBudget() > 0);
assertTrue(testBudget.getLogBufferBudget() > 0);
assertTrue(testBudget.getMaxMemory() <=
MemoryBudget.getRuntimeMaxMemory());
assertTrue((testBudget.getLogBufferBudget() +
testBudget.getCacheBudget()) <=
testBudget.getMaxMemory());
/*
* The tree and log buffer budget together is equal to
* the max memory budget.
*/
assertEquals((testBudget.getCacheBudget() +
testBudget.getLogBufferBudget()),
testBudget.getMaxMemory());
env.close();
}
示例13: testOpenableBean
import com.sleepycat.je.Environment; //導入方法依賴的package包/類
/**
* MBean which can configure and open an environment.
*/
public void testOpenableBean()
throws Throwable {
Environment env = null;
try {
/* Environment is not open, and we can open. */
env = openEnv(false);
env.close();
DynamicMBean mbean = new JEApplicationMBean(environmentDir);
validateGetters(mbean, 5);
validateOperations(mbean, 1, false, null, null); // don't invoke
/* Open the environment. */
mbean.invoke(JEApplicationMBean.OP_OPEN, null, null);
validateGetters(mbean, 7 );
validateOperations(mbean, 8, true, null, null);
/*
* The last call to validateOperations ended up closing the
* environment.
*/
validateGetters(mbean, 5);
validateOperations(mbean, 1, false, null, null);
/* Should be no open handles. */
checkForNoOpenHandles(environmentDir);
} catch (Throwable t) {
t.printStackTrace();
if (env != null) {
env.close();
}
throw t;
}
}
示例14: testDbLookup
import com.sleepycat.je.Environment; //導入方法依賴的package包/類
public void testDbLookup() throws Throwable {
try {
EnvironmentConfig envConfig = TestUtils.initEnvConfig();
envConfig.setTransactional(true);
envConfig.setConfigParam(EnvironmentParams.NODE_MAX.getName(), "6");
envConfig.setAllowCreate(true);
Environment env = new Environment(envHome, envConfig);
// Make two databases
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setTransactional(true);
dbConfig.setAllowCreate(true);
Database dbHandleAbcd = env.openDatabase(null, "abcd", dbConfig);
Database dbHandleXyz = env.openDatabase(null, "xyz", dbConfig);
// Can we get them back?
dbConfig.setAllowCreate(false);
Database newAbcdHandle = env.openDatabase(null, "abcd", dbConfig);
Database newXyzHandle = env.openDatabase(null, "xyz", dbConfig);
dbHandleAbcd.close();
dbHandleXyz.close();
newAbcdHandle.close();
newXyzHandle.close();
env.close();
} catch (Throwable t) {
t.printStackTrace();
throw t;
}
}
示例15: main
import com.sleepycat.je.Environment; //導入方法依賴的package包/類
public static void main(String[] args)
throws Exception {
if (args.length != 1) {
throw new Exception("Home directory arg is required.");
}
File homeDir = new File(args[0]);
File logFile = new File(homeDir, TestUtils.LOG_FILE_NAME);
if (logFile.exists()) {
throw new Exception("Home directory must be empty of log files.");
}
EnvironmentConfig envConfig = TestUtils.initEnvConfig();
envConfig.setAllowCreate(true);
envConfig.setTransactional(true);
/* Make as small a log as possible to save space in CVS. */
envConfig.setConfigParam
(EnvironmentParams.JE_LOGGING_LEVEL.getName(),
Level.OFF.getName());
envConfig.setConfigParam
(EnvironmentParams.ENV_RUN_INCOMPRESSOR.getName(), "false");
envConfig.setConfigParam
(EnvironmentParams.ENV_RUN_CLEANER.getName(), "false");
envConfig.setConfigParam
(EnvironmentParams.ENV_RUN_EVICTOR.getName(), "false");
envConfig.setConfigParam
(EnvironmentParams.ENV_RUN_CHECKPOINTER.getName(), "false");
Environment env = new Environment(homeDir, envConfig);
env.close();
if (!logFile.exists()) {
throw new Exception("Home directory does not contain: " + logFile);
}
System.out.println("Sucessfully created: " + logFile);
}