本文整理汇总了Java中com.microsoft.azure.storage.blob.CloudBlobContainer.create方法的典型用法代码示例。如果您正苦于以下问题:Java CloudBlobContainer.create方法的具体用法?Java CloudBlobContainer.create怎么用?Java CloudBlobContainer.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.microsoft.azure.storage.blob.CloudBlobContainer
的用法示例。
在下文中一共展示了CloudBlobContainer.create方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRetryOn304
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
@Test
public void testRetryOn304() throws StorageException, IOException, URISyntaxException {
OperationContext operationContext = new OperationContext();
operationContext.getRetryingEventHandler().addListener(new StorageEvent<RetryingEvent>() {
@Override
public void eventOccurred(RetryingEvent eventArg) {
fail("Request should not be retried.");
}
});
CloudBlobContainer container = BlobTestHelper.getRandomContainerReference();
try {
container.create();
CloudBlockBlob blockBlobRef = (CloudBlockBlob) BlobTestHelper.uploadNewBlob(container, BlobType.BLOCK_BLOB,
"originalBlob", 1024, null);
AccessCondition accessCondition = AccessCondition.generateIfNoneMatchCondition(blockBlobRef.getProperties().getEtag());
blockBlobRef.download(new ByteArrayOutputStream(), accessCondition, null, operationContext);
fail("Download should fail with a 304.");
} catch (StorageException ex) {
assertEquals("The condition specified using HTTP conditional header(s) is not met.", ex.getMessage());
} finally {
container.deleteIfExists();
}
}
示例2: testCopyBlockBlobSas
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
@Test
@Category(SlowTests.class)
public void testCopyBlockBlobSas() throws Exception {
// Create source on server.
final CloudBlobContainer container = BlobTestHelper.getRandomContainerReference();
try {
container.create();
final CloudBlockBlob source = container.getBlockBlobReference("source");
source.getMetadata().put("Test", "value");
final String data = "String data";
source.uploadText(data, Constants.UTF8_CHARSET, null, null, null);
final CloudFile destination = doCloudBlobCopy(source, data.length());
final String copyData = destination.downloadText(Constants.UTF8_CHARSET, null, null, null);
assertEquals(data, copyData);
}
finally {
container.deleteIfExists();
}
}
示例3: testCopyPageBlobSas
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
@Test
@Category(SlowTests.class)
public void testCopyPageBlobSas() throws Exception {
// Create source on server.
final CloudBlobContainer container = BlobTestHelper.getRandomContainerReference();
try {
container.create();
final CloudPageBlob source = container.getPageBlobReference("source");
source.getMetadata().put("Test", "value");
final int length = 512;
final ByteArrayInputStream data = BlobTestHelper.getRandomDataStream(length);
source.upload(data, length);
final CloudFile destination = doCloudBlobCopy(source, length);
final ByteArrayOutputStream copyData = new ByteArrayOutputStream();
destination.download(copyData);
BlobTestHelper.assertStreamsAreEqual(data, new ByteArrayInputStream(copyData.toByteArray()));
}
finally {
container.deleteIfExists();
}
}
示例4: testContainerExistAfterDoesNotExist
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
@Test
public void testContainerExistAfterDoesNotExist() throws Exception {
testAccount = AzureBlobStorageTestAccount.create("",
EnumSet.noneOf(CreateOptions.class));
assumeNotNull(testAccount);
CloudBlobContainer container = testAccount.getRealContainer();
FileSystem fs = testAccount.getFileSystem();
// Starting off with the container not there
assertFalse(container.exists());
// A list shouldn't create the container and will set file system store
// state to DoesNotExist
try {
fs.listStatus(new Path("/"));
assertTrue("Should've thrown.", false);
} catch (FileNotFoundException ex) {
assertTrue("Unexpected exception: " + ex,
ex.getMessage().contains("does not exist."));
}
assertFalse(container.exists());
// Create a container outside of the WASB FileSystem
container.create();
// Add a file to the container outside of the WASB FileSystem
CloudBlockBlob blob = testAccount.getBlobReference("foo");
BlobOutputStream outputStream = blob.openOutputStream();
outputStream.write(new byte[10]);
outputStream.close();
// Make sure the file is visible
assertTrue(fs.exists(new Path("/foo")));
assertTrue(container.exists());
}
示例5: testContainerCreateAfterDoesNotExist
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
@Test
public void testContainerCreateAfterDoesNotExist() throws Exception {
testAccount = AzureBlobStorageTestAccount.create("",
EnumSet.noneOf(CreateOptions.class));
assumeNotNull(testAccount);
CloudBlobContainer container = testAccount.getRealContainer();
FileSystem fs = testAccount.getFileSystem();
// Starting off with the container not there
assertFalse(container.exists());
// A list shouldn't create the container and will set file system store
// state to DoesNotExist
try {
assertNull(fs.listStatus(new Path("/")));
assertTrue("Should've thrown.", false);
} catch (FileNotFoundException ex) {
assertTrue("Unexpected exception: " + ex,
ex.getMessage().contains("does not exist."));
}
assertFalse(container.exists());
// Create a container outside of the WASB FileSystem
container.create();
// Write should succeed
assertTrue(fs.createNewFile(new Path("/foo")));
assertTrue(container.exists());
}
示例6: createForEmulator
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
/**
* Creates a test account that goes against the storage emulator.
*
* @return The test account, or null if the emulator isn't setup.
*/
public static AzureBlobStorageTestAccount createForEmulator()
throws Exception {
saveMetricsConfigFile();
NativeAzureFileSystem fs = null;
CloudBlobContainer container = null;
Configuration conf = createTestConfiguration();
if (!conf.getBoolean(USE_EMULATOR_PROPERTY_NAME, false)) {
// Not configured to test against the storage emulator.
System.out
.println("Skipping emulator Azure test because configuration " +
"doesn't indicate that it's running." +
" Please see RunningLiveWasbTests.txt for guidance.");
return null;
}
CloudStorageAccount account =
CloudStorageAccount.getDevelopmentStorageAccount();
fs = new NativeAzureFileSystem();
String containerName = String.format("wasbtests-%s-%tQ",
System.getProperty("user.name"), new Date());
container = account.createCloudBlobClient().getContainerReference(
containerName);
container.create();
// Set account URI and initialize Azure file system.
URI accountUri = createAccountUri(DEFAULT_STORAGE_EMULATOR_ACCOUNT_NAME,
containerName);
fs.initialize(accountUri, conf);
// Create test account initializing the appropriate member variables.
//
AzureBlobStorageTestAccount testAcct =
new AzureBlobStorageTestAccount(fs, account, container);
return testAcct;
}
示例7: createContainer
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
@NotNull
public static String createContainer(@NotNull final StorageInputs inputs) throws Exception {
final CloudBlobClient blobClient = getCloudBlobClient(inputs);
final CloudBlobContainer container = blobClient.getContainerReference(inputs.getContainerName());
container.create();
return inputs.getContainerName();
}
示例8: createOutOfBandStore
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
public static AzureBlobStorageTestAccount createOutOfBandStore(
int uploadBlockSize, int downloadBlockSize) throws Exception {
saveMetricsConfigFile();
CloudBlobContainer container = null;
Configuration conf = createTestConfiguration();
CloudStorageAccount account = createTestAccount(conf);
if (null == account) {
return null;
}
String containerName = String.format("wasbtests-%s-%tQ",
System.getProperty("user.name"), new Date());
// Create the container.
container = account.createCloudBlobClient().getContainerReference(
containerName);
container.create();
String accountName = conf.get(TEST_ACCOUNT_NAME_PROPERTY_NAME);
// Ensure that custom throttling is disabled and tolerate concurrent
// out-of-band appends.
conf.setBoolean(KEY_DISABLE_THROTTLING, true);
conf.setBoolean(KEY_READ_TOLERATE_CONCURRENT_APPEND, true);
// Set account URI and initialize Azure file system.
URI accountUri = createAccountUri(accountName, containerName);
// Set up instrumentation.
//
AzureFileSystemMetricsSystem.fileSystemStarted();
String sourceName = NativeAzureFileSystem.newMetricsSourceName();
String sourceDesc = "Azure Storage Volume File System metrics";
AzureFileSystemInstrumentation instrumentation = new AzureFileSystemInstrumentation(conf);
AzureFileSystemMetricsSystem.registerSource(
sourceName, sourceDesc, instrumentation);
// Create a new AzureNativeFileSystemStore object.
AzureNativeFileSystemStore testStorage = new AzureNativeFileSystemStore();
// Initialize the store with the throttling feedback interfaces.
testStorage.initialize(accountUri, conf, instrumentation);
// Create test account initializing the appropriate member variables.
//
AzureBlobStorageTestAccount testAcct =
new AzureBlobStorageTestAccount(testStorage, account, container);
return testAcct;
}
示例9: create
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
public static AzureBlobStorageTestAccount create(String containerNameSuffix,
EnumSet<CreateOptions> createOptions, Configuration initialConfiguration)
throws Exception {
saveMetricsConfigFile();
NativeAzureFileSystem fs = null;
CloudBlobContainer container = null;
Configuration conf = createTestConfiguration(initialConfiguration);
configurePageBlobDir(conf);
configureAtomicRenameDir(conf);
CloudStorageAccount account = createTestAccount(conf);
if (account == null) {
return null;
}
fs = new NativeAzureFileSystem();
String containerName = String.format("wasbtests-%s-%tQ%s",
System.getProperty("user.name"), new Date(), containerNameSuffix);
container = account.createCloudBlobClient().getContainerReference(
containerName);
if (createOptions.contains(CreateOptions.CreateContainer)) {
container.create();
}
String accountName = conf.get(TEST_ACCOUNT_NAME_PROPERTY_NAME);
if (createOptions.contains(CreateOptions.UseSas)) {
String sas = generateSAS(container,
createOptions.contains(CreateOptions.Readonly));
if (!createOptions.contains(CreateOptions.CreateContainer)) {
// The caller doesn't want the container to be pre-created,
// so delete it now that we have generated the SAS.
container.delete();
}
// Remove the account key from the configuration to make sure we don't
// cheat and use that.
conf.set(ACCOUNT_KEY_PROPERTY_NAME + accountName, "");
// Set the SAS key.
conf.set(SAS_PROPERTY_NAME + containerName + "." + accountName, sas);
}
// Check if throttling is turned on and set throttling parameters
// appropriately.
if (createOptions.contains(CreateOptions.useThrottling)) {
conf.setBoolean(KEY_DISABLE_THROTTLING, false);
} else {
conf.setBoolean(KEY_DISABLE_THROTTLING, true);
}
// Set account URI and initialize Azure file system.
URI accountUri = createAccountUri(accountName, containerName);
fs.initialize(accountUri, conf);
// Create test account initializing the appropriate member variables.
//
AzureBlobStorageTestAccount testAcct =
new AzureBlobStorageTestAccount(fs, account, container);
return testAcct;
}
示例10: testStringToSign
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
@Test
public synchronized void testStringToSign()
throws IOException, InvalidKeyException, StorageException, URISyntaxException {
OperationContext.setLoggingEnabledByDefault(true);
final CloudBlobContainer cont = BlobTestHelper.getRandomContainerReference();
try {
cont.create();
final CloudBlob blob = BlobTestHelper.uploadNewBlob(cont, BlobType.BLOCK_BLOB, "", 0, null);
// Test logging for SAS access
baos.reset();
blob.generateSharedAccessSignature(null, null);
baos.flush();
String log = baos.toString();
String[] logEntries = log.split("[\\r\\n]+");
assertEquals(1, logEntries.length);
// example log entry: TRACE ROOT - {0b902691-1a8e-41da-ab60-5b912df186a6}: {Test string}
String[] segment = logEntries[0].split("\\{");
assertEquals(3, segment.length);
assertTrue(segment[1].startsWith("*"));
assertTrue(segment[2].startsWith(String.format(LogConstants.SIGNING, Constants.EMPTY_STRING)));
baos.reset();
// Test logging for Shared Key access
OperationContext ctx = new OperationContext();
blob.downloadAttributes(null, null, ctx);
baos.flush();
log = baos.toString();
logEntries = log.split("[\\r\\n]+");
assertNotEquals(0, logEntries.length);
// Select correct log entry
for (int n = 0; n < logEntries.length; n++) {
if (logEntries[n].startsWith(LoggerTests.TRACE)) {
segment = logEntries[n].split("\\{");
assertEquals(3, segment.length);
assertTrue(segment[1].startsWith(ctx.getClientRequestID()));
assertTrue(segment[2].startsWith(String.format(LogConstants.SIGNING, Constants.EMPTY_STRING)));
return;
}
}
// If this line is reached then the log entry was not found
fail();
}
finally {
cont.deleteIfExists();
}
}