Esempio n. 1
0
        /// <exception cref="System.Exception"/>
        private void CheckMembershipVaryingSizedKeys(string name, IList <Text> keys)
        {
            FileSystem fs = FileSystem.GetLocal(conf);
            Path       qualifiedDirName = fs.MakeQualified(TestDir);

            BloomMapFile.Writer writer = null;
            BloomMapFile.Reader reader = null;
            try
            {
                writer = new BloomMapFile.Writer(conf, fs, qualifiedDirName.ToString(), typeof(Text
                                                                                               ), typeof(NullWritable));
                foreach (Text key in keys)
                {
                    writer.Append(key, NullWritable.Get());
                }
                writer.Close();
                // will check for membership in opposite order of how keys were inserted
                reader = new BloomMapFile.Reader(fs, qualifiedDirName.ToString(), conf);
                Collections.Reverse(keys);
                foreach (Text key_1 in keys)
                {
                    Assert.True("False negative for existing key " + key_1, reader.
                                ProbablyHasKey(key_1));
                }
                reader.Close();
                fs.Delete(qualifiedDirName, true);
            }
            finally
            {
                IOUtils.Cleanup(null, writer, reader);
            }
        }
Esempio n. 2
0
        /// <exception cref="System.IO.IOException"/>
        public virtual void TestClose()
        {
            Configuration   conf = new Configuration();
            LocalFileSystem fs   = FileSystem.GetLocal(conf);
            // create a sequence file 1
            Path path1 = new Path(Runtime.GetProperty("test.build.data", ".") + "/test1.seq");

            SequenceFile.Writer writer = SequenceFile.CreateWriter(fs, conf, path1, typeof(Text
                                                                                           ), typeof(NullWritable), SequenceFile.CompressionType.Block);
            writer.Append(new Text("file1-1"), NullWritable.Get());
            writer.Append(new Text("file1-2"), NullWritable.Get());
            writer.Close();
            Path path2 = new Path(Runtime.GetProperty("test.build.data", ".") + "/test2.seq");

            writer = SequenceFile.CreateWriter(fs, conf, path2, typeof(Text), typeof(NullWritable
                                                                                     ), SequenceFile.CompressionType.Block);
            writer.Append(new Text("file2-1"), NullWritable.Get());
            writer.Append(new Text("file2-2"), NullWritable.Get());
            writer.Close();
            // Create a reader which uses 4 BuiltInZLibInflater instances
            SequenceFile.Reader reader = new SequenceFile.Reader(fs, path1, conf);
            // Returns the 4 BuiltInZLibInflater instances to the CodecPool
            reader.Close();
            // The second close _could_ erroneously returns the same
            // 4 BuiltInZLibInflater instances to the CodecPool again
            reader.Close();
            // The first reader gets 4 BuiltInZLibInflater instances from the CodecPool
            SequenceFile.Reader reader1 = new SequenceFile.Reader(fs, path1, conf);
            // read first value from reader1
            Text text = new Text();

            reader1.Next(text);
            Assert.Equal("file1-1", text.ToString());
            // The second reader _could_ get the same 4 BuiltInZLibInflater
            // instances from the CodePool as reader1
            SequenceFile.Reader reader2 = new SequenceFile.Reader(fs, path2, conf);
            // read first value from reader2
            reader2.Next(text);
            Assert.Equal("file2-1", text.ToString());
            // read second value from reader1
            reader1.Next(text);
            Assert.Equal("file1-2", text.ToString());
            // read second value from reader2 (this throws an exception)
            reader2.Next(text);
            Assert.Equal("file2-2", text.ToString());
            NUnit.Framework.Assert.IsFalse(reader1.Next(text));
            NUnit.Framework.Assert.IsFalse(reader2.Next(text));
        }