Ejemplo n.º 1
0
        public virtual void TestSelection()
        {
            ConfigExtractor extractor = GetTestConfig(false);
            WeightSelector  selector  = new WeightSelector(extractor, rnd);
            // should be 1 of each type - uniform
            int                  expected = Constants.OperationType.Values().Length;
            Operation            op       = null;
            ICollection <string> types    = new HashSet <string>();
            FileSystem           fs       = FileSystem.Get(extractor.GetConfig());

            while (true)
            {
                op = selector.Select(1, 1);
                if (op == null)
                {
                    break;
                }
                // doesn't matter if they work or not
                op.Run(fs);
                types.AddItem(op.GetType());
            }
            NUnit.Framework.Assert.AreEqual(types.Count, expected);
        }
Ejemplo n.º 2
0
        /*
         * (non-Javadoc)
         *
         * @see org.apache.hadoop.mapred.Mapper#map(java.lang.Object,
         * java.lang.Object, org.apache.hadoop.mapred.OutputCollector,
         * org.apache.hadoop.mapred.Reporter)
         */
        /// <exception cref="System.IO.IOException"/>
        public virtual void Map(object key, object value, OutputCollector <Text, Text> output
                                , Reporter reporter)
        {
            // Mapper
            LogAndSetStatus(reporter, "Running slive mapper for dummy key " + key + " and dummy value "
                            + value);
            //Add taskID to randomSeed to deterministically seed rnd.
            Random rnd = config.GetRandomSeed() != null ? new Random(this.taskId + config.GetRandomSeed
                                                                         ()) : new Random();
            WeightSelector selector   = new WeightSelector(config, rnd);
            long           startTime  = Timer.Now();
            long           opAm       = 0;
            long           sleepOps   = 0;
            int            duration   = GetConfig().GetDurationMilliseconds();
            Range <long>   sleepRange = GetConfig().GetSleepRange();
            Operation      sleeper    = null;

            if (sleepRange != null)
            {
                sleeper = new SleepOp(GetConfig(), rnd);
            }
            while (Timer.Elapsed(startTime) < duration)
            {
                try
                {
                    LogAndSetStatus(reporter, "Attempting to select operation #" + (opAm + 1));
                    int       currElapsed = (int)(Timer.Elapsed(startTime));
                    Operation op          = selector.Select(currElapsed, duration);
                    if (op == null)
                    {
                        // no ops left
                        break;
                    }
                    else
                    {
                        // got a good op
                        ++opAm;
                        RunOperation(op, reporter, output, opAm);
                    }
                    // do a sleep??
                    if (sleeper != null)
                    {
                        // these don't count against the number of operations
                        ++sleepOps;
                        RunOperation(sleeper, reporter, output, sleepOps);
                    }
                }
                catch (Exception e)
                {
                    LogAndSetStatus(reporter, "Failed at running due to " + StringUtils.StringifyException
                                        (e));
                    if (GetConfig().ShouldExitOnFirstError())
                    {
                        break;
                    }
                }
            }
            {
                // write out any accumulated mapper stats
                long            timeTaken = Timer.Elapsed(startTime);
                OperationOutput opCount   = new OperationOutput(OperationOutput.OutputType.Long, OpType
                                                                , ReportWriter.OpCount, opAm);
                output.Collect(opCount.GetKey(), opCount.GetOutputValue());
                OperationOutput overallTime = new OperationOutput(OperationOutput.OutputType.Long
                                                                  , OpType, ReportWriter.OkTimeTaken, timeTaken);
                output.Collect(overallTime.GetKey(), overallTime.GetOutputValue());
                LogAndSetStatus(reporter, "Finished " + opAm + " operations in " + timeTaken + " milliseconds"
                                );
            }
        }