Skip to content

Commit

Permalink
new feature: validations via expected conditions (using 0 time wait i.e.
Browse files Browse the repository at this point in the history
invoking the apply method only once)
  • Loading branch information
aharon hacmon committed Jan 26, 2014
1 parent 5035ae2 commit 9f7f26e
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package il.co.topq.integframework.hdfs;

import static org.apache.hadoop.io.IOUtils.copyBytes;
import il.co.topq.integframework.hdfs.support.HdfsExpectedCondition;
import il.co.topq.integframework.hdfs.support.HdfsWait;
import il.co.topq.integframework.support.TimeoutException;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
Expand All @@ -13,6 +15,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.util.EnumSet;
import java.util.concurrent.TimeUnit;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.CreateFlag;
Expand All @@ -26,6 +29,8 @@
import org.apache.hadoop.hdfs.protocol.HdfsConstants;
import org.apache.hadoop.security.AccessControlException;

import com.google.common.base.Predicate;

public class HDFSSystemModule {

protected final Hdfs hdfs;
Expand Down Expand Up @@ -73,4 +78,26 @@ public void copyFromRemote(Path src, File dst)
true);
}

public <T> T validateThat(HdfsExpectedCondition<T> expectedCondition) throws Exception{
HdfsWait oldWait = this.wait;
this.wait = new HdfsWait(hdfs);
wait.withTimeout(0, TimeUnit.MILLISECONDS);
try {
return wait.until(expectedCondition);
}
catch (TimeoutException exception){
if (exception instanceof Exception) {
Exception ex = (Exception) exception;
throw ex;
}
throw new Exception(exception.getCause());
} finally {
this.wait=oldWait;
}

}

public boolean validateThat(Predicate<Hdfs> predicate){
return predicate.apply(hdfs);
}
}

0 comments on commit 9f7f26e

Please sign in to comment.