本文整理汇总了Java中com.microsoft.azure.storage.SendingRequestEvent类的典型用法代码示例。如果您正苦于以下问题:Java SendingRequestEvent类的具体用法?Java SendingRequestEvent怎么用?Java SendingRequestEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SendingRequestEvent类属于com.microsoft.azure.storage包,在下文中一共展示了SendingRequestEvent类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testBlobEmptyHeaderSigningTest
import com.microsoft.azure.storage.SendingRequestEvent; //导入依赖的package包/类
@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);
}
开发者ID:Azure,项目名称:azure-storage-android,代码行数:22,代码来源:CloudPageBlobTests.java
示例2: testBlobEmptyHeaderSigningTest
import com.microsoft.azure.storage.SendingRequestEvent; //导入依赖的package包/类
@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);
}
开发者ID:Azure,项目名称:azure-storage-android,代码行数:23,代码来源:CloudBlockBlobTests.java
示例3: testFileEmptyHeaderSigningTest
import com.microsoft.azure.storage.SendingRequestEvent; //导入依赖的package包/类
@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);
}
开发者ID:Azure,项目名称:azure-storage-android,代码行数:22,代码来源:CloudFileTests.java
示例4: eventOccurred
import com.microsoft.azure.storage.SendingRequestEvent; //导入依赖的package包/类
@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;
}
}
开发者ID:naver,项目名称:hadoop,代码行数:13,代码来源:TestAzureFileSystemErrorConditions.java
示例5: fireSendingRequestEvent
import com.microsoft.azure.storage.SendingRequestEvent; //导入依赖的package包/类
/**
* Fires events representing that a request will be sent.
*/
private static void fireSendingRequestEvent(OperationContext opContext, HttpURLConnection request,
RequestResult result) {
if (opContext.getSendingRequestEventHandler().hasListeners()
|| OperationContext.getGlobalSendingRequestEventHandler().hasListeners()) {
SendingRequestEvent event = new SendingRequestEvent(opContext, request, result);
opContext.getSendingRequestEventHandler().fireEvent(event);
OperationContext.getGlobalSendingRequestEventHandler().fireEvent(event);
}
}
开发者ID:horizon-institute,项目名称:runspotrun-android-client,代码行数:13,代码来源:ExecutionEngine.java
示例6: testBlobSaSWithSharedAccessBlobHeaders
import com.microsoft.azure.storage.SendingRequestEvent; //导入依赖的package包/类
@Test
@Category(SlowTests.class)
public void testBlobSaSWithSharedAccessBlobHeaders() throws InvalidKeyException, IllegalArgumentException,
StorageException, URISyntaxException, InterruptedException {
SharedAccessBlobPolicy sp = createSharedAccessPolicy(EnumSet.of(SharedAccessBlobPermissions.READ,
SharedAccessBlobPermissions.WRITE, SharedAccessBlobPermissions.LIST), 3600);
BlobContainerPermissions perms = new BlobContainerPermissions();
perms.getSharedAccessPolicies().put("readperm", sp);
this.container.uploadPermissions(perms);
Thread.sleep(30000);
SharedAccessBlobHeaders headers = new SharedAccessBlobHeaders();
headers.setCacheControl("no-cache");
headers.setContentDisposition("attachment; filename=\"fname.ext\"");
headers.setContentEncoding("gzip");
headers.setContentLanguage("da");
headers.setContentType("text/html; charset=utf-8");
CloudBlockBlob sasBlob = new CloudBlockBlob(new URI(this.blob.getUri().toString() + "?"
+ this.blob.generateSharedAccessSignature(null, headers, "readperm")));
OperationContext context = new OperationContext();
context.getSendingRequestEventHandler().addListener(new StorageEvent<SendingRequestEvent>() {
@Override
public void eventOccurred(SendingRequestEvent eventArg) {
HttpURLConnection connection = (HttpURLConnection) eventArg.getConnectionObject();
assertEquals("no-cache", connection.getHeaderField(Constants.HeaderConstants.CACHE_CONTROL));
assertEquals("attachment; filename=\"fname.ext\"",
connection.getHeaderField(Constants.HeaderConstants.CONTENT_DISPOSITION));
assertEquals("gzip", connection.getHeaderField(Constants.HeaderConstants.CONTENT_ENCODING));
assertEquals("da", connection.getHeaderField(Constants.HeaderConstants.CONTENT_LANGUAGE));
assertEquals("text/html; charset=utf-8",
connection.getHeaderField(Constants.HeaderConstants.CONTENT_TYPE));
}
});
sasBlob.download(new ByteArrayOutputStream(), null, null, context);
}
开发者ID:Azure,项目名称:azure-storage-android,代码行数:41,代码来源:SasTests.java
示例7: testAppendBlobDeleteIfExists
import com.microsoft.azure.storage.SendingRequestEvent; //导入依赖的package包/类
/**
* Delete an append blob if it exists.
*
* @throws StorageException
* @throws URISyntaxException
*/
@Test
public void testAppendBlobDeleteIfExists() throws URISyntaxException, StorageException {
final CloudAppendBlob blob = this.container.getAppendBlobReference(BlobTestHelper
.generateRandomBlobNameWithPrefix("testBlob"));
assertFalse(blob.exists());
assertFalse(blob.deleteIfExists());
blob.createOrReplace();
assertTrue(blob.exists());
assertTrue(blob.deleteIfExists());
assertFalse(blob.deleteIfExists());
// check if second condition works in delete if exists
OperationContext ctx = new OperationContext();
ctx.getSendingRequestEventHandler().addListener(new StorageEvent<SendingRequestEvent>() {
@Override
public void eventOccurred(SendingRequestEvent eventArg) {
if (((HttpURLConnection) eventArg.getConnectionObject()).getRequestMethod().equals("DELETE")) {
try {
blob.delete();
assertFalse(blob.exists());
}
catch (StorageException e) {
fail("Delete should succeed.");
}
}
}
});
// The second delete of a blob will return a 404
blob.createOrReplace();
assertFalse(blob.deleteIfExists(DeleteSnapshotsOption.NONE, null, null, ctx));
}
开发者ID:Azure,项目名称:azure-storage-android,代码行数:43,代码来源:CloudAppendBlobTests.java
示例8: testBlobEmptyHeaderSigningTest
import com.microsoft.azure.storage.SendingRequestEvent; //导入依赖的package包/类
@Test
public void testBlobEmptyHeaderSigningTest() throws URISyntaxException,
StorageException, IOException {
final String appendBlobName = BlobTestHelper
.generateRandomBlobNameWithPrefix("testAppendBlob");
final CloudAppendBlob appendBlobRef = this.container
.getAppendBlobReference(appendBlobName);
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", "");
}
});
appendBlobRef.upload(srcStream, length, null, null, context);
appendBlobRef
.download(new ByteArrayOutputStream(), null, null, context);
}
开发者ID:Azure,项目名称:azure-storage-android,代码行数:29,代码来源:CloudAppendBlobTests.java
示例9: testCloudBlobContainerInvalidMetadata
import com.microsoft.azure.storage.SendingRequestEvent; //导入依赖的package包/类
@Test
@Category({ DevFabricTests.class, DevStoreTests.class })
public void testCloudBlobContainerInvalidMetadata() throws StorageException{
// test client-side fails correctly
testMetadataFailures(this.container, null, "value1", true);
testMetadataFailures(this.container, "", "value1", true);
testMetadataFailures(this.container, " ", "value1", true);
testMetadataFailures(this.container, "\n \t", "value1", true);
testMetadataFailures(this.container, "key1", null, false);
testMetadataFailures(this.container, "key1", "", false);
testMetadataFailures(this.container, "key1", " ", false);
testMetadataFailures(this.container, "key1", "\n \t", false);
// test client can get empty metadata
this.container.create();
OperationContext opContext = new OperationContext();
opContext.getSendingRequestEventHandler().addListener(new StorageEvent<SendingRequestEvent>() {
// insert a metadata element with an empty value
@Override
public void eventOccurred(SendingRequestEvent eventArg) {
HttpURLConnection request = (HttpURLConnection) eventArg.getConnectionObject();
request.setRequestProperty(Constants.HeaderConstants.PREFIX_FOR_STORAGE_METADATA + "key1", "");
}
});
this.container.uploadMetadata(null, null, opContext);
this.container.downloadAttributes();
assertEquals(1, this.container.getMetadata().size());
assertEquals("", this.container.getMetadata().get("key1"));
}
开发者ID:Azure,项目名称:azure-storage-android,代码行数:33,代码来源:CloudBlobContainerTests.java
示例10: testCopyWithChineseChars
import com.microsoft.azure.storage.SendingRequestEvent; //导入依赖的package包/类
@Test
public void testCopyWithChineseChars() throws StorageException, IOException, URISyntaxException {
String data = "sample data chinese chars 阿䶵";
CloudBlockBlob copySource = container.getBlockBlobReference("sourcechinescharsblob阿䶵.txt");
copySource.uploadText(data);
assertEquals(this.container.getUri() + "/sourcechinescharsblob阿䶵.txt", copySource.getUri().toString());
assertEquals(this.container.getUri() + "/sourcechinescharsblob%E9%98%BF%E4%B6%B5.txt",
copySource.getUri().toASCIIString());
CloudBlockBlob copyDestination = container.getBlockBlobReference("destchinesecharsblob阿䶵.txt");
assertEquals(this.container.getUri() + "/destchinesecharsblob阿䶵.txt", copyDestination.getUri().toString());
assertEquals(this.container.getUri() + "/destchinesecharsblob%E9%98%BF%E4%B6%B5.txt",
copyDestination.getUri().toASCIIString());
OperationContext ctx = new OperationContext();
ctx.getSendingRequestEventHandler().addListener(new StorageEvent<SendingRequestEvent>() {
@Override
public void eventOccurred(SendingRequestEvent eventArg) {
HttpURLConnection con = (HttpURLConnection) eventArg.getConnectionObject();
// Test the copy destination request url
assertEquals(CloudBlockBlobTests.this.container.getUri() + "/destchinesecharsblob%E9%98%BF%E4%B6%B5.txt",
con.getURL().toString());
// Test the copy source request property
assertEquals(CloudBlockBlobTests.this.container.getUri() + "/sourcechinescharsblob%E9%98%BF%E4%B6%B5.txt",
con.getRequestProperty("x-ms-copy-source"));
}
});
copyDestination.startCopy(copySource.getUri(), null, null, null, ctx);
copyDestination.startCopy(copySource, null, null, null, ctx);
}
开发者ID:Azure,项目名称:azure-storage-android,代码行数:36,代码来源:CloudBlockBlobTests.java
示例11: testDeleteBlobIfExists
import com.microsoft.azure.storage.SendingRequestEvent; //导入依赖的package包/类
@Test
@Category({ DevFabricTests.class, DevStoreTests.class })
public void testDeleteBlobIfExists() throws URISyntaxException, StorageException, IOException {
final CloudBlockBlob blob1 = this.container.getBlockBlobReference(BlobTestHelper
.generateRandomBlobNameWithPrefix("testBlob"));
assertFalse(blob1.exists());
assertFalse(blob1.deleteIfExists());
blob1.uploadText("test1");
assertTrue(blob1.exists());
assertTrue(blob1.deleteIfExists());
assertFalse(blob1.deleteIfExists());
// check if second condition works in delete if exists
OperationContext ctx = new OperationContext();
ctx.getSendingRequestEventHandler().addListener(new StorageEvent<SendingRequestEvent>() {
@Override
public void eventOccurred(SendingRequestEvent eventArg) {
if (((HttpURLConnection) eventArg.getConnectionObject()).getRequestMethod().equals("DELETE")) {
try {
blob1.delete();
assertFalse(blob1.exists());
}
catch (StorageException e) {
fail("Delete should succeed.");
}
}
}
});
// The second delete of a blob will return a 404
blob1.uploadText("test1");
assertFalse(blob1.deleteIfExists(DeleteSnapshotsOption.NONE, null, null, ctx));
}
开发者ID:Azure,项目名称:azure-storage-android,代码行数:38,代码来源:CloudBlockBlobTests.java
示例12: testSendingRequestEventBlob
import com.microsoft.azure.storage.SendingRequestEvent; //导入依赖的package包/类
/**
* @throws StorageException
* @throws URISyntaxException
* @throws IOException
* @throws InterruptedException
*/
@Test
@Category({ DevFabricTests.class, DevStoreTests.class })
public void testSendingRequestEventBlob() throws StorageException, URISyntaxException, IOException {
final int length = 128;
final ArrayList<Boolean> callList = new ArrayList<Boolean>();
OperationContext sendingRequestEventContext = new OperationContext();
sendingRequestEventContext.getSendingRequestEventHandler().addListener(new StorageEvent<SendingRequestEvent>() {
@Override
public void eventOccurred(SendingRequestEvent eventArg) {
assertEquals(eventArg.getRequestResult(), eventArg.getOpContext().getLastResult());
callList.add(true);
}
});
assertEquals(0, callList.size());
//Put blob
CloudBlob blob = BlobTestHelper.uploadNewBlob(this.container, BlobType.BLOCK_BLOB, "bb", length,
sendingRequestEventContext);
assertEquals(1, callList.size());
//Get blob
blob.download(new ByteArrayOutputStream(), null, null, sendingRequestEventContext);
assertEquals(2, callList.size());
//uploadMetadata
blob.uploadMetadata(null, null, sendingRequestEventContext);
assertEquals(3, callList.size());
//uploadMetadata
blob.downloadAttributes(null, null, sendingRequestEventContext);
assertEquals(4, callList.size());
}
开发者ID:Azure,项目名称:azure-storage-android,代码行数:44,代码来源:CloudBlockBlobTests.java
示例13: testBlobMultiConditionHeaders
import com.microsoft.azure.storage.SendingRequestEvent; //导入依赖的package包/类
@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);
}
开发者ID:Azure,项目名称:azure-storage-android,代码行数:29,代码来源:CloudBlockBlobTests.java
示例14: testFileSASWithSharedAccessFileHeaders
import com.microsoft.azure.storage.SendingRequestEvent; //导入依赖的package包/类
@Test
public void testFileSASWithSharedAccessFileHeaders() throws InvalidKeyException, IllegalArgumentException,
StorageException, URISyntaxException, InterruptedException {
SharedAccessFilePolicy policy = createSharedAccessPolicy(EnumSet.of(SharedAccessFilePermissions.READ,
SharedAccessFilePermissions.WRITE, SharedAccessFilePermissions.LIST), 300);
FileSharePermissions perms = new FileSharePermissions();
perms.getSharedAccessPolicies().put("rwperm", policy);
this.share.uploadPermissions(perms);
Thread.sleep(30000);
SharedAccessFileHeaders headers = new SharedAccessFileHeaders();
headers.setCacheControl("no-cache");
headers.setContentDisposition("attachment; filename=\"fname.ext\"");
headers.setContentEncoding("gzip");
headers.setContentLanguage("da");
headers.setContentType("text/html; charset=utf-8");
CloudFile sasFile = new CloudFile(
new URI(this.file.getUri().toString() + "?" + this.file.generateSharedAccessSignature(null, headers, "rwperm")));
OperationContext context = new OperationContext();
context.getSendingRequestEventHandler().addListener(new StorageEvent<SendingRequestEvent>() {
@Override
public void eventOccurred(SendingRequestEvent eventArg) {
HttpURLConnection connection = (HttpURLConnection) eventArg.getConnectionObject();
assertEquals("no-cache", connection.getHeaderField(Constants.HeaderConstants.CACHE_CONTROL));
assertEquals("attachment; filename=\"fname.ext\"",
connection.getHeaderField(Constants.HeaderConstants.CONTENT_DISPOSITION));
assertEquals("gzip", connection.getHeaderField(Constants.HeaderConstants.CONTENT_ENCODING));
assertEquals("da", connection.getHeaderField(Constants.HeaderConstants.CONTENT_LANGUAGE));
assertEquals("text/html; charset=utf-8",
connection.getHeaderField(Constants.HeaderConstants.CONTENT_TYPE));
}
});
sasFile.download(new ByteArrayOutputStream(), null, null, context);
}
开发者ID:Azure,项目名称:azure-storage-android,代码行数:39,代码来源:FileSasTests.java
示例15: testCloudTableDeleteIfExistsErrorCode
import com.microsoft.azure.storage.SendingRequestEvent; //导入依赖的package包/类
@Test
public void testCloudTableDeleteIfExistsErrorCode() throws StorageException, URISyntaxException {
final CloudTable table = TableTestHelper.getRandomTableReference();
try {
assertFalse(table.deleteIfExists());
OperationContext ctx = new OperationContext();
ctx.getSendingRequestEventHandler().addListener(new StorageEvent<SendingRequestEvent>() {
@Override
public void eventOccurred(SendingRequestEvent eventArg) {
if (((HttpURLConnection) eventArg.getConnectionObject()).getRequestMethod().equals("DELETE")) {
try {
table.delete();
assertFalse(table.exists());
} catch (StorageException e) {
fail("Delete should succeed.");
}
}
}
});
table.create();
// The second delete of a table will return a 404
assertFalse(table.deleteIfExists(null, ctx));
} finally {
table.deleteIfExists();
}
}
开发者ID:Azure,项目名称:azure-storage-android,代码行数:31,代码来源:TableTests.java
示例16: testBlobSaSWithSharedAccessBlobHeaders
import com.microsoft.azure.storage.SendingRequestEvent; //导入依赖的package包/类
@Test
@Category(SlowTests.class)
public void testBlobSaSWithSharedAccessBlobHeaders() throws InvalidKeyException, IllegalArgumentException,
StorageException, URISyntaxException, InterruptedException {
SharedAccessBlobPolicy sp = createSharedAccessPolicy(EnumSet.of(SharedAccessBlobPermissions.READ,
SharedAccessBlobPermissions.WRITE, SharedAccessBlobPermissions.LIST), 300);
BlobContainerPermissions perms = new BlobContainerPermissions();
perms.getSharedAccessPolicies().put("readperm", sp);
this.container.uploadPermissions(perms);
Thread.sleep(30000);
SharedAccessBlobHeaders headers = new SharedAccessBlobHeaders();
headers.setCacheControl("no-cache");
headers.setContentDisposition("attachment; filename=\"fname.ext\"");
headers.setContentEncoding("gzip");
headers.setContentLanguage("da");
headers.setContentType("text/html; charset=utf-8");
CloudBlockBlob sasBlob = new CloudBlockBlob(new URI(this.blob.getUri().toString() + "?"
+ this.blob.generateSharedAccessSignature(null, headers, "readperm")));
OperationContext context = new OperationContext();
context.getSendingRequestEventHandler().addListener(new StorageEvent<SendingRequestEvent>() {
@Override
public void eventOccurred(SendingRequestEvent eventArg) {
HttpURLConnection connection = (HttpURLConnection) eventArg.getConnectionObject();
assertEquals("no-cache", connection.getHeaderField(Constants.HeaderConstants.CACHE_CONTROL));
assertEquals("attachment; filename=\"fname.ext\"",
connection.getHeaderField(Constants.HeaderConstants.CONTENT_DISPOSITION));
assertEquals("gzip", connection.getHeaderField(Constants.HeaderConstants.CONTENT_ENCODING));
assertEquals("da", connection.getHeaderField(Constants.HeaderConstants.CONTENT_LANGUAGE));
assertEquals("text/html; charset=utf-8",
connection.getHeaderField(Constants.HeaderConstants.CONTENT_TYPE));
}
});
sasBlob.download(new ByteArrayOutputStream(), null, null, context);
}
开发者ID:Azure,项目名称:azure-storage-java,代码行数:41,代码来源:SasTests.java
示例17: testCloudBlobContainerInvalidMetadata
import com.microsoft.azure.storage.SendingRequestEvent; //导入依赖的package包/类
@Test
@Category({ DevFabricTests.class, DevStoreTests.class })
public void testCloudBlobContainerInvalidMetadata() throws StorageException {
// test client-side fails correctly
testMetadataFailures(this.container, null, "value1", true);
testMetadataFailures(this.container, "", "value1", true);
testMetadataFailures(this.container, " ", "value1", true);
testMetadataFailures(this.container, "\n \t", "value1", true);
testMetadataFailures(this.container, "key1", null, false);
testMetadataFailures(this.container, "key1", "", false);
testMetadataFailures(this.container, "key1", " ", false);
testMetadataFailures(this.container, "key1", "\n \t", false);
// test client can get empty metadata
this.container.create();
OperationContext opContext = new OperationContext();
opContext.getSendingRequestEventHandler().addListener(new StorageEvent<SendingRequestEvent>() {
// insert a metadata element with an empty value
@Override
public void eventOccurred(SendingRequestEvent eventArg) {
HttpURLConnection request = (HttpURLConnection) eventArg.getConnectionObject();
request.setRequestProperty(Constants.HeaderConstants.PREFIX_FOR_STORAGE_METADATA + "key1", "");
}
});
this.container.uploadMetadata(null, null, opContext);
this.container.downloadAttributes();
assertEquals(1, this.container.getMetadata().size());
assertEquals("", this.container.getMetadata().get("key1"));
}
开发者ID:Azure,项目名称:azure-storage-java,代码行数:33,代码来源:CloudBlobContainerTests.java
示例18: testCloudTableDeleteIfExistsErrorCode
import com.microsoft.azure.storage.SendingRequestEvent; //导入依赖的package包/类
@Test
public void testCloudTableDeleteIfExistsErrorCode() throws StorageException, URISyntaxException {
final CloudTable table = TableTestHelper.getRandomTableReference();
try {
assertFalse(table.deleteIfExists());
OperationContext ctx = new OperationContext();
ctx.getSendingRequestEventHandler().addListener(new StorageEvent<SendingRequestEvent>() {
@Override
public void eventOccurred(SendingRequestEvent eventArg) {
if (((HttpURLConnection) eventArg.getConnectionObject()).getRequestMethod().equals("DELETE")) {
try {
table.delete();
assertFalse(table.exists());
}
catch (StorageException e) {
fail("Delete should succeed.");
}
}
}
});
table.create();
// The second delete of a table will return a 404
assertFalse(table.deleteIfExists(null, ctx));
}
finally {
table.deleteIfExists();
}
}
开发者ID:Azure,项目名称:azure-storage-java,代码行数:33,代码来源:TableTests.java
示例19: connect
import com.microsoft.azure.storage.SendingRequestEvent; //导入依赖的package包/类
@Override
public CloudBlobClient connect(final HostKeyCallback callback, final LoginCallback prompt) throws BackgroundException {
try {
final StorageCredentialsAccountAndKey credentials
= new StorageCredentialsAccountAndKey(host.getCredentials().getUsername(), "null");
// Client configured with no credentials
final URI uri = new URI(String.format("%s://%s", Scheme.https, host.getHostname()));
final CloudBlobClient client = new CloudBlobClient(uri, credentials);
client.setDirectoryDelimiter(String.valueOf(Path.DELIMITER));
final BlobRequestOptions options = new BlobRequestOptions();
options.setRetryPolicyFactory(new RetryNoRetry());
context.setLoggingEnabled(true);
context.setLogger(LoggerFactory.getLogger(log.getName()));
context.setUserHeaders(new HashMap<String, String>(Collections.singletonMap(
HttpHeaders.USER_AGENT, new PreferencesUseragentProvider().get()))
);
context.getSendingRequestEventHandler().addListener(listener = new StorageEvent<SendingRequestEvent>() {
@Override
public void eventOccurred(final SendingRequestEvent event) {
if(event.getConnectionObject() instanceof HttpsURLConnection) {
final HttpsURLConnection connection = (HttpsURLConnection) event.getConnectionObject();
connection.setSSLSocketFactory(new CustomTrustSSLProtocolSocketFactory(trust, key));
connection.setHostnameVerifier(new DisabledX509HostnameVerifier());
}
}
});
final Proxy proxy = ProxyFactory.get().find(host);
switch(proxy.getType()) {
case SOCKS: {
if(log.isInfoEnabled()) {
log.info(String.format("Configured to use SOCKS proxy %s", proxy));
}
final java.net.Proxy socksProxy = new java.net.Proxy(
java.net.Proxy.Type.SOCKS, new InetSocketAddress(proxy.getHostname(), proxy.getPort()));
context.setProxy(socksProxy);
break;
}
case HTTP:
case HTTPS: {
if(log.isInfoEnabled()) {
log.info(String.format("Configured to use HTTP proxy %s", proxy));
}
final java.net.Proxy httpProxy = new java.net.Proxy(
java.net.Proxy.Type.HTTP, new InetSocketAddress(proxy.getHostname(), proxy.getPort()));
context.setProxy(httpProxy);
break;
}
}
return client;
}
catch(URISyntaxException e) {
throw new LoginFailureException(e.getMessage(), e);
}
}
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:55,代码来源:AzureSession.java
示例20: sendingRequest
import com.microsoft.azure.storage.SendingRequestEvent; //导入依赖的package包/类
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));
}
}
开发者ID:naver,项目名称:hadoop,代码行数:53,代码来源:SelfThrottlingIntercept.java
注:本文中的com.microsoft.azure.storage.SendingRequestEvent类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论