summaryrefslogtreecommitdiff
path: root/db-4.8.30/test/scr037/DatabaseEnvironmentConfigTest.cs
blob: f092ae4361e285b183f79e67bb39cd99b5eb2f6e (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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/*-
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 2009 Oracle.  All rights reserved.
 *
 */
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.XPath;
using BerkeleyDB;
using NUnit.Framework;

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

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

			Configuration.ClearDir(testFixtureHome);
		}

		[Test]
		public void TestConfig()
		{
			testName = "TestConfig";
			XmlElement xmlElem = Configuration.TestSetUp(
			    testFixtureName, testName);
			DatabaseEnvironmentConfig envConfig =
			    new DatabaseEnvironmentConfig();
			Config(xmlElem, ref envConfig, true);
			Confirm(xmlElem, envConfig, true);
		}
		
		public static void Confirm(XmlElement xmlElement,
		    DatabaseEnvironmentConfig envConfig, bool compulsory)
		{
			Configuration.ConfirmBool(xmlElement, "AutoCommit",
			    envConfig.AutoCommit, compulsory);
			Configuration.ConfirmBool(xmlElement, "CDB_ALLDB",
			    envConfig.CDB_ALLDB, compulsory);
			Configuration.ConfirmBool(xmlElement, "Create",
			    envConfig.Create, compulsory);
			Configuration.ConfirmStringList(xmlElement, "DataDirs",
			    envConfig.DataDirs, compulsory);
			Configuration.ConfirmString(xmlElement, "ErrorPrefix",
			    envConfig.ErrorPrefix, compulsory);
			Configuration.ConfirmBool(xmlElement, "ForceFlush",
			    envConfig.ForceFlush, compulsory);
			Configuration.ConfirmBool(xmlElement, "FreeThreaded",
			    envConfig.FreeThreaded, compulsory);
			Configuration.ConfirmBool(xmlElement, "InitRegions",
			    envConfig.InitRegions, compulsory);
			Configuration.ConfirmString(xmlElement,
			    "IntermediateDirMode",
			    envConfig.IntermediateDirMode, compulsory);
			Configuration.ConfirmBool(xmlElement, "Lockdown",
			    envConfig.Lockdown, compulsory);
			Configuration.ConfirmUint(xmlElement, "LockTimeout",
			    envConfig.LockTimeout, compulsory);
			Configuration.ConfirmUint(xmlElement, "MaxTransactions",
			    envConfig.MaxTransactions, compulsory);
			Configuration.ConfirmBool(xmlElement, "NoBuffer",
			    envConfig.NoBuffer, compulsory);
			Configuration.ConfirmBool(xmlElement, "NoLocking",
			    envConfig.NoLocking, compulsory);
			Configuration.ConfirmBool(xmlElement, "NoMMap",
			    envConfig.NoMMap, compulsory);
			Configuration.ConfirmBool(xmlElement, "NoLocking",
			    envConfig.NoLocking, compulsory);
			Configuration.ConfirmBool(xmlElement, "NoPanic",
			    envConfig.NoPanic, compulsory);
			Configuration.ConfirmBool(xmlElement, "Overwrite",
			    envConfig.Overwrite, compulsory);
			Configuration.ConfirmBool(xmlElement, "Private",
			    envConfig.Private, compulsory);
			Configuration.ConfirmBool(xmlElement, "Register",
			    envConfig.Register, compulsory);
			Configuration.ConfirmBool(xmlElement, "RunFatalRecovery", 
			    envConfig.RunFatalRecovery, compulsory);
			Configuration.ConfirmBool(xmlElement, "RunRecovery",
			    envConfig.RunRecovery, compulsory);
			Configuration.ConfirmBool(xmlElement, "SystemMemory",
			    envConfig.SystemMemory, compulsory);
			Configuration.ConfirmString(xmlElement, "TempDir",
			    envConfig.TempDir, compulsory);
			Configuration.ConfirmBool(xmlElement, "TimeNotGranted",
			    envConfig.TimeNotGranted, compulsory);
			Configuration.ConfirmBool(xmlElement, "TxnNoSync",
			    envConfig.TxnNoSync, compulsory);
			Configuration.ConfirmBool(xmlElement, "TxnNoWait",
			    envConfig.TxnNoWait, compulsory);
			Configuration.ConfirmBool(xmlElement, "TxnSnapshot",
			    envConfig.TxnSnapshot, compulsory);
			Configuration.ConfirmDateTime(xmlElement,"TxnTimestamp", 
			    envConfig.TxnTimestamp, compulsory);
			Configuration.ConfirmBool(xmlElement, "TxnWriteNoSync",
			    envConfig.TxnWriteNoSync, compulsory);
			Configuration.ConfirmBool(xmlElement, "UseCDB",
			    envConfig.UseCDB, compulsory);
			Configuration.ConfirmBool(xmlElement, "UseLocking",
			    envConfig.UseLocking, compulsory);
			Configuration.ConfirmBool(xmlElement, "UseLogging",
			    envConfig.UseLogging, compulsory);
			Configuration.ConfirmBool(xmlElement, "UseMPool",
			    envConfig.UseMPool, compulsory);
			Configuration.ConfirmBool(xmlElement, "UseMVCC",
			    envConfig.UseMVCC, compulsory);
			Configuration.ConfirmBool(xmlElement, "UseReplication",
			    envConfig.UseReplication, compulsory);
			Configuration.ConfirmBool(xmlElement, "UseTxns",
			    envConfig.UseTxns, compulsory);
			envConfig.Verbosity = new VerboseMessages();
			Configuration.ConfirmVerboseMessages(xmlElement,
			    "Verbosity", envConfig.Verbosity, compulsory);
			Configuration.ConfirmBool(xmlElement, "YieldCPU",
			    envConfig.YieldCPU, compulsory);
		}

		public static void Config(XmlElement xmlElement,
		    ref DatabaseEnvironmentConfig envConfig, bool compulsory)
		{
			uint value = new uint();
			DateTime time = new DateTime();

			Configuration.ConfigBool(xmlElement, "AutoCommit",
			    ref envConfig.AutoCommit, compulsory);
			Configuration.ConfigBool(xmlElement, "CDB_ALLDB",
			    ref envConfig.CDB_ALLDB, compulsory);
			Configuration.ConfigBool(xmlElement, "Create",
			    ref envConfig.Create, compulsory);
            Configuration.ConfigString(xmlElement, "CreationDir",
                ref envConfig.CreationDir, compulsory);
			Configuration.ConfigStringList(xmlElement, "DataDirs",
			    ref envConfig.DataDirs, compulsory);
			Configuration.ConfigString(xmlElement, "ErrorPrefix",
			    ref envConfig.ErrorPrefix, compulsory);
			Configuration.ConfigBool(xmlElement, "ForceFlush",
			    ref envConfig.ForceFlush, compulsory);
			Configuration.ConfigBool(xmlElement, "FreeThreaded",
			    ref envConfig.FreeThreaded, compulsory);
			Configuration.ConfigBool(xmlElement, "InitRegions",
			    ref envConfig.InitRegions, compulsory);
			Configuration.ConfigString(xmlElement, "IntermediateDirMode",
			    ref envConfig.IntermediateDirMode, compulsory);
			Configuration.ConfigBool(xmlElement, "Lockdown",
			    ref envConfig.Lockdown, compulsory);
			if (Configuration.ConfigUint(xmlElement, "LockTimeout",
			    ref value, compulsory))
				envConfig.LockTimeout = value;
			if (Configuration.ConfigUint(xmlElement, "MaxTransactions",
			    ref value, compulsory))
				envConfig.MaxTransactions = value;
			Configuration.ConfigBool(xmlElement, "NoBuffer",
			    ref envConfig.NoBuffer, compulsory);
			Configuration.ConfigBool(xmlElement, "NoLocking",
			    ref envConfig.NoLocking, compulsory);
			Configuration.ConfigBool(xmlElement, "NoMMap",
			    ref envConfig.NoMMap, compulsory);
			Configuration.ConfigBool(xmlElement, "NoLocking",
			    ref envConfig.NoLocking, compulsory);
			Configuration.ConfigBool(xmlElement, "NoPanic",
			    ref envConfig.NoPanic, compulsory);
			Configuration.ConfigBool(xmlElement, "Overwrite",
			    ref envConfig.Overwrite, compulsory);
			Configuration.ConfigBool(xmlElement, "Private",
			    ref envConfig.Private, compulsory);
			Configuration.ConfigBool(xmlElement, "Register",
			    ref envConfig.Register, compulsory);
			Configuration.ConfigBool(xmlElement, "RunFatalRecovery",
			    ref envConfig.RunFatalRecovery, compulsory);
			Configuration.ConfigBool(xmlElement, "RunRecovery",
			    ref envConfig.RunRecovery, compulsory);
			Configuration.ConfigBool(xmlElement, "SystemMemory",
			    ref envConfig.SystemMemory, compulsory);
			Configuration.ConfigString(xmlElement, "TempDir",
			    ref envConfig.TempDir, compulsory);
			Configuration.ConfigBool(xmlElement, "TimeNotGranted",
			    ref envConfig.TimeNotGranted, compulsory);
			Configuration.ConfigBool(xmlElement, "TxnNoSync",
			    ref envConfig.TxnNoSync, compulsory);
			Configuration.ConfigBool(xmlElement, "TxnNoWait",
			    ref envConfig.TxnNoWait, compulsory);
			Configuration.ConfigBool(xmlElement, "TxnSnapshot",
			    ref envConfig.TxnSnapshot, compulsory);
			if (Configuration.ConfigDateTime(xmlElement, "TxnTimestamp", 
			    ref time, compulsory))
				envConfig.TxnTimestamp = time;
			Configuration.ConfigBool(xmlElement, "TxnWriteNoSync",
			    ref envConfig.TxnWriteNoSync, compulsory);
			Configuration.ConfigBool(xmlElement, "UseLocking",
			    ref envConfig.UseLocking, compulsory);
			Configuration.ConfigBool(xmlElement, "UseLogging",
			    ref envConfig.UseLogging, compulsory);
			Configuration.ConfigBool(xmlElement, "UseMPool",
			    ref envConfig.UseMPool, compulsory);
			Configuration.ConfigBool(xmlElement, "UseMVCC",
			    ref envConfig.UseMVCC, compulsory);
			Configuration.ConfigBool(xmlElement, "UseReplication",
			    ref envConfig.UseReplication, compulsory);
			Configuration.ConfigBool(xmlElement, "UseTxns",
			    ref envConfig.UseTxns, compulsory);
			envConfig.Verbosity = new VerboseMessages();
			Configuration.ConfigVerboseMessages(xmlElement, 
			    "Verbosity", ref envConfig.Verbosity, compulsory);
			Configuration.ConfigBool(xmlElement, "YieldCPU",
			    ref envConfig.YieldCPU, compulsory);
		}

		[Test]
		public void TestConfigLock()
		{
			testName = "TestConfigLock";
			XmlElement xmlElem = Configuration.TestSetUp(
			    testFixtureName, testName);
			DatabaseEnvironmentConfig cfg = 
			    new DatabaseEnvironmentConfig();
			cfg.LockSystemCfg = new LockingConfig();
			LockingConfigTest.Config(xmlElem, 
			    ref cfg.LockSystemCfg, true);
			LockingConfigTest.Confirm(xmlElem, 
			    cfg.LockSystemCfg, true);
		}

		[Test]
		public void TestConfigLog()
		{
			testName = "TestConfigLog";
			XmlElement xmlElem = Configuration.TestSetUp(
			    testFixtureName, testName);
			DatabaseEnvironmentConfig cfg =
			    new DatabaseEnvironmentConfig();
			cfg.LogSystemCfg = new LogConfig();
			LogConfigTest.Config(xmlElem, ref cfg.LogSystemCfg, true);
			LogConfigTest.Confirm(xmlElem, cfg.LogSystemCfg, true);
		}

		[Test]
		public void TestConfigMutex()
		{
			testName = "TestConfigMutex";
			XmlElement xmlElem = Configuration.TestSetUp(
			    testFixtureName, testName);
			DatabaseEnvironmentConfig cfg =
			    new DatabaseEnvironmentConfig();
			cfg.MutexSystemCfg = new MutexConfig();
			MutexConfigTest.Config(xmlElem, ref cfg.MutexSystemCfg, true);
			MutexConfigTest.Confirm(xmlElem, cfg.MutexSystemCfg, true);
		}

		[Test]
		public void TestConfigReplication()
		{
			testName = "TestConfigReplication";
			XmlElement xmlElem = Configuration.TestSetUp(
			    testFixtureName, testName);
			DatabaseEnvironmentConfig cfg =
			    new DatabaseEnvironmentConfig();
			cfg.RepSystemCfg = new ReplicationConfig();
			ReplicationConfigTest.Config(xmlElem, 
			    ref cfg.RepSystemCfg, true);
			ReplicationConfigTest.Confirm(xmlElem, 
			    cfg.RepSystemCfg, true);
		}

		[Test]
		public void TestSetEncryption()
		{
			testName = "TestSetEncryption";
			testHome = testFixtureHome + "/" + testName;

			Configuration.ClearDir(testHome);
			DatabaseEnvironmentConfig envConfig =
			    new DatabaseEnvironmentConfig();
			envConfig.Create = true;
            envConfig.SetEncryption("key", EncryptionAlgorithm.AES);
			Assert.AreEqual("key", envConfig.EncryptionPassword);
            Assert.AreEqual(EncryptionAlgorithm.AES, envConfig.EncryptAlgorithm);
			DatabaseEnvironment env = DatabaseEnvironment.Open(
			    testHome, envConfig);
            Assert.AreEqual(EncryptionAlgorithm.AES, env.EncryptAlgorithm);
			env.Close();
		}

	}
}