Author: rickette
Date: Fri Jun 3 22:33:04 2011
New Revision: 1131271
URL: http://svn.apache.org/viewvc?rev=1131271&view=rev
Log:
CAMEL-4043: Removed hard coded dependency on /tmp directory which may not be
available/accessible on all platforms. Tests no use the Maven 'target'
directory.
Modified:
camel/trunk/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/HdfsConsumerTest.java
camel/trunk/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/HdfsProducerConsumerTest.java
camel/trunk/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/HdfsProducerFileWriteTest.java
camel/trunk/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/HdfsProducerSplitTest.java
camel/trunk/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/HdfsProducerTest.java
Modified:
camel/trunk/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/HdfsConsumerTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/HdfsConsumerTest.java?rev=1131271&r1=1131270&r2=1131271&view=diff
==============================================================================
---
camel/trunk/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/HdfsConsumerTest.java
(original)
+++
camel/trunk/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/HdfsConsumerTest.java
Fri Jun 3 22:33:04 2011
@@ -16,6 +16,7 @@
*/
package org.apache.camel.component.hdfs;
+import java.io.File;
import java.util.List;
import junit.framework.Assert;
@@ -54,8 +55,8 @@ public class HdfsConsumerTest extends Ca
@Test
public void testSimpleConsumer() throws Exception {
+ final Path file = new Path(new
File("target/test/test-camel-normal-file").getAbsolutePath());
Configuration conf = new Configuration();
- Path file = new Path("file:///tmp/test/test-camel-normal-file");
FileSystem fs = FileSystem.get(file.toUri(), conf);
FSDataOutputStream out = fs.create(file);
for (int i = 0; i < 1024; ++i) {
@@ -66,7 +67,7 @@ public class HdfsConsumerTest extends Ca
context.addRoutes(new RouteBuilder() {
public void configure() {
-
from("hdfs:///tmp/test/test-camel-normal-file?fileSystemType=LOCAL&chunkSize=4096&initialDelay=0").to("mock:result");
+ from("hdfs:///" + file.toUri() +
"?fileSystemType=LOCAL&chunkSize=4096&initialDelay=0").to("mock:result");
}
});
MockEndpoint resultEndpoint = (MockEndpoint)
context.getEndpoint("mock:result");
@@ -78,7 +79,7 @@ public class HdfsConsumerTest extends Ca
@Test
public void testReadBoolean() throws Exception {
- Path file = new Path("file:///tmp/test/test-camel-boolean");
+ final Path file = new Path(new
File("target/test/test-camel-boolean").getAbsolutePath());
Configuration conf = new Configuration();
FileSystem fs1 = FileSystem.get(file.toUri(), conf);
SequenceFile.Writer writer = createWriter(fs1, conf, file,
NullWritable.class, BooleanWritable.class);
@@ -91,7 +92,7 @@ public class HdfsConsumerTest extends Ca
context.addRoutes(new RouteBuilder() {
public void configure() {
-
from("hdfs:///tmp/test/test-camel-boolean?fileSystemType=LOCAL&fileType=SEQUENCE_FILE&initialDelay=0").to("mock:result");
+ from("hdfs:///" + file.toUri() +
"?fileSystemType=LOCAL&fileType=SEQUENCE_FILE&initialDelay=0").to("mock:result");
}
});
context.start();
@@ -107,7 +108,7 @@ public class HdfsConsumerTest extends Ca
@Test
public void testReadByte() throws Exception {
- Path file = new Path("file:///tmp/test/test-camel-byte");
+ final Path file = new Path(new
File("target/test/test-camel-byte").getAbsolutePath());
Configuration conf = new Configuration();
FileSystem fs1 = FileSystem.get(file.toUri(), conf);
SequenceFile.Writer writer = createWriter(fs1, conf, file,
NullWritable.class, ByteWritable.class);
@@ -121,7 +122,7 @@ public class HdfsConsumerTest extends Ca
context.addRoutes(new RouteBuilder() {
public void configure() {
-
from("hdfs:///tmp/test/test-camel-byte?fileSystemType=LOCAL&fileType=SEQUENCE_FILE&initialDelay=0").to("mock:result");
+ from("hdfs:///" + file.toUri() +
"?fileSystemType=LOCAL&fileType=SEQUENCE_FILE&initialDelay=0").to("mock:result");
}
});
context.start();
@@ -137,7 +138,7 @@ public class HdfsConsumerTest extends Ca
@Test
public void testReadFloat() throws Exception {
- Path file = new Path("file:///tmp/test/test-camel-float");
+ final Path file = new Path(new
File("target/test/test-camel-float").getAbsolutePath());
Configuration conf = new Configuration();
FileSystem fs1 = FileSystem.get(file.toUri(), conf);
SequenceFile.Writer writer = createWriter(fs1, conf, file,
NullWritable.class, FloatWritable.class);
@@ -151,7 +152,7 @@ public class HdfsConsumerTest extends Ca
context.addRoutes(new RouteBuilder() {
public void configure() {
-
from("hdfs:///tmp/test/test-camel-float?fileSystemType=LOCAL&fileType=SEQUENCE_FILE&initialDelay=0").to("mock:result");
+ from("hdfs:///" + file.toUri() +
"??fileSystemType=LOCAL&fileType=SEQUENCE_FILE&initialDelay=0").to("mock:result");
}
});
context.start();
@@ -167,7 +168,7 @@ public class HdfsConsumerTest extends Ca
@Test
public void testReadDouble() throws Exception {
- Path file = new Path("file:///tmp/test/test-camel-double");
+ final Path file = new Path(new
File("target/test/test-camel-double").getAbsolutePath());
Configuration conf = new Configuration();
FileSystem fs1 = FileSystem.get(file.toUri(), conf);
SequenceFile.Writer writer = createWriter(fs1, conf, file,
NullWritable.class, DoubleWritable.class);
@@ -181,7 +182,7 @@ public class HdfsConsumerTest extends Ca
context.addRoutes(new RouteBuilder() {
public void configure() {
-
from("hdfs:///tmp/test/test-camel-double?fileSystemType=LOCAL&fileType=SEQUENCE_FILE&initialDelay=0").to("mock:result");
+ from("hdfs:///" + file.toUri() +
"??fileSystemType=LOCAL&fileType=SEQUENCE_FILE&initialDelay=0").to("mock:result");
}
});
context.start();
@@ -197,7 +198,7 @@ public class HdfsConsumerTest extends Ca
@Test
public void testReadInt() throws Exception {
- Path file = new Path("file:///tmp/test/test-camel-int");
+ final Path file = new Path(new
File("target/test/test-camel-int").getAbsolutePath());
Configuration conf = new Configuration();
FileSystem fs1 = FileSystem.get(file.toUri(), conf);
SequenceFile.Writer writer = createWriter(fs1, conf, file,
NullWritable.class, IntWritable.class);
@@ -211,7 +212,7 @@ public class HdfsConsumerTest extends Ca
context.addRoutes(new RouteBuilder() {
public void configure() {
-
from("hdfs:///tmp/test/test-camel-int?fileSystemType=LOCAL&fileType=SEQUENCE_FILE&initialDelay=0").to("mock:result");
+ from("hdfs:///" + file.toUri() +
"?fileSystemType=LOCAL&fileType=SEQUENCE_FILE&initialDelay=0").to("mock:result");
}
});
context.start();
@@ -227,7 +228,7 @@ public class HdfsConsumerTest extends Ca
@Test
public void testReadLong() throws Exception {
- Path file = new Path("file:///tmp/test/test-camel-long");
+ final Path file = new Path(new
File("target/test/test-camel-long").getAbsolutePath());
Configuration conf = new Configuration();
FileSystem fs1 = FileSystem.get(file.toUri(), conf);
SequenceFile.Writer writer = createWriter(fs1, conf, file,
NullWritable.class, LongWritable.class);
@@ -241,7 +242,7 @@ public class HdfsConsumerTest extends Ca
context.addRoutes(new RouteBuilder() {
public void configure() {
-
from("hdfs:///tmp/test/test-camel-long?fileSystemType=LOCAL&fileType=SEQUENCE_FILE&initialDelay=0").to("mock:result");
+ from("hdfs:///" + file.toUri() +
"?fileSystemType=LOCAL&fileType=SEQUENCE_FILE&initialDelay=0").to("mock:result");
}
});
context.start();
@@ -257,7 +258,7 @@ public class HdfsConsumerTest extends Ca
@Test
public void testReadBytes() throws Exception {
- Path file = new Path("file:///tmp/test/test-camel-bytes");
+ final Path file = new Path(new
File("target/test/test-camel-bytes").getAbsolutePath());
Configuration conf = new Configuration();
FileSystem fs1 = FileSystem.get(file.toUri(), conf);
SequenceFile.Writer writer = createWriter(fs1, conf, file,
NullWritable.class, BytesWritable.class);
@@ -271,7 +272,7 @@ public class HdfsConsumerTest extends Ca
context.addRoutes(new RouteBuilder() {
public void configure() {
-
from("hdfs:///tmp/test/test-camel-bytes?fileSystemType=LOCAL&fileType=SEQUENCE_FILE&initialDelay=0").to("mock:result");
+ from("hdfs:///" + file.toUri() +
"?fileSystemType=LOCAL&fileType=SEQUENCE_FILE&initialDelay=0").to("mock:result");
}
});
context.start();
@@ -287,7 +288,7 @@ public class HdfsConsumerTest extends Ca
@Test
public void testReadString() throws Exception {
- Path file = new Path("file:///tmp/test/test-camel-string");
+ final Path file = new Path(new
File("target/test/test-camel-string").getAbsolutePath());
Configuration conf = new Configuration();
FileSystem fs1 = FileSystem.get(file.toUri(), conf);
SequenceFile.Writer writer = createWriter(fs1, conf, file,
NullWritable.class, Text.class);
@@ -301,7 +302,7 @@ public class HdfsConsumerTest extends Ca
context.addRoutes(new RouteBuilder() {
public void configure() {
-
from("hdfs:///tmp/test/test-camel-string?fileSystemType=LOCAL&fileType=SEQUENCE_FILE&initialDelay=0").to("mock:result");
+ from("hdfs:///" + file.toUri() +
"?fileSystemType=LOCAL&fileType=SEQUENCE_FILE&initialDelay=0").to("mock:result");
}
});
context.start();
@@ -317,10 +318,10 @@ public class HdfsConsumerTest extends Ca
@Test
public void testReadStringArrayFile() throws Exception {
- Path file = new Path("file:///tmp/test/test-camel-string");
+ final Path file = new Path(new
File("target/test/test-camel-string").getAbsolutePath());
Configuration conf = new Configuration();
FileSystem fs1 = FileSystem.get(file.toUri(), conf);
- ArrayFile.Writer writer = new ArrayFile.Writer(conf, fs1,
"file:///tmp/test/test-camel-string1", Text.class, CompressionType.NONE, new
Progressable() {
+ ArrayFile.Writer writer = new ArrayFile.Writer(conf, fs1,
"target/test/test-camel-string1", Text.class, CompressionType.NONE, new
Progressable() {
@Override
public void progress() {
}
@@ -333,7 +334,7 @@ public class HdfsConsumerTest extends Ca
context.addRoutes(new RouteBuilder() {
public void configure() {
-
from("hdfs:///tmp/test?fileSystemType=LOCAL&fileType=ARRAY_FILE&initialDelay=0").to("mock:result");
+ from("hdfs:///" + file.getParent().toUri() +
"?fileSystemType=LOCAL&fileType=ARRAY_FILE&initialDelay=0").to("mock:result");
}
});
context.start();
@@ -352,7 +353,7 @@ public class HdfsConsumerTest extends Ca
super.tearDown();
Thread.sleep(100);
Configuration conf = new Configuration();
- Path dir = new Path("file:///tmp/test");
+ Path dir = new Path("target/test");
FileSystem fs = FileSystem.get(dir.toUri(), conf);
fs.delete(dir, true);
}
Modified:
camel/trunk/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/HdfsProducerConsumerTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/HdfsProducerConsumerTest.java?rev=1131271&r1=1131270&r2=1131271&view=diff
==============================================================================
---
camel/trunk/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/HdfsProducerConsumerTest.java
(original)
+++
camel/trunk/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/HdfsProducerConsumerTest.java
Fri Jun 3 22:33:04 2011
@@ -16,6 +16,7 @@
*/
package org.apache.camel.component.hdfs;
+import java.io.File;
import java.util.List;
import junit.framework.Assert;
@@ -37,11 +38,13 @@ public class HdfsProducerConsumerTest ex
@Test
public void testSimpleSplitWriteRead() throws Exception {
+ final Path file = new Path(new
File("target/test/test-camel-simple-write-file").getAbsolutePath());
+
context.addRoutes(new RouteBuilder() {
@Override
public void configure() {
-
from("direct:start").to("hdfs://localhost/tmp/test/test-camel-simple-write-file?fileSystemType=LOCAL&splitStrategy=BYTES:5,IDLE:1000");
-
from("hdfs://localhost/tmp/test/test-camel-simple-write-file?pattern=seg*&initialDelay=2000&fileSystemType=LOCAL&chunkSize=5").to("mock:result");
+ from("direct:start").to("hdfs:///localhost/" + file.toUri() +
"?fileSystemType=LOCAL&splitStrategy=BYTES:5,IDLE:1000");
+ from("hdfs:///localhost/" + file.toUri() +
"?pattern=seg*&initialDelay=2000&fileSystemType=LOCAL&chunkSize=5").to("mock:result");
}
});
context.start();
@@ -67,7 +70,7 @@ public class HdfsProducerConsumerTest ex
super.tearDown();
Thread.sleep(100);
Configuration conf = new Configuration();
- Path dir = new Path("file:///tmp/test");
+ Path dir = new Path("target/test");
FileSystem fs = FileSystem.get(dir.toUri(), conf);
fs.delete(dir, true);
}
Modified:
camel/trunk/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/HdfsProducerFileWriteTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/HdfsProducerFileWriteTest.java?rev=1131271&r1=1131270&r2=1131271&view=diff
==============================================================================
---
camel/trunk/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/HdfsProducerFileWriteTest.java
(original)
+++
camel/trunk/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/HdfsProducerFileWriteTest.java
Fri Jun 3 22:33:04 2011
@@ -17,6 +17,7 @@
package org.apache.camel.component.hdfs;
import java.io.ByteArrayOutputStream;
+import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.nio.ByteBuffer;
@@ -41,12 +42,14 @@ public class HdfsProducerFileWriteTest e
@Test
public void testSimpleWriteFile() throws Exception {
+ final Path file = new Path(new
File("target/test/test-camel-simple-write-file").getAbsolutePath());
+
deleteDirectory("target/file-batch1");
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("file://target/file-batch1?sortBy=file:name")
-
.to("hdfs://localhost/tmp/test/test-camel-simple-write-file?fileSystemType=LOCAL");
+ .to("hdfs://localhost/" + file.toUri() +
"?fileSystemType=LOCAL");
}
});
@@ -63,7 +66,7 @@ public class HdfsProducerFileWriteTest e
InputStream in = null;
try {
- in = new
URL("file:///tmp/test/test-camel-simple-write-file").openStream();
+ in = new URL("file:///" + file.toUri()).openStream();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
IOUtils.copyBytes(in, bos, 4096, false);
Assert.assertEquals(40, bos.size());
@@ -74,13 +77,14 @@ public class HdfsProducerFileWriteTest e
@Test
public void testSequenceWriteFile() throws Exception {
+ final Path file = new Path(new
File("target/test/test-camel-simple-write-file1").getAbsolutePath());
deleteDirectory("target/file-batch2");
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("file://target/file-batch2?sortBy=file:name")
-
.to("hdfs://localhost/tmp/test/test-camel-sequence-write-file1?fileSystemType=LOCAL&fileType=SEQUENCE_FILE");
+ .to("hdfs://localhost/" + file.toUri() +
"?fileSystemType=LOCAL&fileType=SEQUENCE_FILE");
}
});
@@ -96,7 +100,7 @@ public class HdfsProducerFileWriteTest e
context.stop();
Configuration conf = new Configuration();
- Path file1 = new
Path("file:///tmp/test/test-camel-sequence-write-file1");
+ Path file1 = new Path("file:///" + file.toUri());
FileSystem fs1 = FileSystem.get(file1.toUri(), conf);
SequenceFile.Reader reader = new SequenceFile.Reader(fs1, file1, conf);
Writable key = (Writable)
ReflectionUtils.newInstance(reader.getKeyClass(), conf);
@@ -112,6 +116,7 @@ public class HdfsProducerFileWriteTest e
@Test
public void testSequenceKeyWriteFile() throws Exception {
+ final Path file = new Path(new
File("target/test/test-camel-simple-write-file2").getAbsolutePath());
deleteDirectory("target/file-batch3");
context.addRoutes(new RouteBuilder() {
@@ -119,7 +124,7 @@ public class HdfsProducerFileWriteTest e
public void configure() throws Exception {
from("file://target/file-batch3?sortBy=file:name")
.setHeader("KEY").simple("${in.header.CamelFileName}")
-
.to("hdfs://localhost/tmp/test/test-camel-sequence-write-file2?fileSystemType=LOCAL&keyType=TEXT&fileType=SEQUENCE_FILE");
+ .to("hdfs://localhost/" + file.toUri() +
"?fileSystemType=LOCAL&keyType=TEXT&fileType=SEQUENCE_FILE");
}
});
@@ -135,7 +140,7 @@ public class HdfsProducerFileWriteTest e
context.stop();
Configuration conf = new Configuration();
- Path file1 = new
Path("file:///tmp/test/test-camel-sequence-write-file2");
+ Path file1 = new Path("file:///" + file.toUri());
FileSystem fs1 = FileSystem.get(file1.toUri(), conf);
SequenceFile.Reader reader = new SequenceFile.Reader(fs1, file1, conf);
Text key = (Text) ReflectionUtils.newInstance(reader.getKeyClass(),
conf);
@@ -152,6 +157,7 @@ public class HdfsProducerFileWriteTest e
@Test
public void testMapKeyWriteFile() throws Exception {
+ final Path file = new Path(new
File("target/test/test-camel-simple-write-file1").getAbsolutePath());
deleteDirectory("target/file-batch4");
context.addRoutes(new RouteBuilder() {
@@ -159,7 +165,7 @@ public class HdfsProducerFileWriteTest e
public void configure() throws Exception {
from("file://target/file-batch4?sortBy=file:name")
.setHeader("KEY").simple("${in.header.CamelFileName}")
-
.to("hdfs://localhost/tmp/test/test-camel-map-write-file1?fileSystemType=LOCAL&keyType=TEXT&fileType=MAP_FILE");
+ .to("hdfs://localhost/" + file.toUri() +
"?fileSystemType=LOCAL&keyType=TEXT&fileType=MAP_FILE");
}
});
@@ -175,9 +181,9 @@ public class HdfsProducerFileWriteTest e
context.stop();
Configuration conf = new Configuration();
- Path file1 = new Path("file:///tmp/test/test-camel-map-write-file1");
+ Path file1 = new Path("file:///" + file.toUri());
FileSystem fs1 = FileSystem.get(file1.toUri(), conf);
- MapFile.Reader reader = new MapFile.Reader(fs1,
"file:///tmp/test/test-camel-map-write-file1", conf);
+ MapFile.Reader reader = new MapFile.Reader(fs1,
"target/test/test-camel-simple-write-file1", conf);
for (int i = 0; i < 10; ++i) {
Text key = new Text("CIAO" + i);
BytesWritable value = new BytesWritable();
@@ -191,13 +197,14 @@ public class HdfsProducerFileWriteTest e
@Test
public void testSequenceKeyWriteBigFile() throws Exception {
+ final Path file = new Path(new
File("target/test/test-camel-simple-write-file1").getAbsolutePath());
deleteDirectory("target/file-batch5");
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("file://target/file-batch5?sortBy=file:name")
-
.to("hdfs://localhost/tmp/test/test-camel-sequence-write-file3?fileSystemType=LOCAL&fileType=SEQUENCE_FILE&splitStrategy=IDLE:100&checkIdleInterval=10");
+ .to("hdfs://localhost/" + file.toUri() +
"?fileSystemType=LOCAL&fileType=SEQUENCE_FILE&splitStrategy=IDLE:100&checkIdleInterval=10");
}
});
@@ -217,7 +224,7 @@ public class HdfsProducerFileWriteTest e
context.stop();
Configuration conf = new Configuration();
- Path file1 = new
Path("file:///tmp/test/test-camel-sequence-write-file3/" + '/' +
HdfsConstants.DEFAULT_SEGMENT_PREFIX + 0);
+ Path file1 = new Path("file:///" + file.toUri() + '/' +
HdfsConstants.DEFAULT_SEGMENT_PREFIX + 0);
FileSystem fs1 = FileSystem.get(file1.toUri(), conf);
SequenceFile.Reader reader = new SequenceFile.Reader(fs1, file1, conf);
Writable key = (Writable)
ReflectionUtils.newInstance(reader.getKeyClass(), conf);
@@ -234,7 +241,7 @@ public class HdfsProducerFileWriteTest e
public void tearDown() throws Exception {
super.tearDown();
Configuration conf = new Configuration();
- Path dir = new Path("file:///tmp/test");
+ Path dir = new Path("target/test");
FileSystem fs = FileSystem.get(dir.toUri(), conf);
fs.delete(dir, true);
}
Modified:
camel/trunk/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/HdfsProducerSplitTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/HdfsProducerSplitTest.java?rev=1131271&r1=1131270&r2=1131271&view=diff
==============================================================================
---
camel/trunk/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/HdfsProducerSplitTest.java
(original)
+++
camel/trunk/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/HdfsProducerSplitTest.java
Fri Jun 3 22:33:04 2011
@@ -17,6 +17,7 @@
package org.apache.camel.component.hdfs;
import java.io.ByteArrayOutputStream;
+import java.io.File;
import java.io.InputStream;
import java.net.URL;
@@ -30,45 +31,17 @@ import org.apache.hadoop.io.IOUtils;
import org.junit.Test;
public class HdfsProducerSplitTest extends CamelTestSupport {
+
+ private static final Path BASE_FILE = new Path(new
File("target/test/test-camel-simple-write-BASE_FILE").getAbsolutePath());
@Test
public void testSimpleWriteFileWithMessageSplit() throws Exception {
- for (int i = 0; i < 10; ++i) {
- template.sendBody("direct:start1", "CIAO" + i);
- }
- stopCamelContext();
-
- for (int i = 0; i < 10; ++i) {
- InputStream in = null;
- try {
- in = new URL("file:///tmp/test/test-camel-simple-write-file1"
+ '/' + HdfsConstants.DEFAULT_SEGMENT_PREFIX + i).openStream();
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- IOUtils.copyBytes(in, bos, 4096, false);
- Assert.assertEquals("CIAO" + i, new String(bos.toByteArray()));
- } finally {
- IOUtils.closeStream(in);
- }
- }
+ doTest(1);
}
@Test
public void testSimpleWriteFileWithBytesSplit() throws Exception {
- for (int i = 0; i < 10; ++i) {
- template.sendBody("direct:start2", "CIAO" + i);
- }
- stopCamelContext();
-
- for (int i = 0; i < 10; ++i) {
- InputStream in = null;
- try {
- in = new URL("file:///tmp/test/test-camel-simple-write-file2"
+ '/' + HdfsConstants.DEFAULT_SEGMENT_PREFIX + i).openStream();
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- IOUtils.copyBytes(in, bos, 4096, false);
- Assert.assertEquals("CIAO" + i, new String(bos.toByteArray()));
- } finally {
- IOUtils.closeStream(in);
- }
- }
+ doTest(2);
}
@Test
@@ -81,7 +54,7 @@ public class HdfsProducerSplitTest exten
for (int i = 0; i < 3; ++i) {
InputStream in = null;
try {
- in = new URL("file:///tmp/test/test-camel-simple-write-file3"
+ '/' + HdfsConstants.DEFAULT_SEGMENT_PREFIX + i).openStream();
+ in = new URL("file:///" + BASE_FILE.toUri() + "3/" +
HdfsConstants.DEFAULT_SEGMENT_PREFIX + i).openStream();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
IOUtils.copyBytes(in, bos, 4096, false);
Assert.assertEquals("CIAO" + i, new String(bos.toByteArray()));
@@ -93,35 +66,24 @@ public class HdfsProducerSplitTest exten
@Test
public void testSimpleWriteFileWithMessageIdleSplit() throws Exception {
- for (int i = 0; i < 10; ++i) {
- template.sendBody("direct:start4", "CIAO" + i);
- }
- Thread.sleep(2000);
-
- for (int i = 0; i < 10; ++i) {
- InputStream in = null;
- try {
- in = new URL("file:///tmp/test/test-camel-simple-write-file4"
+ '/' + HdfsConstants.DEFAULT_SEGMENT_PREFIX + i).openStream();
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- IOUtils.copyBytes(in, bos, 4096, false);
- Assert.assertEquals("CIAO" + i, new String(bos.toByteArray()));
- } finally {
- IOUtils.closeStream(in);
- }
- }
+ doTest(4);
}
@Test
public void testSimpleWriteFileWithBytesIdleSplit() throws Exception {
+ doTest(5);
+ }
+
+ private void doTest(int routeNr) throws Exception {
for (int i = 0; i < 10; ++i) {
- template.sendBody("direct:start5", "CIAO" + i);
+ template.sendBody("direct:start" + routeNr, "CIAO" + i);
}
- Thread.sleep(2000);
+ stopCamelContext();
for (int i = 0; i < 10; ++i) {
InputStream in = null;
try {
- in = new URL("file:///tmp/test/test-camel-simple-write-file5"
+ '/' + HdfsConstants.DEFAULT_SEGMENT_PREFIX + i).openStream();
+ in = new URL("file:///" + BASE_FILE.toUri() + routeNr + '/' +
HdfsConstants.DEFAULT_SEGMENT_PREFIX + i).openStream();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
IOUtils.copyBytes(in, bos, 4096, false);
Assert.assertEquals("CIAO" + i, new String(bos.toByteArray()));
@@ -136,7 +98,7 @@ public class HdfsProducerSplitTest exten
super.tearDown();
Thread.sleep(100);
Configuration conf = new Configuration();
- Path dir = new Path("file:///tmp/test");
+ Path dir = new Path("target/test");
FileSystem fs = FileSystem.get(dir.toUri(), conf);
fs.delete(dir, true);
}
@@ -146,11 +108,11 @@ public class HdfsProducerSplitTest exten
return new RouteBuilder() {
@Override
public void configure() throws Exception {
-
from("direct:start1").to("hdfs://localhost/tmp/test/test-camel-simple-write-file1?fileSystemType=LOCAL&splitStrategy=MESSAGES:1");
-
from("direct:start2").to("hdfs://localhost/tmp/test/test-camel-simple-write-file2?fileSystemType=LOCAL&splitStrategy=BYTES:5");
-
from("direct:start3").to("hdfs://localhost/tmp/test/test-camel-simple-write-file3?fileSystemType=LOCAL&splitStrategy=IDLE:1000");
-
from("direct:start4").to("hdfs://localhost/tmp/test/test-camel-simple-write-file4?fileSystemType=LOCAL&splitStrategy=IDLE:1000,MESSAGES:1");
-
from("direct:start5").to("hdfs://localhost/tmp/test/test-camel-simple-write-file5?fileSystemType=LOCAL&splitStrategy=IDLE:1000,BYTES:5");
+ from("direct:start1").to("hdfs://localhost/" +
BASE_FILE.toUri() + "1?fileSystemType=LOCAL&splitStrategy=MESSAGES:1");
+ from("direct:start2").to("hdfs://localhost/" +
BASE_FILE.toUri() + "2?fileSystemType=LOCAL&splitStrategy=BYTES:5");
+ from("direct:start3").to("hdfs://localhost/" +
BASE_FILE.toUri() + "3?fileSystemType=LOCAL&splitStrategy=IDLE:1000");
+ from("direct:start4").to("hdfs://localhost/" +
BASE_FILE.toUri() +
"4?fileSystemType=LOCAL&splitStrategy=IDLE:1000,MESSAGES:1");
+ from("direct:start5").to("hdfs://localhost/" +
BASE_FILE.toUri() + "5?fileSystemType=LOCAL&splitStrategy=IDLE:1000,BYTES:5");
}
};
}
Modified:
camel/trunk/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/HdfsProducerTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/HdfsProducerTest.java?rev=1131271&r1=1131270&r2=1131271&view=diff
==============================================================================
---
camel/trunk/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/HdfsProducerTest.java
(original)
+++
camel/trunk/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/HdfsProducerTest.java
Fri Jun 3 22:33:04 2011
@@ -16,6 +16,8 @@
*/
package org.apache.camel.component.hdfs;
+import java.io.File;
+
import junit.framework.Assert;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.junit4.CamelTestSupport;
@@ -38,6 +40,8 @@ import org.apache.hadoop.util.Reflection
import org.junit.Test;
public class HdfsProducerTest extends CamelTestSupport {
+
+ private static final Path TEMP_DIR = new Path(new
File("target/test/").getAbsolutePath());
@Test
public void testProducer() throws Exception {
@@ -46,7 +50,7 @@ public class HdfsProducerTest extends Ca
}
stopCamelContext();
Configuration conf = new Configuration();
- Path file1 = new Path("file:///tmp/test/test-camel1");
+ Path file1 = new Path("file:///" + TEMP_DIR.toUri() + "test-camel1");
FileSystem fs1 = FileSystem.get(file1.toUri(), conf);
SequenceFile.Reader reader = new SequenceFile.Reader(fs1, file1, conf);
Writable key = (Writable)
ReflectionUtils.newInstance(reader.getKeyClass(), conf);
@@ -65,7 +69,7 @@ public class HdfsProducerTest extends Ca
template.sendBody("direct:write_boolean", aBoolean);
stopCamelContext();
Configuration conf = new Configuration();
- Path file1 = new Path("file:///tmp/test/test-camel-boolean");
+ Path file1 = new Path("file:///" + TEMP_DIR.toUri() +
"test-camel-boolean");
FileSystem fs1 = FileSystem.get(file1.toUri(), conf);
SequenceFile.Reader reader = new SequenceFile.Reader(fs1, file1, conf);
Writable key = (Writable)
ReflectionUtils.newInstance(reader.getKeyClass(), conf);
@@ -81,7 +85,7 @@ public class HdfsProducerTest extends Ca
template.sendBody("direct:write_byte", aByte);
stopCamelContext();
Configuration conf = new Configuration();
- Path file1 = new Path("file:///tmp/test/test-camel-byte");
+ Path file1 = new Path("file:///" + TEMP_DIR.toUri() +
"test-camel-byte");
FileSystem fs1 = FileSystem.get(file1.toUri(), conf);
SequenceFile.Reader reader = new SequenceFile.Reader(fs1, file1, conf);
Writable key = (Writable)
ReflectionUtils.newInstance(reader.getKeyClass(), conf);
@@ -97,7 +101,7 @@ public class HdfsProducerTest extends Ca
template.sendBody("direct:write_int", anInt);
stopCamelContext();
Configuration conf = new Configuration();
- Path file1 = new Path("file:///tmp/test/test-camel-int");
+ Path file1 = new Path("file:///" + TEMP_DIR.toUri() +
"test-camel-int");
FileSystem fs1 = FileSystem.get(file1.toUri(), conf);
SequenceFile.Reader reader = new SequenceFile.Reader(fs1, file1, conf);
Writable key = (Writable)
ReflectionUtils.newInstance(reader.getKeyClass(), conf);
@@ -113,7 +117,7 @@ public class HdfsProducerTest extends Ca
template.sendBody("direct:write_float", aFloat);
stopCamelContext();
Configuration conf = new Configuration();
- Path file1 = new Path("file:///tmp/test/test-camel-float");
+ Path file1 = new Path("file:///" + TEMP_DIR.toUri() +
"test-camel-float");
FileSystem fs1 = FileSystem.get(file1.toUri(), conf);
SequenceFile.Reader reader = new SequenceFile.Reader(fs1, file1, conf);
Writable key = (Writable)
ReflectionUtils.newInstance(reader.getKeyClass(), conf);
@@ -129,7 +133,7 @@ public class HdfsProducerTest extends Ca
template.sendBody("direct:write_double", aDouble);
stopCamelContext();
Configuration conf = new Configuration();
- Path file1 = new Path("file:///tmp/test/test-camel-double");
+ Path file1 = new Path("file:///" + TEMP_DIR.toUri() +
"test-camel-double");
FileSystem fs1 = FileSystem.get(file1.toUri(), conf);
SequenceFile.Reader reader = new SequenceFile.Reader(fs1, file1, conf);
Writable key = (Writable)
ReflectionUtils.newInstance(reader.getKeyClass(), conf);
@@ -145,7 +149,7 @@ public class HdfsProducerTest extends Ca
template.sendBody("direct:write_long", aLong);
stopCamelContext();
Configuration conf = new Configuration();
- Path file1 = new Path("file:///tmp/test/test-camel-long");
+ Path file1 = new Path("file:///" + TEMP_DIR.toUri() +
"test-camel-long");
FileSystem fs1 = FileSystem.get(file1.toUri(), conf);
SequenceFile.Reader reader = new SequenceFile.Reader(fs1, file1, conf);
Writable key = (Writable)
ReflectionUtils.newInstance(reader.getKeyClass(), conf);
@@ -161,7 +165,7 @@ public class HdfsProducerTest extends Ca
template.sendBody("direct:write_text1", txt);
stopCamelContext();
Configuration conf = new Configuration();
- Path file1 = new Path("file:///tmp/test/test-camel-text1");
+ Path file1 = new Path("file:///" + TEMP_DIR.toUri() +
"test-camel-text1");
FileSystem fs1 = FileSystem.get(file1.toUri(), conf);
SequenceFile.Reader reader = new SequenceFile.Reader(fs1, file1, conf);
Writable key = (Writable)
ReflectionUtils.newInstance(reader.getKeyClass(), conf);
@@ -178,7 +182,7 @@ public class HdfsProducerTest extends Ca
template.sendBodyAndHeader("direct:write_text2", txtValue, "KEY",
txtKey);
stopCamelContext();
Configuration conf = new Configuration();
- Path file1 = new Path("file:///tmp/test/test-camel-text2");
+ 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);
@@ -195,9 +199,9 @@ public class HdfsProducerTest extends Ca
template.sendBodyAndHeader("direct:write_text3", txtValue, "KEY",
txtKey);
stopCamelContext();
Configuration conf = new Configuration();
- Path file1 = new Path("file:///tmp/test/test-camel-text3");
+ Path file1 = new Path("file:///" + TEMP_DIR.toUri() +
"test-camel-text3");
FileSystem fs1 = FileSystem.get(file1.toUri(), conf);
- MapFile.Reader reader = new MapFile.Reader(fs1,
"file:///tmp/test/test-camel-text3", conf);
+ MapFile.Reader reader = new MapFile.Reader(fs1, "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);
@@ -211,9 +215,9 @@ public class HdfsProducerTest extends Ca
template.sendBody("direct:write_text4", txtValue);
stopCamelContext();
Configuration conf = new Configuration();
- Path file1 = new Path("file:///tmp/test/test-camel-text4");
+ 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:///tmp/test/test-camel-text4", 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);
Assert.assertEquals(value.toString(), txtValue);
@@ -226,9 +230,9 @@ public class HdfsProducerTest extends Ca
template.sendBodyAndHeader("direct:write_text5", txtValue, "KEY",
txtKey);
stopCamelContext();
Configuration conf = new Configuration();
- Path file1 = new Path("file:///tmp/test/test-camel-text5");
+ Path file1 = new Path("file:///" + TEMP_DIR.toUri() +
"test-camel-text5");
FileSystem fs1 = FileSystem.get(file1.toUri(), conf);
- BloomMapFile.Reader reader = new BloomMapFile.Reader(fs1,
"file:///tmp/test/test-camel-text5", conf);
+ BloomMapFile.Reader reader = new BloomMapFile.Reader(fs1, "file:///" +
TEMP_DIR.toUri() + "test-camel-text5", conf);
Text key = (Text) ReflectionUtils.newInstance(reader.getKeyClass(),
conf);
Text value = (Text)
ReflectionUtils.newInstance(reader.getValueClass(), conf);
reader.next(key, value);
@@ -241,7 +245,7 @@ public class HdfsProducerTest extends Ca
super.tearDown();
Thread.sleep(100);
Configuration conf = new Configuration();
- Path dir = new Path("file:///tmp/test");
+ Path dir = new Path("target/test");
FileSystem fs = FileSystem.get(dir.toUri(), conf);
fs.delete(dir, true);
}
@@ -252,33 +256,33 @@ public class HdfsProducerTest extends Ca
@Override
public void configure() throws Exception {
-
from("direct:start1").to("hdfs://localhost/tmp/test/test-camel1?fileSystemType=LOCAL&valueType=TEXT&fileType=SEQUENCE_FILE");
+ from("direct:start1").to("hdfs://localhost/" +
TEMP_DIR.toUri() +
"test-camel1?fileSystemType=LOCAL&valueType=TEXT&fileType=SEQUENCE_FILE");
/* For testing writables */
-
from("direct:write_boolean").to("hdfs://localhost/tmp/test/test-camel-boolean?fileSystemType=LOCAL&valueType=BOOLEAN&fileType=SEQUENCE_FILE");
+ from("direct:write_boolean").to("hdfs://localhost/" +
TEMP_DIR.toUri() +
"test-camel-boolean?fileSystemType=LOCAL&valueType=BOOLEAN&fileType=SEQUENCE_FILE");
-
from("direct:write_byte").to("hdfs://localhost/tmp/test/test-camel-byte?fileSystemType=LOCAL&valueType=BYTE&fileType=SEQUENCE_FILE");
+ from("direct:write_byte").to("hdfs://localhost/" +
TEMP_DIR.toUri() +
"test-camel-byte?fileSystemType=LOCAL&valueType=BYTE&fileType=SEQUENCE_FILE");
-
from("direct:write_int").to("hdfs://localhost/tmp/test/test-camel-int?fileSystemType=LOCAL&valueType=INT&fileType=SEQUENCE_FILE");
+ from("direct:write_int").to("hdfs://localhost/" +
TEMP_DIR.toUri() +
"test-camel-int?fileSystemType=LOCAL&valueType=INT&fileType=SEQUENCE_FILE");
-
from("direct:write_float").to("hdfs://localhost/tmp/test/test-camel-float?fileSystemType=LOCAL&valueType=FLOAT&fileType=SEQUENCE_FILE");
+ from("direct:write_float").to("hdfs://localhost/" +
TEMP_DIR.toUri() +
"test-camel-float?fileSystemType=LOCAL&valueType=FLOAT&fileType=SEQUENCE_FILE");
-
from("direct:write_long").to("hdfs://localhost/tmp/test/test-camel-long?fileSystemType=LOCAL&valueType=LONG&fileType=SEQUENCE_FILE");
+ from("direct:write_long").to("hdfs://localhost/" +
TEMP_DIR.toUri() +
"test-camel-long?fileSystemType=LOCAL&valueType=LONG&fileType=SEQUENCE_FILE");
-
from("direct:write_double").to("hdfs://localhost/tmp/test/test-camel-double?fileSystemType=LOCAL&valueType=DOUBLE&fileType=SEQUENCE_FILE");
+ from("direct:write_double").to("hdfs://localhost/" +
TEMP_DIR.toUri() +
"test-camel-double?fileSystemType=LOCAL&valueType=DOUBLE&fileType=SEQUENCE_FILE");
-
from("direct:write_text1").to("hdfs://localhost/tmp/test/test-camel-text1?fileSystemType=LOCAL&valueType=TEXT&fileType=SEQUENCE_FILE");
+ from("direct:write_text1").to("hdfs://localhost/" +
TEMP_DIR.toUri() +
"test-camel-text1?fileSystemType=LOCAL&valueType=TEXT&fileType=SEQUENCE_FILE");
/* For testing key and value writing */
-
from("direct:write_text2").to("hdfs://localhost/tmp/test/test-camel-text2?fileSystemType=LOCAL&keyType=TEXT&valueType=TEXT&fileType=SEQUENCE_FILE");
+ from("direct:write_text2").to("hdfs://localhost/" +
TEMP_DIR.toUri() +
"test-camel-text2?fileSystemType=LOCAL&keyType=TEXT&valueType=TEXT&fileType=SEQUENCE_FILE");
-
from("direct:write_text3").to("hdfs://localhost/tmp/test/test-camel-text3?fileSystemType=LOCAL&keyType=TEXT&valueType=TEXT&fileType=MAP_FILE");
+ from("direct:write_text3").to("hdfs://localhost/" +
TEMP_DIR.toUri() +
"test-camel-text3?fileSystemType=LOCAL&keyType=TEXT&valueType=TEXT&fileType=MAP_FILE");
/* For testing ArrayFile */
-
from("direct:write_text4").to("hdfs://localhost/tmp/test/test-camel-text4?fileSystemType=LOCAL&valueType=TEXT&fileType=ARRAY_FILE");
+ from("direct:write_text4").to("hdfs://localhost/" +
TEMP_DIR.toUri() +
"test-camel-text4?fileSystemType=LOCAL&valueType=TEXT&fileType=ARRAY_FILE");
/* For testing BloomMapFile */
-
from("direct:write_text5").to("hdfs://localhost/tmp/test/test-camel-text5?fileSystemType=LOCAL&keyType=TEXT&valueType=TEXT&fileType=BLOOMMAP_FILE");
+ from("direct:write_text5").to("hdfs://localhost/" +
TEMP_DIR.toUri() +
"test-camel-text5?fileSystemType=LOCAL&keyType=TEXT&valueType=TEXT&fileType=BLOOMMAP_FILE");
}
};
}