예제 #1
0
        /// <summary>Test the most common use case.</summary>
        /// <remarks>
        /// Test the most common use case. Mark before start of the iteration and
        /// reset at the end to go over the entire list
        /// </remarks>
        /// <param name="key"/>
        /// <param name="values"/>
        /// <returns/>
        /// <exception cref="System.IO.IOException"/>
        private static int Test0(IntWritable key, MarkableIterator <IntWritable> values)
        {
            int                 errors = 0;
            IntWritable         i;
            AList <IntWritable> expectedValues = new AList <IntWritable>();

            Log.Info("Executing TEST:0 for Key:" + key.ToString());
            values.Mark();
            Log.Info("TEST:0. Marking");
            while (values.HasNext())
            {
                i = values.Next();
                expectedValues.AddItem(i);
                Log.Info(key + ":" + i);
            }
            values.Reset();
            Log.Info("TEST:0. Reset");
            int count = 0;

            while (values.HasNext())
            {
                i = values.Next();
                Log.Info(key + ":" + i);
                if (i != expectedValues[count])
                {
                    Log.Info("TEST:0. Check:1 Expected: " + expectedValues[count] + ", Got: " + i);
                    errors++;
                    return(errors);
                }
                count++;
            }
            Log.Info("TEST:0 Done");
            return(errors);
        }
예제 #2
0
        /// <summary>Test "clearMark"</summary>
        /// <param name="key"/>
        /// <param name="values"/>
        /// <returns/>
        /// <exception cref="System.IO.IOException"/>
        private static int Test3(IntWritable key, MarkableIterator <IntWritable> values)
        {
            int                 errors = 0;
            IntWritable         i;
            AList <IntWritable> expectedValues = new AList <IntWritable>();

            Log.Info("Executing TEST:3 for Key:" + key);
            values.Mark();
            Log.Info("TEST:3. Marking");
            int count = 0;

            while (values.HasNext())
            {
                i = values.Next();
                Log.Info(key + ":" + i);
                if (count == 5)
                {
                    Log.Info("TEST:3. Clearing Mark");
                    values.ClearMark();
                }
                if (count == 8)
                {
                    Log.Info("TEST:3. Marking -- " + key + ":" + i);
                    values.Mark();
                }
                if (count >= 8)
                {
                    expectedValues.AddItem(i);
                }
                count++;
            }
            values.Reset();
            Log.Info("TEST:3. After reset");
            if (!values.HasNext())
            {
                errors++;
                Log.Info("TEST:3, Check:1. HasNext returned false");
                return(errors);
            }
            count = 0;
            while (values.HasNext())
            {
                i = values.Next();
                Log.Info(key + ":" + i);
                if (count < expectedValues.Count)
                {
                    if (i != expectedValues[count])
                    {
                        errors++;
                        Log.Info("TEST:2. Check:1 Expected: " + expectedValues[count] + ", Got: " + i);
                        return(errors);
                    }
                }
                if (count == 10)
                {
                    values.ClearMark();
                    Log.Info("TEST:3. After clear mark");
                }
                count++;
            }
            bool successfulClearMark = false;

            try
            {
                Log.Info("TEST:3. Before Reset");
                values.Reset();
            }
            catch (IOException)
            {
                successfulClearMark = true;
            }
            if (!successfulClearMark)
            {
                Log.Info("TEST:3 Check:4 reset was successfule even after clearMark");
                errors++;
                return(errors);
            }
            Log.Info("TEST:3 Done.");
            return(errors);
        }
예제 #3
0
        /// <summary>Test the case where we do a mark inside a reset.</summary>
        /// <remarks>
        /// Test the case where we do a mark inside a reset. Test for both file
        /// and memory
        /// </remarks>
        /// <param name="key"/>
        /// <param name="values"/>
        /// <returns/>
        /// <exception cref="System.IO.IOException"/>
        private static int Test2(IntWritable key, MarkableIterator <IntWritable> values)
        {
            IntWritable         i;
            int                 errors          = 0;
            int                 count           = 0;
            AList <IntWritable> expectedValues  = new AList <IntWritable>();
            AList <IntWritable> expectedValues1 = new AList <IntWritable>();

            Log.Info("Executing TEST:2 for Key:" + key);
            values.Mark();
            Log.Info("TEST:2 Marking");
            while (values.HasNext())
            {
                i = values.Next();
                Log.Info(key + ":" + i);
                expectedValues.AddItem(i);
                if (count == 8)
                {
                    break;
                }
                count++;
            }
            values.Reset();
            count = 0;
            Log.Info("TEST:2 reset");
            while (values.HasNext())
            {
                i = values.Next();
                Log.Info(key + ":" + i);
                if (count < expectedValues.Count)
                {
                    if (i != expectedValues[count])
                    {
                        errors++;
                        Log.Info("TEST:2. Check:1 Expected: " + expectedValues[count] + ", Got: " + i);
                        return(errors);
                    }
                }
                // We have moved passed the first mark, but still reading from the
                // memory cache
                if (count == 3)
                {
                    values.Mark();
                    Log.Info("TEST:2. Marking -- " + key + ":" + i);
                }
                if (count >= 3)
                {
                    expectedValues1.AddItem(i);
                }
                count++;
            }
            values.Reset();
            Log.Info("TEST:2. Reset");
            expectedValues.Clear();
            count = 0;
            while (values.HasNext())
            {
                i = values.Next();
                Log.Info(key + ":" + i);
                if (count < expectedValues1.Count)
                {
                    if (i != expectedValues1[count])
                    {
                        errors++;
                        Log.Info("TEST:2. Check:2 Expected: " + expectedValues1[count] + ", Got: " + i);
                        return(errors);
                    }
                }
                // We have moved passed the previous mark, but now we are in the file
                // cache
                if (count == 20)
                {
                    values.Mark();
                    Log.Info("TEST:2. Marking -- " + key + ":" + i);
                }
                if (count >= 20)
                {
                    expectedValues.AddItem(i);
                }
                count++;
            }
            values.Reset();
            count = 0;
            Log.Info("TEST:2. Reset");
            while (values.HasNext())
            {
                i = values.Next();
                Log.Info(key + ":" + i);
                if (i != expectedValues[count])
                {
                    errors++;
                    Log.Info("TEST:2. Check:1 Expected: " + expectedValues[count] + ", Got: " + i);
                    return(errors);
                }
            }
            Log.Info("TEST:2 Done");
            return(errors);
        }