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.ExecutionException;
|
||||||
import java.util.concurrent.ExecutorCompletionService;
|
import java.util.concurrent.ExecutorCompletionService;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* // TODO: Adrian: Document this!
|
* This tests the performance of Digest commands.
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
|
@ -45,46 +47,60 @@ import java.util.concurrent.ExecutorCompletionService;
|
||||||
public class S3UtilsTest extends PerformanceTest {
|
public class S3UtilsTest extends PerformanceTest {
|
||||||
|
|
||||||
@Test(dataProvider = "hmacsha1")
|
@Test(dataProvider = "hmacsha1")
|
||||||
void testBouncyCastleDigestSerialResponseTime(byte[] key, String message, String base64Digest) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException {
|
void testBouncyCastleDigestSerialResponseTime(byte[] key, String message,
|
||||||
for (int i = 0; i < 10000; i++)
|
String base64Digest) throws NoSuchProviderException,
|
||||||
testBouncyCastleDigest(key, message, base64Digest);
|
NoSuchAlgorithmException, InvalidKeyException {
|
||||||
|
for (int i = 0; i < 10000; i++)
|
||||||
|
testBouncyCastleDigest(key, message, base64Digest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dataProvider = "hmacsha1")
|
@Test(dataProvider = "hmacsha1")
|
||||||
void testBouncyCastleDigestParallelResponseTime(final byte[] key, final String message, final String base64Digest) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException, InterruptedException, ExecutionException {
|
void testBouncyCastleDigestParallelResponseTime(final byte[] key,
|
||||||
CompletionService<Boolean> completer = new ExecutorCompletionService<Boolean>(exec);
|
final String message, final String base64Digest)
|
||||||
for (int i = 0; i < 10000; i++)
|
throws NoSuchProviderException, NoSuchAlgorithmException,
|
||||||
completer.submit(new Callable<Boolean>() {
|
InvalidKeyException, InterruptedException, ExecutionException {
|
||||||
public Boolean call() {
|
CompletionService<Boolean> completer = new ExecutorCompletionService<Boolean>(
|
||||||
try {
|
exec);
|
||||||
testBouncyCastleDigest(key, message, base64Digest);
|
for (int i = 0; i < 10000; i++)
|
||||||
return true;
|
completer.submit(new Callable<Boolean>() {
|
||||||
} catch (Exception e) {
|
public Boolean call() throws Exception {
|
||||||
return false;
|
testBouncyCastleDigest(key, message, base64Digest);
|
||||||
}
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
for (int i = 0; i < 10000; i++) assert completer.take().get();
|
for (int i = 0; i < 10000; i++)
|
||||||
|
assert completer.take().get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final static Object[][] base64KeyMessageDigest = {
|
public final static Object[][] base64KeyMessageDigest = {
|
||||||
{Base64.decode("CwsLCwsLCwsLCwsLCwsLCwsLCws="), "Hi There", "thcxhlUFcmTii8C2+zeMjvFGvgA="},
|
{ Base64.decode("CwsLCwsLCwsLCwsLCwsLCwsLCws="), "Hi There",
|
||||||
{Base64.decode("SmVmZQ=="), "what do ya want for nothing?", "7/zfauXrL6LSdBbV8YTfnCWafHk="},
|
"thcxhlUFcmTii8C2+zeMjvFGvgA=" },
|
||||||
{Base64.decode("DAwMDAwMDAwMDAwMDAwMDAwMDAw="), "Test With Truncation", "TBoDQktV4H/n8nvh1Yu5MkqaWgQ="},
|
{ Base64.decode("SmVmZQ=="), "what do ya want for nothing?",
|
||||||
{Base64.decode("qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqo="), "Test Using Larger Than Block-Size Key - Hash Key First", "qkrl4VJy0A6VcFY3zoo7Ve1AIRI="},
|
"7/zfauXrL6LSdBbV8YTfnCWafHk=" },
|
||||||
{Base64.decode("qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqo="), "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data", "6OmdD0UjfXhta7qnllx4CLv/GpE="}
|
{ 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")
|
@DataProvider(name = "hmacsha1")
|
||||||
public Object[][] createData1() {
|
public Object[][] createData1() {
|
||||||
return base64KeyMessageDigest;
|
return base64KeyMessageDigest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test(dataProvider = "hmacsha1")
|
@Test(dataProvider = "hmacsha1")
|
||||||
public void testBouncyCastleDigest(byte[] key, String message, String base64Digest) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException {
|
public void testBouncyCastleDigest(byte[] key, String message,
|
||||||
String b64 = S3Utils.digest(message, key);
|
String base64Digest) throws NoSuchProviderException,
|
||||||
assert b64.equals(base64Digest);
|
NoSuchAlgorithmException, InvalidKeyException {
|
||||||
|
String b64 = S3Utils.digest(message, key);
|
||||||
|
assertEquals(b64, base64Digest);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue