Java源码示例:com.microsoft.azure.storage.ResponseReceivedEvent
示例1
public void responseReceived(ResponseReceivedEvent event) {
RequestResult result = event.getRequestResult();
Date startDate = result.getStartDate();
Date stopDate = result.getStopDate();
long elapsed = stopDate.getTime() - startDate.getTime();
synchronized (this) {
this.lastE2Elatency = elapsed;
}
if (LOG.isDebugEnabled()) {
int statusCode = result.getStatusCode();
String etag = result.getEtag();
HttpURLConnection urlConnection = (HttpURLConnection) event
.getConnectionObject();
int contentLength = urlConnection.getContentLength();
String requestMethod = urlConnection.getRequestMethod();
long threadId = Thread.currentThread().getId();
LOG.debug(String
.format(
"SelfThrottlingIntercept:: ResponseReceived: threadId=%d, Status=%d, Elapsed(ms)=%d, ETAG=%s, contentLength=%d, requestMethod=%s",
threadId, statusCode, elapsed, etag, contentLength, requestMethod));
}
}
示例2
@Override
public void eventOccurred(ResponseReceivedEvent eventArg) {
RequestResult currentResult = operationContext.getLastResult();
int statusCode = currentResult.getStatusCode();
// Check if it's a client-side error: a 4xx status
// We exclude 404 because it happens frequently during the normal
// course of operation (each call to exists() would generate that
// if it's not found).
if (statusCode >= HTTP_BAD_REQUEST && statusCode < HTTP_INTERNAL_ERROR
&& statusCode != HTTP_NOT_FOUND) {
instrumentation.clientErrorEncountered();
} else if (statusCode >= HTTP_INTERNAL_ERROR) {
// It's a server error: a 5xx status. Could be an Azure Storage
// bug or (more likely) throttling.
instrumentation.serverErrorEncountered();
}
}
示例3
public void responseReceived(ResponseReceivedEvent event) {
RequestResult result = event.getRequestResult();
Date startDate = result.getStartDate();
Date stopDate = result.getStopDate();
long elapsed = stopDate.getTime() - startDate.getTime();
synchronized (this) {
this.lastE2Elatency = elapsed;
}
if (LOG.isDebugEnabled()) {
int statusCode = result.getStatusCode();
String etag = result.getEtag();
HttpURLConnection urlConnection = (HttpURLConnection) event
.getConnectionObject();
int contentLength = urlConnection.getContentLength();
String requestMethod = urlConnection.getRequestMethod();
long threadId = Thread.currentThread().getId();
LOG.debug(String
.format(
"SelfThrottlingIntercept:: ResponseReceived: threadId=%d, Status=%d, Elapsed(ms)=%d, ETAG=%s, contentLength=%d, requestMethod=%s",
threadId, statusCode, elapsed, etag, contentLength, requestMethod));
}
}
示例4
@Override
public void eventOccurred(ResponseReceivedEvent eventArg) {
RequestResult currentResult = operationContext.getLastResult();
int statusCode = currentResult.getStatusCode();
// Check if it's a client-side error: a 4xx status
// We exclude 404 because it happens frequently during the normal
// course of operation (each call to exists() would generate that
// if it's not found).
if (statusCode >= HTTP_BAD_REQUEST && statusCode < HTTP_INTERNAL_ERROR
&& statusCode != HTTP_NOT_FOUND) {
instrumentation.clientErrorEncountered();
} else if (statusCode >= HTTP_INTERNAL_ERROR) {
// It's a server error: a 5xx status. Could be an Azure Storage
// bug or (more likely) throttling.
instrumentation.serverErrorEncountered();
}
}
示例5
@Test
public void testApiVersion() throws InvalidKeyException, StorageException, URISyntaxException {
SharedAccessBlobPolicy sp1 = createSharedAccessPolicy(
EnumSet.of(SharedAccessBlobPermissions.READ, SharedAccessBlobPermissions.WRITE,
SharedAccessBlobPermissions.LIST, SharedAccessBlobPermissions.DELETE), 3600);
String sas = this.blob.generateSharedAccessSignature(sp1, null);
// should not be appended before signing
assertEquals(-1, sas.indexOf(Constants.QueryConstants.API_VERSION));
OperationContext ctx = new OperationContext();
ctx.getResponseReceivedEventHandler().addListener(new StorageEvent<ResponseReceivedEvent>() {
@Override
public void eventOccurred(ResponseReceivedEvent eventArg) {
// should be appended after signing
HttpURLConnection conn = (HttpURLConnection) eventArg.getConnectionObject();
assertTrue(conn.getURL().toString().indexOf(Constants.QueryConstants.API_VERSION) != -1);
}
});
CloudBlockBlob sasBlob = new CloudBlockBlob(new URI(this.blob.getUri().toString() + "?" + sas));
sasBlob.uploadMetadata(null, null, ctx);
}
示例6
@Test
public void testApiVersion() throws InvalidKeyException, StorageException, URISyntaxException {
SharedAccessFilePolicy policy = createSharedAccessPolicy(
EnumSet.of(SharedAccessFilePermissions.READ, SharedAccessFilePermissions.WRITE,
SharedAccessFilePermissions.LIST, SharedAccessFilePermissions.DELETE), 300);
String sas = this.file.generateSharedAccessSignature(policy, null);
// should not be appended before signing
assertEquals(-1, sas.indexOf(Constants.QueryConstants.API_VERSION));
OperationContext ctx = new OperationContext();
ctx.getResponseReceivedEventHandler().addListener(new StorageEvent<ResponseReceivedEvent>() {
@Override
public void eventOccurred(ResponseReceivedEvent eventArg) {
// should be appended after signing
HttpURLConnection conn = (HttpURLConnection) eventArg.getConnectionObject();
assertTrue(conn.getURL().toString().indexOf(Constants.QueryConstants.API_VERSION) != -1);
}
});
CloudFile sasFile = new CloudFile(new URI(this.file.getUri().toString() + "?" + sas));
sasFile.uploadMetadata(null, null, ctx);
}
示例7
@Override
public void eventOccurred(ResponseReceivedEvent eventArg) {
HttpURLConnection connection = (HttpURLConnection) eventArg
.getConnectionObject();
if (isGetRange(connection)) {
checkObtainedMd5(connection
.getHeaderField(Constants.HeaderConstants.CONTENT_MD5));
} else if (isPutBlock(connection)) {
checkObtainedMd5(connection
.getRequestProperty(Constants.HeaderConstants.CONTENT_MD5));
}
}
示例8
@Override
public void eventOccurred(ResponseReceivedEvent eventArg) {
HttpURLConnection connection = (HttpURLConnection) eventArg
.getConnectionObject();
if (isGetRange(connection)) {
checkObtainedMd5(connection
.getHeaderField(Constants.HeaderConstants.CONTENT_MD5));
} else if (isPutBlock(connection)) {
checkObtainedMd5(connection
.getRequestProperty(Constants.HeaderConstants.CONTENT_MD5));
}
}
示例9
private void testSelectOnlySendsReservedColumnsOnce(TableRequestOptions options, boolean usePropertyResolver)
{
// Create entity to use property resolver
Class1 randEnt = TableTestHelper.generateRandomEntity(null);
if (usePropertyResolver) {
options.setPropertyResolver(randEnt);
}
OperationContext opContext = new OperationContext();
opContext.getResponseReceivedEventHandler().addListener(new StorageEvent<ResponseReceivedEvent>() {
@Override
public void eventOccurred(ResponseReceivedEvent eventArg) {
HttpURLConnection conn = (HttpURLConnection) eventArg.getConnectionObject();
String urlString = conn.getURL().toString();
assertEquals(urlString.indexOf("PartitionKey"), urlString.lastIndexOf("PartitionKey"));
assertEquals(urlString.indexOf("RowKey"), urlString.lastIndexOf("RowKey"));
assertEquals(urlString.indexOf("Timestamp"), urlString.lastIndexOf("Timestamp"));
}
});
final Iterable<Class1> result = table.execute(
TableQuery.from(Class1.class).select(new String[] { "PartitionKey", "RowKey", "Timestamp" }), options,
opContext);
// Validate results
for (Class1 ent : result) {
assertEquals(ent.getA(), null);
assertEquals(ent.getB(), null);
assertEquals(ent.getC(), null);
assertEquals(ent.getD(), null);
}
}
示例10
@Override
public void eventOccurred(ResponseReceivedEvent event) {
responseReceived(event);
}
示例11
@Override
public void eventOccurred(ResponseReceivedEvent event) {
responseReceived(event);
}
示例12
@Test
public void testFlush() throws Exception {
CloudBlockBlob blockBlob = this.container.getBlockBlobReference(
BlobTestHelper.generateRandomBlobNameWithPrefix("flush"));
OperationContext ctx = new OperationContext();
ctx.getResponseReceivedEventHandler().addListener(new StorageEvent<ResponseReceivedEvent>() {
@Override
public void eventOccurred(ResponseReceivedEvent eventArg) {
try {
HttpURLConnection con = (HttpURLConnection) eventArg.getConnectionObject();
if ("511".equals(con.getRequestProperty(Constants.HeaderConstants.CONTENT_LENGTH))) {
Thread.sleep(3000);
}
} catch (InterruptedException e) {
// do nothing
}
}
});
BlobOutputStream blobOutputStream = blockBlob.openOutputStream(null, null, ctx);
ExecutorService threadExecutor = Executors.newFixedThreadPool(1);
byte[] buffer = BlobTestHelper.getRandomBuffer(511);
blobOutputStream.write(buffer);
Future<Void> future = threadExecutor.submit(new FlushTask(blobOutputStream));
Thread.sleep(1000);
buffer = BlobTestHelper.getRandomBuffer(513);
blobOutputStream.write(buffer);
// Writes complete when the upload is dispatched (not when the upload completes and flush must
// wait for upload1 to complete. So, flush should finish last and writes should finish in order.
while(!future.isDone()) {
Thread.sleep(500);
}
// After flush we should see the first upload
ArrayList<BlockEntry> blocks = blockBlob.downloadBlockList(BlockListingFilter.UNCOMMITTED, null, null, null);
assertEquals(1, blocks.size());
assertEquals(511, blocks.get(0).getSize());
// After close we should see the second upload
blobOutputStream.close();
blocks = blockBlob.downloadBlockList(BlockListingFilter.COMMITTED, null, null, null);
assertEquals(2, blocks.size());
assertEquals(513, blocks.get(1).getSize());
}