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.Xml; 13using NUnit.Framework; 14using BerkeleyDB; 15 16namespace CsharpAPITest 17{ 18 [TestFixture] 19 public class LockingConfigTest 20 { 21 private string testFixtureHome; 22 private string testFixtureName; 23 private string testName; 24 private string testHome; 25 26 [TestFixtureSetUp] 27 public void RunBeforeTests() 28 { 29 testFixtureName = "LockingConfigTest"; 30 testFixtureHome = "./TestOut/" + testFixtureName; 31 32 Configuration.ClearDir(testFixtureHome); 33 } 34 35 [Test] 36 public void TestConfig() 37 { 38 testName = "TestConfig"; 39 40 // Configure the fields/properties. 41 LockingConfig lockingConfig = new LockingConfig(); 42 XmlElement xmlElem = Configuration.TestSetUp( 43 testFixtureName, testName); 44 45 // Configure LockingConfig 46 Config(xmlElem, ref lockingConfig, true); 47 48 // Confirm LockingConfig 49 Confirm(xmlElem, lockingConfig, true); 50 } 51 52 [Test] 53 public void TestMaxLock() { 54 testName = "TestMaxLock"; 55 testHome = testFixtureHome + "/" + testName; 56 Configuration.ClearDir(testHome); 57 58 DatabaseEnvironment env; 59 uint maxLocks; 60 DatabaseEntry obj; 61 62 maxLocks = 1; 63 obj = new DatabaseEntry(); 64 65 /* 66 * Initialize environment using locking subsystem. The max number 67 * of locks should be larger than environment's partitions. So in 68 * order to make the MaxLock work, the environment paritition is 69 * set to be the same value as MaxLock. 70 */ 71 LockTest.LockingEnvSetUp(testHome, testName, out env, 72 maxLocks, 0, 0, maxLocks); 73 Assert.AreEqual(maxLocks, env.MaxLocks); 74 75 env.Close(); 76 } 77 78 [Test] 79 public void TestMaxLocker() { 80 testName = "TestMaxLocker"; 81 testHome = testFixtureHome + "/" + testName; 82 Configuration.ClearDir(testHome); 83 84 DatabaseEnvironment env; 85 uint maxLockers; 86 87 maxLockers = 1; 88 LockTest.LockingEnvSetUp(testHome, testName, out env, 89 0, maxLockers, 0, 0); 90 Assert.AreEqual(maxLockers, env.MaxLockers); 91 env.Close(); 92 } 93 94 [Test] 95 public void TestMaxObjects() { 96 testName = "TestMaxObjects"; 97 testHome = testFixtureHome + "/" + testName; 98 Configuration.ClearDir(testHome); 99 100 DatabaseEnvironment env; 101 uint maxObjects; 102 103 maxObjects = 1; 104 105 /* 106 * Initialize environment using locking subsystem. The max number 107 * of objects should be larger than environment's partitions. So 108 * in order to make the MaxObject work, the environment paritition 109 * is set to be the same value as MaxObject. 110 */ 111 LockTest.LockingEnvSetUp(testHome, testName, out env, 0, 0, 112 maxObjects, maxObjects); 113 Assert.AreEqual(maxObjects, env.MaxObjects); 114 env.Close(); 115 } 116 117 public static void Confirm(XmlElement xmlElement, 118 LockingConfig lockingConfig, bool compulsory) 119 { 120 Configuration.ConfirmByteMatrix(xmlElement, "Conflicts", 121 lockingConfig.Conflicts, compulsory); 122 Configuration.ConfirmDeadlockPolicy(xmlElement, 123 "DeadlockResolution", 124 lockingConfig.DeadlockResolution, compulsory); 125 Configuration.ConfirmUint(xmlElement, "MaxLockers", 126 lockingConfig.MaxLockers, compulsory); 127 Configuration.ConfirmUint(xmlElement, "MaxLocks", 128 lockingConfig.MaxLocks, compulsory); 129 Configuration.ConfirmUint(xmlElement, "MaxObjects", 130 lockingConfig.MaxObjects, compulsory); 131 Configuration.ConfirmUint(xmlElement, "Partitions", 132 lockingConfig.Partitions, compulsory); 133 } 134 135 public static void Config(XmlElement xmlElement, 136 ref LockingConfig lockingConfig, bool compulsory) 137 { 138 byte[,] matrix = new byte[6, 6]; 139 uint value = new uint(); 140 141 if (Configuration.ConfigByteMatrix(xmlElement, "Conflicts", 142 ref matrix, compulsory) == true) 143 lockingConfig.Conflicts = matrix; 144 145 Configuration.ConfigDeadlockPolicy(xmlElement, "DeadlockResolution", 146 ref lockingConfig.DeadlockResolution, compulsory); 147 if (Configuration.ConfigUint(xmlElement, "MaxLockers", 148 ref value, compulsory)) 149 lockingConfig.MaxLockers = value; 150 if (Configuration.ConfigUint(xmlElement, "MaxLocks", 151 ref value, compulsory)) 152 lockingConfig.MaxLocks = value; 153 if (Configuration.ConfigUint(xmlElement, "MaxObjects", 154 ref value, compulsory)) 155 lockingConfig.MaxObjects = value; 156 if (Configuration.ConfigUint(xmlElement, "Partitions", 157 ref value, compulsory)) 158 lockingConfig.Partitions = value; 159 } 160 161 } 162} 163