Java Code Examples for com.microsoft.azure.storage.SendingRequestEvent#getConnectionObject()

The following examples show how to use com.microsoft.azure.storage.SendingRequestEvent#getConnectionObject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestAzureFileSystemErrorConditions.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void eventOccurred(SendingRequestEvent eventArg) {
  HttpURLConnection connection = (HttpURLConnection)eventArg.getConnectionObject();
  if (!connectionRecognizer.isTargetConnection(connection)) {
    return;
  }
  if (!injectedErrorOnce) {
    connection.setReadTimeout(1);
    connection.disconnect();
    injectedErrorOnce = true;
  }
}
 
Example 2
Source File: TestAzureFileSystemErrorConditions.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void eventOccurred(SendingRequestEvent eventArg) {
  HttpURLConnection connection = (HttpURLConnection)eventArg.getConnectionObject();
  if (!connectionRecognizer.isTargetConnection(connection)) {
    return;
  }
  if (!injectedErrorOnce) {
    connection.setReadTimeout(1);
    connection.disconnect();
    injectedErrorOnce = true;
  }
}
 
Example 3
Source File: CloudBlockBlobTests.java    From azure-storage-android with Apache License 2.0 5 votes vote down vote up
@Test
@Category({ DevFabricTests.class, DevStoreTests.class })
public void testBlobMultiConditionHeaders() throws URISyntaxException, StorageException, IOException {
    final String blockBlobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testBlockBlob");
    final CloudBlockBlob blockBlobRef = this.container.getBlockBlobReference(blockBlobName);

    final int length = 2 * 1024;
    ByteArrayInputStream srcStream = BlobTestHelper.getRandomDataStream(length);
    OperationContext context = new OperationContext();
    blockBlobRef.upload(srcStream, -1, null, null, context);

    AccessCondition condition = AccessCondition.generateIfMatchCondition(context.getLastResult().getEtag());
    condition.setIfUnmodifiedSinceDate(context.getLastResult().getStartDate());

    StorageEvent<SendingRequestEvent> event = new StorageEvent<SendingRequestEvent>() {

        @Override
        public void eventOccurred(SendingRequestEvent eventArg) {
            HttpURLConnection connection = (HttpURLConnection) eventArg.getConnectionObject();
            assertNotNull(connection.getRequestProperty("If-Unmodified-Since"));
            assertNotNull(connection.getRequestProperty("If-Match"));
        }
    };

    context.getSendingRequestEventHandler().addListener(event);

    blockBlobRef.upload(srcStream, -1, condition, null, context);
}
 
Example 4
Source File: SelfThrottlingIntercept.java    From hadoop with Apache License 2.0 4 votes vote down vote up
public void sendingRequest(SendingRequestEvent sendEvent) {
  long lastLatency;
  boolean operationIsRead; // for logging
  synchronized (this) {

    lastLatency = this.lastE2Elatency;
  }

  float sleepMultiple;
  HttpURLConnection urlConnection = (HttpURLConnection) sendEvent
      .getConnectionObject();

  // Azure REST API never uses POST, so PUT is a sufficient test for an
  // upload.
  if (urlConnection.getRequestMethod().equalsIgnoreCase("PUT")) {
    operationIsRead = false;
    sleepMultiple = (1 / writeFactor) - 1;
  } else {
    operationIsRead = true;
    sleepMultiple = (1 / readFactor) - 1;
  }

  long sleepDuration = (long) (sleepMultiple * lastLatency);
  if (sleepDuration < 0) {
    sleepDuration = 0;
  }

  if (sleepDuration > 0) {
    try {
      // Thread.sleep() is not exact but it seems sufficiently accurate for
      // our needs. If needed this could become a loop of small waits that
      // tracks actual
      // elapsed time.
      Thread.sleep(sleepDuration);
    } catch (InterruptedException ie) {
      Thread.currentThread().interrupt();
    }

    // reset to avoid counting the sleep against request latency
    sendEvent.getRequestResult().setStartDate(new Date());
  }

  if (LOG.isDebugEnabled()) {
    boolean isFirstRequest = (lastLatency == 0);
    long threadId = Thread.currentThread().getId();
    LOG.debug(String
        .format(
            " SelfThrottlingIntercept:: SendingRequest:   threadId=%d, requestType=%s, isFirstRequest=%b, sleepDuration=%d",
            threadId, operationIsRead ? "read " : "write", isFirstRequest,
            sleepDuration));
  }
}
 
Example 5
Source File: SelfThrottlingIntercept.java    From big-c with Apache License 2.0 4 votes vote down vote up
public void sendingRequest(SendingRequestEvent sendEvent) {
  long lastLatency;
  boolean operationIsRead; // for logging
  synchronized (this) {

    lastLatency = this.lastE2Elatency;
  }

  float sleepMultiple;
  HttpURLConnection urlConnection = (HttpURLConnection) sendEvent
      .getConnectionObject();

  // Azure REST API never uses POST, so PUT is a sufficient test for an
  // upload.
  if (urlConnection.getRequestMethod().equalsIgnoreCase("PUT")) {
    operationIsRead = false;
    sleepMultiple = (1 / writeFactor) - 1;
  } else {
    operationIsRead = true;
    sleepMultiple = (1 / readFactor) - 1;
  }

  long sleepDuration = (long) (sleepMultiple * lastLatency);
  if (sleepDuration < 0) {
    sleepDuration = 0;
  }

  if (sleepDuration > 0) {
    try {
      // Thread.sleep() is not exact but it seems sufficiently accurate for
      // our needs. If needed this could become a loop of small waits that
      // tracks actual
      // elapsed time.
      Thread.sleep(sleepDuration);
    } catch (InterruptedException ie) {
      Thread.currentThread().interrupt();
    }

    // reset to avoid counting the sleep against request latency
    sendEvent.getRequestResult().setStartDate(new Date());
  }

  if (LOG.isDebugEnabled()) {
    boolean isFirstRequest = (lastLatency == 0);
    long threadId = Thread.currentThread().getId();
    LOG.debug(String
        .format(
            " SelfThrottlingIntercept:: SendingRequest:   threadId=%d, requestType=%s, isFirstRequest=%b, sleepDuration=%d",
            threadId, operationIsRead ? "read " : "write", isFirstRequest,
            sleepDuration));
  }
}