List of usage examples for org.apache.hadoop.io Text Text
public Text(byte[] utf8)
From source file:com.asakusafw.testdriver.file.FileImporterPreparatorTest.java
License:Apache License
/** * sequence file./*from w ww .j ava 2 s . c o 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.file.MockTextDefinition.java
License:Apache License
@Override public Text toObject(DataModelReflection reflection) { return new Text((String) reflection.getValue(VALUE)); }
From source file:com.asakusafw.testdriver.FlowDriverPortTestHelper.java
License:Apache License
static List<Text> list(String... texts) { List<Text> results = new ArrayList<>(); for (String text : texts) { results.add(new Text(text)); }/*w w w . j a v a 2 s. c o m*/ return results; }
From source file:com.asakusafw.testdriver.mapreduce.io.TemporaryExporterRetrieverTest.java
License:Apache License
/** * minimum test./*from w ww.ja v a 2 s . c o m*/ * @throws Exception if test was failed */ @Test public void simple() throws Exception { MockFileExporter exporter = new MockFileExporter(Text.class, "target/testing/hello"); TemporaryOutputRetriever retriever = new TemporaryOutputRetriever(factory); putText("target/testing/hello", "Hello, world!", "This is a test."); MockTextDefinition definition = new MockTextDefinition(); try (DataModelSource result = retriever.createSource(definition, exporter, EMPTY)) { DataModelReflection ref; ref = result.next(); assertThat(ref, is(not(nullValue()))); assertThat(definition.toObject(ref), is(new Text("Hello, world!"))); ref = result.next(); assertThat(ref, is(not(nullValue()))); assertThat(definition.toObject(ref), is(new Text("This is a test."))); ref = result.next(); assertThat(ref, is(nullValue())); } }
From source file:com.asakusafw.testdriver.mapreduce.io.TemporaryImporterPreparatorTest.java
License:Apache License
/** * simple case.// w w w . ja v a 2 s. c om * @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.TemporaryExporterRetrieverTest.java
License:Apache License
/** * minimum test./* ww w.j a v a 2s. c o m*/ * @throws Exception if test was failed */ @Test public void simple() throws Exception { MockFileExporter exporter = new MockFileExporter(Text.class, "target/testing/hello"); TemporaryOutputRetriever retriever = new TemporaryOutputRetriever(factory); putText("target/testing/hello", "Hello, world!", "This is a test."); MockTextDefinition definition = new MockTextDefinition(); DataModelSource result = retriever.createSource(definition, exporter, EMPTY); try { DataModelReflection ref; ref = result.next(); assertThat(ref, is(not(nullValue()))); assertThat(definition.toObject(ref), is(new Text("Hello, world!"))); ref = result.next(); assertThat(ref, is(not(nullValue()))); assertThat(definition.toObject(ref), is(new Text("This is a test."))); ref = result.next(); assertThat(ref, is(nullValue())); } finally { result.close(); } }
From source file:com.asakusafw.testdriver.temporary.TemporaryExporterRetrieverTest.java
License:Apache License
private void putText(String path, String... lines) throws IOException { ModelOutput<Text> output = TemporaryStorage.openOutput(factory.newInstance(), Text.class, new Path(path)); try {/*from ww w. j a va 2s .c o m*/ for (String s : lines) { output.write(new Text(s)); } } finally { output.close(); } }
From source file:com.asakusafw.testdriver.temporary.TemporaryImporterPreparatorTest.java
License:Apache License
/** * simple case.// www . j a va 2 s. com * @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.windgate.hadoopfs.HadoopFsMirrorTest.java
License:Apache License
/** * simple drain./* w w w . j a va 2 s .com*/ * @throws Exception if failed */ @Test public void drain() throws Exception { try (HadoopFsMirror resource = new HadoopFsMirror(conf, profile(), new ParameterList())) { ProcessScript<Text> process = drain("target", "testing"); resource.prepare(script(process)); try (DrainDriver<Text> driver = resource.createDrain(process)) { driver.prepare(); driver.put(new Text("Hello, world!")); } } test("testing", "Hello, world!"); }
From source file:com.asakusafw.windgate.hadoopfs.HadoopFsMirrorTest.java
License:Apache License
/** * drain with parameterized path./*from w w w . j av a 2s .c o m*/ * @throws Exception if failed */ @Test public void drain_parameterized() throws Exception { try (HadoopFsMirror resource = new HadoopFsMirror(conf, profile(), new ParameterList(Collections.singletonMap("var", "testing")))) { ProcessScript<Text> process = drain("target", "${var}"); resource.prepare(script(process)); try (DrainDriver<Text> driver = resource.createDrain(process)) { driver.prepare(); driver.put(new Text("Hello, world!")); } } test("testing", "Hello, world!"); }