use of org.apache.hadoop.conf.Configuration in project camel by apache.
the class HdfsAppendTest method testAppend.
@Test
public void testAppend() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start1").to("hdfs://localhost:9000/tmp/test/test-camel-simple-write-file1?append=true&fileSystemType=HDFS");
}
});
startCamelContext();
for (int i = 0; i < 10; ++i) {
template.sendBody("direct:start1", "PIPPO");
}
Configuration conf = new Configuration();
Path file = new Path("hdfs://localhost:9000/tmp/test/test-camel-simple-write-file1");
FileSystem fs = FileSystem.get(file.toUri(), conf);
FSDataInputStream in = fs.open(file);
byte[] buffer = new byte[5];
int ret = 0;
for (int i = 0; i < 20; ++i) {
ret = in.read(buffer);
}
ret = in.read(buffer);
assertEquals(-1, ret);
in.close();
}
use of org.apache.hadoop.conf.Configuration in project camel by apache.
the class HdfsAppendTest method tearDown.
@Override
public void tearDown() throws Exception {
super.tearDown();
Thread.sleep(250);
Configuration conf = new Configuration();
Path dir = new Path("hdfs://localhost:9000/tmp/test");
FileSystem fs = FileSystem.get(dir.toUri(), conf);
fs.delete(dir, true);
}
use of org.apache.hadoop.conf.Configuration in project camel by apache.
the class HdfsProducerConsumerIntegrationTest method tearDown.
@Override
@After
public void tearDown() throws Exception {
super.tearDown();
Thread.sleep(250);
Configuration conf = new Configuration();
Path dir = new Path("hdfs://localhost:9000/tmp/test");
FileSystem fs = FileSystem.get(dir.toUri(), conf);
fs.delete(dir, true);
}
use of org.apache.hadoop.conf.Configuration in project camel by apache.
the class HdfsProducerTest method testWriteLong.
@Test
public void testWriteLong() throws Exception {
if (!canTest()) {
return;
}
long aLong = 1234567890;
template.sendBody("direct:write_long", aLong);
Configuration conf = new Configuration();
Path file1 = new Path("file:///" + TEMP_DIR.toUri() + "/test-camel-long");
SequenceFile.Reader reader = new SequenceFile.Reader(conf, SequenceFile.Reader.file(file1));
Writable key = (Writable) ReflectionUtils.newInstance(reader.getKeyClass(), conf);
Writable value = (Writable) ReflectionUtils.newInstance(reader.getValueClass(), conf);
reader.next(key, value);
long rLong = ((LongWritable) value).get();
assertEquals(rLong, aLong);
IOHelper.close(reader);
}
use of org.apache.hadoop.conf.Configuration in project camel by apache.
the class HdfsProducerTest method testProducerClose.
@Test
public void testProducerClose() throws Exception {
if (!canTest()) {
return;
}
for (int i = 0; i < 10; ++i) {
// send 10 messages, and mark to close in last message
template.sendBodyAndHeader("direct:start1", "PAPPO" + i, HdfsConstants.HDFS_CLOSE, i == 9 ? true : false);
}
Configuration conf = new Configuration();
Path file1 = new Path("file:///" + TEMP_DIR.toUri() + "/test-camel1");
SequenceFile.Reader reader = new SequenceFile.Reader(conf, SequenceFile.Reader.file(file1));
Writable key = (Writable) ReflectionUtils.newInstance(reader.getKeyClass(), conf);
Writable value = (Writable) ReflectionUtils.newInstance(reader.getValueClass(), conf);
int i = 0;
while (reader.next(key, value)) {
Text txt = (Text) value;
assertEquals("PAPPO" + i, txt.toString());
++i;
}
IOHelper.close(reader);
}
Aggregations