Imported Upstream version 5.3.21
[platform/upstream/libdb.git] / test / java / junit / src / com / sleepycat / db / test / VerboseConfigTest.java
1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002, 2012 Oracle and/or its affiliates.  All rights reserved.
5  */
6
7 package com.sleepycat.db.test;
8
9 import org.junit.After;
10 import org.junit.AfterClass;
11 import org.junit.Before;
12 import org.junit.BeforeClass;
13 import org.junit.Test;
14 import static org.junit.Assert.assertEquals;
15 import static org.junit.Assert.assertTrue;
16 import static org.junit.Assert.fail;
17
18 import com.sleepycat.db.*;
19
20 import java.io.File;
21 import java.io.FileNotFoundException;
22 import java.io.FileOutputStream;
23 import java.io.IOException;
24 import java.io.OutputStream;
25
26 import com.sleepycat.db.test.TestUtils;
27 public class VerboseConfigTest {
28     public static final String VERBOSECONFIGTEST_DBNAME = "verboseconfigtest.db";
29     @BeforeClass public static void ClassInit() {
30         TestUtils.loadConfig(null);
31         TestUtils.check_file_removed(TestUtils.getDBFileName(VERBOSECONFIGTEST_DBNAME), true, true);
32         TestUtils.removeall(true, true, TestUtils.BASETEST_DBDIR, TestUtils.getDBFileName(VERBOSECONFIGTEST_DBNAME));
33     }
34
35     @AfterClass public static void ClassShutdown() {
36         TestUtils.check_file_removed(TestUtils.getDBFileName(VERBOSECONFIGTEST_DBNAME), true, true);
37         TestUtils.removeall(true, true, TestUtils.BASETEST_DBDIR, TestUtils.getDBFileName(VERBOSECONFIGTEST_DBNAME));
38     }
39
40     @Before public void PerTestInit()
41         throws Exception {
42     }
43
44     @After public void PerTestShutdown()
45         throws Exception {
46     }
47     /*
48      * Test case implementations.
49      * To disable a test mark it with @Ignore
50      * To set a timeout(ms) notate like: @Test(timeout=1000)
51      * To indicate an expected exception notate like: (expected=Exception)
52      */
53
54     @Test public void test1()
55         throws DatabaseException, FileNotFoundException
56     {
57         EnvironmentConfig envc = new EnvironmentConfig();
58         envc.setAllowCreate(true);
59         envc.setInitializeCache(true);
60                 envc.setVerbose(VerboseConfig.DEADLOCK, true);
61                 envc.setVerbose(VerboseConfig.FILEOPS, true);
62                 envc.setVerbose(VerboseConfig.FILEOPS_ALL, true);
63                 envc.setVerbose(VerboseConfig.RECOVERY, true);
64                 envc.setVerbose(VerboseConfig.REGISTER, true);
65                 envc.setVerbose(VerboseConfig.REPLICATION, true);
66                 envc.setVerbose(VerboseConfig.WAITSFOR, true);
67                 envc.setMessageStream(new FileOutputStream(new File("messages.txt")));
68         Environment db_env = new Environment(TestUtils.BASETEST_DBFILE, envc);
69
70                 new File("messages.txt").delete();
71     }
72
73     /*
74          * Tests for old (now deprecated) API.
75          */
76     @Test public void test2()
77         throws DatabaseException, FileNotFoundException
78     {
79         EnvironmentConfig envc = new EnvironmentConfig();
80         envc.setAllowCreate(true);
81         envc.setInitializeCache(true);
82                 envc.setVerboseDeadlock(true);
83                 envc.setVerboseRecovery(true);
84                 envc.setVerboseRegister(true);
85                 envc.setVerboseReplication(true);
86                 envc.setVerboseWaitsFor(true);
87                 envc.setMessageStream(new FileOutputStream(new File("messages.txt")));
88         Environment db_env = new Environment(TestUtils.BASETEST_DBFILE, envc);
89
90                 new File("messages.txt").delete();
91     }
92     @Test public void test3() throws Exception
93     {
94         EnvironmentConfig ec = new EnvironmentConfig();
95         ec.setAllowCreate(true);
96         ec.setInitializeCache(true);
97         ec.setInitializeLocking(true);
98         ec.setInitializeLogging(true);
99         ec.setInitializeReplication(true);
100         ec.setTransactional(true);
101         ec.setPrivate(true);
102         ec.setVerbose(VerboseConfig.REPLICATION_SYSTEM, false);
103         assertTrue(!ec.getVerbose(VerboseConfig.REPLICATION_SYSTEM));
104         Environment env = new Environment(TestUtils.BASETEST_DBFILE, ec);
105         assertTrue(!env.getConfig().getVerbose(VerboseConfig.REPLICATION_SYSTEM));
106         env.close();
107     }
108 }