summaryrefslogtreecommitdiff
path: root/db-4.8.30/test/scr037/LockingConfigTest.cs
blob: 82cf630af9b80b86f358aa781c78cf6d16b249aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*-
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 2009 Oracle.  All rights reserved.
 *
 */
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
using NUnit.Framework;
using BerkeleyDB;

namespace CsharpAPITest
{
	[TestFixture]
	public class LockingConfigTest
	{
		private string testFixtureHome;
		private string testFixtureName;
		private string testName;
		private string testHome;

		[TestFixtureSetUp]
		public void RunBeforeTests()
		{
			testFixtureName = "LockingConfigTest";
			testFixtureHome = "./TestOut/" + testFixtureName;

			Configuration.ClearDir(testFixtureHome);
		}

		[Test]
		public void TestConfig()
		{
			testName = "TestConfig";

			// Configure the fields/properties.
			LockingConfig lockingConfig = new LockingConfig();
			XmlElement xmlElem = Configuration.TestSetUp(
			    testFixtureName, testName);

			// Configure LockingConfig
			Config(xmlElem, ref lockingConfig, true);

			// Confirm LockingConfig
			Confirm(xmlElem, lockingConfig, true);
		}

		[Test]
		public void TestMaxLock() {
			testName = "TestMaxLock";
			testHome = testFixtureHome + "/" + testName;
			Configuration.ClearDir(testHome);

			DatabaseEnvironment env;
			uint maxLocks;
			DatabaseEntry obj;

			maxLocks = 1;
			obj = new DatabaseEntry();

			/*
			 * Initialize environment using locking subsystem. The max number 
			 * of locks should be larger than environment's partitions. So in 
			 * order to make the MaxLock work, the environment paritition is 
			 * set to be the same value as MaxLock.
			 */
			LockTest.LockingEnvSetUp(testHome, testName, out env,
			    maxLocks, 0, 0, maxLocks);
			Assert.AreEqual(maxLocks, env.MaxLocks);

		    env.Close();
		}

		[Test]
		public void TestMaxLocker() {
			testName = "TestMaxLocker";
			testHome = testFixtureHome + "/" + testName;
			Configuration.ClearDir(testHome);

			DatabaseEnvironment env;
			uint maxLockers;

			maxLockers = 1;
			LockTest.LockingEnvSetUp(testHome, testName, out env,
			    0, maxLockers, 0, 0);
			Assert.AreEqual(maxLockers, env.MaxLockers);
			env.Close();
		}

		[Test]
		public void TestMaxObjects() {
			testName = "TestMaxObjects";
			testHome = testFixtureHome + "/" + testName;
			Configuration.ClearDir(testHome);

			DatabaseEnvironment env;
			uint maxObjects;

			maxObjects = 1;

			/*
			 * Initialize environment using locking subsystem. The max number 
			 * of objects should be larger than environment's partitions. So 
			 * in order to make the MaxObject work, the environment paritition 
			 * is set to be the same value as MaxObject.
			 */ 
			LockTest.LockingEnvSetUp(testHome, testName, out env, 0, 0, 
			    maxObjects, maxObjects);
			Assert.AreEqual(maxObjects, env.MaxObjects);
			env.Close();
		}

		public static void Confirm(XmlElement xmlElement,
		    LockingConfig lockingConfig, bool compulsory)
		{
			Configuration.ConfirmByteMatrix(xmlElement, "Conflicts",
			    lockingConfig.Conflicts, compulsory);
			Configuration.ConfirmDeadlockPolicy(xmlElement,
			    "DeadlockResolution",
			    lockingConfig.DeadlockResolution, compulsory);
			Configuration.ConfirmUint(xmlElement, "MaxLockers",
			    lockingConfig.MaxLockers, compulsory);
			Configuration.ConfirmUint(xmlElement, "MaxLocks",
			    lockingConfig.MaxLocks, compulsory);
			Configuration.ConfirmUint(xmlElement, "MaxObjects",
			    lockingConfig.MaxObjects, compulsory);
			Configuration.ConfirmUint(xmlElement, "Partitions",
			    lockingConfig.Partitions, compulsory);
		}

		public static void Config(XmlElement xmlElement,
		    ref LockingConfig lockingConfig, bool compulsory)
		{
			byte[,] matrix = new byte[6, 6];
			uint value = new uint();

			if (Configuration.ConfigByteMatrix(xmlElement, "Conflicts", 
			    ref matrix, compulsory) == true)
				lockingConfig.Conflicts = matrix;

			Configuration.ConfigDeadlockPolicy(xmlElement, "DeadlockResolution",
			    ref lockingConfig.DeadlockResolution, compulsory);
			if (Configuration.ConfigUint(xmlElement, "MaxLockers", 
			    ref value, compulsory))
				lockingConfig.MaxLockers = value;
			if (Configuration.ConfigUint(xmlElement, "MaxLocks", 
			    ref value, compulsory))
				lockingConfig.MaxLocks = value;
			if (Configuration.ConfigUint(xmlElement, "MaxObjects", 
			    ref value, compulsory))
				lockingConfig.MaxObjects = value;
			if (Configuration.ConfigUint(xmlElement, "Partitions", 
			    ref value, compulsory))
				lockingConfig.Partitions = value;
		}

	}
}