Return-Path: X-Original-To: apmail-directory-commits-archive@www.apache.org Delivered-To: apmail-directory-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 02C9E1738B for ; Thu, 12 Feb 2015 01:30:15 +0000 (UTC) Received: (qmail 4024 invoked by uid 500); 12 Feb 2015 01:30:15 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 3986 invoked by uid 500); 12 Feb 2015 01:30:14 -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 3977 invoked by uid 99); 12 Feb 2015 01:30:14 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Feb 2015 01:30:14 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id A3682AC010E for ; Thu, 12 Feb 2015 01:30:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1659120 - /directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeBrowseTest.java Date: Thu, 12 Feb 2015 01:30:14 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150212013014.A3682AC010E@hades.apache.org> Author: elecharny Date: Thu Feb 12 01:30:14 2015 New Revision: 1659120 URL: http://svn.apache.org/r1659120 Log: Adding a test that checks we can browse a btree with random keys. Currently, this test is failing, we have some issue in teh way we build the browser. Modified: directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeBrowseTest.java Modified: directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeBrowseTest.java URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeBrowseTest.java?rev=1659120&r1=1659119&r2=1659120&view=diff ============================================================================== --- directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeBrowseTest.java (original) +++ directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeBrowseTest.java Thu Feb 12 01:30:14 2015 @@ -28,8 +28,11 @@ import static org.junit.Assert.fail; import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import java.util.NoSuchElementException; +import java.util.Random; import java.util.UUID; import org.apache.commons.io.FileUtils; @@ -1162,4 +1165,55 @@ public class PersistedBTreeBrowseTest System.out.println( cursor.nextKey() ); } } + + + /** + * Test the browse methods on a btree containing 500 random entries, and + * try to browse it. + */ + @Test + public void testBrowseBTree500() throws IOException, BTreeAlreadyManagedException, KeyNotFoundException + { + List values = new ArrayList( 500 ); + long[] randomVals = new long[500]; + Random r = new Random( System.currentTimeMillis() ); + + // Inject some data + for ( long i = 0L; i < 5000L; i++ ) + { + values.add( i ); + } + + for ( int i = 0; i < 500; i++ ) + { + int index = r.nextInt( 500 - i ); + randomVals[i] = values.get( index ); + } + + // Inject some data + for ( int i = 0; i < 500; i++ ) + { + btree.insert( randomVals[i], Long.toString( randomVals[i] ) ); + } + + // Now, browse the BTree starting from 0 to the end + for ( long i = 0L; i < 500L; i++ ) + { + System.out.println( "Browsing from " + i ); + // Create the cursor + TupleCursor cursor = btree.browseFrom( i ); + + assertTrue( cursor.hasNext() ); + Long expected = i; + + while ( cursor.hasNext() ) + { + Tuple tuple = cursor.next(); + assertEquals( expected, tuple.getKey() ); + expected++; + } + + cursor.close(); + } + } } \ No newline at end of file