mirror of https://github.com/apache/jclouds.git
enhanced error checking on test
git-svn-id: http://jclouds.googlecode.com/svn/trunk@69 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
86a2e33f7e
commit
d6284ea47e
|
@ -36,8 +36,10 @@ import java.util.concurrent.CompletionService;
|
|||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorCompletionService;
|
||||
|
||||
import static junit.framework.Assert.*;
|
||||
|
||||
/**
|
||||
* // TODO: Adrian: Document this!
|
||||
* This tests the performance of Digest commands.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
|
@ -45,46 +47,60 @@ import java.util.concurrent.ExecutorCompletionService;
|
|||
public class S3UtilsTest extends PerformanceTest {
|
||||
|
||||
@Test(dataProvider = "hmacsha1")
|
||||
void testBouncyCastleDigestSerialResponseTime(byte[] key, String message, String base64Digest) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException {
|
||||
for (int i = 0; i < 10000; i++)
|
||||
testBouncyCastleDigest(key, message, base64Digest);
|
||||
void testBouncyCastleDigestSerialResponseTime(byte[] key, String message,
|
||||
String base64Digest) throws NoSuchProviderException,
|
||||
NoSuchAlgorithmException, InvalidKeyException {
|
||||
for (int i = 0; i < 10000; i++)
|
||||
testBouncyCastleDigest(key, message, base64Digest);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "hmacsha1")
|
||||
void testBouncyCastleDigestParallelResponseTime(final byte[] key, final String message, final String base64Digest) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException, InterruptedException, ExecutionException {
|
||||
CompletionService<Boolean> completer = new ExecutorCompletionService<Boolean>(exec);
|
||||
for (int i = 0; i < 10000; i++)
|
||||
completer.submit(new Callable<Boolean>() {
|
||||
public Boolean call() {
|
||||
try {
|
||||
testBouncyCastleDigest(key, message, base64Digest);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
for (int i = 0; i < 10000; i++) assert completer.take().get();
|
||||
void testBouncyCastleDigestParallelResponseTime(final byte[] key,
|
||||
final String message, final String base64Digest)
|
||||
throws NoSuchProviderException, NoSuchAlgorithmException,
|
||||
InvalidKeyException, InterruptedException, ExecutionException {
|
||||
CompletionService<Boolean> completer = new ExecutorCompletionService<Boolean>(
|
||||
exec);
|
||||
for (int i = 0; i < 10000; i++)
|
||||
completer.submit(new Callable<Boolean>() {
|
||||
public Boolean call() throws Exception {
|
||||
testBouncyCastleDigest(key, message, base64Digest);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
for (int i = 0; i < 10000; i++)
|
||||
assert completer.take().get();
|
||||
}
|
||||
|
||||
public final static Object[][] base64KeyMessageDigest = {
|
||||
{Base64.decode("CwsLCwsLCwsLCwsLCwsLCwsLCws="), "Hi There", "thcxhlUFcmTii8C2+zeMjvFGvgA="},
|
||||
{Base64.decode("SmVmZQ=="), "what do ya want for nothing?", "7/zfauXrL6LSdBbV8YTfnCWafHk="},
|
||||
{Base64.decode("DAwMDAwMDAwMDAwMDAwMDAwMDAw="), "Test With Truncation", "TBoDQktV4H/n8nvh1Yu5MkqaWgQ="},
|
||||
{Base64.decode("qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqo="), "Test Using Larger Than Block-Size Key - Hash Key First", "qkrl4VJy0A6VcFY3zoo7Ve1AIRI="},
|
||||
{Base64.decode("qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqo="), "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data", "6OmdD0UjfXhta7qnllx4CLv/GpE="}
|
||||
};
|
||||
{ Base64.decode("CwsLCwsLCwsLCwsLCwsLCwsLCws="), "Hi There",
|
||||
"thcxhlUFcmTii8C2+zeMjvFGvgA=" },
|
||||
{ Base64.decode("SmVmZQ=="), "what do ya want for nothing?",
|
||||
"7/zfauXrL6LSdBbV8YTfnCWafHk=" },
|
||||
{ Base64.decode("DAwMDAwMDAwMDAwMDAwMDAwMDAw="),
|
||||
"Test With Truncation", "TBoDQktV4H/n8nvh1Yu5MkqaWgQ=" },
|
||||
{
|
||||
Base64
|
||||
.decode("qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqo="),
|
||||
"Test Using Larger Than Block-Size Key - Hash Key First",
|
||||
"qkrl4VJy0A6VcFY3zoo7Ve1AIRI=" },
|
||||
{
|
||||
Base64
|
||||
.decode("qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqo="),
|
||||
"Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
|
||||
"6OmdD0UjfXhta7qnllx4CLv/GpE=" } };
|
||||
|
||||
@DataProvider(name = "hmacsha1")
|
||||
public Object[][] createData1() {
|
||||
return base64KeyMessageDigest;
|
||||
return base64KeyMessageDigest;
|
||||
}
|
||||
|
||||
|
||||
@Test(dataProvider = "hmacsha1")
|
||||
public void testBouncyCastleDigest(byte[] key, String message, String base64Digest) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException {
|
||||
String b64 = S3Utils.digest(message, key);
|
||||
assert b64.equals(base64Digest);
|
||||
public void testBouncyCastleDigest(byte[] key, String message,
|
||||
String base64Digest) throws NoSuchProviderException,
|
||||
NoSuchAlgorithmException, InvalidKeyException {
|
||||
String b64 = S3Utils.digest(message, key);
|
||||
assertEquals(b64, base64Digest);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue