Skip to content

Commit 65a3d06

Browse files
committed
Rework of the JUNIT code. Creates HCFS test framework and testing harnace to easily replace the basic FileSystem implementer that the unit tests run against.
To test o.a.h.f.FileSystem based class, create a class that implements o.a.h.h.t.c.HcfsTestConnectorInterface. The test connector allows for non-standard configuration and instantiation of the FileSytem. If a file system doesn't need additional configuration, then the default HcfsTestConnector class can be used, and the FileSystem classname given in the HCFS_CLASSNAME env variable. Next, set these environment variables: export HCFS_FILE_SYSTEM_CONNECTOR=org.apache.hadoop.hcfs.test.connector.glusterfs.GlusterFileSystemTestConnector export HCFS_CLASSNAME=org.apache.hadoop.fs.glusterfs.GlusterFileSystem Finall, run the tests. This is demonstrated for both of the GlusterFileSystem classes in the test.sh script. ((the pre-mounted gluster volume must also be specified for glusterfs)).
1 parent 1487714 commit 65a3d06

14 files changed

+296
-326
lines changed

README

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ CONFIGURATION
100100
The default FileSystem API to use (there is little reason to modify this).
101101

102102
name: fs.default.name
103-
value: glusterfs://server:port
103+
value: glusterfs:///
104104

105105
The default name that hadoop uses to represent file as a URI (typically a server:port tuple). Use any host
106106
in the cluster as the server and any port number. This option has to be in server:port format for hadoop
@@ -115,10 +115,10 @@ CONFIGURATION
115115
name: fs.glusterfs.mount
116116
value: /mnt/glusterfs
117117

118-
This is the directory that the plugin will use to mount (FUSE mount) the volume.
118+
This is the directory where the gluster volume is mounted
119119

120120
name: fs.glusterfs.server
121-
value: 192.168.1.36, hackme.zugzug.org
121+
value: localhost
122122

123123
To mount a volume the plugin needs to know the hostname or the IP of a GlusterFS server in the cluster.
124124
Mention it here.
@@ -180,8 +180,9 @@ The unit tests read test resources from glusterconfig.properties - a file which
180180

181181
1) edit your .bashrc, or else at your terminal run :
182182

183-
export GLUSTER_VOLUME=MyVolume <-- replace with your preferred volume name (default is HadoopVol)
184-
export GLUSTER_HOST=192.0.1.2 <-- replace with your host (default will be determined at runtime in the JVM)
183+
export GLUSTER_MOUNT=/mnt/glusterfs
184+
export HCFS_FILE_SYSTEM_CONNECTOR=org.apache.hadoop.hcfs.test.connector.glusterfs.GlusterFileSystemTestConnector
185+
export HCFS_CLASSNAME=org.apache.hadoop.fs.glusterfs.GlusterFileSystem
185186

186187
2) run:
187188
mvn package

pom.xml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,24 @@
5050
<version>2.14</version>
5151
<configuration>
5252
<!--
53-
run "export GLUSTER_HOST=192.X.X.1
54-
export GLUSTER_VOLUME=volname"
53+
run "export GLUSTER_MOUNT=/mnt/glusterfs
54+
export HCFS_FILE_SYSTEM_CONNECTOR=org.gluster.test.GlusterFileSystemTestConnector
55+
export HCFS_CLASSNAME=org.apache.hadoop.fs.glusterfs.GlusterFileSystem"
5556
-->
5657
<systemProperties>
5758
<property>
58-
<name>GLUSTER_HOST</name>
59-
<value>${GLUSTER_HOST}</value>
59+
<name>GLUSTER_MOUNT</name>
60+
<value>${GLUSTER_MOUNT}</value>
6061
</property>
61-
<property>
62-
<name>GLUSTER_VOLUME</name>
63-
<value>${GLUSTER_VOLUME}</value>
62+
<property>
63+
<name>HCFS_CLASSNAME</name>
64+
<value>${HCFS_CLASSNAME}</value>
65+
</property>
66+
<property>
67+
<name>HCFS_FILE_SYSTEM_CONNECTOR</name>
68+
<value>${HCFS_FILE_SYSTEM_CONNECTOR}</value>
6469
</property>
70+
6571
</systemProperties>
6672
</configuration>
6773
</plugin>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.apache.hadoop.hcfs.test.connector;
2+
3+
import java.io.IOException;
4+
5+
import org.apache.hadoop.conf.Configuration;
6+
import org.apache.hadoop.fs.FileSystem;
7+
8+
/*
9+
* Generic HCFS file system test connector.
10+
* This test connector takes a fully qualified o.a.h.f.FileSystem implementor class
11+
* as an environment variable.
12+
*
13+
*/
14+
public class HcfsTestConnector implements HcfsTestConnectorInterface{
15+
16+
public Configuration createConfiguration(){
17+
return new Configuration();
18+
}
19+
20+
public FileSystem create(String HcfsClassName) throws IOException{
21+
try {
22+
FileSystem hcfs = (FileSystem)Class.forName(HcfsClassName).newInstance();
23+
hcfs.initialize(hcfs.getUri(), createConfiguration());
24+
return hcfs;
25+
} catch (Exception e) {
26+
throw new RuntimeException("Cannont instatiate HCFS. Error:\n " + e);
27+
}
28+
}
29+
30+
public FileSystem create() throws IOException {
31+
return create(System.getProperty("HCFS_CLASSNAME"));
32+
}
33+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.apache.hadoop.hcfs.test.connector;
2+
3+
4+
public class HcfsTestConnectorFactory {
5+
6+
/* Loads an HCFS file system adapter via environment variable */
7+
public static HcfsTestConnectorInterface getHcfsTestConnector() throws RuntimeException{
8+
return getHcfsTestConnector(System.getProperty("HCFS_FILE_SYSTEM_CONNECTOR"));
9+
}
10+
11+
public static HcfsTestConnectorInterface getHcfsTestConnector(String hcfsName) throws RuntimeException{
12+
try {
13+
return (HcfsTestConnectorInterface)Class.forName(hcfsName).newInstance();
14+
} catch (Exception e) {
15+
throw new RuntimeException("Cannont instatiate HCFS File System from HCFS_FILE_SYSTEM env variable. Error:\n " + e);
16+
}
17+
18+
}
19+
20+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.apache.hadoop.hcfs.test.connector;
2+
3+
import java.io.IOException;
4+
5+
import org.apache.hadoop.conf.Configuration;
6+
import org.apache.hadoop.fs.FileSystem;
7+
8+
9+
/* generic interface for creating HCFS file sytems for testing purposes */
10+
11+
public interface HcfsTestConnectorInterface {
12+
13+
/* return a fully configured instantiated file system for testing */
14+
public FileSystem create() throws IOException;
15+
16+
/* returns a configuration file with properties for a given FS */
17+
public Configuration createConfiguration();
18+
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.apache.hadoop.hcfs.test.connector.glusterfs;
2+
3+
import org.apache.hadoop.conf.Configuration;
4+
import org.apache.hadoop.hcfs.test.connector.HcfsTestConnector;
5+
6+
/**
7+
* A HCFS test connector specifically for instantiation and testing Glusterfs.
8+
*/
9+
public class GlusterFileSystemTestConnector extends HcfsTestConnector{
10+
11+
public Configuration createConfiguration(){
12+
Configuration c = super.createConfiguration();
13+
c.set("fs.glusterfs.mount",System.getProperty("GLUSTER_MOUNT"));
14+
c.set("fs.glusterfs.impl","org.apache.hadoop.fs.local.GlusterFs");
15+
c.set("fs.default.name","glusterfs:///");
16+
return c;
17+
}
18+
19+
}

src/test/java/org/gluster/test/TestGlusterFileSystemContract.java renamed to src/test/java/org/apache/hadoop/hcfs/test/unit/HcfsFileSystemContractBaseTest.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,27 @@
1616
* limitations under the License.
1717
*/
1818

19-
package org.gluster.test;
19+
package org.apache.hadoop.hcfs.test.unit;
2020

2121
import java.io.IOException;
2222

2323
import org.apache.hadoop.fs.FileSystemContractBaseTest;
24+
import org.apache.hadoop.hcfs.test.connector.HcfsTestConnectorFactory;
25+
import org.apache.hadoop.hcfs.test.connector.HcfsTestConnectorInterface;
2426
import org.slf4j.LoggerFactory;
2527

2628
/**
2729
* This is the full filesystem contract test -which requires the
2830
* Default config set up to point to a filesystem
2931
*/
30-
public class TestGlusterFileSystemContract
32+
public class HcfsFileSystemContractBaseTest
3133
extends FileSystemContractBaseTest {
32-
private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(TestGlusterFileSystemContract.class);
34+
private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(HcfsFileSystemContractBaseTest.class);
3335

3436
@Override
3537
protected void setUp() throws Exception{
36-
fs=GFSUtil.create(true);
38+
HcfsTestConnectorInterface connector = HcfsTestConnectorFactory.getHcfsTestConnector();
39+
fs=connector.create();
3740
super.setUp();
3841
}
3942

0 commit comments

Comments
 (0)