Examples of TransactionRunner


Examples of com.sleepycat.collections.TransactionRunner

            // For testing auto-commit, use a normal (transactional) runner for
            // all reading and for writing via an iterator, and a do-nothing
            // runner for writing via collections; if auto-commit is tested,
            // the per-collection auto-commit property will be set elsewhere.
            //
            TransactionRunner normalRunner = newTransactionRunner(env);
            normalRunner.setAllowNestedTransactions(
                    DbCompat.NESTED_TRANSACTIONS);
            TransactionRunner nullRunner = new NullTransactionRunner(env);
            readRunner = nullRunner;
            writeIterRunner = normalRunner;
            if (isAutoCommit) {
                writeRunner = nullRunner;
            } else {
View Full Code Here

Examples of com.sleepycat.collections.TransactionRunner

     * Is overridden in XACollectionTest.
     */
    protected TransactionRunner newTransactionRunner(Environment env)
        throws DatabaseException {

        return new TransactionRunner(env);
    }
View Full Code Here

Examples of com.sleepycat.collections.TransactionRunner

    public void setUp()
        throws Exception {

        DbTestUtil.printTestName(getName());
        env = TestEnv.TXN.open(getName());
        runner = new TransactionRunner(env);
        createDatabase();
    }
View Full Code Here

Examples of com.sleepycat.collections.TransactionRunner

        throws Exception {

        final Object parent = new Object();
        final Object child1 = new Object();
        final Object child2 = new Object();
        final TransactionRunner runner = new TransactionRunner(env);
        runner.setMaxRetries(0);

        /* Write a record in each db. */
        runner.run(new TransactionWorker() {
            public void doWork() throws Exception {
                assertNull(map1.put(ONE, ONE));
                assertNull(map2.put(ONE, ONE));
            }
        });

        /*
         * A thread to open iterator 1, then wait to be notified, then open
         * iterator 2.
         */
        final Thread thread1 = new Thread(new Runnable() {
            public void run() {
                try {
                    runner.run(new TransactionWorker() {
                        public void doWork() throws Exception {
                            synchronized (child1) {
                                ListIterator i1 =
                                    (ListIterator) map1.values().iterator();
                                i1.next();
                                i1.set(ONE); /* Write lock. */
                                StoredIterator.close(i1);
                                synchronized (parent) { parent.notify(); }
                                child1.wait();
                                Iterator i2 = map2.values().iterator();
                                assertTrue(i2.hasNext());
                                StoredIterator.close(i2);
                            }
                        }
                    });
                } catch (DeadlockException expected) {
                } catch (Exception e) {
                    e.printStackTrace();
                    fail(e.toString());
                }
            }
        });

        /*
         * A thread to open iterator 2, then wait to be notified, then open
         * iterator 1.
         */
        final Thread thread2 = new Thread(new Runnable() {
            public void run() {
                try {
                    runner.run(new TransactionWorker() {
                        public void doWork() throws Exception {
                            synchronized (child2) {
                                ListIterator i2 =
                                    (ListIterator) map2.values().iterator();
                                i2.next();
View Full Code Here

Examples of com.sleepycat.collections.TransactionRunner

    }

    private void commitTest(final boolean explicit)
        throws Exception {

        final TransactionRunner runner = new TransactionRunner(env);
        runner.setAllowNestedTransactions(DbCompat.NESTED_TRANSACTIONS);

        assertNull(currentTxn.getTransaction());

        runner.run(new TransactionWorker() {
            public void doWork() throws Exception {
                final Transaction txn1 = currentTxn.getTransaction();
                assertNotNull(txn1);
                assertNull(map.put(ONE, ONE));
                assertEquals(ONE, map.get(ONE));

                runner.run(new TransactionWorker() {
                    public void doWork() throws Exception {
                        final Transaction txn2 = currentTxn.getTransaction();
                        assertNotNull(txn2);
                        if (DbCompat.NESTED_TRANSACTIONS) {
                            assertTrue(txn1 != txn2);
View Full Code Here

Examples of com.sleepycat.collections.TransactionRunner

    }

    private void abortTest(final boolean explicit)
        throws Exception {

        final TransactionRunner runner = new TransactionRunner(env);
        runner.setAllowNestedTransactions(DbCompat.NESTED_TRANSACTIONS);

        assertNull(currentTxn.getTransaction());

        runner.run(new TransactionWorker() {
            public void doWork() throws Exception {
                final Transaction txn1 = currentTxn.getTransaction();
                assertNotNull(txn1);
                assertNull(map.put(ONE, ONE));
                assertEquals(ONE, map.get(ONE));

                if (DbCompat.NESTED_TRANSACTIONS) {
                    try {
                        runner.run(new TransactionWorker() {
                            public void doWork() throws Exception {
                                final Transaction txn2 =
                                        currentTxn.getTransaction();
                                assertNotNull(txn2);
                                assertTrue(txn1 != txn2);
View Full Code Here

Examples of com.sleepycat.collections.TransactionRunner

    private void doReadCommitted(final StoredSortedMap degree2Map,
                                 TransactionConfig txnConfig)
        throws Exception {

        map.put(ONE, ONE);
        TransactionRunner runner = new TransactionRunner(env);
        runner.setTransactionConfig(txnConfig);
        assertNull(currentTxn.getTransaction());
        runner.run(new TransactionWorker() {
            public void doWork() throws Exception {
                assertNotNull(currentTxn.getTransaction());

                /* Do a read-committed get(), the lock is not retained. */
                assertEquals(ONE, degree2Map.get(ONE));
View Full Code Here

Examples of com.sleepycat.collections.TransactionRunner

    }

    public void testReadUncommittedTransaction()
        throws Exception {

        TransactionRunner runner = new TransactionRunner(env);
        TransactionConfig config = new TransactionConfig();
        config.setReadUncommitted(true);
        runner.setTransactionConfig(config);
        assertNull(currentTxn.getTransaction());
        runner.run(new TransactionWorker() {
            public void doWork() throws Exception {
                assertNotNull(currentTxn.getTransaction());
                doReadUncommitted(map);
            }
        });
View Full Code Here

Examples of com.sleepycat.collections.TransactionRunner

            log("adding: \"" +
    line + "\" : \"" +
    reversed + "\"");

            // Do the work to add the key/data to the HashMap here.
            TransactionRunner tr = new TransactionRunner(env);
            try {
                tr.run(
           new TransactionWorker() {
         public void doWork() {
             if (!map.containsKey(line.getBytes()))
           map.put(line.getBytes(),
                                           reversed.getBytes());
View Full Code Here

Examples of com.sleepycat.collections.TransactionRunner

     * to use depends on the application.
     */
    private void run()
        throws Exception {

        TransactionRunner runner = new TransactionRunner(db.getEnvironment());
        runner.run(new PopulateDatabase());
        runner.run(new PrintDatabase());
    }
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.