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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 1997-2002
* Sleepycat Software. All rights reserved.
*
* $Id: TestLogc.java,v 1.7 2002/08/16 19:35:55 dda Exp $
*/
/*
* A basic regression test for the Logc class.
*/
package com.sleepycat.test;
import com.sleepycat.db.*;
import java.io.FileNotFoundException;
public class TestLogc
{
public static void main(String[] args)
{
try {
DbEnv env = new DbEnv(0);
env.open(".", Db.DB_CREATE | Db.DB_INIT_LOG | Db.DB_INIT_MPOOL, 0);
// Do some database activity to get something into the log.
Db db1 = new Db(env, 0);
db1.open(null, "first.db", null, Db.DB_BTREE, Db.DB_CREATE, 0);
db1.put(null, new Dbt("a".getBytes()), new Dbt("b".getBytes()), 0);
db1.put(null, new Dbt("c".getBytes()), new Dbt("d".getBytes()), 0);
db1.close(0);
Db db2 = new Db(env, 0);
db2.open(null, "second.db", null, Db.DB_BTREE, Db.DB_CREATE, 0644);
db2.put(null, new Dbt("w".getBytes()), new Dbt("x".getBytes()), 0);
db2.put(null, new Dbt("y".getBytes()), new Dbt("z".getBytes()), 0);
db2.close(0);
// Now get a log cursor and walk through.
DbLogc logc = env.log_cursor(0);
int ret = 0;
DbLsn lsn = new DbLsn();
Dbt dbt = new Dbt();
int flags = Db.DB_FIRST;
int count = 0;
while ((ret = logc.get(lsn, dbt, flags)) == 0) {
// We ignore the contents of the log record,
// it's not portable. Even the exact count
// is may change when the underlying implementation
// changes, we'll just make sure at the end we saw
// 'enough'.
//
// System.out.println("logc.get: " + count);
// System.out.println(showDbt(dbt));
//
count++;
flags = Db.DB_NEXT;
}
if (ret != Db.DB_NOTFOUND) {
System.err.println("*** FAIL: logc.get returned: " +
DbEnv.strerror(ret));
}
logc.close(0);
// There has to be at *least* four log records,
// since we did four separate database operations.
//
if (count < 4)
System.out.println("*** FAIL: not enough log records");
System.out.println("TestLogc done.");
}
catch (DbException dbe) {
System.err.println("*** FAIL: Db Exception: " + dbe);
}
catch (FileNotFoundException fnfe) {
System.err.println("*** FAIL: FileNotFoundException: " + fnfe);
}
}
public static String showDbt(Dbt dbt)
{
StringBuffer sb = new StringBuffer();
int size = dbt.get_size();
byte[] data = dbt.get_data();
int i;
for (i=0; i<size && i<10; i++) {
sb.append(Byte.toString(data[i]));
sb.append(' ');
}
if (i<size)
sb.append("...");
return "size: " + size + " data: " + sb.toString();
}
}
|