Examples of JUnitThread


Examples of com.sleepycat.je.junit.JUnitThread

   *
   * tester2: modifyDbRoot finally acquires the write lock on foo-db's
   * MapLN write lock, performs the update to the DbTree and returns from
   * the sync().
   */
  JUnitThread tester1 =
      new JUnitThread("testSR11293DbTreeLocker") {
        public void testBody() {
      try {
          /* Wait for tester2. */
          while (sequence < 1) {
        Thread.yield();
          }

          /* Lock the MapLN for the database. */
          DatabaseId fooId =
        DbInternal.dbGetDatabaseImpl(db).getId();
          DatabaseImpl fooDb = dbTree.getDb(fooId, 500000L);
          assert fooDb != null;

          sequence++;

          /* Wait for tester2. */
          while (sequence < 3) {
        Thread.yield();
          }

          try {
        Thread.sleep(3000);
          } catch (Exception E) {
          }

          try {
        txn.abort();
        db.close();
        env.close();
          } catch (DatabaseException DBE) {
        DBE.printStackTrace();
        fail("unexpected exception: " + DBE);
          }
      } catch (DatabaseException DBE) {
          DBE.printStackTrace();
          fail("caught DatabaseException " + DBE);
      }
        }
    };

  JUnitThread tester2 =
      new JUnitThread("testSR11293DbWriter") {
        public void testBody() {
      try {
          DatabaseEntry key =
        new DatabaseEntry(new byte[] { 1 });
          DatabaseEntry data =
        new DatabaseEntry(new byte[] { 1 });
          assertEquals(OperationStatus.SUCCESS,
           db.put(null, key, data));
          env.sync();

          sequence++;
          while (sequence < 2) {
        Thread.yield();
          }

          key.setData(new byte[] { 2 });
          data.setData(new byte[] { 2 });
          assertEquals(OperationStatus.SUCCESS,
           db.put(null, key, data));
          sequence++;
          env.sync();
      } catch (DatabaseException DBE) {
          DBE.printStackTrace();
          fail("unexpected exception: " + DBE);
      }
        }
    };

  tester1.start();
  tester2.start();
  tester1.finishTest();
  tester2.finishTest();

        EnvironmentConfig recoveryConfig = TestUtils.initEnvConfig();

        recoveryConfig.setConfigParam
      (EnvironmentParams.ENV_RUN_CHECKPOINTER.getName(), "false");
View Full Code Here

Examples of com.sleepycat.je.junit.JUnitThread

           db.delete(txnDel,
               new DatabaseEntry("F".getBytes())));
    txnDel.commit();
      }

      JUnitThread tester1 =
    new JUnitThread(config.testName + "1") {
        public void testBody()
      throws Throwable {

      Cursor cursor = null;
      try {
          Transaction txn1 =
        env.beginTransaction(null, null);
          cursor = db.openCursor(txn1, CursorConfig.DEFAULT);
          OperationStatus status =
        cursor.getSearchKey
        (new DatabaseEntry
         (config.thread1EntryToLock.getBytes()),
         new DatabaseEntry(),
         LockMode.RMW);
          assertEquals(OperationStatus.SUCCESS, status);
          sequence++;  // 0 -> 1

          while (sequence < 2) {
        Thread.yield();
          }

          /*
           * Since we can't increment sequence when tester2
           * blocks on the getNext call, all we can do is
           * bump sequence right before the getNext, and then
           * wait a little in this thread for tester2 to
           * block.
           */
          try {
        Thread.sleep(250);
          } catch (InterruptedException IE) {
          }

          if (config.doInsert) {
        status = db.put
            (txn1,
             new DatabaseEntry
             (config.thread1OpArg.getBytes()),
             new DatabaseEntry(new byte[10]));
          } else {
        status = db.delete
            (txn1,
             new DatabaseEntry
             (config.thread1OpArg.getBytes()));
          }
          assertEquals(OperationStatus.SUCCESS, status);
          sequence++;     // 2 -> 3

          try {
        Thread.sleep(1000);
          } catch (InterruptedException IE) {
          }

          cursor.close();
          cursor = null;
          if (config.doCommit) {
        txn1.commit();
          } else {
        txn1.abort();
          }
      } catch (DatabaseException DBE) {
          if (cursor != null) {
        cursor.close();
          }
          DBE.printStackTrace();
          fail("caught DatabaseException " + DBE);
      }
        }
    };

      JUnitThread tester2 =
    new JUnitThread(config.testName + "2") {
        public void testBody()
      throws Throwable {

      Cursor cursor = null;
      try {
          Transaction txn2 =
        env.beginTransaction(null, null);
          txn2.setLockTimeout(LOCK_TIMEOUT);
          cursor = db.openCursor(txn2, CursorConfig.DEFAULT);

          while (sequence < 1) {
        Thread.yield();
          }

          OperationStatus status =
        cursor.getSearchKey
        (new DatabaseEntry
         (config.thread2Start.getBytes()),
         new DatabaseEntry(),
         LockMode.DEFAULT);
          assertEquals(OperationStatus.SUCCESS, status);

          sequence++;           // 1 -> 2
          DatabaseEntry nextKey = new DatabaseEntry();
          try {

        /*
         * This will block until tester1 above commits.
         */
        if (config.doGetNext) {
            status =
          cursor.getNext(nextKey,
                   new DatabaseEntry(),
                   LockMode.DEFAULT);
        } else {
            status =
          cursor.getPrev(nextKey,
                   new DatabaseEntry(),
                   LockMode.DEFAULT);
        }
          } catch (DatabaseException DBE) {
        System.out.println("t2 caught " + DBE);
          }
          assertEquals(3, sequence);
          byte[] data = nextKey.getData();
          assertEquals(config.expectedResult,
           new String(nextKey.getData()));
          cursor.close();
          cursor = null;
          txn2.commit();
      } catch (DatabaseException DBE) {
          if (cursor != null) {
        cursor.close();
          }
          DBE.printStackTrace();
          fail("caught DatabaseException " + DBE);
      }
        }
    };

      tester1.start();
      tester2.start();

      tester1.finishTest();
      tester2.finishTest();
  } finally {
      db.close();
      env.close();
            env = null;
  }
View Full Code Here

Examples of com.sleepycat.je.junit.JUnitThread

    cursor.close();
    cursor = null;
    txnDel.commit();
      }

      JUnitThread tester1 =
    new JUnitThread(config.testName + "1") {
        public void testBody()
      throws Throwable {

      Cursor cursor = null;
      Cursor c = null;
      try {
          Transaction txn1 =
        env.beginTransaction(null, null);
          cursor = db.openCursor(txn1, CursorConfig.DEFAULT);
          OperationStatus status =
        cursor.getSearchBoth
        (new DatabaseEntry(DUPKEY.getBytes()),
         new DatabaseEntry
         (config.thread1EntryToLock.getBytes()),
         LockMode.RMW);
          assertEquals(OperationStatus.SUCCESS, status);
          cursor.close();
          cursor = null;
          sequence++;  // 0 -> 1

          while (sequence < 2) {
        Thread.yield();
          }

          /*
           * Since we can't increment sequence when tester2
           * blocks on the getNext call, all we can do is
           * bump sequence right before the getNext, and then
           * wait a little in this thread for tester2 to
           * block.
           */
          try {
        Thread.sleep(250);
          } catch (InterruptedException IE) {
          }

          if (config.doInsert) {
        status = db.put
            (txn1,
             new DatabaseEntry(DUPKEY.getBytes()),
             new DatabaseEntry
             (config.thread1OpArg.getBytes()));
          } else {
        c = db.openCursor(txn1, CursorConfig.DEFAULT);
        assertEquals(OperationStatus.SUCCESS,
               c.getSearchBoth
               (new DatabaseEntry
                (DUPKEY.getBytes()),
                new DatabaseEntry
                (config.thread1OpArg.getBytes()),
                LockMode.DEFAULT));
        assertEquals(OperationStatus.SUCCESS,
               c.delete());
        c.close();
        c = null;
          }
          assertEquals(OperationStatus.SUCCESS, status);
          sequence++;     // 2 -> 3

          try {
        Thread.sleep(1000);
          } catch (InterruptedException IE) {
          }

          if (config.doCommit) {
        txn1.commit();
          } else {
        txn1.abort();
          }
      } catch (DatabaseException DBE) {
          if (cursor != null) {
        cursor.close();
          }
          if (c != null) {
        c.close();
          }
          DBE.printStackTrace();
          fail("caught DatabaseException " + DBE);
      }
        }
    };

      JUnitThread tester2 =
    new JUnitThread("testPhantomInsert2") {
        public void testBody()
      throws Throwable {

      Cursor cursor = null;
      try {
          Transaction txn2 =
        env.beginTransaction(null, null);
          txn2.setLockTimeout(LOCK_TIMEOUT);
          cursor = db.openCursor(txn2, CursorConfig.DEFAULT);

          while (sequence < 1) {
        Thread.yield();
          }

          OperationStatus status =
        cursor.getSearchBoth
        (new DatabaseEntry(DUPKEY.getBytes()),
         new DatabaseEntry
         (config.thread2Start.getBytes()),
         LockMode.DEFAULT);
          assertEquals(OperationStatus.SUCCESS, status);

          sequence++;           // 1 -> 2
          DatabaseEntry nextKey = new DatabaseEntry();
          DatabaseEntry nextData = new DatabaseEntry();
          try {

        /*
         * This will block until tester1 above commits.
         */
        if (config.doGetNext) {
            status =
          cursor.getNextDup(nextKey, nextData,
                LockMode.DEFAULT);
        } else {
            status =
          cursor.getPrevDup(nextKey, nextData,
                LockMode.DEFAULT);
        }
          } catch (DatabaseException DBE) {
        System.out.println("t2 caught " + DBE);
          }
          assertEquals(3, sequence);
          byte[] data = nextData.getData();
          assertEquals(config.expectedResult,
           new String(data));
          cursor.close();
          cursor = null;
          txn2.commit();
      } catch (DatabaseException DBE) {
          if (cursor != null) {
        cursor.close();
          }
          DBE.printStackTrace();
          fail("caught DatabaseException " + DBE);
      }
        }
    };

      tester1.start();
      tester2.start();

      tester1.finishTest();
      tester2.finishTest();
  } finally {
      if (cursor != null) {
    cursor.close();
      }
      db.close();
View Full Code Here

Examples of com.sleepycat.je.junit.JUnitThread

    public void xxtestPutNoOverwriteConcurrently()
  throws Throwable {

  pNOCDb = initEnvAndDb(true, true, true, null);
  JUnitThread tester1 =
      new JUnitThread("testNonBlocking1") {
    public void testBody() {
        try {
      Transaction txn1 = env.beginTransaction(null, null);
      DatabaseEntry key = new DatabaseEntry();
      DatabaseEntry data = new DatabaseEntry();
      key.setData(TestUtils.getTestArray(1));
      data.setData(TestUtils.getTestArray(1));
      OperationStatus status =
          pNOCDb.putNoOverwrite(txn1, key, data);
      txn1.commit();
      System.out.println("thread1: " + status);
        } catch (DatabaseException DBE) {
      DBE.printStackTrace();
      fail("caught DatabaseException " + DBE);
        }
    }
      };

  JUnitThread tester2 =
      new JUnitThread("testNonBlocking2") {
    public void testBody() {
        try {
      Transaction txn2 = env.beginTransaction(null, null);
      DatabaseEntry key = new DatabaseEntry();
      DatabaseEntry data = new DatabaseEntry();
      key.setData(TestUtils.getTestArray(1));
      data.setData(TestUtils.getTestArray(2));
      OperationStatus status =
          pNOCDb.putNoOverwrite(txn2, key, data);
      txn2.commit();
      System.out.println("thread2: " + status);
        } catch (DatabaseException DBE) {
                        DBE.printStackTrace();
      fail("caught DatabaseException " + DBE);
        }
    }
      };

  tester1.start();
  tester2.start();
  tester1.finishTest();
  tester2.finishTest();
    }
View Full Code Here

Examples of com.sleepycat.je.junit.JUnitThread

    private void startInsert(final int keyVal, final int dataVal)
        throws DatabaseException, InterruptedException {

        LockStats origStats = env.getLockStats(null);

        writerThread = new JUnitThread("Writer") {
            public void testBody()
                throws DatabaseException {
                DatabaseEntry key = new DatabaseEntry();
                DatabaseEntry data = new DatabaseEntry();
                IntegerBinding.intToEntry(keyVal, key);
View Full Code Here

Examples of com.sleepycat.je.junit.JUnitThread

    private void startReadOper(final int operKeyParam)
        throws DatabaseException, InterruptedException {

        LockStats origStats = env.getLockStats(null);

        readerThread = new JUnitThread("Reader") {
            public void testBody()
                throws DatabaseException {
                Transaction readerTxn = env.beginTransaction(null, null);
                Cursor cursor = db.openCursor(readerTxn, null);
                spec.oper.init(PhantomRestartTest.this, cursor);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.