Skip to content

Commit

Permalink
incremental test case updates
Browse files Browse the repository at this point in the history
  • Loading branch information
childsb committed Feb 20, 2013
1 parent 463d0cc commit 44d04d2
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 113 deletions.
135 changes: 135 additions & 0 deletions resources/setup.test.env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@


print_help() {
echo "Usage: $0 [OPTION]..."
echo ""
echo "Options:"
echo " -w, --work <directory> working directory for gluster bricks"
echo " -v, --volume <gluster volume> gluster volume to create"
echo " -h, --help show this message"
echo ""
}

# parse options
while [ "${1+isset}" ]; do
case "$1" in
-v|--volume)
GLUSTER_VOLUME=$2
shift 2
;;
-w|--work)
WORK_DIR=$2
shift 2
;;
-h|--help)
print_help
exit
;;
*)
echo "Error: Unknown option: $1" >&2
exit 1
;;
esac
done

if [ -z ${GLUSTER_VOLUME} ]
then
echo "I am error. No volume specified."
echo ""
print_help
exit 1;
fi

if [ ! -z ${WORK_DIR} ]
then
echo "I am error. No temp directory set."
echo ""
print_help
exit 1;
fi

NUMBER_OF_BRICKS=3

mkdir -p ${WORK_DIR}/rpm
mkdir -p ${WORK_DIR}/bricks
mkdir -p ${WORK_DIR}/blocks



# Grap and extract the RPM
#cd ${WORK_DIR}/rpm
#wget ${GLUSTER_URL}
#rpm2cpio *.rpm | cpio -idmv

#create some loopback bricks

createGlusterVolume(){
LOOP_BRICKS=( )

# TODO: Need to run a force on this command so it doesn't prompt

GLUSTER_VOLUME_CMD="gluster volume create ${GLUSTER_VOLUME} "
HOSTNAME=`hostname`

for (( i = 0 ; i <= ${NUMBER_OF_BRICKS}; i++ ))
do
# Create an empty block device to use as loop back filesystem
BLOCK=${WORK_DIR}/blocks/block${i}
BRICK=${WORK_DIR}/bricks/brick${i}

dd if=/dev/zero of=${BLOCK} bs=1024 count=30720

# find a free loopback device
# LOOP_BRICKS[${i}]=${WORK_DIR}/bricks/brick${i}
LB_BRICK=`losetup -f`
LOOP_BRICKS[${i}]="${LB_BRICK}"


echo "creating loopback file system on loopback: ${LB_BRICK} block: ${BLOCK}"
losetup ${LB_BRICK} ${BLOCK}
echo "Making loopback block brick on ${LB_BRICK}"
# mkfs.xfs -m 1 -v ${BLOCK}
mkfs -t ext4 -m 1 -v ${LB_BRICK}


mkdir -p ${BRICK}
mount -t ext4 $LB_BRICK $BRICK
GLUSTER_VOLUME_CMD="${GLUSTER_VOLUME_CMD} ${HOSTNAME}:${BRICK}"
done

# Run the gluster command to create the volume


echo "running: ${GLUSTER_VOLUME_CMD}"
$GLUSTER_VOLUME_CMD
gluster volume start ${GLUSTER_VOLUME}
}

createCleanupScript(){
# clean up after ourselfs
# create an unmount script for the bricks
echo "#!/bin/sh" > ${WORK_DIR}/cleanup.sh
chmod +x ${WORK_DIR}/cleanup.sh

echo "gluster volume stop ${GLUSTER_VOLUME}" >> ${WORK_DIR}/cleanup.sh
echo "gluster volume delete ${GLUSTER_VOLUME}" >> ${WORK_DIR}/cleanup.sh
# Unmount the bricks and loopback devices

for (( i = 0 ; i <= ${NUMBER_OF_BRICKS}; i++ ))
do
# Create an empty block device to use as loop back filesystem
BLOCK=${WORK_DIR}/blocks/block${i}
BRICK=${WORK_DIR}/bricks/brick${i}
echo "umount $BRICK" >> ${WORK_DIR}/cleanup.sh
echo "losetup -d ${LOOP_BRICKS[$i]}" >> ${WORK_DIR}/cleanup.sh
echo "rm -rf $BLOCK" >> ${WORK_DIR}/cleanup.sh
echo "rm -rf $BRICK" >> ${WORK_DIR}/cleanup.sh

done

echo "rm -rf ${WORK_DIR}" >> ${WORK_DIR}/cleanup.sh
}

createGlusterVolume
createCleanupScript
echo "Cleanup script: ${WORK_DIR}/cleanup.sh"
73 changes: 49 additions & 24 deletions src/test/java/org/gluster/test/TestGlusterMount.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.gluster.test;


import static org.junit.Assert.assertEquals;

import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
Expand All @@ -16,16 +18,32 @@
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.glusterfs.GlusterFileSystem;
import org.junit.After;
import org.junit.Before;


/**
* Unit test for simple App.
*/
public class TestGlusterMount{

@org.junit.Test
public void tesMount() throws Exception{
GlusterFileSystem gfs = new GlusterFileSystem();

protected File tempDirectory;
protected String glusterVolume="hadoop-gluster";
protected GlusterFileSystem gfs;

@Before
public void before() throws Exception{
glusterVolume = System.getProperty("gluster-volume");
tempDirectory = File.createTempFile("temp", Long.toString(System.nanoTime()));

if(glusterVolume==null){
glusterVolume="hadoop-gluster";
}

tempDirectory.mkdirs();
tempDirectory.deleteOnExit();

gfs = new GlusterFileSystem();
Configuration conf = new Configuration();

/* retrieve the local machines hostname */
Expand All @@ -37,19 +55,18 @@ public void tesMount() throws Exception{
e.printStackTrace();
}
String hostname = addr.getHostName();
File temp = null;
File mount = null;
try {
temp = File.createTempFile("temp", Long.toString(System.nanoTime()));
temp.mkdirs();
mount = File.createTempFile("temp", "mount");
mount.mkdirs();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

conf.set("fs.glusterfs.volname", "hadooptest");
File temp = new File(tempDirectory, "hadoop-temp");
File mount = new File(tempDirectory, "mount");

temp.mkdirs();
mount.mkdirs();
temp.delete();
temp.mkdir();
mount.delete();
mount.mkdir();


conf.set("fs.glusterfs.volname", glusterVolume);
conf.set("fs.glusterfs.mount",mount.getAbsolutePath());
conf.set("fs.glusterfs.server",hostname);
conf.set("quick.slave.io", "true");
Expand All @@ -60,7 +77,15 @@ public void tesMount() throws Exception{
// TODO Auto-generated catch block
e1.printStackTrace();
}

}

@org.junit.Test
public void testTextWrite(){
String testString = "Is there anyone out there?";
String readChars = null;


try {
FSDataOutputStream dfsOut = null;
dfsOut = gfs.create(new Path("test1.txt"));
Expand All @@ -70,21 +95,21 @@ public void tesMount() throws Exception{
// TODO Auto-generated catch block
e.printStackTrace();
}
String readChars = null;

try {
FSDataInputStream dfsin = null;
gfs.initialize(temp.toURI(), conf);

dfsin = gfs.open(new Path("test1.txt"));
readChars = dfsin.readUTF();
dfsin.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}





assertEquals(testString, readChars);
}




}
89 changes: 0 additions & 89 deletions tools/setup.test.env.sh

This file was deleted.

0 comments on commit 44d04d2

Please sign in to comment.