Search in sources :

Example 1 with TestHookOperationContext

use of org.apache.hadoop.fs.azure.AzureNativeFileSystemStore.TestHookOperationContext in project hadoop by apache.

the class TestBlobDataValidation method testCheckBlockMd5.

private void testCheckBlockMd5(final boolean expectMd5Checked) throws Exception {
    assumeNotNull(testAccount);
    Path testFilePath = new Path("/testFile");
    // Add a hook to check that for GET/PUT requests we set/don't set
    // the block-level MD5 field as configured. I tried to do clever
    // testing by also messing with the raw data to see if we actually
    // validate the data as expected, but the HttpURLConnection wasn't
    // pluggable enough for me to do that.
    testAccount.getFileSystem().getStore().addTestHookToOperationContext(new TestHookOperationContext() {

        @Override
        public OperationContext modifyOperationContext(OperationContext original) {
            original.getResponseReceivedEventHandler().addListener(new ContentMD5Checker(expectMd5Checked));
            return original;
        }
    });
    OutputStream outStream = testAccount.getFileSystem().create(testFilePath);
    outStream.write(new byte[] { 5, 15 });
    outStream.close();
    InputStream inStream = testAccount.getFileSystem().open(testFilePath);
    byte[] inBuf = new byte[100];
    while (inStream.read(inBuf) > 0) {
    //nothing;
    }
    inStream.close();
}
Also used : Path(org.apache.hadoop.fs.Path) OperationContext(com.microsoft.azure.storage.OperationContext) TestHookOperationContext(org.apache.hadoop.fs.azure.AzureNativeFileSystemStore.TestHookOperationContext) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) TestHookOperationContext(org.apache.hadoop.fs.azure.AzureNativeFileSystemStore.TestHookOperationContext)

Aggregations

OperationContext (com.microsoft.azure.storage.OperationContext)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Path (org.apache.hadoop.fs.Path)1 TestHookOperationContext (org.apache.hadoop.fs.azure.AzureNativeFileSystemStore.TestHookOperationContext)1