Azure for Java Lab1 テストが全部通った!

やっと全部通った。Azure for Java Lab1 の testBlob_wFile、testBlob_wFile_wMetadata のテストが失敗する原因 - お だ のスペース で testBlob_wFile と testBlob_wFile_wMetadata を同時に実行すると失敗してましたが、これも解決しました!
BlobSample.java に getBlob_wFile_wMetadata というメソッドがあります。これは、渡されたファイルパスにファイルが存在していたら削除しその後、Azure Storage からデータを取得して指定されたファイルパスに出力する処理を行っています。

BlobSample.java Line 799 - 886 抜粋

  public static boolean getBlob_wFile_wMetadata (  
                                      BlobContainer objBlobContainer, 
                                      String strBlobName,
                                      String strFilePath,
                                      NameValueCollection objMetadata,
                                      boolean fOverwrite
                                      )
    throws Exception
  {
    boolean fSuccess = false;
    
    if ( null == objBlobContainer ) {
      throw new IllegalArgumentException("BlobContainer parameter is invalid!");
    }
    if ( ( null == strBlobName ) || strBlobName.isEmpty() ) {
      throw new IllegalArgumentException("Blob Name parameter is invalid!");
    }
    if ( null == strFilePath || strFilePath.isEmpty() ) {
      throw new IllegalArgumentException("File Path parameter is invalid!");
    }

    try  {
      if (!objBlobContainer.doesContainerExist()) {
        throw new IllegalArgumentException("BlobContainer does not exist!");
      }
      if ( !objBlobContainer.doesBlobExist(strBlobName) ) { 
        throw new Exception("Blob does not exist!");
      }
      
      /* Delete if it exists and only if overwrite is OK (true). */
      File objFile = new File(strFilePath);
      if( null != objFile && objFile.exists()) {
        if (!fOverwrite) {
          throw new Exception(String.format("Cannot overwrite, File '%s' exists!", strFilePath));
        }
        
        if( !objFile.delete() ) {
          throw new Exception(String.format("File '%s' was not deleted!", strFilePath));
        }
      }

      FileStream objStream          = new FileStream(strFilePath);
      BlobContents objBlobContents  = new BlobContents(objStream);
      boolean fTransferAsChunks     = false;

      BlobProperties objBlobProperties 
          = objBlobContainer.getBlob( strBlobName, 
                                      objBlobContents, 
                                      fTransferAsChunks
                                      );

      if (null == objBlobProperties) {
        throw new NullPointerException("BlobProperties");
      }
      
      /* Get Blob properties */
      String strContentType  = objBlobProperties.getContentType();
      if (!strContentType.equals(CONTENT_TYPE_FILE)) {
        throw new Exception(String.format("Wrong content type: '%s'!", strContentType));
      }

      String strBlobNameProp = objBlobProperties.getName();
      if ( !strBlobName.equals(strBlobNameProp) ) {
        throw new Exception(String.format("Wrong blob: '%s'!", strBlobNameProp));
      }

      /* Get Blob metadata */
      if ( null != objMetadata ) {
        objMetadata = objBlobProperties.getMetadata();
      }

      /* Validate if file was retrieved from blob. */
      objFile = new File(strFilePath);
      if( null == objFile || !objFile.exists()) {
        throw new Exception(String.format("File '%s' was not created!", strFilePath));
      }

      fSuccess = true;
    } catch (SecurityException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } catch ( Exception e ) {
      e.printStackTrace();
    }

    return fSuccess;
  }

ただ、ファイルを出力するために使用している Stream を Close していませんでした。
testBlob_wFile と testBlob_wFile_wMetadata からこのメソッドを同じファイルパスを指定して呼び出しています。なので、先に実行したテストでファイルを作成するも、Stream を Close していないため、後で呼び出した方は、ファイルが削除出来ずに失敗してしまうのが原因でした。

FileStream objStream          = new FileStream(strFilePath);

この objStream の Close を呼び出してあげると、テストが全部通るようになりました。やっと全部テスト通ったよ、あ〜長かった!