Пример #1
1
 private static void GetEngine(String host, HashTree testTree)
 {
     List<IRemoteEngine> engineList = new List<IRemoteEngine>();
     IRemoteEngine engine = null;
     foreach (String client in host.Split(','))
     {
         NetTcpBinding clientBinding = new NetTcpBinding();
         EndpointAddress clientEndpoint = new EndpointAddress(host);
         EngineChannelFactory = new ChannelFactory<IRemoteEngine>(clientBinding, clientEndpoint);
         try
         {
             engine = EngineChannelFactory.CreateChannel();
             activeClientEngines.Add(engine);
         }
         catch (Exception ex)
         {
             log.Warn(ex.Message);
             System.Console.WriteLine(ex.Message);
             if (engine != null)
             {
                 failedClientEngines.Add(engine);
             }
         }
     }
 }
Пример #2
0
 public void addNode(Object node, HashTree subTree)
 {
     if (typeof(TestElement).IsAssignableFrom(node.GetType()) && !typeof(TestPlan).IsAssignableFrom(node.GetType()))
     {
         ((TestElement) node).SetRunningVersion(true);
     }
 }
Пример #3
0
 /// <summary>
 /// 对当前候选集中的项集求support counting
 /// </summary>
 /// <param name="candidate">候选项集</param>
 /// <param name="depth">当前的候选项集的项的个数</param>
 /// <returns>返回support counting大于等于minsup的项集</returns>
 static Candidates<int> DoSupportCounting(Candidates<int> candidate, int depth)
 {
     //建立hash树
     HashTree<int> tree = new HashTree<int>(HashCode, 0, 2, depth, NodePrint);
     foreach (var tmp in candidate.ItemSets)
     {
         tree.AddNode(tmp);
     }
     //计算候选集中的support counting
     foreach (var tmp in transactions)
     {
         tree.ClearTag(tree.Root);
         tree.SupportCounting(tmp, tree.Root, -1);
     }
     //将support counting大于minsup的加入频繁项的集合
     Candidates<int> tmpCandi = new Candidates<int>();
     tree.ClearTag(tree.Root);
     TreeNode<int> node = tree.GetLeaves(tree.Root);
     while (node != null)
     {
         foreach (var d in node.list)
         {
             if (d.value >= minsup * transactions.Count()) tmpCandi.AddCandidate(d);
         }
         node = tree.GetLeaves(tree.Root);
     }
     return SortInTrie(tmpCandi);
 }
Пример #4
0
 public NetMeterThread(HashTree test, NetMeterThreadMonitor monitor, ListenerNotifier note)
 {
     this.monitor = monitor;
     threadVars = new NetMeterVariables();
     testTree = test;
     compiler = new TestCompiler(testTree);
     controller = (Controller) testTree.GetArray()[0];
     SearchByType<TestIterationListener> threadListenerSearcher = new SearchByType<TestIterationListener>();
     test.Traverse(threadListenerSearcher);
     testIterationStartListeners = threadListenerSearcher.GetSearchResults();
     notifier = note;
     running = true;
 }
Пример #5
0
        public void AddNode(Object node, HashTree subTree)
        {
            if(isRemote && typeof(ResultCollector).IsAssignableFrom(node.GetType()))
            {
                try
                {
                    replacer.ReplaceValues((TestElement) node);
                }
                catch (InvalidVariableException e)
                {
                    log.Error("invalid variables", e);
                }
            }
            if (isRemote) {
                return;
            }
            if(typeof(TestElement).IsAssignableFrom(node.GetType()))
            {
                try
                {
                    replacer.ReplaceValues((TestElement) node);
                }
                catch (Exception ex)
                {
                    log.Error("invalid variables", e);
                }
            }
            if (typeof(TestPlan).IsAssignableFrom(node.GetType()))
            {
                ((TestPlan)node).prepareForPreCompile(); //A hack to make user-defined variables in the testplan element more dynamic
                Dictionary<String, String> args = ((TestPlan) node).GetUserDefinedVariables();
                replacer.SetUserDefinedVariables(args);
                NetMeterVariables vars = new NetMeterVariables();
                vars.PutAll(args);
                NetMeterContextManager.GetContext().SetVariables(vars);
            }

            if (typeof(Arguments).IsAssignableFrom(node.GetType()))
            {
                ((Arguments)node).setRunningVersion(true);
                Dictionary<String, String> args = ((Arguments) node).GetArgumentsAsMap();
                replacer.AddVariables(args);
                NetMeterContextManager.GetContext().GetVariables().PutAll(args);
            }
        }
Пример #6
0
 public void Configure(HashTree testtree, String host)
 {
     log.Info("Creating NetMeterEngine on Host" + host);
     Monitor.Enter(LOCK);
     try
     {
         if (StandardEngine != null && StandardEngine.isActive())
         {
             log.Warn("Engine is busy - cannot create new NetMeterEngine");
             throw new Exception("Engine is busy");
         }
         ownerThread = Thread.CurrentThread;
         StandardEngine = new StandardEngine(host);
         StandardEngine.Configure(testtree);
     }
     finally
     {
         Monitor.Exit(LOCK);
     }
 }
Пример #7
0
        public Factory Register(Factory factory, Type serviceType, object serviceKey)
        {
            var implementationType = factory.ThrowIfNull().ImplementationType;
            if (implementationType != null && serviceType.ThrowIfNull() != typeof(object))
            {
                Throw.If(!implementationType.GetImplementedTypes().Contains(serviceType),
                    Error.EXPECTED_IMPL_TYPE_ASSIGNABLE_TO_SERVICE_TYPE, implementationType, serviceType);
            }

            lock (_syncRoot)
            {
                if (factory.Setup.Type == FactoryType.Decorator)
                {
                    _decorators = _decorators.AddOrUpdate(serviceType, new[] { new DecoratorsEntry(factory) }, Sugar.Append);
                    return factory;
                }

                var entry = _factories.GetOrAdd(serviceType, _ => new FactoriesEntry());
                if (serviceKey == null)
                {   // default factories will contain all the factories and LastDefault will just point to the latest,
                    // for memory saving reasons.
                    if (entry.LastDefaultFactory != null)
                        entry.DefaultFactories = (entry.DefaultFactories
                            ?? HashTree<int, Factory>.Empty.AddOrUpdate(entry.MaxDefaultIndex++, entry.LastDefaultFactory))
                            .AddOrUpdate(entry.MaxDefaultIndex++, factory);
                    entry.LastDefaultFactory = factory;
                }
                else if (serviceKey is int)
                {
                    var index = (int)serviceKey;
                    entry.DefaultFactories = (entry.DefaultFactories ?? HashTree<int, Factory>.Empty).AddOrUpdate(index, factory);
                    entry.MaxDefaultIndex = Math.Max(entry.MaxDefaultIndex, index) + 1;
                }
                else if (serviceKey is string)
                {
                    var name = (string)serviceKey;
                    var named = entry.NamedFactories = entry.NamedFactories ?? new Dictionary<string, Factory>();
                    if (named.ContainsKey(name))
                        Throw.If(true, Error.DUPLICATE_SERVICE_NAME, serviceType, name, named[name].ImplementationType);
                    named.Add(name, factory);
                }
            }

            return factory;
        }
Пример #8
0
        public Container(Action<IRegistry> setup = null)
        {
            _syncRoot = new object();
            _factories = new Dictionary<Type, FactoriesEntry>();
            _decorators = HashTree<Type, DecoratorsEntry[]>.Empty;
            _defaultResolutionCache = HashTree<Type, CompiledFactory>.Empty;
            _keyedResolutionCache = HashTree<Type, HashTree<object, CompiledFactory>>.Empty;

            _constants = new object[3];

            // Put reference to container into constants, to support container access inside expression.
            // It is common for dynamic scenarios.
            _constants[REGISTRY_WEAKREF_CONST_INDEX] = new WeakReference(this);
            _constants[CURRENT_SCOPE_CONST_INDEX] = _constants[SINGLETON_SCOPE_CONST_INDEX] = new Scope();

            ResolutionRules = new ResolutionRules();
            (setup ?? DefaultSetup).Invoke(this);
        }
Пример #9
0
 public void Configure(HashTree testTree)
 {
     // Is testplan serialised?
     SearchByType<TestPlan> testPlan = new SearchByType<TestPlan>();
     testTree.Traverse(testPlan);
     List<TestPlan> plan = testPlan.GetSearchResults();
     if (0 == plan.Count)
     {
         throw new Exception("Could not find the TestPlan class!");
     }
     TestPlan tp = (TestPlan) plan[0];
     serialized = tp.isSerialized();
     tearDownOnShutdown = tp.isTearDownOnShutdown();
     active = true;
     test = testTree;
 }
Пример #10
0
        // Creates child container with singleton scope, constants and cache shared with parent. BUT with new CurrentScope.
        private Container(Container parent)
        {
            ResolutionRules = parent.ResolutionRules;

            var parentConstants = parent._constants;
            _constants = new object[parentConstants.Length];
            Array.Copy(parentConstants, 0, _constants, 0, parentConstants.Length);
            _constants[REGISTRY_WEAKREF_CONST_INDEX] = new WeakReference(this);
            _constants[CURRENT_SCOPE_CONST_INDEX] = new Scope();

            _syncRoot = parent._syncRoot;
            _factories = parent._factories;
            _decorators = parent._decorators;
            _defaultResolutionCache = parent._defaultResolutionCache;
            _keyedResolutionCache = parent._keyedResolutionCache;
        }
Пример #11
0
 public ServerEngine(String host, HashTree testTree)
 {
     this.test = testTree;
     GetEngine(host, test);
     this.host = host;
 }
Пример #12
0
 public void AddNode(Object node, HashTree subTree)
 {
     if (node is ThreadListener)
     {
         ThreadListener tl = (ThreadListener) node;
         if (isStart)
         {
             tl.threadStarted();
         }
         else
         {
             tl.threadFinished();
         }
     }
 }
Пример #13
0
 public void Constructor2NullTest()
 {
     HashTree tree = new HashTree(null, 25);
 }
Пример #14
0
        public void DefaultConstructorTest()
        {
            HashTree tree = new HashTree();

            Assert.AreEqual(1024, tree.BlockSize);
        }
Пример #15
0
 public void Configure(HashTree testtree)
 {
 }
Пример #16
0
 public void Constructor1NullTest()
 {
     HashTree tree = new HashTree(null);
 }
Пример #17
0
 public ServerEngine(String host, HashTree testTree)
 {
     this.test = testTree;
     GetEngine(host, test);
     this.host = host;
 }
Пример #18
0
        /**
         * Refactored from AbstractAction.java
         *
         * @param tree
         */
        public static void ConvertSubTree(HashTree tree)
        {
            LinkedList <Object> copyList = new LinkedList <Object>(tree.list());

            foreach (Object obj  in copyList)
            {
                if (typeof(TestElement).IsAssignableFrom(obj.GetType()))
                {
                    TestElement item = (TestElement)obj;
                    if (item.isEnabled())
                    {
                        if (typeof(ReplaceableController).IsAssignableFrom(item.GetType()))
                        {
                            ReplaceableController rc;

                            // TODO this bit of code needs to be tidied up
                            // Unfortunately ModuleController is in components, not core
                            if (item.GetType().Name.Equals("org.apache.jmeter.control.ModuleController"))
                            { // Bug 47165
                                rc = (ReplaceableController)item;
                            }
                            else
                            {
                                // HACK: force the controller to load its tree
                                rc = (ReplaceableController)item.Clone();
                            }

                            HashTree subTree = tree.GetTree(item);
                            if (subTree != null)
                            {
                                HashTree replacementTree = rc.getReplacementSubTree();
                                if (replacementTree != null)
                                {
                                    ConvertSubTree(replacementTree);
                                    tree.Replace(item, rc);
                                    tree.Set(rc, replacementTree);
                                }
                            }
                            else
                            { // null subTree
                                ConvertSubTree(tree.GetTree(item));
                            }
                        }
                        else
                        { // not Replaceable Controller
                            ConvertSubTree(tree.GetTree(item));
                        }
                    }
                    else
                    { // Not enabled
                        tree.Remove(item);
                    }
                }
                else
                { // Not a TestElement
                    NetMeterTreeNode item = (NetMeterTreeNode)obj;
                    if (item.isEnabled())
                    {
                        // Replacement only needs to occur when starting the engine
                        // @see StandardJMeterEngine.run()
                        if (item.getUserObject() is ReplaceableController)
                        {
                            ReplaceableController rc = (ReplaceableController)item.getTestElement();
                            HashTree subTree         = tree.GetTree(item);

                            if (subTree != null)
                            {
                                HashTree replacementTree = rc.getReplacementSubTree();
                                if (replacementTree != null)
                                {
                                    ConvertSubTree(replacementTree);
                                    tree.Replace(item, rc);
                                    tree.Set(rc, replacementTree);
                                }
                            }
                        }
                        else
                        { // Not a ReplaceableController
                            ConvertSubTree(tree.GetTree(item));
                            TestElement testElement = item.getTestElement();
                            tree.Replace(item, testElement);
                        }
                    }
                    else
                    { // Not enabled
                        tree.Remove(item);
                    }
                }
            }
        }
Пример #19
0
        // run test in batch mode
        private void RunTest(String testFile, String logFile, Boolean remoteStart, String remote_hosts_string)
        {
            FileStream reader = null;

            try
            {
                if (!File.Exists(testFile))
                {
                    println("Could not open " + testFile);
                    return;
                }
                //FileServer.getFileServer().setBaseForScript(f);

                reader = new FileStream(testFile, FileMode.Open, FileAccess.Read, FileShare.Read);
                log.Info("Loading file: " + testFile);

                HashTree tree = IOService.loadTree(reader);

                // Deliberate use of deprecated ctor
                NetMeterTreeModel treeModel = new NetMeterTreeModel(new Object());// Create non-GUI version to avoid headless problems
                NetMeterTreeNode  root      = (NetMeterTreeNode)treeModel.getRoot();
                treeModel.addSubTree(tree, root);

                // Hack to resolve ModuleControllers in non GUI mode
                SearchByType <ReplaceableController> replaceableControllers = new SearchByType <ReplaceableController>();
                tree.Traverse(replaceableControllers);
                List <ReplaceableController> replaceableControllersRes = replaceableControllers.GetSearchResults();

                foreach (ReplaceableController controller in replaceableControllersRes)
                {
                    controller.resolveReplacementSubTree(root);
                }

                // Remove the disabled items
                // For GUI runs this is done in Start.java
                ConvertSubTree(tree);

                ResultCollector summer         = null;
                String          summariserName = "Summariser";//$NON-NLS-1$
                log.Info("Creating summariser <" + summariserName + ">");
                println("Creating summariser <" + summariserName + ">");
                summer = new ResultCollector(summariserName);

                if (logFile != null)
                {
                    ResultCollector logger = new ResultCollector(summer);
                    logger.setFilename(logFile);
                    tree.Add(tree.GetArray()[0], logger);
                }
                else
                {
                    // only add Summariser if it can not be shared with the ResultCollector
                    if (summer != null)
                    {
                        tree.Add(tree.GetArray()[0], summer);
                    }
                }

                LinkedList <NetMeterEngine> engines = new LinkedList <NetMeterEngine>();
                tree.Put(tree.GetArray()[0], new ListenToTest(parent, (remoteStart && remoteStop) ? engines : null));
                println("Created the tree successfully using " + testFile);
                if (!remoteStart)
                {
                    NetMeterEngine engine = new StandardEngine();
                    engine.Configure(tree);
                    Int64 now = DateTime.Now.Ticks;
                    println("Starting the test @ " + DateTime.Now.ToString() + " (" + now + ")");
                    engine.RunTest();
                    engines.AddLast(engine);
                }
                //else
                //{
                //    java.util.StringTokenizer st = new java.util.StringTokenizer(remote_hosts_string, ",");//$NON-NLS-1$
                //    List<String> failingEngines = new ArrayList<String>(st.countTokens());
                //    while (st.hasMoreElements())
                //    {
                //        String el = (String) st.nextElement();
                //        println("Configuring remote engine for " + el);
                //        log.info("Configuring remote engine for " + el);
                //        JMeterEngine eng = doRemoteInit(el.trim(), tree);
                //        if (null != eng)
                //        {
                //            engines.add(eng);
                //        }
                //        else
                //        {
                //            failingEngines.add(el);
                //            println("Failed to configure "+el);
                //        }
                //    }
                //    if (engines.isEmpty())
                //    {
                //        println("No remote engines were started.");
                //        return;
                //    }
                //    if(failingEngines.size()>0) {
                //        throw new IllegalArgumentException("The following remote engines could not be configured:"+failingEngines);
                //    }
                //    println("Starting remote engines");
                //    log.Info("Starting remote engines");
                //    long now = System.currentTimeMillis();
                //    println("Starting the test @ "+new Date(now)+" ("+now+")");
                //    foreach (NetMeterEngine engine in engines)
                //    {
                //        engine.runTest();
                //    }
                //    println("Remote engines have been started");
                //    log.Info("Remote engines have been started");
                //}
                StartUdpDdaemon(engines);
            }
            catch (Exception e)
            {
                System.Console.WriteLine("Error in NonGUIDriver " + e.Message);
                log.Error("Error in NonGUIDriver", e);
            }
            finally
            {
                reader.Close();
            }
        }
Пример #20
0
 public Apriori(HashTree tree)
 {
     _tree = tree;
 }
Пример #21
0
 public TestCompiler(HashTree testTree)
 {
     this.testTree = testTree;
 }
Пример #22
0
        public void TigerTreeVectorTest(byte[] input, byte[] expectedOutput)
        {
            HashTree tree = new HashTree(new Tiger(TigerParameters.GetParameters(TigerStandard.Tiger192BitVersion1)), 1024);

            CustomAssert.AreEqual(expectedOutput, tree.ComputeHash(input));
        }
Пример #23
0
 /** {@inheritDoc} */
 public void AddNode(Object node, HashTree subTree)
 {
     stack.AddLast((TestElement) node);
 }
Пример #24
0
        public void Constructor1Test()
        {
            HashTree tree = new HashTree(new MD5());

            Assert.AreEqual(1024, tree.BlockSize);
        }
Пример #25
0
 public void Configure(HashTree testtree)
 {
 }
Пример #26
0
        public void Constructor2Test()
        {
            HashTree tree = new HashTree(new MD5(), 25);

            Assert.AreEqual(25, tree.BlockSize);
        }
Пример #27
0
        /**
         * Refactored from AbstractAction.java
         *
         * @param tree
         */
        public static void ConvertSubTree(HashTree tree)
        {
            LinkedList<Object> copyList = new LinkedList<Object>(tree.list());
            foreach (Object obj  in copyList)
            {
                if (typeof(TestElement).IsAssignableFrom(obj.GetType()))
                {
                    TestElement item = (TestElement) obj;
                    if (item.isEnabled())
                    {
                        if (typeof(ReplaceableController).IsAssignableFrom(item.GetType()))
                        {
                            ReplaceableController rc;

                            // TODO this bit of code needs to be tidied up
                            // Unfortunately ModuleController is in components, not core
                            if (item.GetType().Name.Equals("org.apache.jmeter.control.ModuleController"))
                            { // Bug 47165
                                rc = (ReplaceableController) item;
                            }
                            else
                            {
                                // HACK: force the controller to load its tree
                                rc = (ReplaceableController) item.Clone();
                            }

                            HashTree subTree = tree.GetTree(item);
                            if (subTree != null)
                            {
                                HashTree replacementTree = rc.getReplacementSubTree();
                                if (replacementTree != null)
                                {
                                    ConvertSubTree(replacementTree);
                                    tree.Replace(item, rc);
                                    tree.Set(rc, replacementTree);
                                }
                            }
                            else
                            { // null subTree
                                ConvertSubTree(tree.GetTree(item));
                            }
                        }
                        else
                        { // not Replaceable Controller
                            ConvertSubTree(tree.GetTree(item));
                        }
                    }
                    else
                    { // Not enabled
                        tree.Remove(item);
                    }
                }
                else
                { // Not a TestElement
                    NetMeterTreeNode item = (NetMeterTreeNode) obj;
                    if (item.isEnabled())
                    {
                        // Replacement only needs to occur when starting the engine
                        // @see StandardJMeterEngine.run()
                        if (item.getUserObject() is ReplaceableController)
                        {
                            ReplaceableController rc = (ReplaceableController) item.getTestElement();
                            HashTree subTree = tree.GetTree(item);

                            if (subTree != null)
                            {
                                HashTree replacementTree = rc.getReplacementSubTree();
                                if (replacementTree != null)
                                {
                                    ConvertSubTree(replacementTree);
                                    tree.Replace(item, rc);
                                    tree.Set(rc, replacementTree);
                                }
                            }
                        }
                        else
                        { // Not a ReplaceableController
                            ConvertSubTree(tree.GetTree(item));
                            TestElement testElement = item.getTestElement();
                            tree.Replace(item, testElement);
                        }
                     }
                    else
                    { // Not enabled
                        tree.Remove(item);
                    }
                }
            }
        }
Пример #28
0
        public void Compute_Unbalanced_Sha256d()
        {
            var hasher = SHA256.Create();
            var nodes  = new byte[][]
            {
                /* A */ hasher.ComputeHash(Encoding.UTF8.GetBytes("La ciudad y los perros")),
                /* B */ hasher.ComputeHash(Encoding.UTF8.GetBytes("La Casa Verde")),
                /* C */ hasher.ComputeHash(Encoding.UTF8.GetBytes("Conversación en La Catedral")),
                /* D */ hasher.ComputeHash(Encoding.UTF8.GetBytes("Pantaleón y las visitadoras")),
                /* E */ hasher.ComputeHash(Encoding.UTF8.GetBytes("La tía Julia y el Escribidor"))
            };

            // Manual computing
            // levels = 3;   ceil(log2(5))

            // 4th level, 5 nodes, need balance: rigth (3)
            var hashA    = hasher.ComputeHash(hasher.ComputeHash(nodes[0]));
            var hashB    = hasher.ComputeHash(hasher.ComputeHash(nodes[1]));
            var hashC    = hasher.ComputeHash(hasher.ComputeHash(nodes[2]));
            var hashD    = hasher.ComputeHash(hasher.ComputeHash(nodes[3]));
            var hashE    = hasher.ComputeHash(hasher.ComputeHash(nodes[4]));
            var hashX4   = hasher.ComputeHash(hasher.ComputeHash(hashA)); // balance
            var hashA_B  = TestUtils.Concat(hashA, hashB);
            var hashC_D  = TestUtils.Concat(hashC, hashD);
            var hashE_X4 = TestUtils.Concat(hashE, hashX4);

            // 3th level, 3 nodes, need balance: left (2)
            hashA_B  = hasher.ComputeHash(hasher.ComputeHash(hashA_B));
            hashC_D  = hasher.ComputeHash(hasher.ComputeHash(hashC_D));
            hashE_X4 = hasher.ComputeHash(hasher.ComputeHash(hashE_X4));
            var hashX3       = hasher.ComputeHash(hasher.ComputeHash(hashE_X4)); // balance
            var hashX3_A_B   = TestUtils.Concat(hashX3, hashA_B);
            var hashC_D_E_X4 = TestUtils.Concat(hashC_D, hashE_X4);

            // 2nd level, 2 nodes, without balance
            hashX3_A_B   = hasher.ComputeHash(hasher.ComputeHash(hashX3_A_B));
            hashC_D_E_X4 = hasher.ComputeHash(hasher.ComputeHash(hashC_D_E_X4));
            var hashROOT = TestUtils.Concat(hashX3_A_B, hashC_D_E_X4);

            // 1st level, 1 node, only hash
            hashROOT = hasher.ComputeHash(hasher.ComputeHash(hashROOT));

            // Computing map:
            //                         ROOT
            //               +-----------+-----------+
            //             X3_A_B                C_D_E_X4
            //         +-----+-----+           +-----+-----+
            //   (X3) E_X4'       A_B         C_D         E_X4
            //                  +--+--+     +--+--+     +--+--+
            //                  A     B     C     D     E     A' (X4)

            var tree = new HashTree();

            tree.HashRecipe.Add(CryptoHashName.Sha256);
            tree.HashRecipe.Add(CryptoHashName.Sha256);
            tree.Nodes.AddRange(nodes);
            tree.ComputeRoot();

            Assert.IsTrue(TestUtils.AreEqual(hashROOT, tree.Root));
            System.Diagnostics.Debug.WriteLine("Time: {0}ms", tree.LastComputeEllapsed);
        }
Пример #29
0
 public new void Set(Object key, HashTree t)
 {
     if (!Data.ContainsKey(key))
     {
         order.Add(key);
     }
     base.Set(key, t);
 }