List of usage examples for org.apache.hadoop.io Text toString
@Override
public String toString()
From source file:com.asakusafw.testdriver.file.FileImporterPreparatorTest.java
License:Apache License
/** * sequence file.//from www . ja va 2s .co m * @throws Exception if test was failed */ @Test public void sequenceFile() throws Exception { FileImporterPreparator target = new FileImporterPreparator(factory); try (ModelOutput<Text> open = target.createOutput(new MockTextDefinition(), new MockFileImporter(Text.class, SequenceFileInputFormat.class, "target/testing/input"), EMPTY)) { open.write(new Text("Hello, world!")); open.write(new Text("This is a test.")); } try (SequenceFile.Reader reader = new SequenceFile.Reader(factory.newInstance(), SequenceFile.Reader.file(fileSystem.makeQualified(new Path("target/testing/input"))))) { Text text = new Text(); assertThat(reader.next(NullWritable.get(), text), is(true)); assertThat(text.toString(), is("Hello, world!")); assertThat(reader.next(NullWritable.get(), text), is(true)); assertThat(text.toString(), is("This is a test.")); assertThat(reader.next(NullWritable.get(), text), is(false)); } }
From source file:com.asakusafw.testdriver.FlowDriverOutputTest.java
License:Apache License
/** * Test method for {@link FlowDriverOutput#transform(ModelTransformer)}. *//*from w ww . j a v a 2s.co m*/ @Test public void transform() { MockFlowDriverOutput mock = new MockFlowDriverOutput(getClass(), tool_rule("Hello3!")); ModelTransformer<Text> transformer = new ModelTransformer<Text>() { @Override public void transform(Text model) { model.set(model.toString() + "!"); } }; mock.transform(transformer); mock.verify(list("Hello1!", "Hello2!", "Hello3!"), "data/dummy"); assertThat(test(mock.getVerifier(), "Hello1", "Hello2", "Hello3"), hasSize(1)); }
From source file:com.asakusafw.testdriver.FlowDriverOutputTest.java
License:Apache License
private final ModelTester<Text> modelTester(final String key) { return new ModelTester<Text>() { @Override/* w w w . ja va2s . c o m*/ public Object verify(Text expected, Text actual) { if (actual.toString().equals(key)) { return key; } return null; } }; }
From source file:com.asakusafw.testdriver.FlowDriverOutputTest.java
License:Apache License
private final ModelVerifier<Text> modelVerifier(final String key) { return new ModelVerifier<Text>() { @Override/*from w w w . j a va 2s . c o m*/ public Object getKey(Text target) { return target.toString(); } @Override public Object verify(Text expected, Text actual) { if (expected.toString().equals(key)) { return key; } return null; } }; }
From source file:com.asakusafw.testdriver.mapreduce.io.TemporaryImporterPreparatorTest.java
License:Apache License
/** * simple case.//from w ww .j av a 2 s . com * @throws Exception if test was failed */ @Test public void simple() throws Exception { TemporaryInputPreparator target = new TemporaryInputPreparator(factory); try (ModelOutput<Text> open = target.createOutput(new MockTextDefinition(), new MockTemporaryImporter(Text.class, "target/testing/input"), 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("target/testing/input"))) { 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.testdriver.temporary.TemporaryImporterPreparatorTest.java
License:Apache License
/** * simple case.//from ww w.j a v a 2 s . c om * @throws Exception if test was failed */ @Test public void simple() throws Exception { TemporaryInputPreparator target = new TemporaryInputPreparator(factory); ModelOutput<Text> open = target.createOutput(new MockTextDefinition(), new MockTemporaryImporter(Text.class, "target/testing/input"), EMPTY); try { open.write(new Text("Hello, world!")); open.write(new Text("This is a test.")); } finally { open.close(); } ModelInput<Text> input = TemporaryStorage.openInput(factory.newInstance(), Text.class, new Path("target/testing/input")); try { 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)); } finally { input.close(); } }
From source file:com.asakusafw.testdriver.testing.dsl.TextStreamFormat.java
License:Apache License
@Override public ModelOutput<Text> createOutput(Class<? extends Text> dataType, String path, OutputStream stream) throws IOException, InterruptedException { PrintWriter writer = new PrintWriter(new OutputStreamWriter(stream, StandardCharsets.UTF_8)); return new ModelOutput<Text>() { @Override/*w ww . j av a2 s . c o m*/ public void write(Text model) throws IOException { writer.print(model.toString()); } @Override public void close() throws IOException { writer.close(); } }; }
From source file:com.asakusafw.windgate.hadoopfs.HadoopFsMirrorTest.java
License:Apache License
private void test(String path, String... expects) throws IOException { List<String> results = new ArrayList<>(); Path resolved = getPath(path); try (ModelInput<Text> input = TemporaryStorage.openInput(conf, Text.class, resolved)) { Text text = new Text(); while (input.readTo(text)) { results.add(text.toString()); }//from w ww.j av a 2s . c o m } assertThat(results, is(Arrays.asList(expects))); }
From source file:com.asakusafw.windgate.hadoopfs.ssh.AbstractSshHadoopFsMirrorTest.java
License:Apache License
private Map<String, List<String>> read(File file) throws IOException { List<File> files = new ArrayList<>(); try (FileInputStream in = new FileInputStream(file); FileList.Reader reader = FileList.createReader(in)) { while (reader.next()) { Path path = reader.getCurrentPath(); File entry = folder.newFile(path.getName()); try (FileOutputStream dst = new FileOutputStream(entry); InputStream src = reader.openContent()) { byte[] buf = new byte[256]; while (true) { int read = src.read(buf); if (read < 0) { break; }//from w w w . j a va 2s . c o m dst.write(buf, 0, read); } } files.add(entry); } } Configuration conf = new Configuration(); Map<String, List<String>> results = new HashMap<>(); Text text = new Text(); for (File entry : files) { List<String> lines = new ArrayList<>(); results.put(entry.getName(), lines); try (ModelInput<Text> input = TemporaryStorage.openInput(conf, Text.class, new Path(entry.toURI()))) { while (input.readTo(text)) { lines.add(text.toString()); } } } return results; }
From source file:com.avira.couchdoop.demo.BenchmarkUpdateMapper.java
License:Apache License
@Override protected HadoopInput<Object> transform(LongWritable hKey, Text hValue, Context context) { String[] splits = hValue.toString().split("\t"); return new HadoopInput<>(splits[0], null); }