Examples of JUnitThread


Examples of com.sleepycat.je.junit.JUnitThread

        throws DatabaseException, InterruptedException {

        LockStats origStats = env.getLockStats(null);
        insertFinished = false;

        writerThread = new JUnitThread("Writer") {
            public void testBody()
                throws DatabaseException {
                DatabaseEntry key = new DatabaseEntry();
                DatabaseEntry data = new DatabaseEntry();
                OperationStatus status;
View Full Code Here

Examples of com.sleepycat.je.junit.JUnitThread

    }

    public void testAcquireAndReacquire()
  throws Throwable {

  JUnitThread tester =
      new JUnitThread("testAcquireAndReacquire") {
    public void testBody() {
        /* Acquire a latch */
        try {
      latch1.acquire();
        } catch (DatabaseException LE) {
      fail("caught DatabaseException");
        }

        /* Try to acquire it again -- should fail*/
        try {
      latch1.acquire();
      fail("didn't catch LatchException");
        } catch (LatchException LE) {
      assertTrue
          (latch1.getLatchStats().nAcquiresSelfOwned == 1);
        } catch (DatabaseException DE) {
      fail("didn't catch LatchException-caught DE instead");
        }

        /* Release it. */
        try {
      latch1.release();
        } catch (LatchNotHeldException LNHE) {
      fail("unexpected LatchNotHeldException");
        }

        /* Release it again -- should fail */
        try {
      latch1.release();
      fail("didn't catch LatchNotHeldException");
        } catch (LatchNotHeldException LNHE) {
        }
    }
      };

  tester.doTest();
    }
View Full Code Here

Examples of com.sleepycat.je.junit.JUnitThread

    /* Do a million acquire/release pairs.
       The junit output will tell us how long it took. */
    public void testAcquireReleasePerformance()
  throws Throwable {

  JUnitThread tester =
      new JUnitThread("testAcquireReleasePerformance") {
    public void testBody() {
        final int N_PERF_TESTS = 1000000;
        for (int i = 0; i < N_PERF_TESTS; i++) {
      /* Acquire a latch */
      try {
          latch1.acquire();
      } catch (DatabaseException LE) {
          fail("caught DatabaseException");
      }

      /* Release it. */
      try {
          latch1.release();
      } catch (LatchNotHeldException LNHE) {
          fail("unexpected LatchNotHeldException");
      }
        }
        LatchStats stats = latch1.getLatchStats();
        assertTrue(stats.nAcquiresNoWaiters == N_PERF_TESTS);
        assertTrue(stats.nReleases == N_PERF_TESTS);
    }
      };

  tester.doTest();
    }
View Full Code Here

Examples of com.sleepycat.je.junit.JUnitThread

    public void doTestWait()
  throws Throwable {

  tester1 =
      new JUnitThread("testWait-Thread1") {
    public void testBody() {
        /* Acquire a latch */
        try {
      latch1.acquire();
        } catch (DatabaseException LE) {
      fail("caught DatabaseException");
        }

        /* Wait for tester2 to try to acquire the latch */
        while (latch1.nWaiters() == 0) {
      Thread.yield();
        }

        try {
      latch1.release();
        } catch (LatchNotHeldException LNHE) {
      fail("unexpected LatchNotHeldException");
        }
    }
      };

  tester2 =
      new JUnitThread("testWait-Thread2") {
    public void testBody() {
        /* Wait for tester1 to start */

        while (latch1.owner() != tester1) {
      Thread.yield();
View Full Code Here

Examples of com.sleepycat.je.junit.JUnitThread

    public void testAcquireNoWait()
  throws Throwable {

  tester1 =
      new JUnitThread("testWait-Thread1") {
    public void testBody() {
        debugMsg("Acquiring Latch");
        /* Acquire a latch */
        try {
      latch1.acquire();
        } catch (DatabaseException LE) {
      fail("caught DatabaseException");
        }

        /* Wait for tester2 to try to acquire the latch */

        debugMsg("Waiting for other thread");
        while (!attemptedAcquireNoWait) {
      Thread.yield();
        }

        debugMsg("Releasing the latch");
        try {
      latch1.release();
        } catch (LatchNotHeldException LNHE) {
      fail("unexpected LatchNotHeldException");
        }
    }
      };

  tester2 =
      new JUnitThread("testWait-Thread2") {
    public void testBody() {
        /* Wait for tester1 to start */

        debugMsg("Waiting for T1 to acquire latch");
        while (latch1.owner() != tester1) {
View Full Code Here

Examples of com.sleepycat.je.junit.JUnitThread

  JUnitThread[] waiterThreads =
      new JUnitThread[N_WAITERS];

  tester1 =
      new JUnitThread("testWait-Thread1") {
    public void testBody() {

        debugMsg("About to acquire latch");

        /* Acquire a latch */
 
View Full Code Here

Examples of com.sleepycat.je.junit.JUnitThread

            WaitVal waitVal = new WaitVal(0);

            FSyncManager syncManager =
                new TestSyncManager(DbInternal.envGetEnvironmentImpl(env),
                                    waitVal);
            JUnitThread t1 = new TestSyncThread(syncManager);
            JUnitThread t2 = new TestSyncThread(syncManager);
            JUnitThread t3 = new TestSyncThread(syncManager);
            t1.start();
            t2.start();
            t3.start();

            /* Wait for all threads to request a sync, so they form a group.*/
            Thread.sleep(500);

            /* Free thread 1. */
            synchronized (waitVal) {
                waitVal.value = 1;
                waitVal.notify();
            }

            t1.join();
            t2.join();
            t3.join();
           
            /*
             * All three threads ask for fsyncs.
             * 2 do fsyncs -- the initial leader, and the leader of the
             * waiting group of 2.
View Full Code Here

Examples of com.sleepycat.je.junit.JUnitThread

  }
  c.close();
  txn.commit();
  sequence = 0;

  JUnitThread tester1 =
      new JUnitThread("testDuplicateDeadlock1") {
    public void testBody()
        throws DatabaseException {

        DatabaseEntry key = new DatabaseEntry();
        DatabaseEntry data = new DatabaseEntry();
        Transaction txn1 = exampleEnv.beginTransaction(null, null);
        Cursor cursor1 = exampleDb.openCursor(txn1, null);
        try {
      cursor1.getFirst(key, data, LockMode.DEFAULT);
      sequence++;
      while (sequence < 2) {
          Thread.yield();
      }
      cursor1.delete();
      sequence++;
      while (sequence < 4) {
          Thread.yield();
      }

        } catch (DeadlockException DBE) {
        } finally {
      cursor1.close();
      txn1.abort();
      sequence = 4;
        }
    }
      };

  JUnitThread tester2 =
      new JUnitThread("testDuplicateDeadlock2") {
    public void testBody()
        throws DatabaseException {
       
        DatabaseEntry key = new DatabaseEntry();
        DatabaseEntry data = new DatabaseEntry();
        Transaction txn2 = exampleEnv.beginTransaction(null, null);
        Cursor cursor2 = exampleDb.openCursor(txn2, null);
        try {
      while (sequence < 1) {
          Thread.yield();
      }
      cursor2.getLast(key, data, LockMode.DEFAULT);
      sequence++;
      //cursor2.put(key,
      //new DatabaseEntry("d1d1d1".getBytes()));
      cursor2.delete();
      sequence++;
      while (sequence < 4) {
          Thread.yield();
      }

        } catch (DeadlockException DBE) {
        } finally {
      cursor2.close();
      txn2.abort();
      sequence = 4;
        }
    }
      };

  try {
      tester1.start();
      tester2.start();
      tester1.finishTest();
      tester2.finishTest();
      DatabaseImpl dbImpl = DbInternal.dbGetDatabaseImpl(exampleDb);
      assertTrue(dbImpl.verify(new VerifyConfig(), dbImpl.getEmptyStats()));
  } catch (Throwable T) {
      fail("testDuplicateDeadlock caught: " + T);
  }
View Full Code Here

Examples of com.sleepycat.je.junit.JUnitThread

    }

    public void testMajorMinorLatching()
  throws Throwable {
       
        JUnitThread tester1 =
            new JUnitThread("testMajorMinorLatching-Thread1") {
                public void testBody() {

                    try {
                        /* Create two initial elements. */
                        for (int i = 0; i < 2; i++) {
                            IN in = new IN(dbImpl, null, 1, 1);
                            inList1.add(in);
                        }

                        /*
                         * Acquire the major latch in preparation for an
                         * iteration.
                         */
                        inList1.latchMajor();

                        /* Wait for tester2 to try to acquire the
                           /* minor latch */
                        sequencer = 1;
                        while (sequencer <= 1) {
                            Thread.yield();
                        }

                        /*
                         * Sequencer is now 2. There should only be
                         * two elements in the list right now even
                         * though thread 2 added a third one.
                         */
                        int count = 0;
                        Iterator iter = inList1.iterator();
                        while (iter.hasNext()) {
                            IN in = (IN) iter.next();
                            count++;
                        }

                        assertEquals(2, count);

                        /*
                         * Allow thread2 to run again.  It will
                         * add another element and throw control
                         * back to thread 1.
                         */
                        sequencer++;   // now it's 3
                        while (sequencer <= 3) {
                            Thread.yield();
                        }

                        /*
                         * Thread2 has exited.  Release the major
                         * latch so that the addedINs can be added
                         * into the main in set.
                         */
                        inList1.releaseMajorLatch();

                        /*
                         * Check that the entry added by tester2 was really
                         * added.
                         */
                        inList1.latchMajor();
                        count = 0;
                        iter = inList1.iterator();
                        while (iter.hasNext()) {
                            IN in = (IN) iter.next();
                            count++;
                        }

                        assertEquals(4, count);
                        inList1.releaseMajorLatch();
                    } catch (Throwable T) {
                        T.printStackTrace(System.out);
                        fail("Thread 1 caught some Throwable: " + T);
                    }
                }
            };

        JUnitThread tester2 =
            new JUnitThread("testMajorMinorLatching-Thread2") {
                public void testBody() {

                    try {
                        /* Wait for tester1 to start */
                        while (sequencer < 1) {
                            Thread.yield();
                        }

                        assertEquals(1, sequencer);

                        /*
                         * Acquire the minor latch in preparation for some
                         * concurrent additions.
                         */
                        inList1.add(new IN(dbImpl, null, 1, 1));
                        sequencer++;

                        /* Sequencer is now 2. */

                        while (sequencer < 3) {
                            Thread.yield();
                        }

                        assertEquals(3, sequencer);
                        /* Add one more element. */
                        inList1.add(new IN(dbImpl, null, 1, 1));
                        sequencer++;
                    } catch (Throwable T) {
                        T.printStackTrace(System.out);
                        fail("Thread 2 caught some Throwable: " + T);
                    }
                }
            };

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

Examples of com.sleepycat.je.junit.JUnitThread

        key.setData(TestUtils.getTestArray(1))
        data.setData(TestUtils.getTestArray(1));
        myDb.put(t1, key, data);

        /* T2 calls getFirst. */
        JUnitThread thread = new JUnitThread("getFirst") {
            public void testBody()
                throws DatabaseException {
                DatabaseEntry key = new DatabaseEntry();
                DatabaseEntry data = new DatabaseEntry();
                Transaction t2 = env.beginTransaction(null, null);
                operationStarted = true;
                Cursor cursor = myDb.openCursor(t2, null);
                OperationStatus status = cursor.getFirst(key, data, null);
                assertEquals(1, TestUtils.getTestVal(key.getData()));
                assertEquals(1, TestUtils.getTestVal(data.getData()));
                assertEquals(OperationStatus.SUCCESS, status);
                cursor.close();
                t2.commitNoSync();
            }
        };
        thread.start();
        while (!operationStarted) {
            Thread.yield();
        }
        Thread.sleep(10);

        /* T1 inserts K1-D2. */
        key.setData(TestUtils.getTestArray(1))
        data.setData(TestUtils.getTestArray(2));
        myDb.put(t1, key, data);
        t1.commitNoSync();

        try {
            thread.finishTest();
        } catch (Throwable e) {
            e.printStackTrace();
            fail(e.toString());
        }
        myDb.close();
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.