~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to libdb/test/scr016/TestLogc.java

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*-
2
 
 * See the file LICENSE for redistribution information.
3
 
 *
4
 
 * Copyright (c) 1997-2002
5
 
 *      Sleepycat Software.  All rights reserved.
6
 
 *
7
 
 * $Id$
8
 
 */
9
 
 
10
 
/*
11
 
 * A basic regression test for the Logc class.
12
 
 */
13
 
 
14
 
package com.sleepycat.test;
15
 
 
16
 
import com.sleepycat.db.*;
17
 
import java.io.FileNotFoundException;
18
 
 
19
 
public class TestLogc
20
 
{
21
 
    public static void main(String[] args)
22
 
    {
23
 
        try {
24
 
            DbEnv env = new DbEnv(0);
25
 
            env.open(".", Db.DB_CREATE | Db.DB_INIT_LOG | Db.DB_INIT_MPOOL, 0);
26
 
 
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);
32
 
            db1.close(0);
33
 
 
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);
38
 
            db2.close(0);
39
 
 
40
 
            // Now get a log cursor and walk through.
41
 
            DbLogc logc = env.log_cursor(0);
42
 
 
43
 
            int ret = 0;
44
 
            DbLsn lsn = new DbLsn();
45
 
            Dbt dbt = new Dbt();
46
 
            int flags = Db.DB_FIRST;
47
 
 
48
 
            int count = 0;
49
 
            while ((ret = logc.get(lsn, dbt, flags)) == 0) {
50
 
 
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
55
 
                // 'enough'.
56
 
                //
57
 
                //     System.out.println("logc.get: " + count);
58
 
                //     System.out.println(showDbt(dbt));
59
 
                //
60
 
                count++;
61
 
                flags = Db.DB_NEXT;
62
 
            }
63
 
            if (ret != Db.DB_NOTFOUND) {
64
 
                System.err.println("*** FAIL: logc.get returned: " +
65
 
                                   DbEnv.strerror(ret));
66
 
            }
67
 
            logc.close(0);
68
 
 
69
 
            // There has to be at *least* four log records,
70
 
            // since we did four separate database operations.
71
 
            //
72
 
            if (count < 4)
73
 
                System.out.println("*** FAIL: not enough log records");
74
 
 
75
 
            System.out.println("TestLogc done.");
76
 
        }
77
 
        catch (DbException dbe) {
78
 
            System.err.println("*** FAIL: Db Exception: " + dbe);
79
 
        }
80
 
        catch (FileNotFoundException fnfe) {
81
 
            System.err.println("*** FAIL: FileNotFoundException: " + fnfe);
82
 
        }
83
 
 
84
 
    }
85
 
 
86
 
    public static String showDbt(Dbt dbt)
87
 
    {
88
 
        StringBuffer sb = new StringBuffer();
89
 
        int size = dbt.get_size();
90
 
        byte[] data = dbt.get_data();
91
 
        int i;
92
 
        for (i=0; i<size && i<10; i++) {
93
 
            sb.append(Byte.toString(data[i]));
94
 
            sb.append(' ');
95
 
        }
96
 
        if (i<size)
97
 
            sb.append("...");
98
 
        return "size: " + size + " data: " + sb.toString();
99
 
    }
100
 
}