/** * Hooks a new listener to the given operationContext that will update the * error metrics for the WASB file system appropriately in response to * ResponseReceived events. * * @param operationContext The operationContext to hook. * @param instrumentation The metrics source to update. */ public static void hook( OperationContext operationContext, AzureFileSystemInstrumentation instrumentation) { ErrorMetricUpdater listener = new ErrorMetricUpdater(operationContext, instrumentation); operationContext.getResponseReceivedEventHandler().addListener(listener); }
/** * Hooks a new listener to the given operationContext that will update the * metrics for the WASB file system appropriately in response to * ResponseReceived events. * * @param operationContext The operationContext to hook. * @param instrumentation The metrics source to update. * @param blockUploadGaugeUpdater The blockUploadGaugeUpdater to use. */ public static void hook( OperationContext operationContext, AzureFileSystemInstrumentation instrumentation, BandwidthGaugeUpdater blockUploadGaugeUpdater) { ResponseReceivedMetricUpdater listener = new ResponseReceivedMetricUpdater(operationContext, instrumentation, blockUploadGaugeUpdater); operationContext.getResponseReceivedEventHandler().addListener(listener); }
/** * Fires events representing that a response has been received. */ private static void fireResponseReceivedEvent(OperationContext opContext, HttpURLConnection request, RequestResult result) { if (opContext.getResponseReceivedEventHandler().hasListeners() || OperationContext.getGlobalResponseReceivedEventHandler().hasListeners()) { ResponseReceivedEvent event = new ResponseReceivedEvent(opContext, request, result); opContext.getResponseReceivedEventHandler().fireEvent(event); OperationContext.getGlobalResponseReceivedEventHandler().fireEvent(event); } }
/** * Fires events representing that a response has been received. */ private static void fireResponseReceivedEvent(OperationContext opContext, HttpURLConnection request, RequestResult result) { if (opContext.getResponseReceivedEventHandler().hasListeners() || OperationContext.getGlobalResponseReceivedEventHandler().hasListeners()) { ResponseReceivedEvent event = new ResponseReceivedEvent(opContext, request, result); opContext.getResponseReceivedEventHandler().fireEvent(event); OperationContext.getGlobalResponseReceivedEventHandler().fireEvent(event); } }
@Override public OperationContext modifyOperationContext( OperationContext original) { original.getResponseReceivedEventHandler().addListener( new ContentMD5Checker(expectMd5Checked)); return original; } });
@Override public OperationContext modifyOperationContext( OperationContext original) { original.getResponseReceivedEventHandler().addListener( new ContentMD5Checker(expectMd5Checked)); return original; } });
public static void hook(OperationContext operationContext, float readFactor, float writeFactor) { SelfThrottlingIntercept throttler = new SelfThrottlingIntercept( operationContext, readFactor, writeFactor); ResponseReceivedListener responseListener = throttler.new ResponseReceivedListener(); SendingRequestListener sendingListener = throttler.new SendingRequestListener(); operationContext.getResponseReceivedEventHandler().addListener( responseListener); operationContext.getSendingRequestEventHandler().addListener( sendingListener); }
static void hook(OperationContext context) { context.getErrorReceivingResponseEventHandler().addListener( new ErrorReceivingResponseEventHandler()); context.getSendingRequestEventHandler().addListener( new SendingRequestEventHandler()); context.getResponseReceivedEventHandler().addListener( new ResponseReceivedEventHandler()); }
@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); }
@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); }
ctx.getResponseReceivedEventHandler().addListener(new StorageEvent<ResponseReceivedEvent>() {
ctx.getResponseReceivedEventHandler().addListener(new StorageEvent<ResponseReceivedEvent>() { ctx.getResponseReceivedEventHandler().addListener(new StorageEvent<ResponseReceivedEvent>() {
eventContext.getResponseReceivedEventHandler().addListener(new StorageEvent<ResponseReceivedEvent>() {
@Test public void testAppendBlockOperations() throws Exception { CloudBlobContainer container = getTestAccount().getRealContainer(); OperationContext context = new OperationContext(); context.getResponseReceivedEventHandler().addListener( new ResponseReceivedEventHandler()); context.getSendingRequestEventHandler().addListener( new SendingRequestEventHandler()); CloudAppendBlob appendBlob = container.getAppendBlobReference( "testAppendBlockOperations"); assertNull(lastOperationTypeSent); assertNull(lastOperationTypeReceived); assertEquals(0, lastContentLengthReceived); try ( BlobOutputStream output = appendBlob.openWriteNew(null, null, context); ) { assertEquals(BlobOperationDescriptor.OperationType.CreateBlob, lastOperationTypeReceived); assertEquals(0, lastContentLengthReceived); String message = "this is a test"; output.write(message.getBytes("UTF-8")); output.flush(); assertEquals(BlobOperationDescriptor.OperationType.AppendBlock, lastOperationTypeSent); assertEquals(BlobOperationDescriptor.OperationType.AppendBlock, lastOperationTypeReceived); assertEquals(message.length(), lastContentLengthReceived); } }
context.getResponseReceivedEventHandler().addListener( new ResponseReceivedEventHandler()); context.getSendingRequestEventHandler().addListener(
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); } }
@Test @Category({ DevFabricTests.class, DevStoreTests.class, SecondaryTests.class }) public void testFileMaximumExecutionTime() throws URISyntaxException, StorageException { OperationContext opContext = new OperationContext(); setDelay(opContext, 2500); opContext.getResponseReceivedEventHandler().addListener(new StorageEvent<ResponseReceivedEvent>() { @Override public void eventOccurred(ResponseReceivedEvent eventArg) { // Set status code to 500 to force a retry eventArg.getRequestResult().setStatusCode(500); } }); // set the maximum execution time FileRequestOptions options = new FileRequestOptions(); options.setMaximumExecutionTimeInMs(2000); options.setTimeoutIntervalInMs(1000); CloudFileClient fileClient = TestHelper.createCloudFileClient(); CloudFileShare share = fileClient.getShareReference(generateRandomName("share")); try { // 1. download attributes will fail as the share does not exist // 2. the executor will attempt to retry as we set the status code to 500 // 3. maximum execution time should prevent the retry from being made share.downloadAttributes(null, options, opContext); fail("Maximum execution time was reached but request did not fail."); } catch (StorageException e) { assertEquals(SR.MAXIMUM_EXECUTION_TIMEOUT_EXCEPTION, e.getMessage()); } }
context.getResponseReceivedEventHandler().addListener( new ResponseReceivedEventHandler()); context.getSendingRequestEventHandler().addListener(
setDelay(opContext, 2500); opContext.getResponseReceivedEventHandler().addListener(new StorageEvent<ResponseReceivedEvent>() {
context.getResponseReceivedEventHandler().addListener( new ResponseReceivedEventHandler()); context.getSendingRequestEventHandler().addListener(