• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java RetryNoRetry类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.microsoft.azure.storage.RetryNoRetry的典型用法代码示例。如果您正苦于以下问题:Java RetryNoRetry类的具体用法?Java RetryNoRetry怎么用?Java RetryNoRetry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



RetryNoRetry类属于com.microsoft.azure.storage包,在下文中一共展示了RetryNoRetry类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testBatchSecondaryWriteShouldThrow

import com.microsoft.azure.storage.RetryNoRetry; //导入依赖的package包/类
@Test
// don't need the category secondary as the request will fail before being sent
public void testBatchSecondaryWriteShouldThrow() {
    // create batch with an insert
    Class1 baseEntity = TableTestHelper.generateRandomEntity("jxscl_odata");
    TableOperation op = TableOperation.insert(baseEntity);

    TableBatchOperation batch = new TableBatchOperation();
    batch.add(op);

    // should not be able to make a request to secondary as there are writes
    try {
        TableRequestOptions options = new TableRequestOptions();
        options.setLocationMode(LocationMode.SECONDARY_ONLY);
        options.setRetryPolicyFactory(new RetryNoRetry());
        this.table.execute(batch, options, null);
        fail("Should not be able to make a request to secondary as there are writes.");
    }
    catch (StorageException e) {
        assertEquals(IllegalArgumentException.class, e.getCause().getClass());
        assertEquals(SR.PRIMARY_ONLY_COMMAND, e.getCause().getMessage());
    }
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:24,代码来源:TableBatchOperationTests.java


示例2: testBatchSecondaryNoWrite

import com.microsoft.azure.storage.RetryNoRetry; //导入依赖的package包/类
@Test
@Category(SecondaryTests.class)
public void testBatchSecondaryNoWrite() throws StorageException {
    // create and insert an entity
    Class1 ref = TableTestHelper.generateRandomEntity("jxscl_odata");
    this.table.execute(TableOperation.insert(ref));

    // create a batch and add a query for this entity
    TableBatchOperation batch = new TableBatchOperation();
    TableOperation queryOp = TableOperation.retrieve(ref.getPartitionKey(), ref.getRowKey(), ref.getClass());
    batch.add(queryOp);

    // should be able to make a request to secondary as there are no writes
    TableRequestOptions options = new TableRequestOptions();
    options.setLocationMode(LocationMode.SECONDARY_ONLY);
    options.setRetryPolicyFactory(new RetryNoRetry());
    this.table.execute(batch, options, null);
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:19,代码来源:TableBatchOperationTests.java


示例3: testPageBlobInputStream

import com.microsoft.azure.storage.RetryNoRetry; //导入依赖的package包/类
/**
 * @throws URISyntaxException
 * @throws StorageException
 * @throws IOException
 */
@Test
public void testPageBlobInputStream() throws URISyntaxException, StorageException, IOException {
    final int blobLength = 16 * 1024;
    final Random randGenerator = new Random();
    String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testblob");
    final CloudPageBlob blobRef = this.container.getPageBlobReference(blobName);

    final byte[] buff = new byte[blobLength];
    randGenerator.nextBytes(buff);
    buff[0] = -1;
    buff[1] = -128;
    final ByteArrayInputStream sourceStream = new ByteArrayInputStream(buff);

    final BlobRequestOptions options = new BlobRequestOptions();
    final OperationContext operationContext = new OperationContext();
    options.setTimeoutIntervalInMs(90000);
    options.setRetryPolicyFactory(new RetryNoRetry());
    blobRef.upload(sourceStream, blobLength, null, options, operationContext);

    BlobInputStream blobStream = blobRef.openInputStream();

    for (int i = 0; i < blobLength; i++) {
        int data = blobStream.read();
        assertTrue(data >= 0);
        assertEquals(buff[i], (byte) data);
    }

    assertEquals(-1, blobStream.read());

    blobRef.delete();
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:37,代码来源:CloudPageBlobTests.java


示例4: testAppendBlobInputStream

import com.microsoft.azure.storage.RetryNoRetry; //导入依赖的package包/类
@Test
public void testAppendBlobInputStream() throws URISyntaxException,
        StorageException, IOException {
    final int blobLength = 16 * 1024;
    final Random randGenerator = new Random();
    String blobName = BlobTestHelper
            .generateRandomBlobNameWithPrefix("testblob");
    final CloudAppendBlob blobRef = this.container
            .getAppendBlobReference(blobName);

    final byte[] buff = new byte[blobLength];
    randGenerator.nextBytes(buff);
    buff[0] = -1;
    buff[1] = -128;
    final ByteArrayInputStream sourceStream = new ByteArrayInputStream(buff);

    final BlobRequestOptions options = new BlobRequestOptions();
    final OperationContext operationContext = new OperationContext();
    options.setTimeoutIntervalInMs(90000);
    options.setRetryPolicyFactory(new RetryNoRetry());
    blobRef.upload(sourceStream, blobLength, null, options,
            operationContext);

    BlobInputStream blobStream = blobRef.openInputStream();

    for (int i = 0; i < blobLength; i++) {
        int data = blobStream.read();
        assertTrue(data >= 0);
        assertEquals(buff[i], (byte) data);
    }

    assertEquals(-1, blobStream.read());

    blobRef.delete();
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:36,代码来源:CloudAppendBlobTests.java


示例5: testBlobUploadFromStreamRequestOptionsTest

import com.microsoft.azure.storage.RetryNoRetry; //导入依赖的package包/类
@Test
@Category({ DevFabricTests.class, DevStoreTests.class })
public void testBlobUploadFromStreamRequestOptionsTest() throws URISyntaxException, StorageException, IOException {
    final String blockBlobName1 = BlobTestHelper.generateRandomBlobNameWithPrefix("testBlockBlob");
    final CloudBlockBlob blockBlobRef1 = this.container.getBlockBlobReference(blockBlobName1);

    final String blockBlobName2 = BlobTestHelper.generateRandomBlobNameWithPrefix("testBlockBlob");
    final CloudBlockBlob blockBlobRef2 = this.container.getBlockBlobReference(blockBlobName2);

    final int length = 2 * com.microsoft.azure.storage.Constants.MB;
    ByteArrayInputStream srcStream = BlobTestHelper.getRandomDataStream(length);

    BlobRequestOptions options = new BlobRequestOptions();
    options.setSingleBlobPutThresholdInBytes(length / 2);
    options.setRetryPolicyFactory(RetryNoRetry.getInstance());
    OperationContext context = new OperationContext();
    blockBlobRef1.upload(srcStream, length, null /* accessCondition */, options, context);

    assertTrue(context.getRequestResults().size() >= 2);

    srcStream.reset();
    options.setSingleBlobPutThresholdInBytes(length);
    context = new OperationContext();
    blockBlobRef2.upload(srcStream, length, null /* accessCondition */, options, context);

    assertTrue(context.getRequestResults().size() <= 2);
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:28,代码来源:CloudBlockBlobTests.java


示例6: testBlobInputStream

import com.microsoft.azure.storage.RetryNoRetry; //导入依赖的package包/类
/**
 * @throws URISyntaxException
 * @throws StorageException
 * @throws IOException
 */
@Test
@Category({ DevFabricTests.class, DevStoreTests.class })
public void testBlobInputStream() throws URISyntaxException, StorageException, IOException {
    final int blobLength = 16 * 1024;
    final Random randGenerator = new Random();
    String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testblob");
    final CloudBlockBlob blobRef = this.container.getBlockBlobReference(blobName);

    final byte[] buff = new byte[blobLength];
    randGenerator.nextBytes(buff);
    buff[0] = -1;
    buff[1] = -128;
    final ByteArrayInputStream sourceStream = new ByteArrayInputStream(buff);

    final BlobRequestOptions options = new BlobRequestOptions();
    final OperationContext operationContext = new OperationContext();
    options.setStoreBlobContentMD5(true);
    options.setTimeoutIntervalInMs(90000);
    options.setRetryPolicyFactory(new RetryNoRetry());
    blobRef.uploadFullBlob(sourceStream, blobLength, null, options, operationContext);

    BlobInputStream blobStream = blobRef.openInputStream();

    for (int i = 0; i < blobLength; i++) {
        int data = blobStream.read();
        assertTrue(data >= 0);
        assertEquals(buff[i], (byte) data);
    }

    assertEquals(-1, blobStream.read());

    blobRef.delete();
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:39,代码来源:CloudBlockBlobTests.java


示例7: testCloudFileInputStream

import com.microsoft.azure.storage.RetryNoRetry; //导入依赖的package包/类
/**
 * Test file input stream.
 * 
 * @throws URISyntaxException
 * @throws StorageException
 * @throws IOException
 */
@Test
public void testCloudFileInputStream() throws URISyntaxException, StorageException, IOException {
    final int fileLength = 16 * 1024;
    final Random randGenerator = new Random();
    String fileName = FileTestHelper.generateRandomFileName();
    final CloudFile fileRef = this.share.getRootDirectoryReference().getFileReference(fileName);

    final byte[] buff = new byte[fileLength];
    randGenerator.nextBytes(buff);
    buff[0] = -1;
    buff[1] = -128;
    final ByteArrayInputStream sourceStream = new ByteArrayInputStream(buff);

    final FileRequestOptions options = new FileRequestOptions();
    final OperationContext operationContext = new OperationContext();
    options.setTimeoutIntervalInMs(90000);
    options.setRetryPolicyFactory(new RetryNoRetry());
    fileRef.upload(sourceStream, fileLength, null, options, operationContext);

    com.microsoft.azure.storage.file.FileInputStream fileStream = fileRef.openRead();

    for (int i = 0; i < fileLength; i++) {
        int data = fileStream.read();
        assertTrue(data >= 0);
        assertEquals(buff[i], (byte) data);
    }

    assertEquals(-1, fileStream.read());

    fileRef.delete();
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:39,代码来源:CloudFileTests.java


示例8: testLargeBlobUploadFromStreamRequestOptionsTest

import com.microsoft.azure.storage.RetryNoRetry; //导入依赖的package包/类
@Test
@Category({ DevFabricTests.class, DevStoreTests.class })
public void testLargeBlobUploadFromStreamRequestOptionsTest() throws URISyntaxException, StorageException, IOException {
    final String blockBlobName1 = BlobTestHelper.generateRandomBlobNameWithPrefix("testBlockBlob");
    final CloudBlockBlob blockBlobRef1 = this.container.getBlockBlobReference(blockBlobName1);

    final String blockBlobName2 = BlobTestHelper.generateRandomBlobNameWithPrefix("testBlockBlob");
    final CloudBlockBlob blockBlobRef2 = this.container.getBlockBlobReference(blockBlobName2);

    final int length = 24 * Constants.MB;
    ByteArrayInputStream srcStream = BlobTestHelper.getRandomDataStream(length);

    BlobRequestOptions options = new BlobRequestOptions();
    options.setSingleBlobPutThresholdInBytes(length / 2);
    options.setRetryPolicyFactory(RetryNoRetry.getInstance());
    options.setConcurrentRequestCount(3);
    options.setStoreBlobContentMD5(false);
    OperationContext context = new OperationContext();
    blockBlobRef1.setStreamWriteSizeInBytes(4 * Constants.MB + 1 );
    blockBlobRef1.upload(srcStream, length, null /* accessCondition */, options, context);
    assertTrue(context.getRequestResults().size() >= 7);

    srcStream.reset();
    context = new OperationContext();
    blockBlobRef2.setStreamWriteSizeInBytes(8 * Constants.MB);
    blockBlobRef2.upload(srcStream, length, null /* accessCondition */, options, context);
    assertTrue(context.getRequestResults().size() >= 4);
}
 
开发者ID:Azure,项目名称:azure-storage-java,代码行数:29,代码来源:CloudBlockBlobTests.java


示例9: connect

import com.microsoft.azure.storage.RetryNoRetry; //导入依赖的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


示例10: suppressRetryPolicyInClientIfNeeded

import com.microsoft.azure.storage.RetryNoRetry; //导入依赖的package包/类
/**
 * If we're asked by unit tests to not retry, set the retry policy factory in
 * the client accordingly.
 */
private void suppressRetryPolicyInClientIfNeeded() {
  if (suppressRetryPolicy) {
    storageInteractionLayer.setRetryPolicyFactory(new RetryNoRetry());
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:10,代码来源:AzureNativeFileSystemStore.java


示例11: testTableSas

import com.microsoft.azure.storage.RetryNoRetry; //导入依赖的package包/类
@Test
@Category(SlowTests.class)
public void testTableSas() throws StorageException, URISyntaxException, InvalidKeyException, InterruptedException {
    CloudTableClient tClient = TableTestHelper.createCloudTableClient();

    // use capital letters to make sure SAS signature converts name to lower case correctly
    String name = "CAPS" + TableTestHelper.generateRandomTableName();
    CloudTable table = tClient.getTableReference(name);
    table.create();

    TablePermissions expectedPermissions = new TablePermissions();
    String identifier = UUID.randomUUID().toString();
    // Add a policy, check setting and getting.
    SharedAccessTablePolicy policy1 = new SharedAccessTablePolicy();
    Calendar now = GregorianCalendar.getInstance();
    now.add(Calendar.MINUTE, -10);
    policy1.setSharedAccessStartTime(now.getTime());
    now.add(Calendar.MINUTE, 30);
    policy1.setSharedAccessExpiryTime(now.getTime());

    policy1.setPermissions(EnumSet.of(SharedAccessTablePermissions.ADD, SharedAccessTablePermissions.QUERY,
            SharedAccessTablePermissions.UPDATE, SharedAccessTablePermissions.DELETE));
    expectedPermissions.getSharedAccessPolicies().put(identifier, policy1);

    table.uploadPermissions(expectedPermissions);
    Thread.sleep(30000);

    // Insert 500 entities in Batches to query
    for (int i = 0; i < 5; i++) {
        TableBatchOperation batch = new TableBatchOperation();

        for (int j = 0; j < 100; j++) {
            Class1 ent = TableTestHelper.generateRandomEntity("javatables_batch_" + Integer.toString(i));
            ent.setRowKey(String.format("%06d", j));
            batch.insert(ent);
        }

        table.execute(batch);
    }

    String sasString = table.generateSharedAccessSignature(policy1, null, "javatables_batch_0", "0",
            "javatables_batch_9", "9");
    CloudTableClient tableClientFromPermission = new CloudTableClient(tClient.getEndpoint(),
            new StorageCredentialsSharedAccessSignature(sasString));

    CloudTable policySasTable = tableClientFromPermission.getTableReference(name);

    // do not give the client and check that the new table's client has the correct perms
    CloudTable tableFromUri = new CloudTable(PathUtility.addToQuery(table.getStorageUri(), table
            .generateSharedAccessSignature((SharedAccessTablePolicy) null, identifier, "javatables_batch_0", "0",
                    "javatables_batch_9", "9")));
    assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), tableFromUri.getServiceClient()
            .getCredentials().getClass().toString());

    // create credentials from sas
    StorageCredentials creds = new StorageCredentialsSharedAccessSignature(
            table.generateSharedAccessSignature((SharedAccessTablePolicy) null, identifier, "javatables_batch_0", "0",
                    "javatables_batch_9", "9"));
    CloudTableClient tableClient = new CloudTableClient(policySasTable.getServiceClient().getStorageUri(), creds);

    // set some arbitrary settings to make sure they are passed on
    tableClient.getDefaultRequestOptions().setLocationMode(LocationMode.PRIMARY_THEN_SECONDARY);
    tableClient.getDefaultRequestOptions().setTimeoutIntervalInMs(1000);
    tableClient.getDefaultRequestOptions().setTablePayloadFormat(TablePayloadFormat.JsonNoMetadata);
    tableClient.getDefaultRequestOptions().setRetryPolicyFactory(new RetryNoRetry());

    tableFromUri = tableClient.getTableReference(table.getName());
    assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), tableFromUri.getServiceClient()
            .getCredentials().getClass().toString());

    assertEquals(tableClient.getDefaultRequestOptions().getLocationMode(), tableFromUri.getServiceClient()
            .getDefaultRequestOptions().getLocationMode());
    assertEquals(tableClient.getDefaultRequestOptions().getTimeoutIntervalInMs(), tableFromUri.getServiceClient()
            .getDefaultRequestOptions().getTimeoutIntervalInMs());
    assertEquals(tableClient.getDefaultRequestOptions().getTablePayloadFormat(), tableFromUri.getServiceClient()
            .getDefaultRequestOptions().getTablePayloadFormat());
    assertEquals(tableClient.getDefaultRequestOptions().getRetryPolicyFactory().getClass(), tableFromUri
            .getServiceClient().getDefaultRequestOptions().getRetryPolicyFactory().getClass());
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:80,代码来源:TableTests.java


示例12: testQueueSAS

import com.microsoft.azure.storage.RetryNoRetry; //导入依赖的package包/类
@Test
@Category({ DevFabricTests.class, DevStoreTests.class, SlowTests.class })
public void testQueueSAS() throws StorageException, URISyntaxException, InvalidKeyException, InterruptedException {
    this.queue.addMessage(new CloudQueueMessage("sas queue test"));
    QueuePermissions expectedPermissions;

    expectedPermissions = new QueuePermissions();
    // Add a policy, check setting and getting.
    SharedAccessQueuePolicy policy1 = new SharedAccessQueuePolicy();
    Calendar now = GregorianCalendar.getInstance();
    now.add(Calendar.MINUTE, -15);
    policy1.setSharedAccessStartTime(now.getTime());
    now.add(Calendar.MINUTE, 30);
    policy1.setSharedAccessExpiryTime(now.getTime());
    String identifier = UUID.randomUUID().toString();

    policy1.setPermissions(EnumSet.of(SharedAccessQueuePermissions.READ,
            SharedAccessQueuePermissions.PROCESSMESSAGES, SharedAccessQueuePermissions.ADD,
            SharedAccessQueuePermissions.UPDATE));
    expectedPermissions.getSharedAccessPolicies().put(identifier, policy1);

    this.queue.uploadPermissions(expectedPermissions);
    Thread.sleep(30000);

    CloudQueue identifierSasQueue = new CloudQueue(PathUtility.addToQuery(this.queue.getUri(),
            this.queue.generateSharedAccessSignature(null, identifier)));

    identifierSasQueue.downloadAttributes();
    identifierSasQueue.exists();

    identifierSasQueue.addMessage(new CloudQueueMessage("message"), 20, 0, null, null);
    CloudQueueMessage message1 = identifierSasQueue.retrieveMessage();
    identifierSasQueue.deleteMessage(message1);

    CloudQueue policySasQueue = new CloudQueue(PathUtility.addToQuery(this.queue.getUri(),
            this.queue.generateSharedAccessSignature(policy1, null)));
    policySasQueue.exists();
    policySasQueue.downloadAttributes();

    policySasQueue.addMessage(new CloudQueueMessage("message"), 20, 0, null, null);
    CloudQueueMessage message2 = policySasQueue.retrieveMessage();
    policySasQueue.deleteMessage(message2);

    // do not give the client and check that the new queue's client has the correct perms
    CloudQueue queueFromUri = new CloudQueue(PathUtility.addToQuery(this.queue.getStorageUri(),
            this.queue.generateSharedAccessSignature(null, "readperm")));
    assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), queueFromUri.getServiceClient()
            .getCredentials().getClass().toString());

    // pass in a client which will have different permissions and check the sas permissions are used
    // and that the properties set in the old service client are passed to the new client
    CloudQueueClient queueClient = policySasQueue.getServiceClient();

    // set some arbitrary settings to make sure they are passed on
    queueClient.getDefaultRequestOptions().setLocationMode(LocationMode.PRIMARY_THEN_SECONDARY);
    queueClient.getDefaultRequestOptions().setTimeoutIntervalInMs(1000);
    queueClient.getDefaultRequestOptions().setRetryPolicyFactory(new RetryNoRetry());

    queueFromUri = new CloudQueue(PathUtility.addToQuery(this.queue.getStorageUri(),
            this.queue.generateSharedAccessSignature(null, "readperm")));
    assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), queueFromUri.getServiceClient()
            .getCredentials().getClass().toString());
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:64,代码来源:CloudQueueTests.java


示例13: testTableSas

import com.microsoft.azure.storage.RetryNoRetry; //导入依赖的package包/类
@Category(SlowTests.class)
@Test
public void testTableSas() throws StorageException, URISyntaxException, InvalidKeyException, InterruptedException {

    CloudTableClient tClient = TableTestHelper.createCloudTableClient();
    tClient.getDefaultRequestOptions().setTablePayloadFormat(TablePayloadFormat.Json);

    // use capital letters to make sure SAS signature converts name to lower case correctly
    String name = "CAPS" + TableTestHelper.generateRandomTableName();
    CloudTable table = tClient.getTableReference(name);
    table.create();

    TablePermissions expectedPermissions = new TablePermissions();
    String identifier = UUID.randomUUID().toString();
    // Add a policy, check setting and getting.
    SharedAccessTablePolicy policy1 = new SharedAccessTablePolicy();
    Calendar now = GregorianCalendar.getInstance();
    now.add(Calendar.MINUTE, -10);
    policy1.setSharedAccessStartTime(now.getTime());
    now.add(Calendar.MINUTE, 30);
    policy1.setSharedAccessExpiryTime(now.getTime());

    policy1.setPermissions(EnumSet.of(SharedAccessTablePermissions.ADD, SharedAccessTablePermissions.QUERY,
            SharedAccessTablePermissions.UPDATE, SharedAccessTablePermissions.DELETE));
    expectedPermissions.getSharedAccessPolicies().put(identifier, policy1);

    table.uploadPermissions(expectedPermissions);
    Thread.sleep(30000);

    // Insert 500 entities in Batches to query
    for (int i = 0; i < 5; i++) {
        TableBatchOperation batch = new TableBatchOperation();

        for (int j = 0; j < 100; j++) {
            Class1 ent = TableTestHelper.generateRandomEntity("javatables_batch_" + Integer.toString(i));
            ent.setRowKey(String.format("%06d", j));
            batch.insert(ent);
        }

        table.execute(batch);
    }

    String sasString = table.generateSharedAccessSignature(policy1, null, "javatables_batch_0", "0",
            "javatables_batch_9", "9");
    CloudTableClient tableClientFromPermission = new CloudTableClient(tClient.getEndpoint(),
            new StorageCredentialsSharedAccessSignature(sasString));

    CloudTable policySasTable = tableClientFromPermission.getTableReference(name);

    // do not give the client and check that the new table's client has the correct perms
    CloudTable tableFromUri = new CloudTable(PathUtility.addToQuery(table.getStorageUri(), table
            .generateSharedAccessSignature((SharedAccessTablePolicy) null, identifier, "javatables_batch_0", "0",
                    "javatables_batch_9", "9")));
    assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), tableFromUri.getServiceClient()
            .getCredentials().getClass().toString());

    // create credentials from sas
    StorageCredentials creds = new StorageCredentialsSharedAccessSignature(
            table.generateSharedAccessSignature((SharedAccessTablePolicy) null, identifier, "javatables_batch_0", "0",
                    "javatables_batch_9", "9"));
    CloudTableClient tableClient = new CloudTableClient(policySasTable.getServiceClient().getStorageUri(), creds);

    // set some arbitrary settings to make sure they are passed on
    tableClient.getDefaultRequestOptions().setLocationMode(LocationMode.PRIMARY_THEN_SECONDARY);
    tableClient.getDefaultRequestOptions().setTimeoutIntervalInMs(1000);
    tableClient.getDefaultRequestOptions().setTablePayloadFormat(TablePayloadFormat.JsonNoMetadata);
    tableClient.getDefaultRequestOptions().setRetryPolicyFactory(new RetryNoRetry());

    tableFromUri = tableClient.getTableReference(table.getName());
    assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), tableFromUri.getServiceClient()
            .getCredentials().getClass().toString());

    assertEquals(tableClient.getDefaultRequestOptions().getLocationMode(), tableFromUri.getServiceClient()
            .getDefaultRequestOptions().getLocationMode());
    assertEquals(tableClient.getDefaultRequestOptions().getTimeoutIntervalInMs(), tableFromUri.getServiceClient()
            .getDefaultRequestOptions().getTimeoutIntervalInMs());
    assertEquals(tableClient.getDefaultRequestOptions().getTablePayloadFormat(), tableFromUri.getServiceClient()
            .getDefaultRequestOptions().getTablePayloadFormat());
    assertEquals(tableClient.getDefaultRequestOptions().getRetryPolicyFactory().getClass(), tableFromUri
            .getServiceClient().getDefaultRequestOptions().getRetryPolicyFactory().getClass());
}
 
开发者ID:Azure,项目名称:azure-storage-java,代码行数:82,代码来源:TableTests.java


示例14: testQueueSAS

import com.microsoft.azure.storage.RetryNoRetry; //导入依赖的package包/类
@Test
@Category({ SlowTests.class, DevFabricTests.class, DevStoreTests.class })
public void testQueueSAS() throws StorageException, URISyntaxException, InvalidKeyException, InterruptedException {
    this.queue.addMessage(new CloudQueueMessage("sas queue test"));
    QueuePermissions expectedPermissions;

    expectedPermissions = new QueuePermissions();
    // Add a policy, check setting and getting.
    SharedAccessQueuePolicy policy1 = new SharedAccessQueuePolicy();
    Calendar now = GregorianCalendar.getInstance();
    now.add(Calendar.MINUTE, -15);
    policy1.setSharedAccessStartTime(now.getTime());
    now.add(Calendar.MINUTE, 30);
    policy1.setSharedAccessExpiryTime(now.getTime());
    String identifier = UUID.randomUUID().toString();

    policy1.setPermissions(EnumSet.of(SharedAccessQueuePermissions.READ,
            SharedAccessQueuePermissions.PROCESSMESSAGES, SharedAccessQueuePermissions.ADD,
            SharedAccessQueuePermissions.UPDATE));
    expectedPermissions.getSharedAccessPolicies().put(identifier, policy1);

    this.queue.uploadPermissions(expectedPermissions);
    Thread.sleep(30000);

    CloudQueue identifierSasQueue = new CloudQueue(PathUtility.addToQuery(this.queue.getUri(),
            this.queue.generateSharedAccessSignature(null, identifier)));

    identifierSasQueue.downloadAttributes();
    identifierSasQueue.exists();

    identifierSasQueue.addMessage(new CloudQueueMessage("message"), 20, 0, null, null);
    CloudQueueMessage message1 = identifierSasQueue.retrieveMessage();
    identifierSasQueue.deleteMessage(message1);

    CloudQueue policySasQueue = new CloudQueue(PathUtility.addToQuery(this.queue.getUri(),
            this.queue.generateSharedAccessSignature(policy1, null)));
    policySasQueue.exists();
    policySasQueue.downloadAttributes();

    policySasQueue.addMessage(new CloudQueueMessage("message"), 20, 0, null, null);
    CloudQueueMessage message2 = policySasQueue.retrieveMessage();
    policySasQueue.deleteMessage(message2);

    // do not give the client and check that the new queue's client has the correct perms
    CloudQueue queueFromUri = new CloudQueue(PathUtility.addToQuery(this.queue.getStorageUri(),
            this.queue.generateSharedAccessSignature(null, "readperm")));
    assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), queueFromUri.getServiceClient()
            .getCredentials().getClass().toString());

    // pass in a client which will have different permissions and check the sas permissions are used
    // and that the properties set in the old service client are passed to the new client
    CloudQueueClient queueClient = policySasQueue.getServiceClient();

    // set some arbitrary settings to make sure they are passed on
    queueClient.getDefaultRequestOptions().setLocationMode(LocationMode.PRIMARY_THEN_SECONDARY);
    queueClient.getDefaultRequestOptions().setTimeoutIntervalInMs(1000);
    queueClient.getDefaultRequestOptions().setRetryPolicyFactory(new RetryNoRetry());

    queueFromUri = new CloudQueue(PathUtility.addToQuery(this.queue.getStorageUri(),
            this.queue.generateSharedAccessSignature(null, "readperm")));
    assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), queueFromUri.getServiceClient()
            .getCredentials().getClass().toString());
}
 
开发者ID:Azure,项目名称:azure-storage-java,代码行数:64,代码来源:CloudQueueTests.java



注:本文中的com.microsoft.azure.storage.RetryNoRetry类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Specialization类代码示例发布时间:2022-05-23
下一篇:
Java LiveFolders类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap