示例#1
0
    public boolean run( CWVerboseStream stream ) {
        try {
            _db = _category.getDatabase( stream.verbose() );
            _conn = _category.getJDBCConnection();

            boolean result = true;
            for ( int i=0; i < 4; i++ ) {
                _cacheType = i;
                if ( !runOnce( stream ) )
                    result = false;
            }
            _db.close();
            _conn.close();
            if ( _errLeak )
                System.out.println("Element leak happened!");
            if ( _errCount )
                System.out.println("Sum do not match!");

            return result && !_errLeak && !_errCount;
        } catch ( Exception e ) {
            stream.write( "Error: "+ e );
            return false;
        }

    }
示例#2
0
    public boolean runOnce( CWVerboseStream stream ) {
        OQLQuery      oql;
        TestObjectEx    object;
        Enumeration   enum;
        Database db2;

        boolean result = true;

        try {
            // clear the table
            int del = _conn.createStatement().executeUpdate( "DELETE FROM test_race" );
            stream.writeVerbose( "row deleted in table test_race: " + del );
            _conn.commit();

            switch ( _cacheType ) {
            case 0:
                _className = "jdo.TestRaceCount";
                _classType = jdo.TestRaceCount.class;
                break;
            case 1:
                _className = "jdo.TestRaceTime";
                _classType = jdo.TestRaceTime.class;
                break;
            case 2:
                _className = "jdo.TestRaceNone";
                _classType = jdo.TestRaceNone.class;
                break;
            case 3:
                _className = "jdo.TestRaceUnlimited";
                _classType = jdo.TestRaceUnlimited.class;
                break;
            }

            CreateDeleteThread cdThread = new CreateDeleteThread( stream, _category, _cacheType, NUM_OF_CREATE_DELETE );

            ReadThread rThread =  new ReadThread( stream, cdThread, _category, NUM_OF_READ );

            cdThread.start();
            rThread.start();

            while ( !cdThread.isDone() /*&& !rThread.isDone()*/ ) {
                Thread.currentThread().sleep( 500 );
            }
            
            // create threads, make a race so each thread
            // keeping increment to the pairs of number.
        } catch ( Exception except ) {
            stream.writeVerbose( "Error: " + except );
            except.printStackTrace();
            result = false;
        }
        return result;
    }
示例#3
0
 CreateDeleteThread( CWVerboseStream stream, JDOCategory c, int cachetype, int n ) throws Exception {
     this.db = c.getDatabase( stream.verbose() );
     this.trial = n;
     this.stream = stream;
     this.ran = new Random();
     this.cachetype = cachetype;
 }
示例#4
0
 ReadThread( CWVerboseStream stream, CreateDeleteThread other, JDOCategory c, int n ) throws Exception {
     this.db = c.getDatabase( stream.verbose() );
     this.trial = n;
     this.stream = stream;
     this.ran = new Random();
     this.other = other;
 }
示例#5
0
        public void run() {
            try {
                int num = 0;
                stream.writeVerbose("start testing");
                TestRace tr;
                TestRace testrace;
                OQLQuery oql;
                QueryResults qr;
                boolean succeed;
                int trials;
                Integer id = new Integer(5);

                out:
                for ( int i=0; i<trial; i++ ) {
                    // create, modified, delete object
                    try {
                        switch ( cachetype ) {
                        case 0:
                            testrace = new TestRaceCount();
                            testrace.setId(5);
                            break;
                        case 1:
                            testrace = new TestRaceTime();
                            testrace.setId(5);
                            break;
                        case 2:
                            testrace = new TestRaceNone();
                            testrace.setId(5);
                            break;
                        case 3:
                            testrace = new TestRaceUnlimited();
                            testrace.setId(5);
                            break;
                        default:
                            testrace = null;
                        }
     
                        // create object
                        //try {
                            db.begin();
                            db.create( testrace );  // may throw duplicateIdentityException
                            db.commit();
                        //} catch ( Exception e ) {
                        //    e.printStackTrace();
                        //}

                        // load it and modify it
                        succeed = false;
                        trials = 0;
                        while ( !succeed && trials < NUM_OF_RETRIAL ) {
                            Thread.currentThread().sleep( 0 );
                            trials++;
                            try {
                                db.begin();
                                tr = (TestRace) db.load( _classType, id );
                                                    // may throw ObjectNotFoundException
                                                    // LockNotGrantedException
                                tr.incValue1();
                                db.commit();
                                succeed = true;
                            } catch ( LockNotGrantedException e ) {
                                succeed = false;
                                // ethernet way of retry
                                if ( db.isActive() ) db.rollback();
                                Thread.currentThread().sleep( (long) ((SLEEP_BASE_TIME^trials) * ran.nextDouble()) );
                            } catch ( TransactionAbortedException e ) {
                                succeed = false;
                                // ethernet way of retry
                                if ( db.isActive() ) db.rollback();
                                Thread.currentThread().sleep( (long) ((SLEEP_BASE_TIME^trials) * ran.nextDouble()) );
                            } 
                        }
                        if ( db.isActive() ) 
                            db.rollback();

                        // load it and release it
                        succeed = false;
                        trials = 0;
                        while ( !succeed && trials < NUM_OF_RETRIAL ) {
                            Thread.currentThread().sleep( 0 );
                            trials++;
                            try {
                                db.begin();
                                tr = (TestRace) db.load( _classType, id );
                                                    // may throw ObjectNotFoundException
                                                    // LockNotGrantedException
                                db.commit();
                                succeed = true;
                            } catch ( LockNotGrantedException e ) {
                                succeed = false;
                                // ethernet way of retry
                                if ( db.isActive() ) db.rollback();
                                Thread.currentThread().sleep( (long) ((SLEEP_BASE_TIME^trials) * ran.nextDouble()) );
                            } 
                        }
                        if ( db.isActive() ) 
                            db.rollback();

                        // load it and delete it
                        succeed = false;
                        trials = 0;
                        while ( !succeed && trials < NUM_OF_RETRIAL ) {
                            Thread.currentThread().sleep( 0 );
                            trials++;    
                            try {
                                db.begin();
                                tr = (TestRace) db.load( _classType, id );
                                                // may throw ObjectNotFoundException
                                                // LockNotGrantedException
                                db.remove( tr );
                                db.commit();
                                succeed = true;
                            } catch ( LockNotGrantedException e ) {
                                succeed = false;
                                if ( db.isActive() ) db.rollback();
                                Thread.currentThread().sleep( (long) ((SLEEP_BASE_TIME^trials) * ran.nextDouble()) );
                            } catch ( TransactionAbortedException e ) {
                                succeed = false;
                                // ethernet way of retry
                                if ( db.isActive() ) db.rollback();
                                Thread.currentThread().sleep( (long) ((SLEEP_BASE_TIME^trials) * ran.nextDouble()) );
                            }
                        }
                        if ( db.isActive() ) 
                            db.rollback();
                        if ( !succeed )
                            throw new Exception("Transaction can't not lock the object within "+trials+" trials");

                    } catch ( TransactionNotInProgressException e ) {
                        stream.writeVerbose( "Thread <CreateDelete> will be killed. Unexcepted exception: "+e.getException() );
                        e.printStackTrace();
                        if ( db.isActive() ) try { db.rollback(); } catch ( TransactionNotInProgressException ee ) {}
                        _errLeak = true;
                        break out;
                    } catch ( PersistenceException e ) {
                        stream.writeVerbose( "Thread <CreateDelete> will be killed. Unexcepted exception: " );
                        e.printStackTrace();
                        if ( db.isActive() ) try { db.rollback(); } catch ( TransactionNotInProgressException ee ) {}
                        _errLeak = true;
                        break out;
                    } catch ( Exception e ) {
                        stream.writeVerbose( "Thread <CreateDelete> will be killed. Element not found: other exception: "+e );
                        e.printStackTrace();
                        if ( db.isActive() ) try { db.rollback(); } catch ( TransactionNotInProgressException ee ) {}
                        _errLeak = true;
                        break out;
                    }
                }

            } finally {
                isDone = true;
            }
        }
示例#6
0
  public boolean run(CWVerboseStream stream) {
    try {

      _db = _category.getDatabase(stream.verbose());
      _conn = _category.getJDBCConnection();

      stream.writeVerbose("Running...");
      stream.writeVerbose("");

      // delete everything
      _conn.createStatement().executeUpdate("DELETE test_serial");
      _conn.commit();

      // create new object with an serializable dependent object
      _db.begin();
      TestSerial master = new TestSerial();
      master.setId(1);
      master.setSerializableObject(new TestSerializableObject());
      master.getSerializableObject().aCoolString = "Very cool!";
      master.getSerializableObject().ints = new int[] {1, 3, 5, 7, 9};
      _db.create(master);
      _db.commit();

      // test if object created properly
      _db.begin();
      TestSerial testSerial = (TestSerial) _db.load(TestSerial.class, new Integer(1));
      if (testSerial == null) throw new Exception("Object creation failed!");

      if (testSerial.getSerializableObject() == null
          || !testSerial.getSerializableObject().aCoolString.equals("Very cool!")
          || testSerial.getSerializableObject().ints == null
          || testSerial.getSerializableObject().ints.length != 5
          || testSerial.getSerializableObject().ints[0] != 1
          || testSerial.getSerializableObject().ints[1] != 3
          || testSerial.getSerializableObject().ints[2] != 5
          || testSerial.getSerializableObject().ints[3] != 7
          || testSerial.getSerializableObject().ints[4] != 9)
        throw new Exception("dependent objects creation failed!" + testSerial);

      // modify the object
      testSerial.getSerializableObject().ints[1] = 103;
      testSerial.getSerializableObject().ints[3] = 107;
      testSerial.getSerializableObject().aCoolString = "Very very cool!";
      _db.commit();

      _db.begin();
      testSerial = (TestSerial) _db.load(TestSerial.class, new Integer(1));
      if (testSerial == null) throw new Exception("dependent modfiication failed!" + testSerial);

      if (testSerial.getSerializableObject() == null
          || !testSerial.getSerializableObject().aCoolString.equals("Very very cool!")
          || testSerial.getSerializableObject().ints == null
          || testSerial.getSerializableObject().ints.length != 5
          || testSerial.getSerializableObject().ints[0] != 1
          || testSerial.getSerializableObject().ints[1] != 103
          || testSerial.getSerializableObject().ints[2] != 5
          || testSerial.getSerializableObject().ints[3] != 107
          || testSerial.getSerializableObject().ints[4] != 9)
        throw new Exception("dependent modification failed!" + testSerial);

      // set the field to null;
      testSerial.getSerializableObject().ints = null;
      testSerial.getSerializableObject().aCoolString = null;
      _db.commit();

      _db.begin();
      testSerial = (TestSerial) _db.load(TestSerial.class, new Integer(1));
      if (testSerial == null) throw new Exception("dependent modfiication failed!" + testSerial);

      if (testSerial.getSerializableObject() == null
          || testSerial.getSerializableObject().aCoolString != null
          || testSerial.getSerializableObject().ints != null)
        throw new Exception("dependent modification failed!" + testSerial);

      // setSerializableObject( null );
      testSerial.setSerializableObject(null);
      _db.commit();

      _db.begin();
      testSerial = (TestSerial) _db.load(TestSerial.class, new Integer(1));
      if (testSerial == null) throw new Exception("dependent modfiication failed!" + testSerial);

      if (testSerial.getSerializableObject() != null)
        throw new Exception("dependent modification failed!" + testSerial);
      _db.commit();

    } catch (Exception e) {
      e.printStackTrace();

      stream.writeVerbose("Exception: " + e);
      try {
        if (_db.isActive()) _db.close();
        return false;
      } catch (Exception ex) {
        return false;
      }
    }
    return true;
  }