Search in sources :

Example 6 with Text

use of org.apache.hadoop.io.Text in project camel by apache.

the class HdfsProducerTest method testWriteTextWithKey.

@Test
public void testWriteTextWithKey() throws Exception {
    if (!canTest()) {
        return;
    }
    String txtKey = "THEKEY";
    String txtValue = "CIAO MONDO !";
    template.sendBodyAndHeader("direct:write_text2", txtValue, "KEY", txtKey);
    Configuration conf = new Configuration();
    Path file1 = new Path("file:///" + TEMP_DIR.toUri() + "/test-camel-text2");
    FileSystem fs1 = FileSystem.get(file1.toUri(), conf);
    SequenceFile.Reader reader = new SequenceFile.Reader(fs1, file1, conf);
    Text key = (Text) ReflectionUtils.newInstance(reader.getKeyClass(), conf);
    Text value = (Text) ReflectionUtils.newInstance(reader.getValueClass(), conf);
    reader.next(key, value);
    assertEquals(key.toString(), txtKey);
    assertEquals(value.toString(), txtValue);
    IOHelper.close(reader);
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) SequenceFile(org.apache.hadoop.io.SequenceFile) FileSystem(org.apache.hadoop.fs.FileSystem) Text(org.apache.hadoop.io.Text) Test(org.junit.Test)

Example 7 with Text

use of org.apache.hadoop.io.Text in project camel by apache.

the class HdfsProducerTest method testArrayWriteText.

@Test
public void testArrayWriteText() throws Exception {
    if (!canTest()) {
        return;
    }
    String txtValue = "CIAO MONDO !";
    template.sendBody("direct:write_text4", txtValue);
    Configuration conf = new Configuration();
    Path file1 = new Path("file:///" + TEMP_DIR.toUri() + "/test-camel-text4");
    FileSystem fs1 = FileSystem.get(file1.toUri(), conf);
    ArrayFile.Reader reader = new ArrayFile.Reader(fs1, "file:///" + TEMP_DIR.toUri() + "/test-camel-text4", conf);
    Text value = (Text) ReflectionUtils.newInstance(reader.getValueClass(), conf);
    reader.next(value);
    assertEquals(value.toString(), txtValue);
    IOHelper.close(reader);
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) FileSystem(org.apache.hadoop.fs.FileSystem) ArrayFile(org.apache.hadoop.io.ArrayFile) Text(org.apache.hadoop.io.Text) Test(org.junit.Test)

Example 8 with Text

use of org.apache.hadoop.io.Text 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);
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) SequenceFile(org.apache.hadoop.io.SequenceFile) Writable(org.apache.hadoop.io.Writable) DoubleWritable(org.apache.hadoop.io.DoubleWritable) LongWritable(org.apache.hadoop.io.LongWritable) ByteWritable(org.apache.hadoop.io.ByteWritable) IntWritable(org.apache.hadoop.io.IntWritable) BooleanWritable(org.apache.hadoop.io.BooleanWritable) FloatWritable(org.apache.hadoop.io.FloatWritable) Text(org.apache.hadoop.io.Text) Test(org.junit.Test)

Example 9 with Text

use of org.apache.hadoop.io.Text in project camel by apache.

the class HdfsProducerTest method testMapWriteTextWithKey.

@Test
public void testMapWriteTextWithKey() throws Exception {
    if (!canTest()) {
        return;
    }
    String txtKey = "THEKEY";
    String txtValue = "CIAO MONDO !";
    template.sendBodyAndHeader("direct:write_text3", txtValue, "KEY", txtKey);
    Configuration conf = new Configuration();
    MapFile.Reader reader = new MapFile.Reader(new Path("file:///" + TEMP_DIR.toUri() + "/test-camel-text3"), conf);
    Text key = (Text) ReflectionUtils.newInstance(reader.getKeyClass(), conf);
    Text value = (Text) ReflectionUtils.newInstance(reader.getValueClass(), conf);
    reader.next(key, value);
    assertEquals(key.toString(), txtKey);
    assertEquals(value.toString(), txtValue);
    IOHelper.close(reader);
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) BloomMapFile(org.apache.hadoop.io.BloomMapFile) MapFile(org.apache.hadoop.io.MapFile) Text(org.apache.hadoop.io.Text) Test(org.junit.Test)

Example 10 with Text

use of org.apache.hadoop.io.Text in project hadoop by apache.

the class DelegationTokenAuthenticationHandler method initTokenManager.

@VisibleForTesting
@SuppressWarnings("unchecked")
public void initTokenManager(Properties config) {
    Configuration conf = new Configuration(false);
    for (Map.Entry entry : config.entrySet()) {
        conf.set((String) entry.getKey(), (String) entry.getValue());
    }
    String tokenKind = conf.get(TOKEN_KIND);
    if (tokenKind == null) {
        throw new IllegalArgumentException("The configuration does not define the token kind");
    }
    tokenKind = tokenKind.trim();
    tokenManager = new DelegationTokenManager(conf, new Text(tokenKind));
    tokenManager.init();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Text(org.apache.hadoop.io.Text) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

Text (org.apache.hadoop.io.Text)1012 Test (org.junit.Test)397 Path (org.apache.hadoop.fs.Path)180 Configuration (org.apache.hadoop.conf.Configuration)169 LongWritable (org.apache.hadoop.io.LongWritable)141 IOException (java.io.IOException)139 IntWritable (org.apache.hadoop.io.IntWritable)115 FileSystem (org.apache.hadoop.fs.FileSystem)109 ArrayList (java.util.ArrayList)100 Token (org.apache.hadoop.security.token.Token)94 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)86 BytesWritable (org.apache.hadoop.io.BytesWritable)73 SequenceFile (org.apache.hadoop.io.SequenceFile)68 Credentials (org.apache.hadoop.security.Credentials)63 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)54 DeferredJavaObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)53 JobConf (org.apache.hadoop.mapred.JobConf)50 FloatWritable (org.apache.hadoop.io.FloatWritable)46 BooleanWritable (org.apache.hadoop.io.BooleanWritable)45 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)42