Examples of JUnitThread


Examples of com.sleepycat.je.junit.JUnitThread

        final int N_ITERS = 10;
        openEnv(80, BIG_CACHE_SIZE);
        insertData(NUM_KEYS);

        JUnitThread writer = new JUnitThread("Writer") {
            public void testBody()
                throws DatabaseException {
                for (int i = 0; i < N_ITERS; i += 1) {
                    env.evictMemory();
                    /* insertData will update if data exists. */
                    insertData(NUM_KEYS);
                    env.evictMemory();
                    EnvironmentMutableConfig config = env.getMutableConfig();
                    config.setCacheSize(SMALL_CACHE_SIZE);
                    env.setMutableConfig(config);
                }
            }
        };

        JUnitThread reader = new JUnitThread("Reader") {
            public void testBody()
                throws DatabaseException {
                for (int i = 0; i < N_ITERS; i += 1) {
                    env.evictMemory();
                    verifyData(NUM_KEYS);
                    env.evictMemory();
                    EnvironmentMutableConfig config = env.getMutableConfig();
                    config.setCacheSize(BIG_CACHE_SIZE);
                    env.setMutableConfig(config);
                }
            }
        };

        writer.start();
        reader.start();

        try {
            writer.finishTest();
        } catch (Throwable e) {
            try {
                reader.finishTest();
            } catch (Throwable ignore) { }
            e.printStackTrace();
            fail(e.toString());
        }

        try {
            reader.finishTest();
        } catch (Throwable e) {
            e.printStackTrace();
            fail(e.toString());
        }

View Full Code Here

Examples of com.sleepycat.je.junit.JUnitThread

        throws Throwable {

        open();

        /* Cause splits in the last BIN. */
        JUnitThread writer = new JUnitThread("writer") {
            public void testBody() {
                try {
                    DatabaseEntry key = new DatabaseEntry(new byte[1]);
                    DatabaseEntry data = new DatabaseEntry(new byte[1]);
                    OperationStatus status;

                    Cursor cursor = db.openCursor(null, null);

                    for (int i = 0; i < 100000; i += 1) {
                        IntegerBinding.intToEntry(i, dups ? data : key);
                        if (dups) {
                            status = cursor.putNoDupData(key, data);
                        } else {
                            status = cursor.putNoOverwrite(key, data);
                        }
                        assertEquals(OperationStatus.SUCCESS, status);

                        if (i % 5000 == 0) {
                            System.out.println("Iteration: " + i);
                        }
                    }

                    cursor.close();
                    writerStopped = true;

                } catch (Exception e) {
                    try {
                        FileOutputStream os =
                            new FileOutputStream(new File("./err.txt"));
                        e.printStackTrace(new PrintStream(os));
                        os.close();
                    } catch (IOException ignored) {}
                    System.exit(1);
                }
            }
        };

        /* Move repeatedly from the last BIN to the prior BIN. */
        JUnitThread reader = new JUnitThread("reader") {
            public void testBody() {
                try {
                    DatabaseEntry key = new DatabaseEntry();
                    DatabaseEntry data = new DatabaseEntry();

                    CursorConfig cursorConfig = new CursorConfig();
                    cursorConfig.setReadUncommitted(true);
                    Cursor cursor = db.openCursor(null, cursorConfig);

                    while (!writerStopped) {
                        cursor.getLast(key, data, null);
                        for (int i = 0; i <= NODE_MAX; i += 1) {
                            cursor.getPrev(key, data, null);
                        }
                    }

                    cursor.close();

                } catch (Exception e) {
                    try {
                        FileOutputStream os =
                            new FileOutputStream(new File("./err.txt"));
                        e.printStackTrace(new PrintStream(os));
                        os.close();
                    } catch (IOException ignored) {}
                    System.exit(1);
                }
            }
        };

        writer.start();
        reader.start();
        writer.finishTest();
        reader.finishTest();

        close();
        System.out.println("SUCCESS");
    }
View Full Code Here

Examples of com.sleepycat.je.junit.JUnitThread

     * Acquire three read locks and make sure that they share nicely.
     */
    public void testMultipleReaders()
  throws Throwable {

  JUnitThread tester1 =
      new JUnitThread("testMultipleReaders1") {
    public void testBody() {
        try {
      lockManager.lock(1, txn1, LockType.READ, 0,
           false, null);
      assertTrue
          (lockManager.isOwner(nid, txn1, LockType.READ));
      sequence++;
      while (sequence < 3) {
          Thread.yield();
      }
      lockManager.release(1L, txn1);
        } catch (DatabaseException DBE) {
                        DBE.printStackTrace();
      fail("caught DatabaseException " + DBE);
        }
    }
      };

  JUnitThread tester2 =
      new JUnitThread("testMultipleReaders2") {
    public void testBody() {
        try {
      lockManager.lock(1, txn2, LockType.READ, 0,
           false, null);
      assertTrue
          (lockManager.isOwner(nid, txn2, LockType.READ));
      sequence++;
      while (sequence < 3) {
          Thread.yield();
      }
      lockManager.release(1L, txn2);
        } catch (DatabaseException DBE) {
                        DBE.printStackTrace();
      fail("caught DatabaseException " + DBE);
        }
    }
      };

  JUnitThread tester3 =
      new JUnitThread("testMultipleReaders3") {
    public void testBody() {
        try {
      lockManager.lock(1, txn3, LockType.READ, 0,
           false, null);
      assertTrue
          (lockManager.isOwner(nid, txn3, LockType.READ));
      sequence++;
      while (sequence < 3) {
          Thread.yield();
      }
      lockManager.release(1L, txn3);
        } catch (DatabaseException DBE) {
                        DBE.printStackTrace();
      fail("caught DatabaseException " + DBE);
        }
    }
      };

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

Examples of com.sleepycat.je.junit.JUnitThread

     * waits for them to be released.
     */
    public void testMultipleReadersSingleWrite1()
  throws Throwable {

  JUnitThread tester1 =
      new JUnitThread("testMultipleReaders1") {
    public void testBody() {
        try {
      lockManager.lock(1, txn1, LockType.READ, 0,
           false, null);
      assertTrue
          (lockManager.isOwner(nid, txn1, LockType.READ));
      while (lockManager.nWaiters(nid) < 1) {
          Thread.yield();
      }
      assertTrue(lockManager.isWaiter(nid, txn3));
      assertFalse(lockManager.isWaiter(nid, txn1));
      lockManager.release(1L, txn1);
      assertFalse
          (lockManager.isOwner(nid, txn1, LockType.READ));
        } catch (DatabaseException DBE) {
                        DBE.printStackTrace();
      fail("caught DatabaseException " + DBE);
        }
    }
      };

  JUnitThread tester2 =
      new JUnitThread("testMultipleReaders2") {
    public void testBody() {
        try {
      lockManager.lock(1, txn2, LockType.READ, 0,
           false, null);
      assertTrue
          (lockManager.isOwner(nid, txn2, LockType.READ));
      while (lockManager.nWaiters(nid) < 1) {
          Thread.yield();
      }
      assertTrue(lockManager.isWaiter(nid, txn3));
      lockManager.release(1L, txn2);
      assertFalse
          (lockManager.isOwner(nid, txn2, LockType.READ));
        } catch (DatabaseException DBE) {
                        DBE.printStackTrace();
      fail("caught DatabaseException " + DBE);
        }
    }
      };

  JUnitThread tester3 =
      new JUnitThread("testMultipleReaders3") {
    public void testBody() {
        try {
      while (lockManager.nOwners(nid) < 2) {
          Thread.yield();
      }
      lockManager.lock(1, txn3, LockType.WRITE, 0,
           false, null);
      assertTrue
          (lockManager.isOwner(nid, txn3, LockType.WRITE));
        } catch (DatabaseException DBE) {
                        DBE.printStackTrace();
      fail("caught DatabaseException " + DBE);
        }
    }
      };

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

Examples of com.sleepycat.je.junit.JUnitThread

     * releases the lock.
     */
    public void testMultipleReadersSingleWrite2()
  throws Throwable {

  JUnitThread tester1 =
      new JUnitThread("testMultipleReaders1") {
    public void testBody() {
        try {
      lockManager.lock(1, txn1, LockType.READ, 0,
           false, null);
      assertTrue
          (lockManager.isOwner(nid, txn1, LockType.READ));
      while (lockManager.nWaiters(nid) < 2) {
          Thread.yield();
      }
      lockManager.release(1L, txn1);
        } catch (DatabaseException DBE) {
                        DBE.printStackTrace();
      fail("caught DatabaseException " + DBE);
        }
    }
      };

  JUnitThread tester2 =
      new JUnitThread("testMultipleReaders2") {
    public void testBody() {
        try {
      lockManager.lock(1, txn2, LockType.READ, 0,
           false, null);
      assertTrue
          (lockManager.isOwner(nid, txn2, LockType.READ));
      while (lockManager.nWaiters(nid) < 2) {
          Thread.yield();
      }
      lockManager.release(1L, txn2);
        } catch (DatabaseException DBE) {
                        DBE.printStackTrace();
      fail("caught DatabaseException " + DBE);
        }
    }
      };

  JUnitThread tester3 =
      new JUnitThread("testMultipleReaders3") {
    public void testBody() {
        try {
      while (lockManager.nOwners(nid) < 2) {
          Thread.yield();
      }
      lockManager.lock(1, txn3, LockType.WRITE, 0,
           false, null);
      while (lockManager.nWaiters(nid) < 1) {
          Thread.yield();
      }
      assertTrue
          (lockManager.isOwner(nid, txn3, LockType.WRITE));
      lockManager.release(1L, txn3);
        } catch (DatabaseException DBE) {
                        DBE.printStackTrace();
      fail("caught DatabaseException " + DBE);
        }
    }
      };

  JUnitThread tester4 =
      new JUnitThread("testMultipleReaders4") {
    public void testBody() {
        try {
      while (lockManager.nWaiters(nid) < 1) {
          Thread.yield();
      }
      lockManager.lock(1, txn4, LockType.READ, 0,
           false, null);
      assertTrue
          (lockManager.isOwner(nid, txn4, LockType.READ));
      lockManager.release(1L, txn4);
        } catch (DatabaseException DBE) {
                        DBE.printStackTrace();
      fail("caught DatabaseException " + DBE);
        }
    }
      };

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

Examples of com.sleepycat.je.junit.JUnitThread

     * existing wait lock.
     */
    public void testUpgradeLock()
  throws Throwable {

  JUnitThread tester1 =
      new JUnitThread("testUpgradeLock1") {
    public void testBody() {
        try {
      lockManager.lock(1, txn1, LockType.READ, 0,
           false, null);
      assertTrue
          (lockManager.isOwner(nid, txn1, LockType.READ));
      while (lockManager.nWaiters(nid) < 2) {
          Thread.yield();
      }
      lockManager.release(1L, txn1);
        } catch (DatabaseException DBE) {
                        DBE.printStackTrace();
      fail("caught DatabaseException " + DBE);
        }
    }
      };

  JUnitThread tester2 =
      new JUnitThread("testUpgradeLock2") {
    public void testBody() {
        try {
      lockManager.lock(1, txn2, LockType.READ, 0,
           false, null);
      assertTrue
          (lockManager.isOwner(nid, txn2, LockType.READ));
      while (lockManager.nWaiters(nid) < 1) {
          Thread.yield();
      }
      lockManager.lock(1, txn2, LockType.WRITE, 0,
           false, null);
      assertTrue(lockManager.nWaiters(nid) == 1);
      lockManager.release(1L, txn2);
        } catch (DatabaseException DBE) {
                        DBE.printStackTrace();
      fail("caught DatabaseException " + DBE);
        }
    }
      };

  JUnitThread tester3 =
      new JUnitThread("testUpgradeLock3") {
    public void testBody() {
        try {
      while (lockManager.nOwners(nid) < 2) {
          Thread.yield();
      }
      lockManager.lock(1, txn3, LockType.WRITE, 0,
           false, null);
      assertTrue
          (lockManager.isOwner(nid, txn3, LockType.WRITE));
      lockManager.release(1L, txn3);
        } catch (DatabaseException DBE) {
                        DBE.printStackTrace();
      fail("caught DatabaseException " + DBE);
        }
    }
      };

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

Examples of com.sleepycat.je.junit.JUnitThread

     * transaction in non-blocking mode.  Make sure it fails.
     */
    public void testNonBlockingLock1()
  throws Throwable {

  JUnitThread tester1 =
      new JUnitThread("testNonBlocking1") {
    public void testBody() {
        try {
      lockManager.lock(1, txn1, LockType.READ, 0,
           false, null);
      assertTrue
          (lockManager.isOwner(nid, txn1, LockType.READ));
      while (sequence < 1) {
          Thread.yield();
      }
      lockManager.release(1L, txn1);
        } catch (DatabaseException DBE) {
                        DBE.printStackTrace();
      fail("caught DatabaseException " + DBE);
        }
    }
      };

  JUnitThread tester2 =
      new JUnitThread("testNonBlocking2") {
    public void testBody() {
        try {
      /* wait for tester1 */
      while (lockManager.nOwners(nid) < 1) {
          Thread.yield();
      }
      try {
          lockManager.lock(1, txn2, LockType.WRITE,
               0, true, null);
                            fail();
                        } catch (LockNotGrantedException expected) {}
      assertFalse
          (lockManager.isOwner(nid, txn2, LockType.WRITE));
      assertFalse
          (lockManager.isOwner(nid, txn2, LockType.READ));
      assertTrue(lockManager.nWaiters(nid) == 0);
      assertTrue(lockManager.nOwners(nid) == 1);
      sequence++;
      /* wait for tester1 to release the lock */
      while (lockManager.nOwners(nid) > 0) {
          Thread.yield();
      }
      assertTrue
          (lockManager.lock(1, txn2, LockType.WRITE, 0,
                                              false, null) ==
           LockGrantType.NEW);
      assertTrue
          (lockManager.isOwner(nid, txn2, LockType.WRITE));
      assertTrue
          (lockManager.isOwner(nid, txn2, LockType.READ));
      assertTrue(lockManager.nWaiters(nid) == 0);
      assertTrue(lockManager.nOwners(nid) == 1);
      lockManager.release(1L, txn2);
        } 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

     * transaction in non-blocking mode.  Make sure it fails.
     */
    public void testNonBlockingLock2()
  throws Throwable {

  JUnitThread tester1 =
      new JUnitThread("testNonBlocking1") {
    public void testBody() {
        try {
      lockManager.lock(1, txn1, LockType.WRITE, 0,
           false, null);
      assertTrue
          (lockManager.isOwner(nid, txn1, LockType.WRITE));
      sequence++;
      while (sequence < 2) {
          Thread.yield();
      }
      lockManager.release(1L, txn1);
        } catch (DatabaseException DBE) {
                        DBE.printStackTrace();
      fail("caught DatabaseException " + DBE);
        }
    }
      };

  JUnitThread tester2 =
      new JUnitThread("testNonBlocking2") {
    public void testBody() {
        try {
      /* wait for tester1 */
      while (sequence < 1) {
          Thread.yield();
      }
                        try {
          lockManager.lock(1, txn2, LockType.READ,
               0, true, null);
                            fail();
                        } catch (LockNotGrantedException expected) {}
      assertFalse
          (lockManager.isOwner(nid, txn2, LockType.READ));
      assertFalse
          (lockManager.isOwner(nid, txn2, LockType.WRITE));
      assertTrue(lockManager.nWaiters(nid) == 0);
      assertTrue(lockManager.nOwners(nid) == 1);
      sequence++;
      /* wait for tester1 to release the lock */
      while (lockManager.nOwners(nid) > 0) {
          Thread.yield();
      }
      assertTrue
          (lockManager.lock(1, txn2, LockType.READ, 0,
                                              false, null) ==
           LockGrantType.NEW);
      assertTrue
          (lockManager.isOwner(nid, txn2, LockType.READ));
      assertFalse
          (lockManager.isOwner(nid, txn2, LockType.WRITE));
      assertTrue(lockManager.nWaiters(nid) == 0);
      assertTrue(lockManager.nOwners(nid) == 1);
      lockManager.release(1L, txn2);
        } 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

     * transaction in blocking mode.  Make sure it waits.
     */
    public void testWaitingLock()
  throws Throwable {

  JUnitThread tester1 =
      new JUnitThread("testBlocking1") {
    public void testBody() {
        try {
      lockManager.lock(1, txn1, LockType.WRITE, 0,
           false, null);
      assertTrue
          (lockManager.isOwner(nid, txn1, LockType.WRITE));
      sequence++;
      while (sequence < 2) {
          Thread.yield();
      }
      lockManager.release(1L, txn1);
        } catch (DatabaseException DBE) {
                        DBE.printStackTrace();
      fail("caught DatabaseException " + DBE);
        }
    }
      };

  JUnitThread tester2 =
      new JUnitThread("testBlocking2") {
    public void testBody() {
        try {
      /* wait for tester1 */
      while (sequence < 1) {
          Thread.yield();
      }
      try {
          lockManager.lock(1, txn2, LockType.READ, 500,
                                             false, null);
          fail("didn't time out");
      } catch (LockTimeOutException e) {
      }
      assertFalse
          (lockManager.isOwner(nid, txn2, LockType.READ));
      assertFalse
          (lockManager.isOwner(nid, txn2, LockType.WRITE));
      assertTrue(lockManager.nWaiters(nid) == 0);
      assertTrue(lockManager.nOwners(nid) == 1);
      sequence++;
      /* wait for tester1 to release the lock */
      while (lockManager.nOwners(nid) > 0) {
          Thread.yield();
      }
      assertTrue
          (lockManager.lock(1, txn2, LockType.READ, 0,
                                              false, null) ==
           LockGrantType.NEW);
      assertTrue
          (lockManager.isOwner(nid, txn2, LockType.READ));
      assertFalse
          (lockManager.isOwner(nid, txn2, LockType.WRITE));
      assertTrue(lockManager.nWaiters(nid) == 0);
      assertTrue(lockManager.nOwners(nid) == 1);
      lockManager.release(1L, txn2);
        } 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

    }

    public void xtestDeadlock()
  throws Throwable {

  JUnitThread tester1 =
      new JUnitThread("testDeadlock1") {
    public void testBody() {
        try {
      lockManager.lock(1, txn1, LockType.WRITE, 0,
           false, null);
      System.out.println("t1 has locked 1");
      assertTrue
          (lockManager.isOwner(nid, txn1, LockType.WRITE));
      sequence++;     // bump to 1

      /* wait for tester2 */
      while (sequence < 2) {
          Thread.yield();
      }

      lockManager.lock(2, txn1, LockType.READ, 1000,
           false, null);
      System.out.println("t1 about to sleep");
      Thread.sleep(5000);

      lockManager.release(1, txn1);
      lockManager.release(2, txn1);
        } catch (DatabaseException DBE) {
                        DBE.printStackTrace();
      fail("tester1 caught DatabaseException " + DBE);
        } catch (InterruptedException IE) {
      fail("tester1 caught InterruptedException " + IE);
        }
    }
      };

  JUnitThread tester2 =
      new JUnitThread("testDeadlock2") {
    public void testBody() {
        try {
      /* wait for tester1 */
      while (sequence < 1) {
          Thread.yield();
      }

      lockManager.lock(2, txn2, LockType.WRITE, 0,
           false, null);
      System.out.println("t2 has locked 2");

      sequence++;   // bump to 2

      System.out.println("t2 about to lock 1");
      lockManager.lock(1, txn2, LockType.READ, 1000,
           false, null);
      System.out.println("t2 about to sleep");
      Thread.sleep(5000);

      lockManager.release(1, txn2);
      lockManager.release(2, txn1);
        } catch (DatabaseException DBE) {
                        DBE.printStackTrace();
      fail("tester2 caught DatabaseException " + DBE);
        } catch (InterruptedException IE) {
      fail("tester2 caught InterruptedException " + IE);
        }
    }
      };

  tester1.start();
  tester2.start();
  //tester3.start();
  tester1.finishTest();
  tester2.finishTest();
  //tester3.finishTest();
    }
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.