Java tutorial
/** * Copyright 2014-2015 SHAF-WORK * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.shaf.core.io.emulator; import static org.junit.Assert.assertEquals; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.io.NullWritable; import org.apache.hadoop.mapreduce.MRJobConfig; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; import org.apache.hadoop.mapreduce.lib.output.SequenceFileOutputFormat; import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; import org.junit.Test; import org.shaf.core._helper_.DummyDistributedProcess; import org.shaf.core.anno.JobOutput; import org.shaf.core.io.RecordWriterFactory; /** * The class {@code RecordWriterFactoryTest} contains tests for the class * {@link RecordWriterFactory}. * * @author Mykola Galushka */ public class RecordWriterFactoryTest extends GenericIOTest { /** * Run the record reader factory tests. * * @throws Exception * if the test fails for some reason. */ @Test public void testFactory() throws Exception { Configuration config = job.getConfiguration(); config.set(FileOutputFormat.OUTDIR, super.dir.toString()); config.set(MRJobConfig.OUTPUT_KEY_CLASS, "org.apache.hadoop.io.NullWritable"); config.set(MRJobConfig.OUTPUT_VALUE_CLASS, "org.apache.hadoop.io.NullWritable"); assertEquals(TextWriter.class, RecordWriterFactory.createRecordWriter(SomeProcess1.class, job.getConfiguration()).getClass()); assertEquals(SequenceWriter.class, RecordWriterFactory.createRecordWriter(SomeProcess2.class, job.getConfiguration()).getClass()); } @JobOutput(formatClass = TextOutputFormat.class, keyClass = NullWritable.class, valueClass = NullWritable.class) public static class SomeProcess1 extends DummyDistributedProcess { } @JobOutput(formatClass = SequenceFileOutputFormat.class, keyClass = NullWritable.class, valueClass = NullWritable.class) public static class SomeProcess2 extends DummyDistributedProcess { } }