Remove unneeded InputSupplier helper

Also convert byte[] to HashCode.
This commit is contained in:
Andrew Gaul 2014-07-10 22:36:32 -07:00
parent f4eca0422d
commit cf830af4d2

View File

@ -79,7 +79,6 @@ import com.google.common.hash.HashCode;
import com.google.common.io.ByteSource; import com.google.common.io.ByteSource;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;
import com.google.common.io.Files; import com.google.common.io.Files;
import com.google.common.io.InputSupplier;
import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.Uninterruptibles; import com.google.common.util.concurrent.Uninterruptibles;
@ -97,10 +96,6 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
oneHundredOneConstitutionsMD5 = oneHundredOneConstitutions.hash(md5()).asBytes(); oneHundredOneConstitutionsMD5 = oneHundredOneConstitutions.hash(md5()).asBytes();
} }
private static byte[] md5Supplier(InputSupplier<? extends InputStream> supplier) throws IOException {
return ByteStreams.hash(supplier, md5()).asBytes();
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static ByteSource getTestDataSupplier() throws IOException { public static ByteSource getTestDataSupplier() throws IOException {
byte[] oneConstitution = ByteStreams.toByteArray(new GZIPInputStream(BaseJettyTest.class byte[] oneConstitution = ByteStreams.toByteArray(new GZIPInputStream(BaseJettyTest.class
@ -134,7 +129,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
createTestInput(32 * 1024).copyTo(Files.asByteSink(payloadFile)); createTestInput(32 * 1024).copyTo(Files.asByteSink(payloadFile));
final Payload testPayload = Payloads.newFilePayload(payloadFile); final Payload testPayload = Payloads.newFilePayload(payloadFile);
final byte[] md5 = md5Supplier(testPayload); final HashCode md5 = ByteStreams.hash(testPayload, md5());
testPayload.getContentMetadata().setContentType("image/png"); testPayload.getContentMetadata().setContentType("image/png");
final AtomicInteger blobCount = new AtomicInteger(); final AtomicInteger blobCount = new AtomicInteger();
@ -153,8 +148,8 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
assertConsistencyAwareBlobExists(container, name); assertConsistencyAwareBlobExists(container, name);
blob = view.getBlobStore().getBlob(container, name); blob = view.getBlobStore().getBlob(container, name);
assert Arrays.equals(md5Supplier(blob.getPayload()), md5) : String.format( assertEquals(ByteStreams.hash(blob.getPayload(), md5()), md5,
"md5 didn't match on %s/%s", container, name); String.format("md5 didn't match on %s/%s", container, name));
view.getBlobStore().removeBlob(container, name); view.getBlobStore().removeBlob(container, name);
assertConsistencyAwareBlobDoesntExist(container, name); assertConsistencyAwareBlobDoesntExist(container, name);
@ -192,7 +187,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
public Void apply(Blob from) { public Void apply(Blob from) {
try { try {
validateMetadata(from.getMetadata(), container, name); validateMetadata(from.getMetadata(), container, name);
assertEquals(md5Supplier(from.getPayload()), supplier.hash(md5()).asBytes()); assertEquals(ByteStreams.hash(from.getPayload(), md5()), supplier.hash(md5()));
checkContentDisposition(from, expectedContentDisposition); checkContentDisposition(from, expectedContentDisposition);
} catch (IOException e) { } catch (IOException e) {
Throwables.propagate(e); Throwables.propagate(e);