/source/db-5.0.26.NC/test/scr037/Configuration.cs

https://github.com/cparedes/omnibus · C# · 1107 lines · 947 code · 111 blank · 49 comment · 588 complexity · c23e4e68317ef620611ac59216841eb9 MD5 · raw file

  1. /*-
  2. * See the file LICENSE for redistribution information.
  3. *
  4. * Copyright (c) 2009, 2010 Oracle and/or its affiliates. All rights reserved.
  5. *
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using System.IO;
  10. using System.Text;
  11. using System.Xml;
  12. using BerkeleyDB;
  13. using NUnit.Framework;
  14. namespace CsharpAPITest
  15. {
  16. public class Configuration
  17. {
  18. /*
  19. * Configure the value with data in xml and return true or
  20. * false to indicate if the value is configured. If there
  21. * is no testing data and it is optional, return false. If
  22. * there is no testing data in xml and it is compulsory,
  23. * ConfigNotFoundException will be thrown. If any testing
  24. * data is provided, the value will be set by the testing
  25. * data and true will be returned.
  26. */
  27. #region Config
  28. public static void ConfigAckPolicy(XmlElement xmlElem,
  29. string name, ref AckPolicy ackPolicy, bool compulsory)
  30. {
  31. XmlNode xmlNode = XMLReader.GetNode(xmlElem,
  32. name);
  33. if (xmlNode == null && compulsory == true)
  34. throw new ConfigNotFoundException(name);
  35. else if (xmlNode != null)
  36. {
  37. string policy = xmlNode.InnerText;
  38. if (policy == "ALL")
  39. ackPolicy = AckPolicy.ALL;
  40. else if (policy == "ALL_PEERS")
  41. ackPolicy = AckPolicy.ALL_PEERS;
  42. else if (policy == "NONE")
  43. ackPolicy = AckPolicy.NONE;
  44. else if (policy == "ONE")
  45. ackPolicy = AckPolicy.ONE;
  46. else if (policy == "ONE_PEER")
  47. ackPolicy = AckPolicy.ONE_PEER;
  48. else if (policy == "QUORUM")
  49. ackPolicy = AckPolicy.QUORUM;
  50. else
  51. throw new InvalidConfigException(name);
  52. }
  53. }
  54. public static bool ConfigBool(XmlElement xmlElem,
  55. string name, ref bool value, bool compulsory)
  56. {
  57. XmlNode xmlNode;
  58. xmlNode = XMLReader.GetNode(xmlElem, name);
  59. if (xmlNode == null && compulsory == false)
  60. return false;
  61. else if (xmlNode == null && compulsory == true)
  62. throw new ConfigNotFoundException(name);
  63. value = bool.Parse(xmlNode.InnerText);
  64. return true;
  65. }
  66. public static bool ConfigByteOrder(XmlElement xmlElem,
  67. string name, ref ByteOrder byteOrder, bool compulsory)
  68. {
  69. XmlNode xmlNode;
  70. xmlNode = XMLReader.GetNode(xmlElem, name);
  71. if (xmlNode == null && compulsory == false)
  72. return false;
  73. else if (xmlNode == null && compulsory == true)
  74. throw new ConfigNotFoundException(name);
  75. byteOrder = ByteOrder.FromConst(
  76. int.Parse(xmlNode.InnerText));
  77. return true;
  78. }
  79. public static bool ConfigByteMatrix(XmlElement xmlElem,
  80. string name, ref byte[,] byteMatrix, bool compulsory)
  81. {
  82. int i, j, matrixLen;
  83. XmlNode xmlNode = XMLReader.GetNode(xmlElem, name);
  84. if (xmlNode == null && compulsory == false)
  85. return false;
  86. else if (xmlNode == null && compulsory == true)
  87. throw new ConfigNotFoundException(name);
  88. matrixLen = xmlNode.ChildNodes.Count;
  89. byte[,] matrix = new byte[matrixLen, matrixLen];
  90. for (i = 0; i < matrixLen; i++)
  91. {
  92. if (xmlNode.ChildNodes[i].ChildNodes.Count != matrixLen)
  93. throw new ConfigNotFoundException(name);
  94. for (j = 0; j < matrixLen; j++)
  95. {
  96. matrix[i, j] = byte.Parse(
  97. xmlNode.ChildNodes[i].ChildNodes[j].InnerText);
  98. }
  99. }
  100. byteMatrix = matrix;
  101. return true;
  102. }
  103. public static bool ConfigCacheInfo(XmlElement xmlElem,
  104. string name, ref CacheInfo cacheSize, bool compulsory)
  105. {
  106. XmlNode xmlNode;
  107. XmlNode xmlChildNode;
  108. uint bytes;
  109. uint gigabytes;
  110. int nCaches;
  111. xmlNode = XMLReader.GetNode(xmlElem, name);
  112. if (xmlNode == null && compulsory == true)
  113. throw new ConfigNotFoundException(name);
  114. else if (xmlNode != null)
  115. {
  116. if ((xmlChildNode = XMLReader.GetNode(
  117. (XmlElement)xmlNode, "Bytes")) != null)
  118. {
  119. bytes = uint.Parse(xmlChildNode.InnerText);
  120. if ((xmlChildNode = XMLReader.GetNode(
  121. (XmlElement)xmlNode, "Gigabytes")) != null)
  122. {
  123. gigabytes = uint.Parse(xmlChildNode.InnerText);
  124. if ((xmlChildNode = XMLReader.GetNode(
  125. (XmlElement)xmlNode, "NCaches")) != null)
  126. {
  127. nCaches = int.Parse(xmlChildNode.InnerText);
  128. cacheSize = new CacheInfo(gigabytes,bytes,nCaches);
  129. return true;
  130. }
  131. }
  132. }
  133. }
  134. return false;
  135. }
  136. public static bool ConfigCachePriority(XmlElement xmlElem,
  137. string name, ref CachePriority cachePriority, bool compulsory)
  138. {
  139. XmlNode xmlNode;
  140. string priority;
  141. xmlNode = XMLReader.GetNode(xmlElem, name);
  142. if (xmlNode == null && compulsory == false)
  143. return false;
  144. else if (xmlNode == null && compulsory == true)
  145. throw new ConfigNotFoundException(name);
  146. priority = xmlNode.InnerText;
  147. if (priority == "DEFAULT")
  148. cachePriority = CachePriority.DEFAULT;
  149. else if (priority == "HIGH")
  150. cachePriority = CachePriority.HIGH;
  151. else if (priority == "LOW")
  152. cachePriority = CachePriority.LOW;
  153. else if (priority == "VERY_HIGH")
  154. cachePriority = CachePriority.VERY_HIGH;
  155. else if (priority == "VERY_LOW")
  156. cachePriority = CachePriority.VERY_LOW;
  157. else
  158. throw new InvalidConfigException(name);
  159. return true;
  160. }
  161. public static bool ConfigCreatePolicy(XmlElement xmlElem,
  162. string name, ref CreatePolicy createPolicy, bool compulsory)
  163. {
  164. XmlNode xmlNode;
  165. xmlNode = XMLReader.GetNode(xmlElem, name);
  166. if (xmlNode == null && compulsory == false)
  167. return false;
  168. else if (xmlNode == null && compulsory == true)
  169. throw new ConfigNotFoundException(name);
  170. if (xmlNode.InnerText == "ALWAYS")
  171. createPolicy = CreatePolicy.ALWAYS;
  172. else if (xmlNode.InnerText == "IF_NEEDED")
  173. createPolicy = CreatePolicy.IF_NEEDED;
  174. else if (xmlNode.InnerText == "NEVER")
  175. createPolicy = CreatePolicy.NEVER;
  176. else
  177. throw new InvalidConfigException(name);
  178. return true;
  179. }
  180. public static bool ConfigDuplicatesPolicy(XmlElement xmlElem,
  181. string name, ref DuplicatesPolicy duplicatePolicy,bool compulsory)
  182. {
  183. XmlNode xmlNode;
  184. xmlNode = XMLReader.GetNode(xmlElem, name);
  185. if (xmlNode == null && compulsory == false)
  186. return false;
  187. else if (xmlNode == null && compulsory == true)
  188. throw new ConfigNotFoundException(name);
  189. if (xmlNode.InnerText == "NONE")
  190. duplicatePolicy = DuplicatesPolicy.NONE;
  191. else if (xmlNode.InnerText == "SORTED")
  192. duplicatePolicy = DuplicatesPolicy.SORTED;
  193. else if (xmlNode.InnerText == "UNSORTED")
  194. duplicatePolicy = DuplicatesPolicy.UNSORTED;
  195. else
  196. throw new InvalidConfigException(name);
  197. return true;
  198. }
  199. public static bool ConfigDateTime(XmlElement xmlElem,
  200. string name, ref DateTime time, bool compulsory)
  201. {
  202. XmlNode xmlNode;
  203. xmlNode = XMLReader.GetNode(xmlElem, name);
  204. if (xmlNode == null && compulsory == false)
  205. return false;
  206. else if (xmlNode == null && compulsory == true)
  207. throw new ConfigNotFoundException(name);
  208. time = DateTime.Parse(xmlNode.InnerText);
  209. return true;
  210. }
  211. public static bool ConfigDeadlockPolicy(XmlElement xmlElem,
  212. string name, ref DeadlockPolicy deadlockPolicy, bool compulsory)
  213. {
  214. XmlNode xmlNode = XMLReader.GetNode(xmlElem, name);
  215. if (xmlNode == null && compulsory == false)
  216. return false;
  217. else if (xmlNode == null && compulsory == true)
  218. throw new ConfigNotFoundException(name);
  219. string policy = xmlNode.InnerText;
  220. if (policy == "DEFAULT")
  221. deadlockPolicy = DeadlockPolicy.DEFAULT;
  222. else if (policy == "EXPIRE")
  223. deadlockPolicy = DeadlockPolicy.EXPIRE;
  224. else if (policy == "MAX_LOCKS")
  225. deadlockPolicy = DeadlockPolicy.MAX_LOCKS;
  226. else if (policy == "MAX_WRITE")
  227. deadlockPolicy = DeadlockPolicy.MAX_WRITE;
  228. else if (policy == "MIN_LOCKS")
  229. deadlockPolicy = DeadlockPolicy.MIN_LOCKS;
  230. else if (policy == "MIN_WRITE")
  231. deadlockPolicy = DeadlockPolicy.MIN_WRITE;
  232. else if (policy == "OLDEST")
  233. deadlockPolicy = DeadlockPolicy.OLDEST;
  234. else if (policy == "RANDOM")
  235. deadlockPolicy = DeadlockPolicy.RANDOM;
  236. else if (policy == "YOUNGEST")
  237. deadlockPolicy = DeadlockPolicy.YOUNGEST;
  238. else
  239. throw new InvalidConfigException(name);
  240. return true;
  241. }
  242. public static bool ConfigEncryption(XmlElement xmlElem,
  243. string name, DatabaseConfig dbConfig, bool compulsory)
  244. {
  245. EncryptionAlgorithm alg;
  246. XmlNode xmlNode;
  247. string tmp, password;
  248. xmlNode = XMLReader.GetNode(xmlElem, name);
  249. if (xmlNode == null && compulsory == false)
  250. return false;
  251. else if (xmlNode == null && compulsory == true)
  252. throw new ConfigNotFoundException(name);
  253. password = XMLReader.GetNode((XmlElement)xmlNode,
  254. "password").InnerText;
  255. tmp = XMLReader.GetNode((XmlElement)xmlNode, "algorithm").InnerText;
  256. if (tmp == "AES")
  257. alg = EncryptionAlgorithm.AES;
  258. else
  259. alg = EncryptionAlgorithm.DEFAULT;
  260. dbConfig.SetEncryption(password, alg);
  261. return true;
  262. }
  263. public static bool ConfigInt(XmlElement xmlElem,
  264. string name, ref int value, bool compulsory)
  265. {
  266. XmlNode xmlNode;
  267. xmlNode = XMLReader.GetNode(xmlElem, name);
  268. if (xmlNode == null && compulsory == false)
  269. return false;
  270. else if (xmlNode == null && compulsory == true)
  271. throw new ConfigNotFoundException(name);
  272. value = int.Parse(xmlNode.InnerText);
  273. return true;
  274. }
  275. public static bool ConfigIsolation(XmlElement xmlElem,
  276. string name, ref Isolation value, bool compulsory)
  277. {
  278. XmlNode xmlNode;
  279. int isolationDegree;
  280. xmlNode = XMLReader.GetNode(xmlElem, name);
  281. if (xmlNode == null && compulsory == false)
  282. return false;
  283. else if (xmlNode == null && compulsory == true)
  284. throw new ConfigNotFoundException(name);
  285. isolationDegree = int.Parse(xmlNode.InnerText);
  286. if (isolationDegree == 1)
  287. value = Isolation.DEGREE_ONE;
  288. else if (isolationDegree == 2)
  289. value = Isolation.DEGREE_TWO;
  290. else if (isolationDegree == 3)
  291. value = Isolation.DEGREE_THREE;
  292. else
  293. throw new InvalidConfigException(name);
  294. return true;
  295. }
  296. public static bool ConfigLogFlush(XmlElement xmlElem,
  297. string name, ref TransactionConfig.LogFlush value,
  298. bool compulsory)
  299. {
  300. XmlNode xmlNode;
  301. string logFlush;
  302. xmlNode = XMLReader.GetNode(xmlElem, name);
  303. if (xmlNode == null && compulsory == false)
  304. return false;
  305. else if (xmlNode == null && compulsory == true)
  306. throw new ConfigNotFoundException(name);
  307. logFlush = xmlNode.InnerText;
  308. if (logFlush == "DEFAULT")
  309. value = TransactionConfig.LogFlush.DEFAULT;
  310. else if (logFlush == "NOSYNC")
  311. value = TransactionConfig.LogFlush.NOSYNC;
  312. else if (logFlush == "WRITE_NOSYNC")
  313. value = TransactionConfig.LogFlush.WRITE_NOSYNC;
  314. else if (logFlush == "SYNC")
  315. value = TransactionConfig.LogFlush.SYNC;
  316. else
  317. throw new InvalidConfigException(name);
  318. return true;
  319. }
  320. public static bool ConfigLong(XmlElement xmlElem,
  321. string name, ref long value, bool compulsory)
  322. {
  323. XmlNode xmlNode;
  324. xmlNode = XMLReader.GetNode(xmlElem, name);
  325. if (xmlNode == null && compulsory == false)
  326. return false;
  327. else if (xmlNode == null && compulsory == true)
  328. throw new ConfigNotFoundException(name);
  329. value = long.Parse(xmlNode.InnerText);
  330. return true;
  331. }
  332. public static bool ConfigMaxSequentialWrites(
  333. XmlElement xmlElem, string name,
  334. MPoolConfig mpoolConfig, bool compulsory)
  335. {
  336. XmlNode xmlNode;
  337. uint pause;
  338. int writes;
  339. xmlNode = XMLReader.GetNode(xmlElem, name);
  340. if (xmlNode == null && compulsory == false)
  341. return false;
  342. else if (xmlNode == null && compulsory == true)
  343. throw new ConfigNotFoundException(name);
  344. pause = uint.Parse(XMLReader.GetNode(
  345. (XmlElement)xmlNode, "pause").InnerText);
  346. writes = int.Parse(XMLReader.GetNode(
  347. (XmlElement)xmlNode,"maxWrites").InnerText);
  348. mpoolConfig.SetMaxSequentialWrites(writes, pause);
  349. return true;
  350. }
  351. public static bool ConfigReplicationHostAddress(
  352. XmlElement xmlElem, string name,
  353. ref ReplicationHostAddress address, bool compulsory)
  354. {
  355. XmlNode xmlNode = XMLReader.GetNode(
  356. xmlElem, name);
  357. if (xmlNode == null && compulsory == false)
  358. return false;
  359. else if (xmlNode == null && compulsory == true)
  360. throw new ConfigNotFoundException(name);
  361. address.Host = XMLReader.GetNode(
  362. (XmlElement)xmlNode, "Host").InnerText;
  363. address.Port = uint.Parse(XMLReader.GetNode(
  364. (XmlElement)xmlNode, "Port").InnerText);
  365. return true;
  366. }
  367. public static bool ConfigString(XmlElement xmlElem,
  368. string name, ref string valChar, bool compulsory)
  369. {
  370. XmlNode xmlNode;
  371. xmlNode = XMLReader.GetNode(xmlElem, name);
  372. if (xmlNode == null && compulsory == false)
  373. return false;
  374. else if (xmlNode == null && compulsory == true)
  375. throw new ConfigNotFoundException(name);
  376. valChar = xmlNode.InnerText;
  377. return true;
  378. }
  379. public static bool ConfigStringList(XmlElement xmlElem,
  380. string name, ref List<string> strings, bool compulsory)
  381. {
  382. XmlNode xmlNode;
  383. xmlNode = XMLReader.GetNode(xmlElem, name);
  384. if (xmlNode == null && compulsory == false)
  385. return false;
  386. else if (xmlNode == null && compulsory == true)
  387. throw new ConfigNotFoundException(name);
  388. XmlNodeList list = xmlNode.ChildNodes;
  389. for (int i = 0; i < list.Count; i++)
  390. strings.Add(list[i].InnerText);
  391. return true;
  392. }
  393. public static bool ConfigUint(XmlElement xmlElem,
  394. string name, ref uint value, bool compulsory)
  395. {
  396. XmlNode xmlNode;
  397. xmlNode = XMLReader.GetNode(xmlElem, name);
  398. if (xmlNode == null && compulsory == false)
  399. return false;
  400. else if (xmlNode == null && compulsory == true)
  401. throw new ConfigNotFoundException(name);
  402. value = uint.Parse(xmlNode.InnerText);
  403. return true;
  404. }
  405. public static bool ConfigVerboseMessages(
  406. XmlElement xmlElem, string name,
  407. ref VerboseMessages verbose, bool compulsory)
  408. {
  409. XmlNode xmlNode = XMLReader.GetNode(xmlElem,
  410. name);
  411. if (xmlNode == null && compulsory == false)
  412. return false;
  413. else if (xmlNode == null && compulsory == true)
  414. throw new ConfigNotFoundException(name);
  415. ConfigBool((XmlElement)xmlNode, "AllFileOps",
  416. ref verbose.AllFileOps, compulsory);
  417. ConfigBool((XmlElement)xmlNode, "Deadlock",
  418. ref verbose.Deadlock, compulsory);
  419. ConfigBool((XmlElement)xmlNode, "FileOps",
  420. ref verbose.FileOps, compulsory);
  421. ConfigBool((XmlElement)xmlNode, "Recovery",
  422. ref verbose.Recovery, compulsory);
  423. ConfigBool((XmlElement)xmlNode, "Register",
  424. ref verbose.Register, compulsory);
  425. ConfigBool((XmlElement)xmlNode, "Replication",
  426. ref verbose.Replication, compulsory);
  427. ConfigBool((XmlElement)xmlNode, "ReplicationElection",
  428. ref verbose.ReplicationElection, compulsory);
  429. ConfigBool((XmlElement)xmlNode, "ReplicationLease",
  430. ref verbose.ReplicationLease, compulsory);
  431. ConfigBool((XmlElement)xmlNode, "ReplicationMessages",
  432. ref verbose.ReplicationMessages, compulsory);
  433. ConfigBool((XmlElement)xmlNode, "ReplicationMisc",
  434. ref verbose.ReplicationMisc, compulsory);
  435. ConfigBool((XmlElement)xmlNode, "ReplicationSync",
  436. ref verbose.ReplicationSync, compulsory);
  437. ConfigBool((XmlElement)xmlNode, "RepMgrConnectionFailure",
  438. ref verbose.RepMgrConnectionFailure, compulsory);
  439. ConfigBool((XmlElement)xmlNode, "RepMgrMisc",
  440. ref verbose.RepMgrMisc, compulsory);
  441. ConfigBool((XmlElement)xmlNode, "WaitsForTable",
  442. ref verbose.WaitsForTable, compulsory);
  443. return true;
  444. }
  445. #endregion Config
  446. /*
  447. * Confirm that the given value is the same with that in
  448. * xml. If there is no testing data in xml and it is
  449. * compulsory, the ConfigNotFoundException will be thrown.
  450. * If there is no testing data and it is optional, nothing
  451. * will be done. If any testing data is provided, the value
  452. * will be checked.
  453. */
  454. #region Confirm
  455. public static void ConfirmAckPolicy(XmlElement xmlElem,
  456. string name, AckPolicy ackPolicy, bool compulsory)
  457. {
  458. XmlNode xmlNode = XMLReader.GetNode(xmlElem,
  459. name);
  460. if (xmlNode == null && compulsory == true)
  461. throw new ConfigNotFoundException(name);
  462. else if (xmlNode != null)
  463. {
  464. string policy = xmlNode.InnerText;
  465. if (policy == "ALL")
  466. Assert.AreEqual(AckPolicy.ALL,
  467. ackPolicy);
  468. else if (policy == "ALL_PEERS")
  469. Assert.AreEqual(AckPolicy.ALL_PEERS,
  470. ackPolicy);
  471. else if (policy == "NONE")
  472. Assert.AreEqual(AckPolicy.NONE,
  473. ackPolicy);
  474. else if (policy == "ONE")
  475. Assert.AreEqual(AckPolicy.ONE,
  476. ackPolicy);
  477. else if (policy == "ONE_PEER")
  478. Assert.AreEqual(AckPolicy.ONE_PEER,
  479. ackPolicy);
  480. else if (policy == "QUORUM")
  481. Assert.AreEqual(AckPolicy.QUORUM,
  482. ackPolicy);
  483. else
  484. throw new InvalidConfigException(name);
  485. }
  486. }
  487. public static void ConfirmBool(XmlElement xmlElem,
  488. string name, bool value, bool compulsory)
  489. {
  490. XmlNode xmlNode;
  491. bool expected;
  492. xmlNode = XMLReader.GetNode(xmlElem,
  493. name);
  494. if (xmlNode == null && compulsory == true)
  495. throw new ConfigNotFoundException(name);
  496. else if (xmlNode != null)
  497. {
  498. if (xmlNode.ChildNodes.Count > 1)
  499. {
  500. expected = bool.Parse(
  501. xmlNode.FirstChild.NextSibling.InnerText);
  502. Assert.AreEqual(expected, value);
  503. }
  504. }
  505. }
  506. /*
  507. * If configure MACHINE, the ByteOrder in database will
  508. * switch to LITTLE_ENDIAN or BIG_ENDIAN according to the
  509. * current machine.
  510. */
  511. public static void ConfirmByteOrder(XmlElement xmlElem,
  512. string name, ByteOrder byteOrder, bool compulsory)
  513. {
  514. XmlNode xmlNode;
  515. ByteOrder specOrder;
  516. xmlNode = XMLReader.GetNode(xmlElem, name);
  517. if (xmlNode == null && compulsory == true)
  518. throw new ConfigNotFoundException(name);
  519. else if (xmlNode != null)
  520. {
  521. specOrder = ByteOrder.FromConst(int.Parse(
  522. xmlNode.InnerText));
  523. if (specOrder == ByteOrder.MACHINE)
  524. Assert.AreNotEqual(specOrder, byteOrder);
  525. else
  526. Assert.AreEqual(specOrder, byteOrder);
  527. }
  528. }
  529. public static void ConfirmByteMatrix(XmlElement xmlElem,
  530. string name, byte[,] byteMatrix, bool compulsory)
  531. {
  532. int i, j, matrixLen;
  533. XmlNode xmlNode = XMLReader.GetNode(xmlElem, name);
  534. if (xmlNode == null && compulsory == true)
  535. throw new ConfigNotFoundException(name);
  536. else if (xmlNode != null)
  537. {
  538. /*
  539. * If the length of the 2 matrixes are not
  540. * the same, the matrixes are definately
  541. * not equal.
  542. */
  543. matrixLen = xmlNode.ChildNodes.Count;
  544. Assert.AreEqual(matrixLen * matrixLen,byteMatrix.Length);
  545. /*
  546. * Go over every element in the matrix to
  547. * see if the same with the given xml data.
  548. */
  549. for (i = 0; i < matrixLen; i++)
  550. {
  551. if (xmlNode.ChildNodes[i].ChildNodes.Count != matrixLen)
  552. throw new ConfigNotFoundException(name);
  553. for (j = 0; j < matrixLen; j++)
  554. Assert.AreEqual(
  555. byte.Parse(xmlNode.ChildNodes[i].ChildNodes[j].InnerText),
  556. byteMatrix[i, j]);
  557. }
  558. }
  559. }
  560. public static void ConfirmCachePriority(XmlElement xmlElem,
  561. string name, CachePriority priority, bool compulsory)
  562. {
  563. XmlNode xmlNode;
  564. xmlNode = XMLReader.GetNode(xmlElem, name);
  565. if (xmlNode == null && compulsory == true)
  566. throw new ConfigNotFoundException(name);
  567. else if (xmlNode != null)
  568. {
  569. if (xmlNode.InnerText == "DEFAULT")
  570. Assert.AreEqual(CachePriority.DEFAULT, priority);
  571. else if (xmlNode.InnerText == "HIGH")
  572. Assert.AreEqual(CachePriority.HIGH, priority);
  573. else if (xmlNode.InnerText == "LOW")
  574. Assert.AreEqual(CachePriority.LOW, priority);
  575. else if (xmlNode.InnerText == "VERY_HIGH")
  576. Assert.AreEqual(CachePriority.VERY_HIGH, priority);
  577. else if (xmlNode.InnerText == "VERY_LOW")
  578. Assert.AreEqual(CachePriority.VERY_LOW, priority);
  579. }
  580. }
  581. public static void ConfirmCacheSize(XmlElement xmlElem,
  582. string name, CacheInfo cache, bool compulsory)
  583. {
  584. uint bytes;
  585. uint gigabytes;
  586. int nCaches;
  587. XmlNode xmlNode;
  588. XmlNode xmlChildNode;
  589. xmlNode = XMLReader.GetNode(xmlElem, name);
  590. if (xmlNode == null && compulsory == true)
  591. throw new ConfigNotFoundException(name);
  592. else if (xmlNode != null)
  593. {
  594. if ((xmlChildNode = XMLReader.GetNode(
  595. (XmlElement)xmlNode, "Bytes")) != null)
  596. {
  597. bytes = uint.Parse(xmlChildNode.InnerText);
  598. if ((xmlChildNode = XMLReader.GetNode(
  599. (XmlElement)xmlNode, "Gigabytes")) != null)
  600. {
  601. gigabytes = uint.Parse(xmlChildNode.InnerText);
  602. if ((xmlChildNode = XMLReader.GetNode(
  603. (XmlElement)xmlNode,
  604. "NCaches")) != null)
  605. {
  606. nCaches = int.Parse(xmlChildNode.InnerText);
  607. Assert.LessOrEqual(bytes, cache.Bytes);
  608. Assert.AreEqual(gigabytes, cache.Gigabytes);
  609. Assert.AreEqual(nCaches, cache.NCaches);
  610. }
  611. }
  612. }
  613. }
  614. }
  615. /*
  616. * If bytes in CacheSize is assigned, the bytes in cachesize
  617. * couldn't be the default one.
  618. */
  619. public static void ConfirmCacheSize(XmlElement xmlElem,
  620. string name, CacheInfo cache, uint defaultCache,
  621. bool compulsory)
  622. {
  623. uint bytes;
  624. uint gigabytes;
  625. int nCaches;
  626. XmlNode xmlNode;
  627. XmlNode xmlChildNode;
  628. xmlNode = XMLReader.GetNode(xmlElem, name);
  629. if (xmlNode == null && compulsory == true)
  630. throw new ConfigNotFoundException(name);
  631. else if (xmlNode != null)
  632. {
  633. if ((xmlChildNode = XMLReader.GetNode(
  634. (XmlElement)xmlNode, "Bytes")) != null)
  635. {
  636. bytes = defaultCache;
  637. if ((xmlChildNode = XMLReader.GetNode(
  638. (XmlElement)xmlNode, "Gigabytes")) != null)
  639. {
  640. gigabytes = uint.Parse(xmlChildNode.InnerText);
  641. if ((xmlChildNode = XMLReader.GetNode(
  642. (XmlElement)xmlNode, "NCaches")) != null)
  643. {
  644. nCaches = int.Parse(xmlChildNode.InnerText);
  645. Assert.AreNotEqual(bytes, cache.Bytes);
  646. Assert.AreEqual(gigabytes, cache.Gigabytes);
  647. Assert.AreEqual(nCaches, cache.NCaches);
  648. }
  649. }
  650. }
  651. }
  652. }
  653. public static void ConfirmCreatePolicy(XmlElement xmlElem,
  654. string name, CreatePolicy createPolicy, bool compulsory)
  655. {
  656. XmlNode xmlNode;
  657. xmlNode = XMLReader.GetNode(xmlElem, name);
  658. if (xmlNode == null && compulsory == true)
  659. throw new ConfigNotFoundException(name);
  660. else if (xmlNode != null)
  661. {
  662. if (xmlNode.InnerText == "ALWAYS")
  663. Assert.IsTrue(createPolicy.Equals(CreatePolicy.ALWAYS));
  664. else if (xmlNode.InnerText == "IF_NEEDED")
  665. Assert.IsTrue(createPolicy.Equals(CreatePolicy.IF_NEEDED));
  666. else if (xmlNode.InnerText == "NEVER")
  667. Assert.IsTrue(createPolicy.Equals(CreatePolicy.NEVER));
  668. }
  669. }
  670. public static void ConfirmDataBaseType(XmlElement xmlElem,
  671. string name, DatabaseType dbType, bool compulsory)
  672. {
  673. XmlNode xmlNode;
  674. xmlNode = XMLReader.GetNode(xmlElem, name);
  675. if (xmlNode == null && compulsory == true)
  676. throw new ConfigNotFoundException(name);
  677. else if (xmlNode != null)
  678. {
  679. if (xmlNode.InnerText == "BTREE")
  680. Assert.AreEqual(dbType, DatabaseType.BTREE);
  681. else if (xmlNode.InnerText == "HASH")
  682. Assert.AreEqual(dbType, DatabaseType.HASH);
  683. else if (xmlNode.InnerText == "QUEUE")
  684. Assert.AreEqual(dbType, DatabaseType.QUEUE);
  685. else if (xmlNode.InnerText == "RECNO")
  686. Assert.AreEqual(dbType, DatabaseType.RECNO);
  687. else if (xmlNode.InnerText == "UNKNOWN")
  688. Assert.AreEqual(dbType, DatabaseType.UNKNOWN);
  689. }
  690. }
  691. public static void ConfirmDateTime(XmlElement xmlElem,
  692. string name, DateTime time, bool compulsory)
  693. {
  694. XmlNode xmlNode;
  695. xmlNode = XMLReader.GetNode(xmlElem, name);
  696. if (xmlNode == null && compulsory == true)
  697. throw new ConfigNotFoundException(name);
  698. else if (xmlNode != null)
  699. Assert.AreEqual(DateTime.Parse(
  700. xmlNode.InnerText), time);
  701. }
  702. public static void ConfirmDeadlockPolicy(XmlElement xmlElem,
  703. string name, DeadlockPolicy deadlockPolicy, bool compulsory)
  704. {
  705. XmlNode xmlNode = XMLReader.GetNode(xmlElem, name);
  706. if (xmlNode == null && compulsory == true)
  707. throw new ConfigNotFoundException(name);
  708. else if (xmlNode != null)
  709. {
  710. string policy = xmlNode.InnerText;
  711. if (policy == "DEFAULT")
  712. Assert.AreEqual(DeadlockPolicy.DEFAULT, deadlockPolicy);
  713. else if (policy == "EXPIRE")
  714. Assert.AreEqual(DeadlockPolicy.EXPIRE, deadlockPolicy);
  715. else if (policy == "MAX_LOCKS")
  716. Assert.AreEqual(DeadlockPolicy.MAX_LOCKS, deadlockPolicy);
  717. else if (policy == "MAX_WRITE")
  718. Assert.AreEqual(DeadlockPolicy.MAX_WRITE, deadlockPolicy);
  719. else if (policy == "MIN_LOCKS")
  720. Assert.AreEqual(DeadlockPolicy.MIN_LOCKS, deadlockPolicy);
  721. else if (policy == "MIN_WRITE")
  722. Assert.AreEqual(DeadlockPolicy.MIN_WRITE, deadlockPolicy);
  723. else if (policy == "OLDEST")
  724. Assert.AreEqual(DeadlockPolicy.OLDEST, deadlockPolicy);
  725. else if (policy == "RANDOM")
  726. Assert.AreEqual(DeadlockPolicy.RANDOM, deadlockPolicy);
  727. else if (policy == "YOUNGEST")
  728. Assert.AreEqual(DeadlockPolicy.YOUNGEST, deadlockPolicy);
  729. else
  730. throw new InvalidConfigException(name);
  731. }
  732. }
  733. public static void ConfirmDuplicatesPolicy(
  734. XmlElement xmlElem, string name,
  735. DuplicatesPolicy duplicatedPolicy, bool compulsory)
  736. {
  737. XmlNode xmlNode;
  738. xmlNode = XMLReader.GetNode(xmlElem, name);
  739. if (xmlNode == null && compulsory == true)
  740. throw new ConfigNotFoundException(name);
  741. else if (xmlNode != null)
  742. {
  743. if (xmlNode.InnerText == "NONE")
  744. Assert.AreEqual(duplicatedPolicy, DuplicatesPolicy.NONE);
  745. else if (xmlNode.InnerText == "SORTED")
  746. Assert.AreEqual(duplicatedPolicy, DuplicatesPolicy.SORTED);
  747. else if (xmlNode.InnerText == "UNSORTED")
  748. Assert.AreEqual(duplicatedPolicy, DuplicatesPolicy.UNSORTED);
  749. }
  750. }
  751. public static void ConfirmEncryption(XmlElement xmlElem,
  752. string name, string dPwd, EncryptionAlgorithm dAlg, bool compulsory)
  753. {
  754. EncryptionAlgorithm alg;
  755. XmlNode xmlNode = XMLReader.GetNode(xmlElem,
  756. name);
  757. if (xmlNode == null && compulsory == true)
  758. throw new ConfigNotFoundException(name);
  759. else if (xmlNode != null)
  760. {
  761. string password = XMLReader.GetNode(
  762. (XmlElement)xmlNode, "password").InnerText;
  763. string tmp = XMLReader.GetNode(
  764. (XmlElement)xmlNode, "algorithm").InnerText;
  765. if (tmp == "AES")
  766. alg = EncryptionAlgorithm.AES;
  767. else
  768. alg = EncryptionAlgorithm.DEFAULT;
  769. Assert.AreEqual(dAlg, alg);
  770. Assert.AreEqual(dPwd, dPwd);
  771. }
  772. }
  773. public static void ConfirmInt(XmlElement xmlElem,
  774. string name, int value, bool compulsory)
  775. {
  776. XmlNode xmlNode;
  777. xmlNode = XMLReader.GetNode(xmlElem, name);
  778. if (xmlNode == null && compulsory == true)
  779. throw new ConfigNotFoundException(name);
  780. else if (xmlNode != null)
  781. Assert.AreEqual(int.Parse(xmlNode.InnerText), value);
  782. }
  783. public static void ConfirmIsolation(XmlElement xmlElem,
  784. string name, Isolation value, bool compulsory)
  785. {
  786. XmlNode xmlNode;
  787. int isolationDegree;
  788. xmlNode = XMLReader.GetNode(xmlElem, name);
  789. if (xmlNode == null && compulsory == true)
  790. throw new ConfigNotFoundException(name);
  791. else if (xmlNode != null)
  792. {
  793. isolationDegree = int.Parse(xmlNode.InnerText);
  794. if (isolationDegree == 1)
  795. Assert.AreEqual(Isolation.DEGREE_ONE, value);
  796. else if (isolationDegree == 2)
  797. Assert.AreEqual(Isolation.DEGREE_TWO, value);
  798. else if (isolationDegree == 3)
  799. Assert.AreEqual(Isolation.DEGREE_THREE, value);
  800. else
  801. throw new InvalidConfigException(name);
  802. }
  803. }
  804. public static void ConfirmLogFlush(XmlElement xmlElem,
  805. string name, TransactionConfig.LogFlush value,
  806. bool compulsory)
  807. {
  808. XmlNode xmlNode;
  809. string logFlush;
  810. xmlNode = XMLReader.GetNode(xmlElem, name);
  811. if (xmlNode == null && compulsory == true)
  812. throw new ConfigNotFoundException(name);
  813. else if (xmlNode != null)
  814. {
  815. logFlush = xmlNode.InnerText;
  816. if (logFlush == "DEFAULT")
  817. Assert.AreEqual(TransactionConfig.LogFlush.DEFAULT, value);
  818. else if (logFlush == "NOSYNC")
  819. Assert.AreEqual(TransactionConfig.LogFlush.NOSYNC, value);
  820. else if (logFlush == "WRITE_NOSYNC")
  821. Assert.AreEqual(TransactionConfig.LogFlush.WRITE_NOSYNC, value);
  822. else if (logFlush == "SYNC")
  823. Assert.AreEqual(TransactionConfig.LogFlush.SYNC, value);
  824. else
  825. throw new InvalidConfigException(name);
  826. }
  827. }
  828. public static void ConfirmLong(XmlElement xmlElem,
  829. string name, long value, bool compulsory)
  830. {
  831. XmlNode xmlNode;
  832. xmlNode = XMLReader.GetNode(xmlElem, name);
  833. if (xmlNode == null && compulsory == true)
  834. throw new ConfigNotFoundException(name);
  835. else if (xmlNode != null)
  836. Assert.AreEqual(long.Parse(xmlNode.InnerText), value);
  837. }
  838. public static void ConfirmMaxSequentialWrites(
  839. XmlElement xmlElem, string name,
  840. uint mPause, int mWrites, bool compulsory)
  841. {
  842. XmlNode xmlNode;
  843. uint pause;
  844. int writes;
  845. xmlNode = XMLReader.GetNode(xmlElem, name);
  846. if (xmlNode == null && compulsory == true)
  847. throw new ConfigNotFoundException(name);
  848. else if (xmlNode != null)
  849. {
  850. writes = int.Parse(XMLReader.GetNode(
  851. (XmlElement)xmlNode, "maxWrites").InnerText);
  852. pause = uint.Parse(XMLReader.GetNode(
  853. (XmlElement)xmlNode, "pause").InnerText);
  854. Assert.AreEqual(mPause, pause);
  855. Assert.AreEqual(mWrites, writes);
  856. }
  857. }
  858. public static void ConfirmReplicationHostAddress(
  859. XmlElement xmlElem, string name,
  860. ReplicationHostAddress address, bool compulsory)
  861. {
  862. XmlNode xmlNode = XMLReader.GetNode(xmlElem, name);
  863. if (xmlNode == null && compulsory == true)
  864. throw new ConfigNotFoundException(name);
  865. else if (xmlNode != null)
  866. {
  867. string host = XMLReader.GetNode(
  868. (XmlElement)xmlNode, "Host").InnerText;
  869. uint port = uint.Parse(XMLReader.GetNode(
  870. (XmlElement)xmlNode, "Port").InnerText);
  871. Assert.AreEqual(host, address.Host);
  872. Assert.AreEqual(port, address.Port);
  873. }
  874. }
  875. public static void ConfirmString(XmlElement xmlElem,
  876. string name, string str, bool compulsory)
  877. {
  878. XmlNode xmlNode;
  879. if (str != null)
  880. {
  881. xmlNode = XMLReader.GetNode(xmlElem, name);
  882. if (xmlNode == null && compulsory == true)
  883. throw new ConfigNotFoundException(name);
  884. else if (xmlNode != null)
  885. {
  886. if (xmlNode.HasChildNodes)
  887. Assert.AreEqual(
  888. xmlNode.FirstChild.InnerText, str);
  889. }
  890. }
  891. }
  892. public static void ConfirmStringList(XmlElement xmlElem,
  893. string name, List<string> strings, bool compulsory)
  894. {
  895. XmlNode xmlNode;
  896. if (strings != null)
  897. {
  898. xmlNode = XMLReader.GetNode(xmlElem, name);
  899. if (xmlNode == null && compulsory == true)
  900. throw new ConfigNotFoundException(name);
  901. else if (xmlNode != null)
  902. {
  903. if (xmlNode.HasChildNodes)
  904. {
  905. XmlNodeList list = xmlNode.ChildNodes;
  906. for (int i = 0; i < xmlNode.ChildNodes.Count;i++)
  907. Assert.IsTrue(
  908. strings.Contains(list[i].InnerText));
  909. }
  910. }
  911. }
  912. }
  913. public static void ConfirmUint(XmlElement xmlElem,
  914. string name, uint value, bool compulsory)
  915. {
  916. XmlNode xmlNode;
  917. xmlNode = XMLReader.GetNode(xmlElem, name);
  918. if (xmlNode == null && compulsory == true)
  919. throw new ConfigNotFoundException(name);
  920. else if (xmlNode != null)
  921. Assert.AreEqual(uint.Parse(xmlNode.InnerText), value);
  922. }
  923. public static void ConfirmVerboseMessages(
  924. XmlElement xmlElem, string name,
  925. VerboseMessages verbose, bool compulsory)
  926. {
  927. XmlNode xmlNode = XMLReader.GetNode(xmlElem, name);
  928. if (xmlNode == null && compulsory == true)
  929. throw new ConfigNotFoundException(name);
  930. else if (xmlNode != null)
  931. {
  932. ConfirmBool((XmlElement)xmlNode, "AllFileOps",
  933. verbose.AllFileOps, compulsory);
  934. ConfirmBool((XmlElement)xmlNode, "Deadlock",
  935. verbose.Deadlock, compulsory);
  936. ConfirmBool((XmlElement)xmlNode, "FileOps",
  937. verbose.FileOps, compulsory);
  938. ConfirmBool((XmlElement)xmlNode, "Recovery",
  939. verbose.Recovery, compulsory);
  940. ConfirmBool((XmlElement)xmlNode, "Register",
  941. verbose.Register, compulsory);
  942. ConfirmBool((XmlElement)xmlNode, "Replication",
  943. verbose.Replication, compulsory);
  944. ConfirmBool((XmlElement)xmlNode, "ReplicationElection",
  945. verbose.ReplicationElection, compulsory);
  946. ConfirmBool((XmlElement)xmlNode, "ReplicationLease",
  947. verbose.ReplicationLease, compulsory);
  948. ConfirmBool((XmlElement)xmlNode, "ReplicationMessages",
  949. verbose.ReplicationMessages, compulsory);
  950. ConfirmBool((XmlElement)xmlNode, "ReplicationMisc",
  951. verbose.ReplicationMisc, compulsory);
  952. ConfirmBool((XmlElement)xmlNode, "ReplicationSync",
  953. verbose.ReplicationSync, compulsory);
  954. ConfirmBool((XmlElement)xmlNode, "RepMgrConnectionFailure",
  955. verbose.RepMgrConnectionFailure, compulsory);
  956. ConfirmBool((XmlElement)xmlNode, "RepMgrMisc",
  957. verbose.RepMgrMisc, compulsory);
  958. ConfirmBool((XmlElement)xmlNode,"WaitsForTable",
  959. verbose.WaitsForTable, compulsory);
  960. }
  961. }
  962. #endregion Confirm
  963. public static void dbtFromString(DatabaseEntry dbt, string s)
  964. {
  965. dbt.Data = System.Text.Encoding.ASCII.GetBytes(s);
  966. }
  967. public static string strFromDBT(DatabaseEntry dbt)
  968. {
  969. System.Text.ASCIIEncoding decode = new ASCIIEncoding();
  970. return decode.GetString(dbt.Data);
  971. }
  972. /*
  973. * Reading params successfully returns true. Unless returns
  974. * false. The retrieved Xml fragment is returning in xmlElem.
  975. */
  976. public static XmlElement TestSetUp(string testFixtureName, string testName)
  977. {
  978. XMLReader xmlReader = new XMLReader("../../AllTestData.xml");
  979. XmlElement xmlElem = xmlReader.GetXmlElement(testFixtureName, testName);
  980. if (xmlElem == null)
  981. throw new ConfigNotFoundException(testFixtureName + ":" + testName);
  982. else
  983. return xmlElem;
  984. }
  985. /*
  986. * Delete existing test output directory and its files,
  987. * then create a new one.
  988. */
  989. public static void ClearDir(string testDir)
  990. {
  991. if (Directory.Exists(testDir))
  992. Directory.Delete(testDir, true);
  993. Directory.CreateDirectory(testDir);
  994. }
  995. }
  996. }