2
* See the file LICENSE for redistribution information.
4
* Copyright (c) 1997-2002
5
* Sleepycat Software. All rights reserved.
11
* A basic regression test for the Logc class.
14
package com.sleepycat.test;
16
import com.sleepycat.db.*;
17
import java.io.FileNotFoundException;
21
public static void main(String[] args)
24
DbEnv env = new DbEnv(0);
25
env.open(".", Db.DB_CREATE | Db.DB_INIT_LOG | Db.DB_INIT_MPOOL, 0);
27
// Do some database activity to get something into the log.
28
Db db1 = new Db(env, 0);
29
db1.open(null, "first.db", null, Db.DB_BTREE, Db.DB_CREATE, 0);
30
db1.put(null, new Dbt("a".getBytes()), new Dbt("b".getBytes()), 0);
31
db1.put(null, new Dbt("c".getBytes()), new Dbt("d".getBytes()), 0);
34
Db db2 = new Db(env, 0);
35
db2.open(null, "second.db", null, Db.DB_BTREE, Db.DB_CREATE, 0644);
36
db2.put(null, new Dbt("w".getBytes()), new Dbt("x".getBytes()), 0);
37
db2.put(null, new Dbt("y".getBytes()), new Dbt("z".getBytes()), 0);
40
// Now get a log cursor and walk through.
41
DbLogc logc = env.log_cursor(0);
44
DbLsn lsn = new DbLsn();
46
int flags = Db.DB_FIRST;
49
while ((ret = logc.get(lsn, dbt, flags)) == 0) {
51
// We ignore the contents of the log record,
52
// it's not portable. Even the exact count
53
// is may change when the underlying implementation
54
// changes, we'll just make sure at the end we saw
57
// System.out.println("logc.get: " + count);
58
// System.out.println(showDbt(dbt));
63
if (ret != Db.DB_NOTFOUND) {
64
System.err.println("*** FAIL: logc.get returned: " +
69
// There has to be at *least* four log records,
70
// since we did four separate database operations.
73
System.out.println("*** FAIL: not enough log records");
75
System.out.println("TestLogc done.");
77
catch (DbException dbe) {
78
System.err.println("*** FAIL: Db Exception: " + dbe);
80
catch (FileNotFoundException fnfe) {
81
System.err.println("*** FAIL: FileNotFoundException: " + fnfe);
86
public static String showDbt(Dbt dbt)
88
StringBuffer sb = new StringBuffer();
89
int size = dbt.get_size();
90
byte[] data = dbt.get_data();
92
for (i=0; i<size && i<10; i++) {
93
sb.append(Byte.toString(data[i]));
98
return "size: " + size + " data: " + sb.toString();