File: LSNArrayTest.java

package info (click to toggle)
libdb-je-java 3.3.98-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,052 kB
  • sloc: java: 153,077; xml: 2,034; makefile: 3
file content (77 lines) | stat: -rw-r--r-- 2,042 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*-
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 2002,2010 Oracle.  All rights reserved.
 *
 * $Id: LSNArrayTest.java,v 1.7.2.2 2010/01/04 15:30:48 cwl Exp $
 */

package com.sleepycat.je.tree;

import junit.framework.TestCase;

import com.sleepycat.je.utilint.DbLsn;

public class LSNArrayTest extends TestCase {
    private static final int N_ELTS = 128;

    private IN theIN;

    public void setUp() {
	theIN = new IN();
    }

    public void tearDown() {
    }

    public void testPutGetElement() {
	doTest(N_ELTS);
    }

    public void testOverflow() {
	doTest(N_ELTS << 2);
    }

    public void testFileOffsetGreaterThan3Bytes() {
	theIN.initEntryLsn(10);
	theIN.setLsnElement(0, 0xfffffe);
	assertTrue(theIN.getLsn(0) == 0xfffffe);
	assertTrue(theIN.getEntryLsnByteArray() != null);
	assertTrue(theIN.getEntryLsnLongArray() == null);
	theIN.setLsnElement(1, 0xffffff);
	assertTrue(theIN.getLsn(1) == 0xffffff);
	assertTrue(theIN.getEntryLsnLongArray() != null);
	assertTrue(theIN.getEntryLsnByteArray() == null);

	theIN.initEntryLsn(10);
	theIN.setLsnElement(0, 0xfffffe);
	assertTrue(theIN.getLsn(0) == 0xfffffe);
	assertTrue(theIN.getEntryLsnByteArray() != null);
	assertTrue(theIN.getEntryLsnLongArray() == null);
	theIN.setLsnElement(1, 0xffffff + 1);
	assertTrue(theIN.getLsn(1) == 0xffffff + 1);
	assertTrue(theIN.getEntryLsnLongArray() != null);
	assertTrue(theIN.getEntryLsnByteArray() == null);
    }

    private void doTest(int nElts) {
	theIN.initEntryLsn(nElts);
	for (int i = nElts - 1; i >= 0; i--) {
	    long thisLsn = DbLsn.makeLsn(i, i);
	    theIN.setLsnElement(i, thisLsn);
	    if (theIN.getLsn(i) != thisLsn) {
		System.out.println(i + " found: " +
				   DbLsn.toString(theIN.getLsn(i)) +
				   " expected: " +
				   DbLsn.toString(thisLsn));
	    }
	    assertTrue(theIN.getLsn(i) == thisLsn);
	}

	for (int i = 0; i < nElts; i++) {
	    long thisLsn = DbLsn.makeLsn(i, i);
	    theIN.setLsnElement(i, thisLsn);
	    assertTrue(theIN.getLsn(i) == thisLsn);
	}
    }
}