public void AddClients(params ClientBase[] clients) { m_clientGroup.Add(clients); }
public FwkTask(XmlNode node, string testName, UnitFnMethod <FwkTask, ClientBase> taskStartedHandler, UnitFnMethod <FwkTask, ClientBase, Exception> taskDoneHandler) { if (node == null) { throw new IllegalArgException("Null node for FwkTask constructor."); } #region Read the attributes string taskName = string.Empty; string containerStr = null; string methodName = null; string typeAttrib = null; m_timesToRun = 1; m_threadCount = 1; m_parallel = false; m_timeoutMillis = DefaultTimeoutMillis; m_continueOnError = false; m_class = null; XmlAttributeCollection xmlAttribs = node.Attributes; if (xmlAttribs != null) { foreach (XmlAttribute xmlAttrib in xmlAttribs) { switch (xmlAttrib.Name) { case NameAttrib: taskName = xmlAttrib.Value; break; case ArgTypes: typeAttrib = xmlAttrib.Value; break; case ContainerAttrib: containerStr = xmlAttrib.Value; break; case MethodAttrib: methodName = xmlAttrib.Value; break; case TimesToRunAttrib: m_timesToRun = XmlNodeReaderWriter.String2Int(xmlAttrib.Value, 1); break; case ThreadCountAttrib: m_threadCount = XmlNodeReaderWriter.String2Int(xmlAttrib.Value, 1); break; case ParallelAttrib: m_parallel = XmlNodeReaderWriter.String2Bool(xmlAttrib.Value, false); break; case WaitTimeAttrib: m_timeoutMillis = XmlNodeReaderWriter.String2Seconds(xmlAttrib.Value, DefaultTimeoutMillis) * 1000; break; case ContinueAttrib: m_continueOnError = XmlNodeReaderWriter.String2Bool(xmlAttrib.Value, false); break; case ClassAttrib: m_class = xmlAttrib.Value; break; default: throw new IllegalArgException("Unknown attribute '" + xmlAttrib.Name + "' found in '" + node.Name + "' node."); } } } int taskNum = 1; if (m_GlobalTaskNames.ContainsKey(taskName)) { taskNum = m_GlobalTaskNames[taskName] + 1; } m_GlobalTaskNames[taskName] = taskNum; taskName += '_' + taskNum.ToString(); #endregion m_timeBomb = new TimeBomb(); m_timeBomb.TaskName = testName + '.' + taskName; #region Create a delegate by loading the assembly Assembly loadAssmb = null; string typeName = null; if (containerStr != null && methodName != null) { object inst = null; int dotIndx; if ((dotIndx = containerStr.IndexOf('.')) < 0) { Type myType = this.GetType(); loadAssmb = myType.Assembly; typeName = myType.Namespace + '.' + containerStr; Util.Log(Util.LogLevel.Info, "Assembly {0} loaded and typename is {1}", loadAssmb, typeName); } else { string assmbName = containerStr.Substring(0, dotIndx); if (!m_AssemblyMap.TryGetValue(assmbName, out loadAssmb)) { try { loadAssmb = Assembly.Load(assmbName); Util.Log(Util.LogLevel.Info, "Assembly {0} loaded ", assmbName); } catch (Exception e) { throw new IllegalArgException("Cannot load assembly '" + assmbName + "' for task: " + m_timeBomb.TaskName + " exception: " + e); } m_AssemblyMap.Add(assmbName, loadAssmb); } typeName = containerStr.Substring(dotIndx + 1); } //string typeAttrib; if (loadAssmb != null) { if (typeAttrib == null) { inst = loadAssmb.CreateInstance(typeName, true); } else { //typeAttrib = "Apache.Geode.Client.Tests.ArrayOfByte,Apache.Geode.Client.Tests.ArrayOfByte"; //typeAttrib = "System.int,System.Int32"; string[] typeNames = typeAttrib.Split(','); string mangledName = typeName + "`" + typeNames.Length.ToString(); //Type type = loadAssmb.GetType(mangledName, true, true); Type[] types = new Type[typeNames.Length]; for (int index = 0; index < typeNames.Length; ++index) { string typName = typeNames[index].Trim(); if (typName == "int" || typName == "Int32" || typName == "string" || typName == "String" || typName == "byte[]" || typName == "Byte[]" || typName == "string[]" || typName == "String[]" || typName == "Object" || typName == "object") { if (typName.Equals("int")) { typName = "Int32"; } else if (typName.Equals("string")) { typName = "String"; } else if (typName.Equals("string[]")) { typName = "String[]"; } else if (typName.Equals("byte[]")) { typName = "Byte[]"; } else if (typName.Equals("object")) { typName = "Object"; } typName = "System." + typName; //Util.Log("rjk: FwkTask: typeAttrib 33 argname {0}", typName); types[index] = Type.GetType(typName.Trim()); //Util.Log("rjk: FwkTask: typeAttrib 34 argname {0}", typName); } else { typName = "Apache.Geode.Client.Tests." + typName; types[index] = loadAssmb.GetType(typName.Trim(), true, true); //Util.Log("rjk: FwkTask: typeAttrib for userobject 34 argname {0}", typName); } } Type type = loadAssmb.GetType(mangledName, true, true).MakeGenericType(types); inst = type.GetConstructor(System.Type.EmptyTypes).Invoke(null); } } if (inst != null) { try { MethodInfo mInfo = inst.GetType().GetMethod(methodName, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy | BindingFlags.Instance); m_delegate = Delegate.CreateDelegate(typeof(UnitFnMethod), inst, mInfo, true); } catch (Exception ex) { throw new IllegalArgException( "Exception while creating delegate [" + methodName + "]: " + ex); } m_pushTaskNameDelegate = Delegate.CreateDelegate( typeof(UnitFnMethod <string>), inst, PushTaskNameMethod, true); m_endDelegate = Delegate.CreateDelegate( typeof(UnitFnMethod), inst, EndTaskMethod, true); } } if (m_delegate == null) { throw new IllegalArgException("Cannot create delegate '" + methodName + "' for task: " + m_timeBomb.TaskName); } #endregion #region Add the clients m_clients = new List <string>(); m_clientGroup = new ClientGroup(false); m_clients = FwkClient.ReadClientNames(node, false); List <ClientBase> clients = FwkClient.GetClients(m_clients); m_clientGroup.Add(clients); m_timeBomb.AddClients(new ClientBase[] { m_clientGroup }); m_taskStartedHandler = taskStartedHandler; m_taskDoneHandler = taskDoneHandler; int clientCount = m_clients.Count; #endregion #region Add any data m_localDataNames = new List <string>(); Dictionary <string, FwkData> data = FwkData.ReadDataNodes(node); // Task specific data is written as <taskname>.<key> to avoid // overwriting the global data, since that needs to be preserved // across tasks. if (m_threadCount > 1) { // We shall treat 'threadCount' and 'numThreads' as equivalent, // i.e. if 'threadCount' is defined for a task then 'numThreads' // shall also be written as data. foreach (string threadKey in ThreadCountKeys) { m_localDataNames.Add(threadKey); Util.BBSet(Name, threadKey, new FwkData(m_threadCount.ToString(), null, DataKind.String)); } } if (clientCount > 0) { // Overwrite the clientCount (if any) with the actual value. Util.BBSet(Name, ClientCountKey, new FwkData(clientCount.ToString(), null, DataKind.String)); } foreach (KeyValuePair <string, FwkData> pair in data) { m_localDataNames.Add(pair.Key); Util.BBSet(Name, pair.Key, pair.Value); } #endregion }