1 8 package com.sleepycat.collections.test.serial; 9 10 import junit.framework.Test; 11 import junit.framework.TestCase; 12 import junit.framework.TestSuite; 13 14 import com.sleepycat.bind.serial.StoredClassCatalog; 15 import com.sleepycat.collections.test.DbTestUtil; 16 import com.sleepycat.collections.test.TestEnv; 17 import com.sleepycat.compat.DbCompat; 18 import com.sleepycat.je.Database; 19 import com.sleepycat.je.DatabaseConfig; 20 import com.sleepycat.je.Environment; 21 22 25 public class CatalogCornerCaseTest extends TestCase { 26 27 public static void main(String [] args) 28 throws Exception { 29 30 junit.framework.TestResult tr = 31 junit.textui.TestRunner.run(suite()); 32 if (tr.errorCount() > 0 || 33 tr.failureCount() > 0) { 34 System.exit(1); 35 } else { 36 System.exit(0); 37 } 38 } 39 40 public static Test suite() 41 throws Exception { 42 43 return new TestSuite(CatalogCornerCaseTest.class); 44 } 45 46 private Environment env; 47 48 public CatalogCornerCaseTest(String name) { 49 50 super(name); 51 } 52 53 public void setUp() 54 throws Exception { 55 56 DbTestUtil.printTestName(getName()); 57 env = TestEnv.BDB.open(getName()); 58 } 59 60 public void tearDown() { 61 62 try { 63 if (env != null) { 64 env.close(); 65 } 66 } catch (Exception e) { 67 System.out.println("Ignored exception during tearDown: " + e); 68 } finally { 69 70 env = null; 71 } 72 } 73 74 public void testReadOnlyEmptyCatalog() 75 throws Exception { 76 77 String file = "catalog.db"; 78 79 80 DatabaseConfig config = new DatabaseConfig(); 81 config.setAllowCreate(true); 82 DbCompat.setTypeBtree(config); 83 Database db = DbCompat.openDatabase(env, null, file, null, config); 84 db.close(); 85 86 87 config.setAllowCreate(false); 88 config.setReadOnly(true); 89 db = DbCompat.openDatabase(env, null, file, null, config); 90 91 92 try { 93 new StoredClassCatalog(db); 94 fail(); 95 } catch (IllegalStateException e) { } 96 db.close(); 97 } 98 } 99 | Popular Tags |