001: /*
002: (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: [See end of file]
004: $Id: TestConnection.java,v 1.32 2008/01/02 12:08:13 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.db.test;
008:
009: /**
010: *
011: * This tests basic open/create operations on the modelRDB.
012: *
013: * To run, you must have a mySQL database operational on
014: * localhost with a database name of "test" and allow use
015: * by a user named "test" with an empty password.
016: *
017: * (based in part on model tests written earlier by bwm and kers)
018: *
019: * @author csayers
020: * @version 0.1
021: */
022:
023: import org.apache.commons.logging.Log;
024: import org.apache.commons.logging.LogFactory;
025:
026: import com.hp.hpl.jena.db.*;
027: import com.hp.hpl.jena.db.impl.IRDBDriver;
028:
029: import junit.framework.*;
030:
031: import com.hp.hpl.jena.rdf.model.*;
032: import com.hp.hpl.jena.shared.*;
033: import com.hp.hpl.jena.vocabulary.DB;
034:
035: public class TestConnection extends TestCase {
036:
037: protected static Log logger = LogFactory
038: .getLog(TestConnection.class);
039:
040: String DefModel = GraphRDB.DEFAULT;
041:
042: public TestConnection(String name) {
043: super (name);
044: }
045:
046: public static TestSuite suite() {
047: return new TestSuite(TestConnection.class);
048: }
049:
050: protected void setUp() throws java.lang.Exception {
051: }
052:
053: protected void tearDown() throws java.lang.Exception {
054: }
055:
056: private static void loadClass() {
057: try {
058: Class.forName(TestPackage.M_DBDRIVER_CLASS);
059: } catch (Exception e) {
060: throw new JenaException(e);
061: }
062: }
063:
064: public static IDBConnection makeTestConnection() {
065: loadClass();
066: return new DBConnection(TestPackage.M_DB_URL,
067: TestPackage.M_DB_USER, TestPackage.M_DB_PASSWD,
068: TestPackage.M_DB);
069: }
070:
071: public static IDBConnection makeAndCleanTestConnection() {
072: IDBConnection result = makeTestConnection();
073: boolean tryClean = true;
074: boolean didClean = false;
075: boolean tryUnlock = true;
076: String err = null;
077: while (tryClean && !didClean) {
078: try {
079: result.cleanDB();
080: didClean = true;
081: } catch (Exception e) {
082: err = err + "\n" + e;
083: if (tryUnlock) {
084: tryUnlock = false;
085: if (result.getDriver().DBisLocked())
086: try {
087: result.getDriver().unlockDB();
088: } catch (Exception e1) {
089: err = err + "\n" + e1;
090: }
091: } else
092: tryClean = false;
093: }
094: }
095: if (didClean == false)
096: throw new JenaException("Failed to clean database.\n" + err);
097: return result;
098: }
099:
100: /* public void testNoClass() throws java.lang.Exception {
101: try {
102: IDBConnection conn = new DBConnection(
103: TestPackage.M_DB_URL,
104: TestPackage.M_DB_USER,
105: TestPackage.M_DB_PASSWD,
106: TestPackage.M_DB);
107: conn.cleanDB();
108: assertTrue(false); // should not get here
109: } catch (Exception e) {
110: }
111: } */
112:
113: public void testRecovery() throws java.lang.Exception {
114: IDBConnection conn = makeAndCleanTestConnection();
115: ModelRDB m = null;
116: try {
117: m = ModelRDB.createModel(conn, "myName");
118: m.close();
119: } catch (Exception e) {
120: assertTrue(false);
121: }
122: try {
123: m = ModelRDB.createModel(conn, "myName");
124: assertTrue(false);
125: } catch (Exception e) {
126: }
127: conn.close();
128: }
129:
130: public void testDBConnect() throws java.lang.Exception {
131: IDBConnection conn = makeTestConnection();
132: conn.close();
133: }
134:
135: public void testBadConnection() throws java.lang.Exception {
136: /*
137: * try { IDBConnection conn = new DBConnection( "Bad URL",
138: * TestPackage.M_DB_USER, TestPackage.M_DB_PASSWD, TestPackage.M_DB);
139: * conn.cleanDB(); assertTrue(false); // should not get here } catch
140: * (Exception e) { }
141: */
142: try {
143: IDBConnection conn = new DBConnection(TestPackage.M_DB_URL,
144: TestPackage.M_DB_USER, TestPackage.M_DB_PASSWD,
145: "Bad DB");
146: conn.cleanDB();
147: assertTrue(false); // should not get here
148: } catch (Exception e) {
149: }
150: }
151:
152: public void testConstructDefaultModel() throws java.lang.Exception {
153: IDBConnection conn = makeAndCleanTestConnection();
154: ModelRDB m = ModelRDB.createModel(conn);
155: m.remove();
156: conn.close();
157: }
158:
159: public void testConstructAndOpenDefaultModel()
160: throws java.lang.Exception {
161: IDBConnection conn = makeAndCleanTestConnection();
162: ModelRDB m = ModelRDB.createModel(conn);
163: m.close();
164: ModelRDB m2 = ModelRDB.open(conn);
165: m2.remove();
166: conn.close();
167: }
168:
169: public void testConstructNamedModel() throws java.lang.Exception {
170: IDBConnection conn = makeAndCleanTestConnection();
171: ModelRDB m = ModelRDB.createModel(conn, "myName");
172: m.remove();
173: conn.close();
174: }
175:
176: public void testBadNamedModel() throws java.lang.Exception {
177: IDBConnection conn = makeAndCleanTestConnection();
178: ModelRDB m = null;
179: try {
180: m = ModelRDB.createModel(conn, DefModel);
181: assertTrue(false);
182: } catch (Exception e) {
183: }
184: conn.close();
185: }
186:
187: public void testBadNamedFactoryModel() throws java.lang.Exception {
188: IDBConnection conn = makeAndCleanTestConnection();
189: ModelMaker maker = ModelFactory.createModelRDBMaker(conn);
190: Model m = null;
191: try {
192: m = maker.createModel(DefModel);
193: assertTrue(false);
194: } catch (Exception e) {
195: }
196: conn.close();
197: }
198:
199: public void testReconstructDefaultModel()
200: throws java.lang.Exception {
201: IDBConnection conn = makeAndCleanTestConnection();
202: ModelRDB m = ModelRDB.createModel(conn);
203: m.remove();
204: ModelRDB m1 = ModelRDB.createModel(conn);
205: m1.remove();
206: conn.close();
207: }
208:
209: public void testReconstructNamedModel() throws java.lang.Exception {
210: IDBConnection conn = makeAndCleanTestConnection();
211: ModelRDB m = ModelRDB.createModel(conn, "myName");
212: m.remove();
213: ModelRDB m1 = ModelRDB.createModel(conn, "myName");
214: m1.remove();
215: conn.close();
216: }
217:
218: public void testConstructAndOpenNamedModel()
219: throws java.lang.Exception {
220: IDBConnection conn = makeAndCleanTestConnection();
221: ModelRDB m = ModelRDB.createModel(conn, "myName");
222: m.close();
223: ModelRDB m2 = ModelRDB.open(conn, "myName");
224: m2.remove();
225: conn.close();
226: }
227:
228: public void testConstructParamaterizedModel()
229: throws java.lang.Exception {
230: IDBConnection conn = makeAndCleanTestConnection();
231: ModelRDB m = ModelRDB.createModel(conn, ModelRDB
232: .getDefaultModelProperties(conn));
233: m.remove();
234: conn.close();
235: }
236:
237: public void testConstructAndOpenParamaterizedModel()
238: throws java.lang.Exception {
239: IDBConnection conn = makeAndCleanTestConnection();
240: ModelRDB m = ModelRDB.createModel(conn, ModelRDB
241: .getDefaultModelProperties(conn));
242: m.close();
243: ModelRDB m2 = ModelRDB.open(conn);
244: m2.remove();
245: conn.close();
246: }
247:
248: public void testConstructNamedParamaterizedModel()
249: throws java.lang.Exception {
250: IDBConnection conn = makeAndCleanTestConnection();
251: ModelRDB m = ModelRDB.createModel(conn, "myName", ModelRDB
252: .getDefaultModelProperties(conn));
253: m.remove();
254: conn.close();
255: }
256:
257: public void testConstructAndOpenNamedParamaterizedModel()
258: throws java.lang.Exception {
259: IDBConnection conn = makeAndCleanTestConnection();
260: ModelRDB m = ModelRDB.createModel(conn, "myName", ModelRDB
261: .getDefaultModelProperties(conn));
262: m.close();
263: ModelRDB m2 = ModelRDB.open(conn, "myName");
264: m2.remove();
265: conn.close();
266: }
267:
268: public void testOpenNamedNonExistentModel()
269: throws java.lang.Exception {
270: IDBConnection conn = makeTestConnection();
271: try {
272: ModelRDB m2 = ModelRDB.open(conn, "myName");
273: m2.remove();
274: conn.close();
275: assertTrue("Successfully opened non-existent model", false);
276: } catch (RDFRDBException e) {
277: conn.close();
278: }
279: }
280:
281: public void testOpenUnnamedNonExistentModel()
282: throws java.lang.Exception {
283: IDBConnection conn = makeTestConnection();
284: try {
285: conn.cleanDB();
286: ModelRDB m2 = ModelRDB.open(conn);
287: m2.remove();
288: conn.close();
289: assertTrue(
290: "Successfully opened unnamed non-existent model",
291: false);
292: } catch (RDFRDBException e) {
293: conn.close();
294: }
295: }
296:
297: public void testCreateExistingModel() throws java.lang.Exception {
298: IDBConnection conn = makeAndCleanTestConnection();
299: ModelRDB m = ModelRDB.createModel(conn, "myName", ModelRDB
300: .getDefaultModelProperties(conn));
301: try {
302: ModelRDB m2 = ModelRDB.createModel(conn, "myName", ModelRDB
303: .getDefaultModelProperties(conn));
304: m.remove();
305: m2.remove();
306: conn.close();
307: assertTrue("Successfully created pre-existing model", false);
308: } catch (RDFRDBException e) {
309: m.remove();
310: conn.close();
311: }
312: }
313:
314: public void addToDBGraphProp(Model model, Property prop, String val) {
315: // first, get URI of the graph
316: StmtIterator iter = model.listStatements(new SimpleSelector(
317: null, DB.graphName, (RDFNode) null));
318: assertTrue(iter.hasNext());
319:
320: Statement stmt = iter.nextStatement();
321: assertTrue(iter.hasNext() == false);
322: Resource graphURI = stmt.getSubject();
323: Literal l = model.createLiteral(val);
324: Statement s = model.createStatement(graphURI, prop, l);
325: model.add(s);
326: assertTrue(model.contains(s));
327: }
328:
329: public void testConstructDefSchemaModel()
330: throws java.lang.Exception {
331: IDBConnection conn = makeAndCleanTestConnection();
332: conn.getDriver().setStoreWithModel("");
333: // Model props = ModelRDB.getDefaultModelProperties(conn);
334: // addToDBGraphProp(props,DB.graphDBSchema,DefModel);
335: // ModelRDB m = ModelRDB.createModel(conn, props);
336: ModelRDB m = ModelRDB.createModel(conn);
337: m.remove();
338: conn.close();
339: }
340:
341: public void testConstructBadSchemaModel()
342: throws java.lang.Exception {
343: IDBConnection conn = makeAndCleanTestConnection();
344: // Model props = ModelRDB.getDefaultModelProperties(conn);
345: // addToDBGraphProp(props,DB.graphDBSchema,"SCHEMA_DOES_NOT_EXIST");
346: conn.getDriver().setStoreWithModel(DefModel);
347: try {
348: // ModelRDB m = ModelRDB.createModel(conn, props);
349: ModelRDB m = ModelRDB.createModel(conn);
350: m.remove();
351: assertFalse("Created model with non-existent schema", true);
352: } catch (RDFRDBException e) {
353: }
354: conn.getDriver().setStoreWithModel("MODEL_DOES_NOT_EXIST");
355: try {
356: // ModelRDB m = ModelRDB.createModel(conn, props);
357: ModelRDB m = ModelRDB.createModel(conn);
358: m.remove();
359: assertFalse("Created model with non-existent schema", true);
360: } catch (RDFRDBException e) {
361: }
362: conn.close();
363: }
364:
365: public void testConstructNamedModelDefSchema()
366: throws java.lang.Exception {
367: // this named model uses the default schema
368: IDBConnection conn = makeAndCleanTestConnection();
369: // Model props = ModelRDB.getDefaultModelProperties(conn);
370: // addToDBGraphProp(props,DB.graphDBSchema,DefModel);
371: conn.getDriver().setStoreWithModel(null);
372: // ModelRDB m = ModelRDB.createModel(conn, "myName", props);
373: ModelRDB m = ModelRDB.createModel(conn, "myName");
374: m.remove();
375: conn.close();
376: }
377:
378: public void testConstructNamedModelDefSchema1()
379: throws java.lang.Exception {
380: // same as testConstructNamedModelDefSchema except the default model already exists.
381: // should new model should share tables with default. no way now to verify this
382: // from the API though. have to check it manually.
383: IDBConnection conn = makeAndCleanTestConnection();
384: // ModelRDB mdef = ModelRDB.createModel(conn, ModelRDB.getDefaultModelProperties(conn));
385: // Model props = ModelRDB.getDefaultModelProperties(conn);
386: // addToDBGraphProp(props,DB.graphDBSchema,DefModel);
387: // ModelRDB m = ModelRDB.createModel(conn, "myName", props);
388: ModelRDB mdef = ModelRDB.createModel(conn);
389: conn.getDriver().setStoreWithModel(DefModel);
390: ModelRDB m = ModelRDB.createModel(conn, "myName");
391: mdef.remove();
392: m.remove();
393: conn.close();
394: }
395:
396: public void testConstructNamedModelDefSchema2()
397: throws java.lang.Exception {
398: // similar to testConstructNamedModelDefSchema1 except the newly created
399: // model should not share the default schema.
400: IDBConnection conn = makeAndCleanTestConnection();
401: // ModelRDB mdef = ModelRDB.createModel(conn, ModelRDB.getDefaultModelProperties(conn));
402: // Model props = ModelRDB.getDefaultModelProperties(conn);
403: // addToDBGraphProp(props,DB.graphDBSchema,DefModel);
404: // ModelRDB m = ModelRDB.createModel(conn, "myName", props);
405: ModelRDB mdef = ModelRDB.createModel(conn);
406: conn.getDriver().setStoreWithModel(null);
407: ModelRDB m = ModelRDB.createModel(conn, "myName");
408: mdef.remove();
409: m.remove();
410: conn.close();
411: }
412:
413: public void testConstructNamedModelSchema()
414: throws java.lang.Exception {
415: // construct two named models that share a schema
416: IDBConnection conn = makeAndCleanTestConnection();
417: // ModelRDB m1 = ModelRDB.createModel(conn, "model1", ModelRDB.getDefaultModelProperties(conn));
418: ModelRDB m1 = ModelRDB.createModel(conn, "model1");
419: // Model props = ModelRDB.getDefaultModelProperties(conn);
420: // addToDBGraphProp(props,DB.graphDBSchema,"model1");
421: // ModelRDB m2 = ModelRDB.createModel(conn, "model2", props);
422: conn.getDriver().setStoreWithModel("model1");
423: ModelRDB m2 = ModelRDB.createModel(conn, "model2");
424: m1.remove();
425: m2.remove();
426: conn.close();
427: }
428:
429: public void testNamedPrefixedModel() throws java.lang.Exception {
430: IDBConnection conn = makeAndCleanTestConnection();
431: IRDBDriver d = conn.getDriver();
432: d.setTableNamePrefix("foo_");
433: conn.cleanDB(); // just in case any crud lying about from previous test
434: ModelRDB m = ModelRDB.createModel(conn, "myName");
435: m.remove();
436: conn.cleanDB();
437: conn.close();
438: }
439:
440: public void testNamedPrefixedPersists() throws java.lang.Exception {
441: IDBConnection conn = makeTestConnection();
442: IRDBDriver d = conn.getDriver();
443: String pfx = "foo_";
444: d.setTableNamePrefix(pfx);
445: conn.cleanDB(); // just in case any crud lying about from previous test
446: ModelRDB m = ModelRDB.createModel(conn, "myName");
447: m.close();
448: conn.close();
449: conn = makeTestConnection();
450: d = conn.getDriver();
451: d.setTableNamePrefix(pfx);
452: m = ModelRDB.open(conn, "myName");
453: assertTrue(d.getTableNamePrefix().equalsIgnoreCase(pfx));
454: conn.cleanDB();
455: }
456:
457: public void testNamedPrefixFailure() throws java.lang.Exception {
458: IDBConnection conn = makeAndCleanTestConnection();
459: IRDBDriver d = conn.getDriver();
460: String longPfx = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
461: + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
462: + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
463: + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
464: + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
465: + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
466: + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
467: + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
468: + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
469: try {
470: d.setTableNamePrefix(longPfx);
471: assertTrue(false); // should not get here
472: } catch (Exception e) {
473: }
474: ModelRDB m = ModelRDB.createModel(conn);
475: try {
476: d.setTableNamePrefix("foo_");
477: assertTrue(false); // should not get here
478: } catch (Exception e) {
479: }
480: m.close();
481: conn.close();
482: }
483:
484: // helper class to sync threads
485: public class syncOnCount {
486: private int count;
487:
488: public syncOnCount() {
489: count = 0;
490: }
491:
492: public synchronized boolean testCount(int i) {
493: return count >= i;
494: }
495:
496: public void incCount() {
497: incCount(1);
498: }
499:
500: public synchronized void incCount(int N) {
501: count = count + N;
502: }
503:
504: public void waitOnCount(int cnt) {
505: int i = 0;
506: for (i = 0; i < 100; i++)
507: try {
508: //System.err.println(cnt+"/"+count) ;
509: if (testCount(cnt))
510: break;
511: Thread.yield();
512: Thread.sleep(1000);
513: } catch (Exception e) {
514: throw new RuntimeException(
515: "waitOnCount interrupted" + e);
516: }
517: if (!testCount(cnt)) {
518: System.err.println();
519: System.err.println("Expected=" + cnt + " Actual="
520: + count);
521: assertTrue("waitOnCount", false);
522: }
523: }
524:
525: }
526:
527: syncOnCount s;
528: volatile String msg = "";
529:
530: public void testConcurrentThread() {
531:
532: class thread1 extends Thread {
533: syncOnCount s;
534:
535: public thread1(syncOnCount sc) {
536: super ("thread1");
537: s = sc;
538: }
539:
540: public void run() {
541: IDBConnection conn = makeAndCleanTestConnection();
542: // try {
543: // // 0, 1, 2, 4, 8
544: // System.err.println("Connection.TRANSACTION_NONE = "+Connection.TRANSACTION_NONE) ;
545: // System.err.println("Connection.TRANSACTION_READ_UNCOMMITTED = "+Connection.TRANSACTION_READ_UNCOMMITTED) ;
546: // System.err.println("Connection.TRANSACTION_READ_COMMITTED = "+Connection.TRANSACTION_READ_COMMITTED) ;
547: // System.err.println("Connection.TRANSACTION_REPEATABLE_READ = "+Connection.TRANSACTION_REPEATABLE_READ) ;
548: // System.err.println("Connection.TRANSACTION_SERIALIZABLE = "+Connection.TRANSACTION_SERIALIZABLE) ;
549: // System.err.println("Level: "+conn.getConnection().getTransactionIsolation()) ;
550: // } catch (Exception e) {}
551:
552: try {
553: ModelRDB foo = ModelRDB.createModel(conn, "foo");
554: s.incCount(); // count is now 1
555: s.waitOnCount(2);
556: Resource u = foo.createResource("test#subject");
557: Property p = foo.createProperty("test#predicate");
558: Resource o = foo.createResource("test#object");
559: Statement stmt = foo.createStatement(u, p, o);
560: if (foo.contains(stmt))
561: synchronized (msg) {
562: if (msg.length() == 0)
563: msg = "Thread 1 can see uncommited statement";
564: s.incCount(99);
565: return;
566: }
567:
568: //assertFalse(foo.contains(stmt));
569: s.incCount();
570: s.waitOnCount(4);
571: if (!foo.contains(stmt))
572: synchronized (msg) {
573: if (msg.length() == 0)
574: msg = "Thread 1 can't see commited statement";
575: s.incCount(99);
576: return;
577: }
578: //assertTrue(foo.contains(stmt));
579: foo.remove(stmt);
580: s.incCount();
581: } finally {
582: try {
583: conn.close();
584: } catch (Exception e) {
585: e.printStackTrace();
586: }
587: }
588: }
589: }
590:
591: class thread2 extends Thread {
592: syncOnCount s;
593:
594: public thread2(syncOnCount sc) {
595: super ("thread2");
596: s = sc;
597: }
598:
599: public void run() {
600: s.waitOnCount(1);
601: IDBConnection conn = makeTestConnection();
602:
603: try {
604: ModelRDB foo = ModelRDB.open(conn, "foo");
605: foo.begin();
606: Resource u = foo.createResource("test#subject");
607: Property p = foo.createProperty("test#predicate");
608: Resource o = foo.createResource("test#object");
609: Statement stmt = foo.createStatement(u, p, o);
610: foo.add(stmt);
611: s.incCount();
612: s.waitOnCount(3);
613: if (!foo.contains(stmt))
614: synchronized (msg) {
615: if (msg.length() == 0)
616: msg = "Thread 2 can't see statement it just added";
617: s.incCount(99);
618: return;
619: }
620: //assertTrue(foo.contains(stmt));
621: try {
622: foo.commit();
623: } catch (Exception e) {
624: if (msg.length() == 0)
625: msg = "Failed to commit transaction: "
626: + e.getMessage();
627: return;
628: }
629: s.incCount(); // wake up thread 1
630: s.waitOnCount(5); // thread1 has now removed stmt
631: //assertFalse(foo.contains(stmt));
632: if (foo.contains(stmt))
633: synchronized (msg) {
634: if (msg.length() == 0)
635: msg = "Thread 2 can see statement thread 1 should have removed";
636: s.incCount(99);
637: return;
638: }
639:
640: } finally {
641: try {
642: conn.close();
643: } catch (Exception e) {
644: e.printStackTrace();
645: }
646: }
647: }
648: }
649:
650: if (!TestPackage.M_DBCONCURRENT) {
651: logger.warn("Transaction isolation test surpressed");
652: return;
653: }
654: syncOnCount s = new syncOnCount();
655: Thread t1 = new thread1(s);
656: Thread t2 = new thread2(s);
657: t2.start();
658: t1.start();
659: try {
660: t1.join();
661: t2.join();
662: } catch (Exception e) {
663: assertTrue(false);
664: }
665: if (msg != null && msg.length() > 0)
666: assertTrue(msg, false);
667:
668: }
669:
670: public void testDBMutex() {
671: IDBConnection conn = makeAndCleanTestConnection();
672: IRDBDriver d = conn.getDriver();
673:
674: d.lockDB();
675: try {
676: ModelRDB foo = ModelRDB.createModel(conn, "foo");
677: assertTrue(false); // db lock should prevent model create
678: } catch (Exception e) {
679: }
680:
681: d.unlockDB();
682:
683: if (d.isDBFormatOK())
684: assertTrue(false); // db contains no model
685:
686: if (conn.containsModel("foo"))
687: assertTrue(false);
688:
689: // check that containsModel does not format db
690: if (d.isDBFormatOK())
691: assertTrue(false); // db contains no model
692:
693: ModelRDB foo = ModelRDB.createModel(conn, "foo");
694:
695: if (d.isDBFormatOK() == false)
696: assertTrue(false); // db should be formatted
697:
698: if (conn.containsModel("foo") == false)
699: assertTrue(false);
700:
701: if (conn.containsModel("bar"))
702: assertTrue(false);
703:
704: // now, delete a system table so db fmt is bad
705: d.deleteTable(d.getSystemTableName(0));
706:
707: if (d.isDBFormatOK())
708: assertTrue(false); // db should not be formatted
709:
710: try {
711: conn.close();
712: } catch (Exception e) {
713: assertTrue(false);
714: }
715:
716: conn = makeTestConnection();
717: d = conn.getDriver();
718:
719: if (conn.containsModel("foo"))
720: assertTrue(false);
721:
722: if (d.isDBFormatOK())
723: assertTrue(false); // db should still not be formatted
724:
725: // following should format db
726: ModelRDB bar = ModelRDB.createModel(conn, "bar");
727:
728: if (d.isDBFormatOK() == false)
729: assertTrue(false); // db should be formatted
730:
731: if (conn.containsModel("foo"))
732: assertTrue(false);
733:
734: if (conn.containsModel("bar") == false)
735: assertTrue(false);
736:
737: bar.begin();
738:
739: try {
740: bar.remove(); // should fail due to active xact
741: assertTrue(false);
742: } catch (Exception e) {
743: }
744:
745: bar.abort();
746:
747: bar.remove();
748:
749: try {
750: conn.close();
751: } catch (Exception e) {
752: assertTrue(false);
753: }
754: }
755:
756: }
757:
758: /*
759: (c) Copyright 2002, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
760: All rights reserved.
761:
762: Redistribution and use in source and binary forms, with or without
763: modification, are permitted provided that the following conditions
764: are met:
765:
766: 1. Redistributions of source code must retain the above copyright
767: notice, this list of conditions and the following disclaimer.
768:
769: 2. Redistributions in binary form must reproduce the above copyright
770: notice, this list of conditions and the following disclaimer in the
771: documentation and/or other materials provided with the distribution.
772:
773: 3. The name of the author may not be used to endorse or promote products
774: derived from this software without specific prior written permission.
775:
776: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
777: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
778: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
779: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
780: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
781: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
782: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
783: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
784: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
785: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
786: */
|