summaryrefslogtreecommitdiff
path: root/jstests/capped2.js
blob: a9b209efa8f1c6fadc9c6abf90c269d9c2e22553 (plain)
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
db.capped2.drop();
db._dbCommand( { create: "capped2", capped: true, size: 1000, $nExtents: 11, autoIndexId: false } );
t = db.capped2;

var val = new Array( 2000 );
var c = "";
for( i = 0; i < 2000; ++i, c += "-" ) {
    val[ i ] = { a: c };
}

function checkIncreasing( i ) {
    res = t.find().sort( { $natural: -1 } );
    assert( res.hasNext() );
    var j = i;
    while( res.hasNext() ) {
      	assert.eq( val[ j-- ].a, res.next().a );
    }
    res = t.find().sort( { $natural: 1 } );
    assert( res.hasNext() );
    while( res.hasNext() )
	assert.eq( val[ ++j ].a, res.next().a );
    assert.eq( j, i );
}

function checkDecreasing( i ) {
    res = t.find().sort( { $natural: -1 } );
    assert( res.hasNext() );
    var j = i;
    while( res.hasNext() ) {
      	assert.eq( val[ j++ ].a, res.next().a );
    }
    res = t.find().sort( { $natural: 1 } );
    assert( res.hasNext() );
    while( res.hasNext() )
	assert.eq( val[ --j ].a, res.next().a );
    assert.eq( j, i );
}

for( i = 0 ;; ++i ) {
    t.save( val[ i ] );
    if ( t.count() == 0 ) {
	assert( i > 100 );
	break;
    }
    checkIncreasing( i );
}

for( i = 600 ; i >= 0 ; --i ) {
    t.save( val[ i ] );
    checkDecreasing( i );
}