Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 6F799200D18 for ; Wed, 11 Oct 2017 12:07:28 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 6DA7B1609E4; Wed, 11 Oct 2017 10:07:28 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 8D9F21609CA for ; Wed, 11 Oct 2017 12:07:27 +0200 (CEST) Received: (qmail 5935 invoked by uid 500); 11 Oct 2017 10:07:26 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 5926 invoked by uid 99); 11 Oct 2017 10:07:26 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Oct 2017 10:07:26 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id D13D63A02BE for ; Wed, 11 Oct 2017 10:07:25 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1811806 - /directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/BTreeTransactionTest.java Date: Wed, 11 Oct 2017 10:07:25 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20171011100725.D13D63A02BE@svn01-us-west.apache.org> archived-at: Wed, 11 Oct 2017 10:07:28 -0000 Author: elecharny Date: Wed Oct 11 10:07:25 2017 New Revision: 1811806 URL: http://svn.apache.org/viewvc?rev=1811806&view=rev Log: Fixed some test to have them use Transactions Modified: directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/BTreeTransactionTest.java Modified: directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/BTreeTransactionTest.java URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/BTreeTransactionTest.java?rev=1811806&r1=1811805&r2=1811806&view=diff ============================================================================== --- directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/BTreeTransactionTest.java (original) +++ directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/BTreeTransactionTest.java Wed Oct 11 10:07:25 2017 @@ -44,27 +44,22 @@ public class BTreeTransactionTest { @Rule public TemporaryFolder tempFolder = new TemporaryFolder(); - private File dataDirWithTxn = null; - private File dataDirNoTxn = null; - private BTree btreeWithTransactions = null; - private BTree btreeNoTransactions = null; - private RecordManager recordManagerTxn = null; - private RecordManager recordManagerNoTxn = null; + private File dataDir = null; + private BTree btree = null; + private RecordManager recordManager = null; @Before public void createBTree() throws IOException { - dataDirWithTxn = tempFolder.newFolder( UUID.randomUUID().toString() ); - dataDirNoTxn = tempFolder.newFolder( UUID.randomUUID().toString() ); + dataDir = tempFolder.newFolder( UUID.randomUUID().toString() ); openRecordManagerAndBtrees(); try { // Create a new BTree with transaction and another one without - btreeWithTransactions = recordManagerTxn.addBTree( "testWithTxn", LongSerializer.INSTANCE, StringSerializer.INSTANCE, false ); - btreeNoTransactions = recordManagerNoTxn.addBTree( "testNoTxn", LongSerializer.INSTANCE, StringSerializer.INSTANCE, false ); + btree = recordManager.addBTree( "testWithTxn", LongSerializer.INSTANCE, StringSerializer.INSTANCE, false ); } catch ( Exception e ) { @@ -76,20 +71,13 @@ public class BTreeTransactionTest @After public void cleanup() throws IOException { - btreeNoTransactions.close(); - btreeWithTransactions.close(); + btree.close(); - recordManagerNoTxn.close(); - recordManagerTxn.close(); + recordManager.close(); - if ( dataDirNoTxn.exists() ) + if ( dataDir.exists() ) { - FileUtils.deleteDirectory( dataDirNoTxn ); - } - - if ( dataDirWithTxn.exists() ) - { - FileUtils.deleteDirectory( dataDirWithTxn ); + FileUtils.deleteDirectory( dataDir ); } } @@ -98,29 +86,21 @@ public class BTreeTransactionTest { try { - if ( recordManagerTxn != null ) - { - recordManagerTxn.close(); - } - - if ( recordManagerNoTxn != null ) + if ( recordManager != null ) { - recordManagerNoTxn.close(); + recordManager.close(); } // Now, try to reload the file back - recordManagerTxn = new RecordManager( dataDirWithTxn.getAbsolutePath() ); - recordManagerNoTxn = new RecordManager( dataDirNoTxn.getAbsolutePath() ); + recordManager = new RecordManager( dataDir.getAbsolutePath() ); // load the last created btree - if ( btreeWithTransactions != null ) + if ( btree != null ) { - btreeWithTransactions = recordManagerTxn.getBtree( btreeWithTransactions.getName() ); - } - - if ( btreeNoTransactions != null ) - { - btreeNoTransactions = recordManagerNoTxn.getBtree( btreeNoTransactions.getName() ); + try ( Transaction readTransaction = recordManager.beginReadTransaction() ) + { + btree = recordManager.getBtree( readTransaction, btree.getName(), 0L ); + } } } catch ( Exception e ) @@ -131,37 +111,22 @@ public class BTreeTransactionTest @Test - public void testWithoutTransaction() throws IOException - { - long t0 = System.currentTimeMillis(); - - for ( long i = 0L; i < 1000L; i++ ) - { - btreeNoTransactions.insert( i, Long.toString( i ) ); - } - - long t1 = System.currentTimeMillis(); - - System.out.println( "Delta without transaction for 100K elements = " + ( t1 - t0 ) ); - } - - - @Test @Ignore("Fails atm") public void testWithTransaction() throws IOException { + long nbIteration = 100_000L; long t0 = System.currentTimeMillis(); - for ( long i = 0L; i < 1000L; i++ ) + for ( long i = 0L; i < nbIteration; i++ ) { - System.out.println( i ); - //btreeWithTransactions.beginTransaction(); - btreeWithTransactions.insert( i, Long.toString( i ) ); - //btreeWithTransactions.commit(); + try ( WriteTransaction writeTransaction = recordManager.beginWriteTransaction() ) + { + btree.insert( writeTransaction, i, Long.toString( i ) ); + } } long t1 = System.currentTimeMillis(); - System.out.println( "Delta with transaction for 100K elements = " + ( t1 - t0 ) ); + System.out.println( "Delta with transaction for " + nbIteration + " elements = " + ( t1 - t0 ) ); } }