List of usage examples for org.apache.hadoop.io Text toString
@Override
public String toString()
From source file:com.asakusafw.dag.runtime.internalio.InternalInputAdapterTest.java
License:Apache License
private static List<String> collect(InternalInputAdapter adapter) throws IOException, InterruptedException { List<String> results = new ArrayList<>(); TaskSchedule schedule = adapter.getSchedule(); InputHandler<Input, ? super TaskProcessorContext> handler = adapter.newHandler(); for (TaskInfo info : schedule.getTasks()) { try (InputSession<Input> session = handler.start(new MockTaskProcessorContext(info))) { while (session.next()) { Input input = session.get(); Text object = input.getObject(); results.add(object.toString()); }//from w w w .java 2 s . co m } } return results; }
From source file:com.asakusafw.dag.runtime.internalio.LocalInternalInputTaskInfoTest.java
License:Apache License
/** * simple case.//from w ww . j ava 2 s . c om * @throws Exception if failed */ @Test public void simple() throws Exception { File file = temporary.newFile(); put(file, "Hello, world!"); List<String> results = new ArrayList<>(); LocalInternalInputTaskInfo<Text> info = new LocalInternalInputTaskInfo<>(file, 0, 0, Text::new); try (ModelInput<Text> in = info.open()) { Text buf = info.newDataObject(); while (in.readTo(buf)) { results.add(buf.toString()); } } assertThat(results, containsInAnyOrder("Hello, world!")); }
From source file:com.asakusafw.lang.compiler.extension.testdriver.InternalExporterRetrieverTest.java
License:Apache License
/** * prepare./*from w w w .java 2 s . co m*/ * @throws Exception if test was failed */ @Test public void prepare() throws Exception { String base = new File(folder.getRoot(), "part").toURI().toString(); String prefix = base + "-*"; InternalExporterRetriever target = new InternalExporterRetriever(factory); try (ModelOutput<Text> open = target.createOutput(new MockTextDefinition(), new InternalExporterDescription.Basic(Text.class, prefix), EMPTY)) { open.write(new Text("Hello, world!")); open.write(new Text("This is a test.")); } try (ModelInput<Text> input = TemporaryStorage.openInput(factory.newInstance(), Text.class, new Path(InternalImporterPreparator.resolvePathPrefix(EMPTY, prefix)))) { Text text = new Text(); assertThat(input.readTo(text), is(true)); assertThat(text.toString(), is("Hello, world!")); assertThat(input.readTo(text), is(true)); assertThat(text.toString(), is("This is a test.")); assertThat(input.readTo(text), is(false)); } }
From source file:com.asakusafw.lang.compiler.extension.testdriver.InternalImporterPreparatorTest.java
License:Apache License
/** * prepare./*from w w w . j a va2 s . c o m*/ * @throws Exception if test was failed */ @Test public void prepare() throws Exception { String base = new File(folder.getRoot(), "part").toURI().toString(); String prefix = base + "-*"; InternalImporterPreparator target = new InternalImporterPreparator(factory); try (ModelOutput<Text> open = target.createOutput(new MockTextDefinition(), new InternalImporterDescription.Basic(Text.class, prefix), EMPTY)) { open.write(new Text("Hello, world!")); open.write(new Text("This is a test.")); } try (ModelInput<Text> input = TemporaryStorage.openInput(factory.newInstance(), Text.class, new Path(InternalImporterPreparator.resolvePathPrefix(EMPTY, prefix)))) { Text text = new Text(); assertThat(input.readTo(text), is(true)); assertThat(text.toString(), is("Hello, world!")); assertThat(input.readTo(text), is(true)); assertThat(text.toString(), is("This is a test.")); assertThat(input.readTo(text), is(false)); } }
From source file:com.asakusafw.lang.compiler.extension.testdriver.mock.MockTextDefinition.java
License:Apache License
@Override public DataModelReflection toReflection(Text object) { return newReflection().add(VALUE, object.toString()).build(); }
From source file:com.asakusafw.runtime.directio.hadoop.SequenceFileFormatTest.java
License:Apache License
/** * Test method for output./*from ww w .j av a 2s . c o m*/ * @throws Exception if failed */ @SuppressWarnings("deprecation") @Test public void output() throws Exception { final int count = 10000; LocalFileSystem fs = FileSystem.getLocal(conf); Path path = new Path(folder.newFile("testing").toURI()); try (ModelOutput<StringOption> out = format.createOutput(StringOption.class, fs, path, new Counter())) { StringOption value = new StringOption(); for (int i = 0; i < count; i++) { value.modify("Hello, world at " + i); out.write(value); } } try (SequenceFile.Reader reader = new SequenceFile.Reader(fs, path, conf)) { LongWritable k = new LongWritable(); Text v = new Text(); for (int i = 0; i < count; i++) { String answer = "Hello, world at " + i; assertThat(answer, reader.next(k, v), is(true)); assertThat(answer, k.get(), is(1L)); assertThat(answer, v.toString(), is(answer)); } assertThat("eof", reader.next(k), is(false)); } }
From source file:com.asakusafw.runtime.io.sequencefile.SequenceFileUtilTest.java
License:Apache License
/** * Reads a sequence file./*w w w.java 2 s . com*/ * @throws Exception if failed */ @Test public void read() throws Exception { Path path = new Path("testing"); Text key = new Text(); Text value = new Text(); try (SequenceFile.Writer writer = SequenceFile.createWriter(fs, conf, path, key.getClass(), value.getClass())) { key.set("Hello"); value.set("World"); writer.append(key, value); } key.clear(); value.clear(); FileStatus status = fs.getFileStatus(path); try (InputStream in = new FileInputStream(fs.pathToFile(path)); SequenceFile.Reader reader = SequenceFileUtil.openReader(in, status, conf)) { assertThat(reader.next(key, value), is(true)); assertThat(key.toString(), is("Hello")); assertThat(value.toString(), is("World")); assertThat(reader.next(key, value), is(false)); } }
From source file:com.asakusafw.runtime.io.sequencefile.SequenceFileUtilTest.java
License:Apache License
/** * Reads a sequence file.//from ww w.j a va 2 s .c o m * @throws Exception if failed */ @Test public void read_new() throws Exception { Path path = new Path("testing"); Text key = new Text(); Text value = new Text(); try (SequenceFile.Writer writer = SequenceFile.createWriter(fs, conf, path, key.getClass(), value.getClass())) { key.set("Hello"); value.set("World"); writer.append(key, value); } key.clear(); value.clear(); FileStatus status = fs.getFileStatus(path); try (InputStream in = new FileInputStream(fs.pathToFile(path)); SequenceFile.Reader reader = SequenceFileUtil.openReader(in, status.getLen(), conf)) { assertThat(reader.next(key, value), is(true)); assertThat(key.toString(), is("Hello")); assertThat(value.toString(), is("World")); assertThat(reader.next(key, value), is(false)); } }
From source file:com.asakusafw.runtime.io.sequencefile.SequenceFileUtilTest.java
License:Apache License
/** * Creates a sequence file.//from w w w .j av a2 s. c o m * @throws Exception if failed */ @Test public void write() throws Exception { Path path = new Path("testing"); Text key = new Text(); Text value = new Text(); try (OutputStream out = new FileOutputStream(fs.pathToFile(path)); SequenceFile.Writer writer = SequenceFileUtil.openWriter(new BufferedOutputStream(out), conf, key.getClass(), value.getClass(), null)) { key.set("Hello"); value.set("World"); writer.append(key, value); } key.clear(); value.clear(); try (SequenceFile.Reader reader = new SequenceFile.Reader(fs, path, conf)) { assertThat(reader.next(key, value), is(true)); assertThat(key.toString(), is("Hello")); assertThat(value.toString(), is("World")); assertThat(reader.next(key, value), is(false)); } }
From source file:com.asakusafw.testdriver.directio.MockStreamFormat.java
License:Apache License
@Override public ModelOutput<Text> createOutput(Class<? extends Text> dataType, String path, OutputStream stream) throws IOException, InterruptedException { final PrintWriter w = new PrintWriter(new OutputStreamWriter(stream)); return new ModelOutput<Text>() { @Override/*from www . ja v a 2 s. c o m*/ public void write(Text model) throws IOException { w.println(model.toString()); } @Override public void close() throws IOException { w.close(); } }; }