📄 txtest.java
字号:
// You can redistribute this software and/or modify it under the terms of// the Ozone Library License version 1 published by ozone-db.org.//// The original code and portions created by SMB are// Copyright (C) 1997-2000 by SMB GmbH. All rights reserved.//// $Id: TxTest.java,v 1.3 2000/10/28 16:55:20 daniela Exp $package org.ozoneDB.test.tx;import javax.transaction.*;import org.ozoneDB.*;import org.ozoneDB.test.*;import test.framework.*;/** * @author <a href="http://www.softwarebuero.de/">SMB</a> * @version $Revision: 1.3 $Date: 2000/10/28 16:55:20 $ */public class TxTest extends OzoneTestCase { public static void addSuite( TestSuite suite ) { suite.addTest( new TxTest( "testAll" ) ); } public static void main( String[] args ) throws Exception { TestSuite suite = new TestSuite(); suite.addTest( new TxTest( "testAll" ) ); Suite.main( args, suite ); } public TxTest( String name ) { super( name ); } public void testAll() throws Exception { db.reloadClasses(); ExternalTransaction tx = db.newTransaction(); tx.begin(); Group group = (Group)db.objectForName( "group1" ); if (group != null) { db.deleteObject( group ); } group = (Group)db.createObject( GroupImpl.class.getName(), OzoneInterface.Public, "group1" ); tx.commit(); // check external abort tx.begin(); group.setName( "Gruppe" ); assert( group.name().equals( "Gruppe" ) ); tx.rollback(); assert( !group.name().equals( "Gruppe" ) ); // check external abort after crash tx.begin(); try { group.setName( "Gruppe" ); group.crash(); tx.commit(); } catch (Exception e) { tx.rollback(); } assert( !group.name().equals( "Gruppe" ) ); // check external commit tx.begin(); group.setName( "Gruppe" ); assert( group.name().equals( "Gruppe" ) ); tx.commit(); assert( group.name().equals( "Gruppe" ) ); // check multiple threads per transaction tx.begin(); group.setName( "Gruppe2" ); Thread t1 = new AccessThread( this, tx, "group1", "Gruppe2" ); t1.start(); Thread t2 = new AccessThread( this, null, "group1", null ); t2.start(); Thread.sleep( 3000 ); tx.rollback(); assert( !group.name().equals( "Gruppe2" ) ); } protected static void print( Group g ) throws Exception { System.out.println( Thread.currentThread().getName() + " - Group:" ); User[] users = g.getAll(); for (int i = 0; i < users.length; i++) { System.out.println( " " + Thread.currentThread().getName() + ": " + users[i] ); } System.out.println(); } }class AccessThread extends Thread { TxTest test; ExternalTransaction tx; String dbName; String name; public AccessThread( TxTest _test, ExternalTransaction _tx, String _dbName, String _name ) { test = _test; tx = _tx; dbName = _dbName; name = _name; } public void run() { try { if (tx != null) { System.out.println( "thread(" + getName() + "): joining transaction..." ); tx.join(); } else { System.out.println( "thread(" + getName() + "): creating new transaction..." ); // tx = test.db().newTransaction(); // tx.begin(); } Group group = (Group)test.db().objectForName( dbName ); test.assert( group != null, "thread(" + getName() + "): group != null" ); System.out.println( "thread(" + getName() + "): " + group.toString() ); if (name != null) { test.assert( group.name().equals( name ), "group.name().equals (name)" ); } } catch (Throwable e) { System.out.println( "\nAssertion failed in thread!\n" ); e.printStackTrace(); System.exit( 1 ); } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -