예제 #1
0
  /**
   * Utility to test blob POST, GET, HEAD and DELETE operations for a specified size
   *
   * @param contentSize the size of the blob to be tested
   * @param multipartPost {@code true} if multipart POST is desired, {@code false} otherwise.
   * @throws Exception
   */
  private void doPostGetHeadDeleteTest(int contentSize, boolean multipartPost) throws Exception {
    ByteBuffer content = ByteBuffer.wrap(RestTestUtils.getRandomBytes(contentSize));
    String serviceId = "postGetHeadDeleteServiceID";
    String contentType = "application/octet-stream";
    String ownerId = "postGetHeadDeleteOwnerID";
    HttpHeaders headers = new DefaultHttpHeaders();
    setAmbryHeaders(headers, content.capacity(), 7200, false, serviceId, contentType, ownerId);
    headers.set(HttpHeaders.Names.CONTENT_LENGTH, content.capacity());
    String blobId;
    byte[] usermetadata = null;
    if (multipartPost) {
      usermetadata = UtilsTest.getRandomString(32).getBytes();
      blobId = multipartPostBlobAndVerify(headers, content, ByteBuffer.wrap(usermetadata));
    } else {
      headers.add(RestUtils.Headers.USER_META_DATA_HEADER_PREFIX + "key1", "value1");
      headers.add(RestUtils.Headers.USER_META_DATA_HEADER_PREFIX + "key2", "value2");
      blobId = postBlobAndVerify(headers, content);
    }
    getBlobAndVerify(blobId, null, headers, content);
    getHeadAndVerify(blobId, null, headers);
    ByteRange range =
        ByteRange.fromLastNBytes(ThreadLocalRandom.current().nextLong(content.capacity() + 1));
    getBlobAndVerify(blobId, range, headers, content);
    getHeadAndVerify(blobId, range, headers);
    if (contentSize > 0) {
      range = ByteRange.fromStartOffset(ThreadLocalRandom.current().nextLong(content.capacity()));
      getBlobAndVerify(blobId, range, headers, content);
      getHeadAndVerify(blobId, range, headers);
      long random1 = ThreadLocalRandom.current().nextLong(content.capacity());
      long random2 = ThreadLocalRandom.current().nextLong(content.capacity());
      range = ByteRange.fromOffsetRange(Math.min(random1, random2), Math.max(random1, random2));
      getBlobAndVerify(blobId, range, headers, content);
      getHeadAndVerify(blobId, range, headers);
    }
    getNotModifiedBlobAndVerify(blobId);
    getUserMetadataAndVerify(blobId, headers, usermetadata);
    getBlobInfoAndVerify(blobId, headers, usermetadata);
    deleteBlobAndVerify(blobId);

    // check GET, HEAD and DELETE after delete.
    verifyOperationsAfterDelete(blobId);
  }
예제 #2
0
 /**
  * Sets up a temporary directory that can be used.
  *
  * @throws IOException
  */
 public LogSegmentTest() throws IOException {
   tempDir = Files.createTempDirectory("logSegmentDir-" + UtilsTest.getRandomString(10)).toFile();
   tempDir.deleteOnExit();
   metrics = new StoreMetrics(tempDir.getName(), new MetricRegistry());
 }