• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/router/db-4.8.30/test/scr037/
1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2009 Oracle.  All rights reserved.
5 *
6 */
7using System;
8using System.Collections;
9using System.Collections.Generic;
10using System.IO;
11using System.Text;
12using System.Threading;
13using System.Xml;
14using NUnit.Framework;
15using BerkeleyDB;
16
17namespace CsharpAPITest {
18    [TestFixture]
19    public class LockTest {
20        private string testFixtureHome;
21        private string testFixtureName;
22        private string testName;
23        private string testHome;
24
25        [TestFixtureSetUp]
26        public void RunBeforeTests() {
27            testFixtureName = "LockTest";
28            testFixtureHome = "./TestOut/" + testFixtureName;
29
30            /*
31             * Delete existing test ouput directory and files specified
32             * for the current test fixture and then create a new one.
33             */
34            Configuration.ClearDir(testFixtureHome);
35        }
36
37        [Test]
38        public void TestLockStats() {
39            testName = "TestLockManyAndStats";
40            testHome = testFixtureHome + "/" + testName;
41            Configuration.ClearDir(testHome);
42
43            // Configure locking subsystem.
44            LockingConfig lkConfig = new LockingConfig();
45            lkConfig.MaxLockers = 60;
46            lkConfig.MaxLocks = 50;
47            lkConfig.MaxObjects = 70;
48            lkConfig.Partitions = 20;
49
50            // Configure and open environment.
51            DatabaseEnvironmentConfig envConfig =
52                new DatabaseEnvironmentConfig();
53            envConfig.MPoolSystemCfg = new MPoolConfig();
54            envConfig.Create = true;
55            envConfig.LockSystemCfg = lkConfig;
56            envConfig.UseLocking = true;
57            envConfig.UseMPool = true;
58            envConfig.UseTxns = true;
59            envConfig.ErrorPrefix = testName;
60            envConfig.NoLocking = false;
61            envConfig.LockTimeout = 1000;
62            envConfig.TxnTimeout = 2000;
63            envConfig.MPoolSystemCfg.CacheSize = new CacheInfo(0, 10485760, 1);
64            DatabaseEnvironment env =
65                DatabaseEnvironment.Open(testHome, envConfig);
66
67            // Get and confirm locking subsystem statistics.
68            LockStats stats = env.LockingSystemStats();
69            env.PrintLockingSystemStats(true, true);
70            Assert.AreEqual(1000, stats.LockTimeoutLength);
71            Assert.AreEqual(60, stats.MaxLockersInTable);
72            Assert.AreEqual(50, stats.MaxLocksInTable);
73            Assert.AreEqual(70, stats.MaxObjectsInTable);
74            Assert.AreNotEqual(0, stats.MaxUnusedID);
75            Assert.AreEqual(20, stats.nPartitions);
76            Assert.AreNotEqual(0, stats.RegionNoWait);
77            Assert.AreNotEqual(0, stats.RegionSize);
78            Assert.AreEqual(0, stats.RegionWait);
79            Assert.AreEqual(2000, stats.TxnTimeoutLength);
80
81            env.PrintLockingSystemStats();
82
83            env.Close();
84        }
85
86        public static void LockingEnvSetUp(string testHome,
87            string testName, out DatabaseEnvironment env,
88            uint maxLock, uint maxLocker, uint maxObject,
89            uint partition) {
90            // Configure env and locking subsystem.
91            LockingConfig lkConfig = new LockingConfig();
92            /*
93             * If the maximum number of locks/lockers/objects
94             * is given, then the LockingConfig is set. Unless,
95             * it is not set to any value.
96             */
97            if (maxLock != 0)
98                lkConfig.MaxLocks = maxLock;
99            if (maxLocker != 0)
100                lkConfig.MaxLockers = maxLocker;
101            if (maxObject != 0)
102                lkConfig.MaxObjects = maxObject;
103            if (partition != 0)
104                lkConfig.Partitions = partition;
105
106            DatabaseEnvironmentConfig envConfig =
107                new DatabaseEnvironmentConfig();
108            envConfig.Create = true;
109            envConfig.LockSystemCfg = lkConfig;
110            envConfig.UseLocking = true;
111            envConfig.ErrorPrefix = testName;
112
113            env = DatabaseEnvironment.Open(testHome, envConfig);
114        }
115    }
116}
117