/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2000, 2015 Oracle and/or its affiliates. All rights reserved.
*
*/
package com.sleepycat.collections.test.serial;
import static org.junit.Assert.fail;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.sleepycat.bind.serial.StoredClassCatalog;
import com.sleepycat.compat.DbCompat;
import com.sleepycat.db.Database;
import com.sleepycat.db.DatabaseConfig;
import com.sleepycat.db.Environment;
import com.sleepycat.util.test.SharedTestUtils;
import com.sleepycat.util.test.TestBase;
import com.sleepycat.util.test.TestEnv;
/**
* @author Mark Hayes
*/
public class CatalogCornerCaseTest extends TestBase {
private Environment env;
public CatalogCornerCaseTest() {
customName = "CatalogCornerCaseTest";
}
@Before
public void setUp()
throws Exception {
super.setUp();
SharedTestUtils.printTestName(customName);
env = TestEnv.BDB.open(customName);
}
@After
public void tearDown() {
try {
if (env != null) {
env.close();
}
} catch (Exception e) {
System.out.println("Ignored exception during tearDown: " + e);
} finally {
/* Ensure that GC can cleanup. */
env = null;
}
}
@Test
public void testReadOnlyEmptyCatalog()
throws Exception {
String file = "catalog.db";
/* Create an empty database. */
DatabaseConfig config = new DatabaseConfig();
config.setAllowCreate(true);
DbCompat.setTypeBtree(config);
Database db =
DbCompat.testOpenDatabase(env, null, file, null, config);
db.close();
/* Open the empty database read-only. */
config.setAllowCreate(false);
config.setReadOnly(true);
db = DbCompat.testOpenDatabase(env, null, file, null, config);
/* Expect exception when creating the catalog. */
try {
new StoredClassCatalog(db);
fail();
} catch (RuntimeException e) { }
db.close();
}
}