/** * Binds a new lister to the operation context so the WASB file system can * appropriately intercept sends and allow concurrent OOB I/Os. This * by-passes the blob immutability check when reading streams. * * @param opContext the operation context assocated with this request. */ public static void bind(OperationContext opContext) { opContext.getSendingRequestEventHandler().addListener(new SendRequestIntercept()); }
static void hook(OperationContext context) { context.getErrorReceivingResponseEventHandler().addListener( new ErrorReceivingResponseEventHandler()); context.getSendingRequestEventHandler().addListener( new SendingRequestEventHandler()); context.getResponseReceivedEventHandler().addListener( new ResponseReceivedEventHandler()); }
/** * 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); }
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); }
private void setDelay(final OperationContext ctx, final int timeInMs) { ctx.getSendingRequestEventHandler().addListener(new StorageEvent<SendingRequestEvent>() { @Override public void eventOccurred(SendingRequestEvent eventArg) { try { Thread.sleep(timeInMs); } catch (InterruptedException e) { // do nothing } } }); } }
@Override public OperationContext modifyOperationContext(OperationContext original) { original.getSendingRequestEventHandler().addListener( new TransientErrorInjector(connectionRecognizer)); return original; } });
@Override public OperationContext modifyOperationContext( OperationContext original) { original.getResponseReceivedEventHandler().addListener( new ContentMD5Checker(expectMd5Checked)); return original; } });
@Override public OperationContext modifyOperationContext(OperationContext original) { original.getSendingRequestEventHandler().addListener( new TransientErrorInjector(connectionRecognizer)); return original; } });
@Override public OperationContext modifyOperationContext( OperationContext original) { original.getResponseReceivedEventHandler().addListener( new ContentMD5Checker(expectMd5Checked)); return original; } });
@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); }
public MultiLocationTestHelper(final StorageUri storageUri, final StorageLocation initialLocation, final List<RetryContext> retryContextList, final List<RetryInfo> retryInfoList) { this.initialLocation = initialLocation; this.retryContextList = retryContextList; this.retryInfoList = retryInfoList; this.operationContext = new OperationContext(); this.operationContext.getSendingRequestEventHandler().addListener(new StorageEvent<SendingRequestEvent>() { @Override public void eventOccurred(SendingRequestEvent eventArg) { if (MultiLocationTestHelper.this.error == null) { StorageLocation location = (MultiLocationTestHelper.this.requestCounter == 0) ? initialLocation : retryInfoList.get( MultiLocationTestHelper.this.requestCounter - 1).getTargetLocation(); if (!eventArg.getRequestResult().getTargetLocation().equals(location)) { MultiLocationTestHelper.this.error = String.format("Request %s was sent to %s while the location should have been %s", MultiLocationTestHelper.this.requestCounter, eventArg.getRequestResult().getTargetLocation(), location); } } MultiLocationTestHelper.this.requestCounter++; } }); this.retryPolicy = new AlwaysRetry(this.retryContextList, this.retryInfoList); }
@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); }
@Test public void testBlobEncryption() throws URISyntaxException, StorageException, IOException { this.requestFound = false; OperationContext ctxt = new OperationContext(); ctxt.getRequestCompletedEventHandler().addListener(new StorageEvent<RequestCompletedEvent>() { @Override public void eventOccurred(RequestCompletedEvent eventArg) { assertTrue(eventArg.getRequestResult().isRequestServiceEncrypted()); CloudBlobServerEncryptionTests.this.requestFound = true; } }); this.blob.uploadText("test", null, null, null, ctxt); assertTrue(this.requestFound); } }
@Test public void testBlobEmptyHeaderSigningTest() throws URISyntaxException, StorageException, IOException { final String pageBlobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testPageBlob"); final CloudPageBlob pageBlobRef = this.container.getPageBlobReference(pageBlobName); final int length = 2 * 1024; ByteArrayInputStream srcStream = BlobTestHelper.getRandomDataStream(length); OperationContext context = new OperationContext(); context.getSendingRequestEventHandler().addListener(new StorageEvent<SendingRequestEvent>() { @Override public void eventOccurred(SendingRequestEvent eventArg) { HttpURLConnection connection = (HttpURLConnection) eventArg.getConnectionObject(); connection.setRequestProperty("x-ms-foo", ""); } }); pageBlobRef.upload(srcStream, length, null, null, context); pageBlobRef.download(new ByteArrayOutputStream(), null, null, context); }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testBlobEmptyHeaderSigningTest() 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(); context.getSendingRequestEventHandler().addListener(new StorageEvent<SendingRequestEvent>() { @Override public void eventOccurred(SendingRequestEvent eventArg) { HttpURLConnection connection = (HttpURLConnection) eventArg.getConnectionObject(); connection.setRequestProperty("x-ms-foo", ""); } }); blockBlobRef.upload(srcStream, -1, null, null, context); blockBlobRef.download(new ByteArrayOutputStream(), null, null, context); }
@Test public void testFileEmptyHeaderSigningTest() throws URISyntaxException, StorageException, IOException { final String fileName = FileTestHelper.generateRandomFileName(); final CloudFile fileRef = this.share.getRootDirectoryReference().getFileReference(fileName); final int length = 2 * 1024; ByteArrayInputStream srcStream = FileTestHelper.getRandomDataStream(length); OperationContext context = new OperationContext(); context.getSendingRequestEventHandler().addListener(new StorageEvent<SendingRequestEvent>() { @Override public void eventOccurred(SendingRequestEvent eventArg) { HttpURLConnection connection = (HttpURLConnection) eventArg.getConnectionObject(); connection.setRequestProperty("x-ms-foo", ""); } }); fileRef.upload(srcStream, length, null, null, context); fileRef.download(new ByteArrayOutputStream(), null, null, context); }
@Test public void testCloudFileDirectoryEncryption() throws URISyntaxException, StorageException, IOException { this.requestFound = false; OperationContext ctxt = new OperationContext(); ctxt.getRequestCompletedEventHandler().addListener(new StorageEvent<RequestCompletedEvent>() { @Override public void eventOccurred(RequestCompletedEvent eventArg) { assertTrue(eventArg.getRequestResult().isRequestServiceEncrypted()); CloudFileServerEncryptionTests.this.requestFound = true; } }); this.dir.uploadMetadata(null, null, ctxt); assertTrue(this.requestFound); this.requestFound = false; CloudFileDirectory dir2 = this.share.getRootDirectoryReference().getDirectoryReference("dir2"); dir2.create(null, ctxt); assertTrue(this.requestFound); } }
@Test public void testCloudFileUploadEncryption() throws URISyntaxException, StorageException, IOException { this.requestFound = false; OperationContext ctxt = new OperationContext(); ctxt.getRequestCompletedEventHandler().addListener(new StorageEvent<RequestCompletedEvent>() { @Override public void eventOccurred(RequestCompletedEvent eventArg) { assertTrue(eventArg.getRequestResult().isRequestServiceEncrypted()); CloudFileServerEncryptionTests.this.requestFound = true; } }); this.file.uploadText("test", null, null, null, ctxt); assertTrue(this.requestFound); this.requestFound = false; this.file.uploadProperties(null, null, ctxt); assertTrue(this.requestFound); this.requestFound = false; this.file.uploadMetadata(null, null, ctxt); assertTrue(this.requestFound); }
@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); }