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 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119
|
/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2009, 2013 Oracle and/or its affiliates. All rights reserved.
*
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
using BerkeleyDB;
using NUnit.Framework;
namespace CsharpAPITest
{
public class Configuration
{
public static Random random = new Random();
/*
* Configure the value with data in xml and return true or
* false to indicate if the value is configured. If there
* is no testing data and it is optional, return false. If
* there is no testing data in xml and it is compulsory,
* ConfigNotFoundException will be thrown. If any testing
* data is provided, the value will be set by the testing
* data and true will be returned.
*/
#region Config
public static void ConfigAckPolicy(XmlElement xmlElem,
string name, ref AckPolicy ackPolicy, bool compulsory)
{
XmlNode xmlNode = XMLReader.GetNode(xmlElem,
name);
if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
else if (xmlNode != null)
{
string policy = xmlNode.InnerText;
if (policy == "ALL")
ackPolicy = AckPolicy.ALL;
else if (policy == "ALL_PEERS")
ackPolicy = AckPolicy.ALL_PEERS;
else if (policy == "NONE")
ackPolicy = AckPolicy.NONE;
else if (policy == "ONE")
ackPolicy = AckPolicy.ONE;
else if (policy == "ONE_PEER")
ackPolicy = AckPolicy.ONE_PEER;
else if (policy == "QUORUM")
ackPolicy = AckPolicy.QUORUM;
else
throw new InvalidConfigException(name);
}
}
public static bool ConfigBool(XmlElement xmlElem,
string name, ref bool value, bool compulsory)
{
XmlNode xmlNode;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == false)
return false;
else if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
value = bool.Parse(xmlNode.InnerText);
return true;
}
public static bool ConfigByteOrder(XmlElement xmlElem,
string name, ref ByteOrder byteOrder, bool compulsory)
{
XmlNode xmlNode;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == false)
return false;
else if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
byteOrder = ByteOrder.FromConst(
int.Parse(xmlNode.InnerText));
return true;
}
public static bool ConfigByteMatrix(XmlElement xmlElem,
string name, ref byte[,] byteMatrix, bool compulsory)
{
int i, j, matrixLen;
XmlNode xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == false)
return false;
else if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
matrixLen = xmlNode.ChildNodes.Count;
byte[,] matrix = new byte[matrixLen, matrixLen];
for (i = 0; i < matrixLen; i++)
{
if (xmlNode.ChildNodes[i].ChildNodes.Count != matrixLen)
throw new ConfigNotFoundException(name);
for (j = 0; j < matrixLen; j++)
{
matrix[i, j] = byte.Parse(
xmlNode.ChildNodes[i].ChildNodes[j].InnerText);
}
}
byteMatrix = matrix;
return true;
}
public static bool ConfigCacheInfo(XmlElement xmlElem,
string name, ref CacheInfo cacheSize, bool compulsory)
{
XmlNode xmlNode;
XmlNode xmlChildNode;
uint bytes;
uint gigabytes;
int nCaches;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
else if (xmlNode != null)
{
if ((xmlChildNode = XMLReader.GetNode(
(XmlElement)xmlNode, "Bytes")) != null)
{
bytes = uint.Parse(xmlChildNode.InnerText);
if ((xmlChildNode = XMLReader.GetNode(
(XmlElement)xmlNode, "Gigabytes")) != null)
{
gigabytes = uint.Parse(xmlChildNode.InnerText);
if ((xmlChildNode = XMLReader.GetNode(
(XmlElement)xmlNode, "NCaches")) != null)
{
nCaches = int.Parse(xmlChildNode.InnerText);
cacheSize = new CacheInfo(gigabytes,bytes,nCaches);
return true;
}
}
}
}
return false;
}
public static bool ConfigCachePriority(XmlElement xmlElem,
string name, ref CachePriority cachePriority, bool compulsory)
{
XmlNode xmlNode;
string priority;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == false)
return false;
else if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
priority = xmlNode.InnerText;
if (priority == "DEFAULT")
cachePriority = CachePriority.DEFAULT;
else if (priority == "HIGH")
cachePriority = CachePriority.HIGH;
else if (priority == "LOW")
cachePriority = CachePriority.LOW;
else if (priority == "VERY_HIGH")
cachePriority = CachePriority.VERY_HIGH;
else if (priority == "VERY_LOW")
cachePriority = CachePriority.VERY_LOW;
else
throw new InvalidConfigException(name);
return true;
}
public static bool ConfigCreatePolicy(XmlElement xmlElem,
string name, ref CreatePolicy createPolicy, bool compulsory)
{
XmlNode xmlNode;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == false)
return false;
else if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
if (xmlNode.InnerText == "ALWAYS")
createPolicy = CreatePolicy.ALWAYS;
else if (xmlNode.InnerText == "IF_NEEDED")
createPolicy = CreatePolicy.IF_NEEDED;
else if (xmlNode.InnerText == "NEVER")
createPolicy = CreatePolicy.NEVER;
else
throw new InvalidConfigException(name);
return true;
}
public static bool ConfigDuplicatesPolicy(XmlElement xmlElem,
string name, ref DuplicatesPolicy duplicatePolicy,bool compulsory)
{
XmlNode xmlNode;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == false)
return false;
else if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
if (xmlNode.InnerText == "NONE")
duplicatePolicy = DuplicatesPolicy.NONE;
else if (xmlNode.InnerText == "SORTED")
duplicatePolicy = DuplicatesPolicy.SORTED;
else if (xmlNode.InnerText == "UNSORTED")
duplicatePolicy = DuplicatesPolicy.UNSORTED;
else
throw new InvalidConfigException(name);
return true;
}
public static bool ConfigDateTime(XmlElement xmlElem,
string name, ref DateTime time, bool compulsory)
{
XmlNode xmlNode;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == false)
return false;
else if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
time = DateTime.Parse(xmlNode.InnerText);
return true;
}
public static bool ConfigDeadlockPolicy(XmlElement xmlElem,
string name, ref DeadlockPolicy deadlockPolicy, bool compulsory)
{
XmlNode xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == false)
return false;
else if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
string policy = xmlNode.InnerText;
if (policy == "DEFAULT")
deadlockPolicy = DeadlockPolicy.DEFAULT;
else if (policy == "EXPIRE")
deadlockPolicy = DeadlockPolicy.EXPIRE;
else if (policy == "MAX_LOCKS")
deadlockPolicy = DeadlockPolicy.MAX_LOCKS;
else if (policy == "MAX_WRITE")
deadlockPolicy = DeadlockPolicy.MAX_WRITE;
else if (policy == "MIN_LOCKS")
deadlockPolicy = DeadlockPolicy.MIN_LOCKS;
else if (policy == "MIN_WRITE")
deadlockPolicy = DeadlockPolicy.MIN_WRITE;
else if (policy == "OLDEST")
deadlockPolicy = DeadlockPolicy.OLDEST;
else if (policy == "RANDOM")
deadlockPolicy = DeadlockPolicy.RANDOM;
else if (policy == "YOUNGEST")
deadlockPolicy = DeadlockPolicy.YOUNGEST;
else
throw new InvalidConfigException(name);
return true;
}
public static bool ConfigEncryption(XmlElement xmlElem,
string name, DatabaseConfig dbConfig, bool compulsory)
{
EncryptionAlgorithm alg;
XmlNode xmlNode;
string tmp, password;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == false)
return false;
else if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
password = XMLReader.GetNode((XmlElement)xmlNode,
"password").InnerText;
tmp = XMLReader.GetNode((XmlElement)xmlNode, "algorithm").InnerText;
if (tmp == "AES")
alg = EncryptionAlgorithm.AES;
else
alg = EncryptionAlgorithm.DEFAULT;
dbConfig.SetEncryption(password, alg);
return true;
}
public static bool ConfigInt(XmlElement xmlElem,
string name, ref int value, bool compulsory)
{
XmlNode xmlNode;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == false)
return false;
else if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
value = int.Parse(xmlNode.InnerText);
return true;
}
public static bool ConfigIsolation(XmlElement xmlElem,
string name, ref Isolation value, bool compulsory)
{
XmlNode xmlNode;
int isolationDegree;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == false)
return false;
else if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
isolationDegree = int.Parse(xmlNode.InnerText);
if (isolationDegree == 1)
value = Isolation.DEGREE_ONE;
else if (isolationDegree == 2)
value = Isolation.DEGREE_TWO;
else if (isolationDegree == 3)
value = Isolation.DEGREE_THREE;
else
throw new InvalidConfigException(name);
return true;
}
public static bool ConfigLogFlush(XmlElement xmlElem,
string name, ref TransactionConfig.LogFlush value,
bool compulsory)
{
XmlNode xmlNode;
string logFlush;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == false)
return false;
else if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
logFlush = xmlNode.InnerText;
if (logFlush == "DEFAULT")
value = TransactionConfig.LogFlush.DEFAULT;
else if (logFlush == "NOSYNC")
value = TransactionConfig.LogFlush.NOSYNC;
else if (logFlush == "WRITE_NOSYNC")
value = TransactionConfig.LogFlush.WRITE_NOSYNC;
else if (logFlush == "SYNC")
value = TransactionConfig.LogFlush.SYNC;
else
throw new InvalidConfigException(name);
return true;
}
public static bool ConfigLong(XmlElement xmlElem,
string name, ref long value, bool compulsory)
{
XmlNode xmlNode;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == false)
return false;
else if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
value = long.Parse(xmlNode.InnerText);
return true;
}
public static bool ConfigMaxSequentialWrites(
XmlElement xmlElem, string name,
MPoolConfig mpoolConfig, bool compulsory)
{
XmlNode xmlNode;
uint pause;
int writes;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == false)
return false;
else if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
pause = uint.Parse(XMLReader.GetNode(
(XmlElement)xmlNode, "pause").InnerText);
writes = int.Parse(XMLReader.GetNode(
(XmlElement)xmlNode,"maxWrites").InnerText);
mpoolConfig.SetMaxSequentialWrites(writes, pause);
return true;
}
public static bool ConfigReplicationHostAddress(
XmlElement xmlElem, string name,
ref DbSiteConfig siteConfig, bool compulsory)
{
XmlNode xmlNode = XMLReader.GetNode(
xmlElem, name);
if (xmlNode == null && compulsory == false)
return false;
else if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
siteConfig.Host = XMLReader.GetNode(
(XmlElement)xmlNode, "Host").InnerText;
siteConfig.Port = uint.Parse(XMLReader.GetNode(
(XmlElement)xmlNode, "Port").InnerText);
return true;
}
public static bool ConfigString(XmlElement xmlElem,
string name, ref string valChar, bool compulsory)
{
XmlNode xmlNode;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == false)
return false;
else if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
valChar = xmlNode.InnerText;
return true;
}
public static bool ConfigStringList(XmlElement xmlElem,
string name, ref List<string> strings, bool compulsory)
{
XmlNode xmlNode;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == false)
return false;
else if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
XmlNodeList list = xmlNode.ChildNodes;
for (int i = 0; i < list.Count; i++)
strings.Add(list[i].InnerText);
return true;
}
public static bool ConfigUint(XmlElement xmlElem,
string name, ref uint value, bool compulsory)
{
XmlNode xmlNode;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == false)
return false;
else if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
value = uint.Parse(xmlNode.InnerText);
return true;
}
public static bool ConfigVerboseMessages(
XmlElement xmlElem, string name,
ref VerboseMessages verbose, bool compulsory)
{
XmlNode xmlNode = XMLReader.GetNode(xmlElem,
name);
if (xmlNode == null && compulsory == false)
return false;
else if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
ConfigBool((XmlElement)xmlNode, "AllFileOps",
ref verbose.AllFileOps, compulsory);
ConfigBool((XmlElement)xmlNode, "Deadlock",
ref verbose.Deadlock, compulsory);
ConfigBool((XmlElement)xmlNode, "FileOps",
ref verbose.FileOps, compulsory);
ConfigBool((XmlElement)xmlNode, "Recovery",
ref verbose.Recovery, compulsory);
ConfigBool((XmlElement)xmlNode, "Register",
ref verbose.Register, compulsory);
ConfigBool((XmlElement)xmlNode, "Replication",
ref verbose.Replication, compulsory);
ConfigBool((XmlElement)xmlNode, "ReplicationElection",
ref verbose.ReplicationElection, compulsory);
ConfigBool((XmlElement)xmlNode, "ReplicationLease",
ref verbose.ReplicationLease, compulsory);
ConfigBool((XmlElement)xmlNode, "ReplicationMessages",
ref verbose.ReplicationMessages, compulsory);
ConfigBool((XmlElement)xmlNode, "ReplicationMisc",
ref verbose.ReplicationMisc, compulsory);
ConfigBool((XmlElement)xmlNode, "ReplicationSync",
ref verbose.ReplicationSync, compulsory);
ConfigBool((XmlElement)xmlNode, "RepMgrConnectionFailure",
ref verbose.RepMgrConnectionFailure, compulsory);
ConfigBool((XmlElement)xmlNode, "RepMgrMisc",
ref verbose.RepMgrMisc, compulsory);
ConfigBool((XmlElement)xmlNode, "WaitsForTable",
ref verbose.WaitsForTable, compulsory);
return true;
}
#endregion Config
/*
* Confirm that the given value is the same with that in
* xml. If there is no testing data in xml and it is
* compulsory, the ConfigNotFoundException will be thrown.
* If there is no testing data and it is optional, nothing
* will be done. If any testing data is provided, the value
* will be checked.
*/
#region Confirm
public static void ConfirmAckPolicy(XmlElement xmlElem,
string name, AckPolicy ackPolicy, bool compulsory)
{
XmlNode xmlNode = XMLReader.GetNode(xmlElem,
name);
if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
else if (xmlNode != null)
{
string policy = xmlNode.InnerText;
if (policy == "ALL")
Assert.AreEqual(AckPolicy.ALL,
ackPolicy);
else if (policy == "ALL_PEERS")
Assert.AreEqual(AckPolicy.ALL_PEERS,
ackPolicy);
else if (policy == "NONE")
Assert.AreEqual(AckPolicy.NONE,
ackPolicy);
else if (policy == "ONE")
Assert.AreEqual(AckPolicy.ONE,
ackPolicy);
else if (policy == "ONE_PEER")
Assert.AreEqual(AckPolicy.ONE_PEER,
ackPolicy);
else if (policy == "QUORUM")
Assert.AreEqual(AckPolicy.QUORUM,
ackPolicy);
else
throw new InvalidConfigException(name);
}
}
public static void ConfirmBool(XmlElement xmlElem,
string name, bool value, bool compulsory)
{
XmlNode xmlNode;
bool expected;
xmlNode = XMLReader.GetNode(xmlElem,
name);
if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
else if (xmlNode != null)
{
if (xmlNode.ChildNodes.Count > 1)
{
expected = bool.Parse(
xmlNode.FirstChild.NextSibling.InnerText);
Assert.AreEqual(expected, value);
}
}
}
/*
* If configure MACHINE, the ByteOrder in database will
* switch to LITTLE_ENDIAN or BIG_ENDIAN according to the
* current machine.
*/
public static void ConfirmByteOrder(XmlElement xmlElem,
string name, ByteOrder byteOrder, bool compulsory)
{
XmlNode xmlNode;
ByteOrder specOrder;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
else if (xmlNode != null)
{
specOrder = ByteOrder.FromConst(int.Parse(
xmlNode.InnerText));
if (specOrder == ByteOrder.MACHINE)
Assert.AreNotEqual(specOrder, byteOrder);
else
Assert.AreEqual(specOrder, byteOrder);
}
}
public static void ConfirmByteMatrix(XmlElement xmlElem,
string name, byte[,] byteMatrix, bool compulsory)
{
int i, j, matrixLen;
XmlNode xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
else if (xmlNode != null)
{
/*
* If the length of the 2 matrixes are not
* the same, the matrixes are definately
* not equal.
*/
matrixLen = xmlNode.ChildNodes.Count;
Assert.AreEqual(matrixLen * matrixLen,byteMatrix.Length);
/*
* Go over every element in the matrix to
* see if the same with the given xml data.
*/
for (i = 0; i < matrixLen; i++)
{
if (xmlNode.ChildNodes[i].ChildNodes.Count != matrixLen)
throw new ConfigNotFoundException(name);
for (j = 0; j < matrixLen; j++)
Assert.AreEqual(
byte.Parse(xmlNode.ChildNodes[i].ChildNodes[j].InnerText),
byteMatrix[i, j]);
}
}
}
public static void ConfirmCachePriority(XmlElement xmlElem,
string name, CachePriority priority, bool compulsory)
{
XmlNode xmlNode;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
else if (xmlNode != null)
{
if (xmlNode.InnerText == "DEFAULT")
Assert.AreEqual(CachePriority.DEFAULT, priority);
else if (xmlNode.InnerText == "HIGH")
Assert.AreEqual(CachePriority.HIGH, priority);
else if (xmlNode.InnerText == "LOW")
Assert.AreEqual(CachePriority.LOW, priority);
else if (xmlNode.InnerText == "VERY_HIGH")
Assert.AreEqual(CachePriority.VERY_HIGH, priority);
else if (xmlNode.InnerText == "VERY_LOW")
Assert.AreEqual(CachePriority.VERY_LOW, priority);
}
}
public static void ConfirmCacheSize(XmlElement xmlElem,
string name, CacheInfo cache, bool compulsory)
{
uint bytes;
uint gigabytes;
int nCaches;
XmlNode xmlNode;
XmlNode xmlChildNode;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
else if (xmlNode != null)
{
if ((xmlChildNode = XMLReader.GetNode(
(XmlElement)xmlNode, "Bytes")) != null)
{
bytes = uint.Parse(xmlChildNode.InnerText);
if ((xmlChildNode = XMLReader.GetNode(
(XmlElement)xmlNode, "Gigabytes")) != null)
{
gigabytes = uint.Parse(xmlChildNode.InnerText);
if ((xmlChildNode = XMLReader.GetNode(
(XmlElement)xmlNode,
"NCaches")) != null)
{
nCaches = int.Parse(xmlChildNode.InnerText);
Assert.LessOrEqual(bytes, cache.Bytes);
Assert.AreEqual(gigabytes, cache.Gigabytes);
Assert.AreEqual(nCaches, cache.NCaches);
}
}
}
}
}
/*
* If bytes in CacheSize is assigned, the bytes in cachesize
* couldn't be the default one.
*/
public static void ConfirmCacheSize(XmlElement xmlElem,
string name, CacheInfo cache, uint defaultCache,
bool compulsory)
{
uint bytes;
uint gigabytes;
int nCaches;
XmlNode xmlNode;
XmlNode xmlChildNode;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
else if (xmlNode != null)
{
if ((xmlChildNode = XMLReader.GetNode(
(XmlElement)xmlNode, "Bytes")) != null)
{
bytes = defaultCache;
if ((xmlChildNode = XMLReader.GetNode(
(XmlElement)xmlNode, "Gigabytes")) != null)
{
gigabytes = uint.Parse(xmlChildNode.InnerText);
if ((xmlChildNode = XMLReader.GetNode(
(XmlElement)xmlNode, "NCaches")) != null)
{
nCaches = int.Parse(xmlChildNode.InnerText);
Assert.AreNotEqual(bytes, cache.Bytes);
Assert.AreEqual(gigabytes, cache.Gigabytes);
Assert.AreEqual(nCaches, cache.NCaches);
}
}
}
}
}
public static void ConfirmCreatePolicy(XmlElement xmlElem,
string name, CreatePolicy createPolicy, bool compulsory)
{
XmlNode xmlNode;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
else if (xmlNode != null)
{
if (xmlNode.InnerText == "ALWAYS")
Assert.IsTrue(createPolicy.Equals(CreatePolicy.ALWAYS));
else if (xmlNode.InnerText == "IF_NEEDED")
Assert.IsTrue(createPolicy.Equals(CreatePolicy.IF_NEEDED));
else if (xmlNode.InnerText == "NEVER")
Assert.IsTrue(createPolicy.Equals(CreatePolicy.NEVER));
}
}
public static void ConfirmDataBaseType(XmlElement xmlElem,
string name, DatabaseType dbType, bool compulsory)
{
XmlNode xmlNode;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
else if (xmlNode != null)
{
if (xmlNode.InnerText == "BTREE")
Assert.AreEqual(dbType, DatabaseType.BTREE);
else if (xmlNode.InnerText == "HASH")
Assert.AreEqual(dbType, DatabaseType.HASH);
else if (xmlNode.InnerText == "QUEUE")
Assert.AreEqual(dbType, DatabaseType.QUEUE);
else if (xmlNode.InnerText == "RECNO")
Assert.AreEqual(dbType, DatabaseType.RECNO);
else if (xmlNode.InnerText == "UNKNOWN")
Assert.AreEqual(dbType, DatabaseType.UNKNOWN);
}
}
public static void ConfirmDateTime(XmlElement xmlElem,
string name, DateTime time, bool compulsory)
{
XmlNode xmlNode;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
else if (xmlNode != null)
Assert.AreEqual(DateTime.Parse(
xmlNode.InnerText), time);
}
public static void ConfirmDeadlockPolicy(XmlElement xmlElem,
string name, DeadlockPolicy deadlockPolicy, bool compulsory)
{
XmlNode xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
else if (xmlNode != null)
{
string policy = xmlNode.InnerText;
if (policy == "DEFAULT")
Assert.AreEqual(DeadlockPolicy.DEFAULT, deadlockPolicy);
else if (policy == "EXPIRE")
Assert.AreEqual(DeadlockPolicy.EXPIRE, deadlockPolicy);
else if (policy == "MAX_LOCKS")
Assert.AreEqual(DeadlockPolicy.MAX_LOCKS, deadlockPolicy);
else if (policy == "MAX_WRITE")
Assert.AreEqual(DeadlockPolicy.MAX_WRITE, deadlockPolicy);
else if (policy == "MIN_LOCKS")
Assert.AreEqual(DeadlockPolicy.MIN_LOCKS, deadlockPolicy);
else if (policy == "MIN_WRITE")
Assert.AreEqual(DeadlockPolicy.MIN_WRITE, deadlockPolicy);
else if (policy == "OLDEST")
Assert.AreEqual(DeadlockPolicy.OLDEST, deadlockPolicy);
else if (policy == "RANDOM")
Assert.AreEqual(DeadlockPolicy.RANDOM, deadlockPolicy);
else if (policy == "YOUNGEST")
Assert.AreEqual(DeadlockPolicy.YOUNGEST, deadlockPolicy);
else
throw new InvalidConfigException(name);
}
}
public static void ConfirmDuplicatesPolicy(
XmlElement xmlElem, string name,
DuplicatesPolicy duplicatedPolicy, bool compulsory)
{
XmlNode xmlNode;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
else if (xmlNode != null)
{
if (xmlNode.InnerText == "NONE")
Assert.AreEqual(duplicatedPolicy, DuplicatesPolicy.NONE);
else if (xmlNode.InnerText == "SORTED")
Assert.AreEqual(duplicatedPolicy, DuplicatesPolicy.SORTED);
else if (xmlNode.InnerText == "UNSORTED")
Assert.AreEqual(duplicatedPolicy, DuplicatesPolicy.UNSORTED);
}
}
public static void ConfirmEncryption(XmlElement xmlElem,
string name, string dPwd, EncryptionAlgorithm dAlg, bool compulsory)
{
EncryptionAlgorithm alg;
XmlNode xmlNode = XMLReader.GetNode(xmlElem,
name);
if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
else if (xmlNode != null)
{
string password = XMLReader.GetNode(
(XmlElement)xmlNode, "password").InnerText;
string tmp = XMLReader.GetNode(
(XmlElement)xmlNode, "algorithm").InnerText;
if (tmp == "AES")
alg = EncryptionAlgorithm.AES;
else
alg = EncryptionAlgorithm.DEFAULT;
Assert.AreEqual(dAlg, alg);
Assert.AreEqual(dPwd, dPwd);
}
}
public static void ConfirmInt(XmlElement xmlElem,
string name, int value, bool compulsory)
{
XmlNode xmlNode;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
else if (xmlNode != null)
Assert.AreEqual(int.Parse(xmlNode.InnerText), value);
}
public static void ConfirmIsolation(XmlElement xmlElem,
string name, Isolation value, bool compulsory)
{
XmlNode xmlNode;
int isolationDegree;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
else if (xmlNode != null)
{
isolationDegree = int.Parse(xmlNode.InnerText);
if (isolationDegree == 1)
Assert.AreEqual(Isolation.DEGREE_ONE, value);
else if (isolationDegree == 2)
Assert.AreEqual(Isolation.DEGREE_TWO, value);
else if (isolationDegree == 3)
Assert.AreEqual(Isolation.DEGREE_THREE, value);
else
throw new InvalidConfigException(name);
}
}
public static void ConfirmLogFlush(XmlElement xmlElem,
string name, TransactionConfig.LogFlush value,
bool compulsory)
{
XmlNode xmlNode;
string logFlush;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
else if (xmlNode != null)
{
logFlush = xmlNode.InnerText;
if (logFlush == "DEFAULT")
Assert.AreEqual(TransactionConfig.LogFlush.DEFAULT, value);
else if (logFlush == "NOSYNC")
Assert.AreEqual(TransactionConfig.LogFlush.NOSYNC, value);
else if (logFlush == "WRITE_NOSYNC")
Assert.AreEqual(TransactionConfig.LogFlush.WRITE_NOSYNC, value);
else if (logFlush == "SYNC")
Assert.AreEqual(TransactionConfig.LogFlush.SYNC, value);
else
throw new InvalidConfigException(name);
}
}
public static void ConfirmLong(XmlElement xmlElem,
string name, long value, bool compulsory)
{
XmlNode xmlNode;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
else if (xmlNode != null)
Assert.AreEqual(long.Parse(xmlNode.InnerText), value);
}
public static void ConfirmMaxSequentialWrites(
XmlElement xmlElem, string name,
uint mPause, int mWrites, bool compulsory)
{
XmlNode xmlNode;
uint pause;
int writes;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
else if (xmlNode != null)
{
writes = int.Parse(XMLReader.GetNode(
(XmlElement)xmlNode, "maxWrites").InnerText);
pause = uint.Parse(XMLReader.GetNode(
(XmlElement)xmlNode, "pause").InnerText);
Assert.AreEqual(mPause, pause);
Assert.AreEqual(mWrites, writes);
}
}
public static void ConfirmReplicationHostAddress(
XmlElement xmlElem, string name,
DbSiteConfig siteConfig, bool compulsory)
{
XmlNode xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
else if (xmlNode != null)
{
string host = XMLReader.GetNode(
(XmlElement)xmlNode, "Host").InnerText;
uint port = uint.Parse(XMLReader.GetNode(
(XmlElement)xmlNode, "Port").InnerText);
Assert.AreEqual(host, siteConfig.Host);
Assert.AreEqual(port, siteConfig.Port);
}
}
public static void ConfirmString(XmlElement xmlElem,
string name, string str, bool compulsory)
{
XmlNode xmlNode;
if (str != null)
{
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
else if (xmlNode != null)
{
if (xmlNode.HasChildNodes)
Assert.AreEqual(
xmlNode.FirstChild.InnerText, str);
}
}
}
public static void ConfirmStringList(XmlElement xmlElem,
string name, List<string> strings, bool compulsory)
{
XmlNode xmlNode;
if (strings != null)
{
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
else if (xmlNode != null)
{
if (xmlNode.HasChildNodes)
{
XmlNodeList list = xmlNode.ChildNodes;
for (int i = 0; i < xmlNode.ChildNodes.Count;i++)
Assert.IsTrue(
strings.Contains(list[i].InnerText));
}
}
}
}
public static void ConfirmUint(XmlElement xmlElem,
string name, uint value, bool compulsory)
{
XmlNode xmlNode;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
else if (xmlNode != null)
Assert.AreEqual(uint.Parse(xmlNode.InnerText), value);
}
public static void ConfirmVerboseMessages(
XmlElement xmlElem, string name,
VerboseMessages verbose, bool compulsory)
{
XmlNode xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
else if (xmlNode != null)
{
ConfirmBool((XmlElement)xmlNode, "AllFileOps",
verbose.AllFileOps, compulsory);
ConfirmBool((XmlElement)xmlNode, "Deadlock",
verbose.Deadlock, compulsory);
ConfirmBool((XmlElement)xmlNode, "FileOps",
verbose.FileOps, compulsory);
ConfirmBool((XmlElement)xmlNode, "Recovery",
verbose.Recovery, compulsory);
ConfirmBool((XmlElement)xmlNode, "Register",
verbose.Register, compulsory);
ConfirmBool((XmlElement)xmlNode, "Replication",
verbose.Replication, compulsory);
ConfirmBool((XmlElement)xmlNode, "ReplicationElection",
verbose.ReplicationElection, compulsory);
ConfirmBool((XmlElement)xmlNode, "ReplicationLease",
verbose.ReplicationLease, compulsory);
ConfirmBool((XmlElement)xmlNode, "ReplicationMessages",
verbose.ReplicationMessages, compulsory);
ConfirmBool((XmlElement)xmlNode, "ReplicationMisc",
verbose.ReplicationMisc, compulsory);
ConfirmBool((XmlElement)xmlNode, "ReplicationSync",
verbose.ReplicationSync, compulsory);
ConfirmBool((XmlElement)xmlNode, "RepMgrConnectionFailure",
verbose.RepMgrConnectionFailure, compulsory);
ConfirmBool((XmlElement)xmlNode, "RepMgrMisc",
verbose.RepMgrMisc, compulsory);
ConfirmBool((XmlElement)xmlNode,"WaitsForTable",
verbose.WaitsForTable, compulsory);
}
}
#endregion Confirm
public static void dbtFromString(DatabaseEntry dbt, string s)
{
dbt.Data = System.Text.Encoding.ASCII.GetBytes(s);
}
public static string strFromDBT(DatabaseEntry dbt)
{
System.Text.ASCIIEncoding decode = new ASCIIEncoding();
return decode.GetString(dbt.Data);
}
/*
* Reading params successfully returns true. Unless returns
* false. The retrieved Xml fragment is returning in xmlElem.
*/
public static XmlElement TestSetUp(string testFixtureName, string testName)
{
XMLReader xmlReader = new XMLReader("../../AllTestData.xml");
XmlElement xmlElem = xmlReader.GetXmlElement(testFixtureName, testName);
if (xmlElem == null)
throw new ConfigNotFoundException(testFixtureName + ":" + testName);
else
return xmlElem;
}
/*
* Delete existing test output directory and its files,
* then create a new one.
*/
public static void ClearDir(string testDir)
{
if (Directory.Exists(testDir))
Directory.Delete(testDir, true);
Directory.CreateDirectory(testDir);
}
public static string RandomString(int max) {
string text = "";
int len = random.Next(max);
for (int i = 0; i < len; i++)
text += "a";
return text;
}
}
}
|