01: /*-
02: * See the file LICENSE for redistribution information.
03: *
04: * Copyright (c) 2000,2008 Oracle. All rights reserved.
05: *
06: * $Id: CatalogCornerCaseTest.java,v 1.6.2.2 2008/01/07 15:14:24 cwl Exp $
07: */
08: package com.sleepycat.collections.test.serial;
09:
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: /**
23: * @author Mark Hayes
24: */
25: public class CatalogCornerCaseTest extends TestCase {
26:
27: public static void main(String[] args) throws Exception {
28:
29: junit.framework.TestResult tr = junit.textui.TestRunner
30: .run(suite());
31: if (tr.errorCount() > 0 || tr.failureCount() > 0) {
32: System.exit(1);
33: } else {
34: System.exit(0);
35: }
36: }
37:
38: public static Test suite() throws Exception {
39:
40: return new TestSuite(CatalogCornerCaseTest.class);
41: }
42:
43: private Environment env;
44:
45: public CatalogCornerCaseTest(String name) {
46:
47: super (name);
48: }
49:
50: public void setUp() throws Exception {
51:
52: DbTestUtil.printTestName(getName());
53: env = TestEnv.BDB.open(getName());
54: }
55:
56: public void tearDown() {
57:
58: try {
59: if (env != null) {
60: env.close();
61: }
62: } catch (Exception e) {
63: System.out.println("Ignored exception during tearDown: "
64: + e);
65: } finally {
66: /* Ensure that GC can cleanup. */
67: env = null;
68: }
69: }
70:
71: public void testReadOnlyEmptyCatalog() throws Exception {
72:
73: String file = "catalog.db";
74:
75: /* Create an empty database. */
76: DatabaseConfig config = new DatabaseConfig();
77: config.setAllowCreate(true);
78: DbCompat.setTypeBtree(config);
79: Database db = DbCompat.openDatabase(env, null, file, null,
80: config);
81: db.close();
82:
83: /* Open the empty database read-only. */
84: config.setAllowCreate(false);
85: config.setReadOnly(true);
86: db = DbCompat.openDatabase(env, null, file, null, config);
87:
88: /* Expect exception when creating the catalog. */
89: try {
90: new StoredClassCatalog(db);
91: fail();
92: } catch (IllegalStateException e) {
93: }
94: db.close();
95: }
96: }
|