⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 storagetest.java

📁 这个是perst-269.zip下面的SOURCECODE,和大家分享了。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    /**     * Checks the <CODE>commit</CODE> and <CODE>rollback</CODE>     * methods.<P>     * <B>Conditions:</B> <CODE>rollback</CODE> invoked after storage     * root has changed.<P>     * <B>Result:</B> changes successfully rolled back.     */    /**     * <B>Goal:</B> To verify the transaction functionality.     * <P>* <B>Conditions:</B>     * <ul>     * <li><code>setRoot(root)</code> is invoked.</li>     * <li><code>getRoot()</code> is invoked.</li>     * </ul>     * <P>     * <B>Result:</B>     * <ul>     * <li>no exceptions are thrown.</li>     * <li><code>getRoot()</code> returned <i>root</i>.</li>     * </ul>     */    public void testTransaction01(){        storage.open(new NullFile(), INFINITE_PAGE_POOL);        Root root = new Root( (IPersistentSet) storage.createSet() );        root.i = 10;        storage.setRoot(root);        storage.commit();        root.i = 20;        storage.rollback();        root = (Root)storage.getRoot();        assertEquals(root.i, 10);    }    /**     * <B>Goal:</B> To verify the transaction functionality.     * <P>     * <B>Conditions:</B>     * <ul>     * <li><CODE>rollback</CODE> invoked after storage root has changed.</li>     * </ul>     * <P>     * <B>Result:</B>     * <ul>     * <li>no exceptions are thrown.</li>     * <li>changes successfully rolled back.</li>     * </ul>     */    public void testTransaction02(){        storage.open(new NullFile(), INFINITE_PAGE_POOL);        Root root = new Root( (IPersistentSet) storage.createSet() );        storage.setRoot(root);        storage.commit();        root.records.add( new Stored("rec1") );        storage.rollback();        root = (Root)storage.getRoot();        Iterator iterator = root.records.iterator();        assertFalse(iterator.hasNext());    }    /**     * <B>Goal:</B> To verify the transaction functionality.     * <P>     * <B>Conditions:</B>     * <ul>     * <li><CODE>rollback</CODE> invoked after storage root has changed.</li>     * </ul>     * <P>     * <B>Result:</B>     * <ul>     * <li>no exceptions are thrown.</li>     * <li>changes successfully rolled back.</li>     * </ul>     */    public void testTransaction03(){        storage.open(new NullFile(), INFINITE_PAGE_POOL);        Root root = new Root( (IPersistentSet)storage.createSet() );        storage.setRoot(root);        root.records.add( new Stored("rec1") );        storage.commit();        root.records.add( new Stored("rec2") );        storage.rollback();        root = (Root)storage.getRoot();        Iterator iterator = root.records.iterator();        assertTrue(iterator.hasNext());        assertEquals( ((Stored)iterator.next()).name, "rec1" );        assertFalse(iterator.hasNext());    }    /**     * <B>Goal:</B> To verify the storage listener functionality.     * <P>     * <B>Conditions:</B>     * <ul>     * <li>set storage listener by invocation of <code>setListener(listener)</code>.</li>     * <li>invoke <code>select(...)</code> with runtime exception (division by zero).</li>     * </ul>     * <P>     * <B>Result:</B>     * <ul>     * <li>no exceptions are thrown.</li>     * </ul>     */    public void testStorageListener00() {        storage.open(new NullFile(), INFINITE_PAGE_POOL);        TestStorageListener listener = new TestStorageListener();        Root root = new Root((IPersistentSet) storage.createSet());        storage.setRoot(root);        root.records.add( new Stored() );        storage.setListener(listener);        Query query = storage.createQuery();        query.enableRuntimeErrorReporting(true);        Iterator i = query.select(Stored.class, root.records.iterator(), "(1/i)=1");        i.hasNext();    }    /**     * <B>Goal:</B> To verify the storage listener functionality.     * <P>     * <B>Conditions:</B>     * <ul>     * <li>set storage listener by invocation of <code>setListener(listener)</code>.</li>     * <li>invoke <code>select(...)</code> with runtime exception (division by zero).</li>     * </ul>     * <P>     * <B>Result:</B>     * <ul>     * <li>One exception was passed to storage listener.</li>     * </ul>     */    public void testStorageListener01() {        storage.open(new NullFile(), INFINITE_PAGE_POOL);        TestStorageListener listener = new TestStorageListener();        Root root = new Root((IPersistentSet) storage.createSet());        storage.setRoot(root);        root.records.add(new Stored());        storage.setListener(listener);        Query query = storage.createQuery();        query.enableRuntimeErrorReporting(true);        try {            Iterator i = query.select(Stored.class, root.records.iterator(), "(1/i)=1");            i.hasNext();        } catch (Exception e) {            //        };        assertEquals(1, listener.exceptions.size());    }    /**     * <B>Goal:</B> To prove coreect storing and loading objects.     * <P>     * <B>Conditions:</B>     * <ul>     * <li>the <code>root</code> object implements the <code>Persistent</code> interface.</li>     * <li>the <code>setRoot(root)</code> method is invoked.</li>     * <li>the <code>close()</code> method is invoked.</li>     * <li>the <code>open(...)</code> method is invoked.</li>     * <li>the <code>getRoot()</code> method is invoked.</li>     * </ul>     * <P>     * <B>Result:</B>     * <ul>     * <li><code>integer</code> field correctly stored in db-file:     * stored and retrieved fields are identical.</li>     * </ul>     */    public void testStoreLoad00() {        storage.open("StorageTest.dbs");        Root root = new Root((IPersistentSet) storage.createSet());        root.i = 25;        storage.setRoot(root);        storage.close();        storage.open("StorageTest.dbs");        root = (Root) storage.getRoot();        assertEquals(25, root.i);    }    /**     * <B>Goal:</B> To prove coreect storing and loading objects.     * <P>     * <B>Conditions:</B>     * <ul>     * <li>the <code>root</code> object implements the <code>Persistent</code> interface.</li>     * <li>the <code>setRoot(root)</code> method is invoked.</li>     * <li>the <code>close()</code> method is invoked.</li>     * <li>the <code>open(...)</code> method is invoked.</li>     * <li>the <code>getRoot()</code> method is invoked.</li>     * </ul>     * <P>     * <B>Result:</B>     * <ul>     * <li><code>String</code> field correctly stored in db-file:     * stored and retrieved fields are identical.</li>     * </ul>     */    public void testStoreLoad01() {        storage.open("StorageTest.dbs");        Root root = new Root((IPersistentSet) storage.createSet());        String str = "test string";        root.s = str;        storage.setRoot(root);        storage.close();        storage.open("StorageTest.dbs");        root = (Root) storage.getRoot();        assertEquals(str, root.s);    }    /**     * <B>Goal:</B> To prove coreect storing and loading objects.     * <P>     * <B>Conditions:</B>     * <ul>     * <li>the <code>root</code> object implements the <code>Persistent</code> interface.</li>     * <li>the <code>setRoot(root)</code> method is invoked.</li>     * <li>the <code>close()</code> method is invoked.</li>     * <li>the <code>open(...)</code> method is invoked.</li>     * <li>the <code>getRoot()</code> method is invoked.</li>     * </ul>     * <P>     * <B>Result:</B>     * <ul>     * <li><code>double</code> field correctly stored in db-file:     * stored and retrieved fields are identical.</li>     * </ul>     */    public void testStoreLoad02() {        storage.open("StorageTest.dbs");        Root root = new Root((IPersistentSet) storage.createSet());        double d = 12345E-42;        root.d = d;        storage.setRoot(root);        storage.close();        storage.open("StorageTest.dbs");        root = (Root) storage.getRoot();        assertEquals(d, root.d);    }    /**     * <B>Goal:</B> To prove correct storing and loading objects.     * <P>     * <B>Conditions:</B>     * <ul>     * <li>the <code>root</code> object implements the <code>Persistent</code> interface.</li>     * <li>the <code>setRoot(root)</code> method is invoked.</li>     * <li>the <code>close()</code> method is invoked.</li>     * <li>the <code>open(...)</code> method is invoked.</li>     * <li>the <code>getRoot()</code> method is invoked.</li>     * </ul>     * <P>     * <B>Result:</B>     * <ul>     * <li>Object reference field correctly stored in db-file:     * stored and retrieved objects are identical.</li>     * </ul>     */    public void testStoreLoad03() {        storage.open("StorageTest.dbs");        Root root = new Root(null);        root.next = new Root(null);        root.next.i = 25;        storage.setRoot(root);        storage.close();        storage.open("StorageTest.dbs");        root = (Root) storage.getRoot();        assertEquals(25, root.next.i);    }    /**     * Internal class.     */    private static class Root extends Persistent{        IPersistentSet records;        int i;        Root next;        String s;        double d;        public Root(IPersistentSet records){            this.records = records;        }        public Root(){        }    }    /**     * Internal class.     */    private static class Stored extends Persistent{        public String name;        int i=0;        public Stored(String name){            this.name = name;        }        public Stored(){}    }    private static class TestStorageListener extends StorageListener{        public Vector<JSQLRuntimeException> exceptions =                new Vector<JSQLRuntimeException>();        public void JSQLRuntimeError(JSQLRuntimeException x) {            exceptions.add(x);        }    } }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -