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

« back to all changes in this revision

Viewing changes to libdb/test/scr016/TestTruncate.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
 
 * Simple test for get/put of specific values.
12
 
 */
13
 
 
14
 
package com.sleepycat.test;
15
 
 
16
 
import com.sleepycat.db.*;
17
 
import java.io.FileNotFoundException;
18
 
 
19
 
public class TestTruncate
20
 
{
21
 
    public static void main(String[] args)
22
 
    {
23
 
        try {
24
 
            Db db = new Db(null, 0);
25
 
            db.open(null, "my.db", null, Db.DB_BTREE, Db.DB_CREATE, 0644);
26
 
 
27
 
            // populate our massive database.
28
 
            Dbt keydbt = new Dbt("key".getBytes());
29
 
            Dbt datadbt = new Dbt("data".getBytes());
30
 
            db.put(null, keydbt, datadbt, 0);
31
 
 
32
 
            // Now, retrieve.  We could use keydbt over again,
33
 
            // but that wouldn't be typical in an application.
34
 
            Dbt goodkeydbt = new Dbt("key".getBytes());
35
 
            Dbt badkeydbt = new Dbt("badkey".getBytes());
36
 
            Dbt resultdbt = new Dbt();
37
 
            resultdbt.set_flags(Db.DB_DBT_MALLOC);
38
 
 
39
 
            int ret;
40
 
 
41
 
            if ((ret = db.get(null, goodkeydbt, resultdbt, 0)) != 0) {
42
 
                System.out.println("get: " + DbEnv.strerror(ret));
43
 
            }
44
 
            else {
45
 
                String result =
46
 
                    new String(resultdbt.get_data(), 0, resultdbt.get_size());
47
 
                System.out.println("got data: " + result);
48
 
            }
49
 
 
50
 
            if ((ret = db.get(null, badkeydbt, resultdbt, 0)) != 0) {
51
 
                // We expect this...
52
 
                System.out.println("get using bad key: " + DbEnv.strerror(ret));
53
 
            }
54
 
            else {
55
 
                String result =
56
 
                    new String(resultdbt.get_data(), 0, resultdbt.get_size());
57
 
                System.out.println("*** got data using bad key!!: " + result);
58
 
            }
59
 
 
60
 
            // Now, truncate and make sure that it's really gone.
61
 
            System.out.println("truncating data...");
62
 
            int nrecords = db.truncate(null, 0);
63
 
            System.out.println("truncate returns " + nrecords);
64
 
            if ((ret = db.get(null, goodkeydbt, resultdbt, 0)) != 0) {
65
 
                // We expect this...
66
 
                System.out.println("after trunctate get: " +
67
 
                                   DbEnv.strerror(ret));
68
 
            }
69
 
            else {
70
 
                String result =
71
 
                    new String(resultdbt.get_data(), 0, resultdbt.get_size());
72
 
                System.out.println("got data: " + result);
73
 
            }
74
 
 
75
 
            db.close(0);
76
 
            System.out.println("finished test");
77
 
        }
78
 
        catch (DbException dbe) {
79
 
            System.err.println("Db Exception: " + dbe);
80
 
        }
81
 
        catch (FileNotFoundException fnfe) {
82
 
            System.err.println("FileNotFoundException: " + fnfe);
83
 
        }
84
 
 
85
 
    }
86
 
 
87
 
}