00001
00002
00003
00004
00005
00006
00007
00008
00009 package com.sleepycat.collections.test.serial;
00010
00011 import junit.framework.Test;
00012 import junit.framework.TestCase;
00013 import junit.framework.TestSuite;
00014
00015 import com.sleepycat.bind.serial.StoredClassCatalog;
00016 import com.sleepycat.collections.test.DbTestUtil;
00017 import com.sleepycat.collections.test.TestEnv;
00018 import com.sleepycat.compat.DbCompat;
00019 import com.sleepycat.db.Database;
00020 import com.sleepycat.db.DatabaseConfig;
00021 import com.sleepycat.db.Environment;
00022
00026 public class CatalogCornerCaseTest extends TestCase {
00027
00028 public static void main(String[] args)
00029 throws Exception {
00030
00031 junit.framework.TestResult tr =
00032 junit.textui.TestRunner.run(suite());
00033 if (tr.errorCount() > 0 ||
00034 tr.failureCount() > 0) {
00035 System.exit(1);
00036 } else {
00037 System.exit(0);
00038 }
00039 }
00040
00041 public static Test suite()
00042 throws Exception {
00043
00044 return new TestSuite(CatalogCornerCaseTest.class);
00045 }
00046
00047 private Environment env;
00048
00049 public CatalogCornerCaseTest(String name) {
00050
00051 super(name);
00052 }
00053
00054 public void setUp()
00055 throws Exception {
00056
00057 DbTestUtil.printTestName(getName());
00058 env = TestEnv.BDB.open(getName());
00059 }
00060
00061 public void tearDown() {
00062
00063 try {
00064 if (env != null) {
00065 env.close();
00066 }
00067 } catch (Exception e) {
00068 System.out.println("Ignored exception during tearDown: " + e);
00069 } finally {
00070
00071 env = null;
00072 }
00073 }
00074
00075 public void testReadOnlyEmptyCatalog()
00076 throws Exception {
00077
00078 String file = "catalog.db";
00079
00080
00081 DatabaseConfig config = new DatabaseConfig();
00082 config.setAllowCreate(true);
00083 DbCompat.setTypeBtree(config);
00084 Database db = DbCompat.openDatabase(env, null, file, null, config);
00085 db.close();
00086
00087
00088 config.setAllowCreate(false);
00089 config.setReadOnly(true);
00090 db = DbCompat.openDatabase(env, null, file, null, config);
00091
00092
00093 try {
00094 new StoredClassCatalog(db);
00095 fail();
00096 } catch (IllegalStateException e) { }
00097 db.close();
00098 }
00099 }