Example #1
0
 /// <exception cref="System.IO.IOException"/>
 private SequenceFile.Metadata ReadMetadata(FileSystem fs, Path file)
 {
     Log.Info("reading file: " + file.ToString());
     SequenceFile.Reader   reader = new SequenceFile.Reader(fs, file, conf);
     SequenceFile.Metadata meta   = reader.GetMetadata();
     reader.Close();
     return(meta);
 }
Example #2
0
        /// <exception cref="System.Exception"/>
        public virtual void TestAppend()
        {
            Path file = new Path(RootPath, "testseqappend.seq");

            fs.Delete(file, true);
            Text key1   = new Text("Key1");
            Text value1 = new Text("Value1");
            Text value2 = new Text("Updated");

            SequenceFile.Metadata metadata = new SequenceFile.Metadata();
            metadata.Set(key1, value1);
            SequenceFile.Writer.Option metadataOption = SequenceFile.Writer.Metadata(metadata
                                                                                     );
            SequenceFile.Writer writer = SequenceFile.CreateWriter(conf, SequenceFile.Writer.
                                                                   File(file), SequenceFile.Writer.KeyClass(typeof(long)), SequenceFile.Writer.ValueClass
                                                                       (typeof(string)), metadataOption);
            writer.Append(1L, "one");
            writer.Append(2L, "two");
            writer.Close();
            Verify2Values(file);
            metadata.Set(key1, value2);
            writer = SequenceFile.CreateWriter(conf, SequenceFile.Writer.File(file), SequenceFile.Writer
                                               .KeyClass(typeof(long)), SequenceFile.Writer.ValueClass(typeof(string)), SequenceFile.Writer
                                               .AppendIfExists(true), metadataOption);
            // Verify the Meta data is not changed
            Assert.Equal(value1, writer.metadata.Get(key1));
            writer.Append(3L, "three");
            writer.Append(4L, "four");
            writer.Close();
            VerifyAll4Values(file);
            // Verify the Meta data readable after append
            SequenceFile.Reader reader = new SequenceFile.Reader(conf, SequenceFile.Reader.File
                                                                     (file));
            Assert.Equal(value1, reader.GetMetadata().Get(key1));
            reader.Close();
            // Verify failure if the compression details are different
            try
            {
                SequenceFile.Writer.Option wrongCompressOption = SequenceFile.Writer.Compression(
                    SequenceFile.CompressionType.Record, new GzipCodec());
                writer = SequenceFile.CreateWriter(conf, SequenceFile.Writer.File(file), SequenceFile.Writer
                                                   .KeyClass(typeof(long)), SequenceFile.Writer.ValueClass(typeof(string)), SequenceFile.Writer
                                                   .AppendIfExists(true), wrongCompressOption);
                writer.Close();
                NUnit.Framework.Assert.Fail("Expected IllegalArgumentException for compression options"
                                            );
            }
            catch (ArgumentException)
            {
            }
            // Expected exception. Ignore it
            try
            {
                SequenceFile.Writer.Option wrongCompressOption = SequenceFile.Writer.Compression(
                    SequenceFile.CompressionType.Block, new DefaultCodec());
                writer = SequenceFile.CreateWriter(conf, SequenceFile.Writer.File(file), SequenceFile.Writer
                                                   .KeyClass(typeof(long)), SequenceFile.Writer.ValueClass(typeof(string)), SequenceFile.Writer
                                                   .AppendIfExists(true), wrongCompressOption);
                writer.Close();
                NUnit.Framework.Assert.Fail("Expected IllegalArgumentException for compression options"
                                            );
            }
            catch (ArgumentException)
            {
            }
            // Expected exception. Ignore it
            fs.DeleteOnExit(file);
        }