コード例 #1
0
        public static List <string> ReadClientNames(XmlNode node, bool global)
        {
            List <string>             clientNames = new List <string>();
            Dictionary <string, bool> excludeList = new Dictionary <string, bool>();

            if (node != null)
            {
                XmlNodeList            clientSetNodes = node.SelectNodes(ClientSetNodeName);
                XmlAttributeCollection xmlAttribs;
                if (clientSetNodes != null)
                {
                    foreach (XmlNode clientSetNode in clientSetNodes)
                    {
                        List <string> clientSetNames = new List <string>();
                        bool          exclude        = false;
                        string        clientSetName  = null;
                        string        hostGroupName  = string.Empty;
                        int           clientCount    = 1;
                        int           beginIndx      = 1;

                        xmlAttribs = clientSetNode.Attributes;
                        if (xmlAttribs != null)
                        {
                            foreach (XmlAttribute xmlAttrib in xmlAttribs)
                            {
                                switch (xmlAttrib.Name)
                                {
                                case NameAttrib:
                                    clientSetName = xmlAttrib.Value;
                                    break;

                                case ExcludeAttrib:
                                    exclude = XmlNodeReaderWriter.String2Bool(xmlAttrib.Value, false);
                                    break;

                                case CountAttrib:
                                    clientCount = XmlNodeReaderWriter.String2Int(xmlAttrib.Value, 1);
                                    break;

                                case BeginAttrib:
                                    beginIndx = XmlNodeReaderWriter.String2Int(xmlAttrib.Value, 1);
                                    break;

                                case HostGroupAttrib:
                                    hostGroupName = xmlAttrib.Value;
                                    break;

                                default:
                                    throw new IllegalArgException("Unknown attribute '" +
                                                                  xmlAttrib.Name + "' found in '" + ClientSetNodeName +
                                                                  "' node.");
                                }
                            }
                        }
                        XmlNodeList clientNodeList = clientSetNode.SelectNodes(ClientNodeName);
                        if (clientNodeList != null && clientNodeList.Count > 0)
                        {
                            foreach (XmlNode clientNode in clientNodeList)
                            {
                                string clientName = string.Empty;
                                xmlAttribs = clientNode.Attributes;
                                if (xmlAttribs != null)
                                {
                                    foreach (XmlAttribute xmlAttrib in xmlAttribs)
                                    {
                                        if (xmlAttrib.Name == NameAttrib)
                                        {
                                            clientName = xmlAttrib.Value;
                                        }
                                        else
                                        {
                                            throw new IllegalArgException("Unknown attribute '" +
                                                                          xmlAttrib.Name + "' found in '" + ClientNodeName +
                                                                          "' node.");
                                        }
                                    }
                                }
                                if (exclude)
                                {
                                    excludeList[clientSetName + '.' + clientName] = true;
                                }
                                else
                                {
                                    clientSetNames.Add(clientSetName + '.' + clientName);
                                }
                            }
                        }
                        else
                        {
                            for (int i = beginIndx; i < beginIndx + clientCount; i++)
                            {
                                if (exclude)
                                {
                                    excludeList[clientSetName + '.' + i.ToString()] = true;
                                }
                                else
                                {
                                    clientSetNames.Add(clientSetName + '.' + i.ToString());
                                }
                            }
                        }
                        if (global)
                        {
                            foreach (string name in clientSetNames)
                            {
                                GlobalHostGroups.Add(name, hostGroupName);
                            }
                        }
                        clientNames.AddRange(clientSetNames);
                    }
                }
                if (clientNames.Count == 0)
                {
                    lock (((ICollection)GlobalClients).SyncRoot)
                    {
                        foreach (string clientName in GlobalClients.Keys)
                        {
                            if (!excludeList.ContainsKey(clientName))
                            {
                                clientNames.Add(clientName);
                            }
                        }
                    }
                }
                else if (excludeList.Count > 0)
                {
                    int i = 0;
                    foreach (string clientName in clientNames)
                    {
                        if (excludeList.ContainsKey(clientName))
                        {
                            clientNames.RemoveAt(i);
                        }
                        i++;
                    }
                }
            }
            return(clientNames);
        }
コード例 #2
0
 /// <summary>
 /// Read the value of an object as time in seconds from the server
 /// for the given key.
 /// </summary>
 /// <remarks>
 /// If the value contains 'h' or 'm' then it is assumed to be in
 /// hours and minutes respectively.
 /// </remarks>
 /// <param name="key">The key of the value to read.</param>
 /// <returns>
 /// The integer value with the given key; -1 if not found.
 /// </returns>
 public int GetTimeValue(string key)
 {
     return(XmlNodeReaderWriter.String2Seconds(GetStringValue(key), -1));
 }
コード例 #3
0
ファイル: FwkTask.cs プロジェクト: s0/geode-native
        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
        }