KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > tree > LSNArrayTest


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: LSNArrayTest.java,v 1.5 2006/10/30 21:14:52 bostic Exp $
7  */

8
9 package com.sleepycat.je.tree;
10
11 import junit.framework.TestCase;
12
13 import com.sleepycat.je.utilint.DbLsn;
14
15 public class LSNArrayTest extends TestCase {
16     private static final int N_ELTS = 128;
17
18     private IN theIN;
19
20     public void setUp() {
21     theIN = new IN();
22     }
23
24     public void tearDown() {
25     }
26
27     public void testPutGetElement() {
28     doTest(N_ELTS);
29     }
30
31     public void testOverflow() {
32     doTest(N_ELTS << 2);
33     }
34
35     public void testFileOffsetGreaterThan3Bytes() {
36     theIN.initEntryLsn(10);
37     theIN.setLsnElement(0, 0xfffffe);
38     assertTrue(theIN.getLsn(0) == 0xfffffe);
39     assertTrue(theIN.getEntryLsnByteArray() != null);
40     assertTrue(theIN.getEntryLsnLongArray() == null);
41     theIN.setLsnElement(1, 0xffffff);
42     assertTrue(theIN.getLsn(1) == 0xffffff);
43     assertTrue(theIN.getEntryLsnLongArray() != null);
44     assertTrue(theIN.getEntryLsnByteArray() == null);
45
46     theIN.initEntryLsn(10);
47     theIN.setLsnElement(0, 0xfffffe);
48     assertTrue(theIN.getLsn(0) == 0xfffffe);
49     assertTrue(theIN.getEntryLsnByteArray() != null);
50     assertTrue(theIN.getEntryLsnLongArray() == null);
51     theIN.setLsnElement(1, 0xffffff + 1);
52     assertTrue(theIN.getLsn(1) == 0xffffff + 1);
53     assertTrue(theIN.getEntryLsnLongArray() != null);
54     assertTrue(theIN.getEntryLsnByteArray() == null);
55     }
56
57     private void doTest(int nElts) {
58     theIN.initEntryLsn(nElts);
59     for (int i = nElts - 1; i >= 0; i--) {
60         long thisLsn = DbLsn.makeLsn(i, i);
61         theIN.setLsnElement(i, thisLsn);
62         if (theIN.getLsn(i) != thisLsn) {
63         System.out.println(i + " found: " +
64                    DbLsn.toString(theIN.getLsn(i)) +
65                    " expected: " +
66                    DbLsn.toString(thisLsn));
67         }
68         assertTrue(theIN.getLsn(i) == thisLsn);
69     }
70
71     for (int i = 0; i < nElts; i++) {
72         long thisLsn = DbLsn.makeLsn(i, i);
73         theIN.setLsnElement(i, thisLsn);
74         assertTrue(theIN.getLsn(i) == thisLsn);
75     }
76     }
77 }
78
Popular Tags