Repository: metamodel Updated Branches: refs/heads/master d43e907d9 -> 8156d76fd
Added a proper integration test for the HdfsResource Project: http://git-wip-us.apache.org/repos/asf/metamodel/repo Commit: http://git-wip-us.apache.org/repos/asf/metamodel/commit/4496872e Tree: http://git-wip-us.apache.org/repos/asf/metamodel/tree/4496872e Diff: http://git-wip-us.apache.org/repos/asf/metamodel/diff/4496872e Branch: refs/heads/master Commit: 4496872efafd823cfc3331c1771f7fcdef8f66b7 Parents: bbc460f Author: Kasper Sørensen <[email protected]> Authored: Sat Jun 13 20:01:22 2015 +0200 Committer: Kasper Sørensen <[email protected]> Committed: Sat Jun 13 20:01:22 2015 +0200 ---------------------------------------------------------------------- ...del-integrationtest-configuration.properties | 9 +++ .../util/HdfsResourceIntegrationTest.java | 81 ++++++++++++++++++++ 2 files changed, 90 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/metamodel/blob/4496872e/example-metamodel-integrationtest-configuration.properties ---------------------------------------------------------------------- diff --git a/example-metamodel-integrationtest-configuration.properties b/example-metamodel-integrationtest-configuration.properties index ad556db..8f726fa 100644 --- a/example-metamodel-integrationtest-configuration.properties +++ b/example-metamodel-integrationtest-configuration.properties @@ -22,6 +22,15 @@ #mongodb.databaseName=metamodel_test #mongodb.collectionName=my_collection +# ------------------------- +# Hadoop module properties: +# ------------------------- + +#hadoop.hdfs.hostname=localhost +#hadoop.hdfs.port=9000 +#hadoop.hdfs.file.path=/apache_metamodel_testfile.txt + + # ------------------------ # HBase module properties: # ------------------------ http://git-wip-us.apache.org/repos/asf/metamodel/blob/4496872e/hadoop/src/test/java/org/apache/metamodel/util/HdfsResourceIntegrationTest.java ---------------------------------------------------------------------- diff --git a/hadoop/src/test/java/org/apache/metamodel/util/HdfsResourceIntegrationTest.java b/hadoop/src/test/java/org/apache/metamodel/util/HdfsResourceIntegrationTest.java new file mode 100644 index 0000000..02a5dc8 --- /dev/null +++ b/hadoop/src/test/java/org/apache/metamodel/util/HdfsResourceIntegrationTest.java @@ -0,0 +1,81 @@ +package org.apache.metamodel.util; + +import java.io.File; +import java.io.FileReader; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Properties; + +import junit.framework.TestCase; + +public class HdfsResourceIntegrationTest extends TestCase { + + private boolean _configured; + private Properties _properties; + private String _filePath; + private String _hostname; + private int _port; + + @Override + protected final void setUp() throws Exception { + super.setUp(); + + _properties = new Properties(); + final File file = new File(getPropertyFilePath()); + if (file.exists()) { + _properties.load(new FileReader(file)); + _filePath = _properties.getProperty("hadoop.hdfs.file.path"); + _hostname = _properties.getProperty("hadoop.hdfs.hostname"); + final String portString = _properties.getProperty("hadoop.hdfs.port"); + _configured = _filePath != null && _hostname != null && portString != null; + if (_configured) { + _port = Integer.parseInt(portString); + } + } else { + _configured = false; + } + } + + private String getPropertyFilePath() { + String userHome = System.getProperty("user.home"); + return userHome + "/metamodel-integrationtest-configuration.properties"; + } + + public void testReadOnRealHdfsInstall() throws Exception { + if (!_configured) { + System.err.println("!!! WARN !!! Hadoop HDFS integration test ignored\r\n" + + "Please configure Hadoop HDFS test-properties (" + getPropertyFilePath() + + "), to run integration tests"); + return; + } + final String contentString = "fun and games with Apache MetaModel and Hadoop is what we do"; + final HdfsResource res1 = new HdfsResource(_hostname, _port, _filePath); + try { + assertFalse(res1.isExists()); + + res1.write(new Action<OutputStream>() { + @Override + public void run(OutputStream out) throws Exception { + out.write(contentString.getBytes()); + } + }); + + assertTrue(res1.isExists()); + + final String str = res1.read(new Func<InputStream, String>() { + @Override + public String eval(InputStream in) { + return FileHelper.readInputStreamAsString(in, "UTF8"); + } + }); + + assertEquals(contentString, str); + res1.getHadoopFileSystem().delete(res1.getHadoopPath(), false); + + assertFalse(res1.isExists()); + + } finally { + res1.close(); + } + } +}
