下面列出了怎么用org.apache.hadoop.fs.azure.AzureException的API类实例代码及写法,或者点击链接到github查看源代码。
@Test
public void testClientErrorMetrics() throws Exception {
String directoryName = "metricsTestDirectory_ClientError";
Path directoryPath = new Path("/" + directoryName);
assertTrue(fs.mkdirs(directoryPath));
String leaseID = testAccount.acquireShortLease(directoryName);
try {
try {
fs.delete(directoryPath, true);
assertTrue("Should've thrown.", false);
} catch (AzureException ex) {
assertTrue("Unexpected exception: " + ex,
ex.getMessage().contains("lease"));
}
assertEquals(1, AzureMetricsTestUtil.getLongCounterValue(getInstrumentation(), WASB_CLIENT_ERRORS));
assertEquals(0, AzureMetricsTestUtil.getLongCounterValue(getInstrumentation(), WASB_SERVER_ERRORS));
} finally {
testAccount.releaseLease(leaseID, directoryName);
}
}
@Test
public void testClientErrorMetrics() throws Exception {
String directoryName = "metricsTestDirectory_ClientError";
Path directoryPath = new Path("/" + directoryName);
assertTrue(fs.mkdirs(directoryPath));
String leaseID = testAccount.acquireShortLease(directoryName);
try {
try {
fs.delete(directoryPath, true);
assertTrue("Should've thrown.", false);
} catch (AzureException ex) {
assertTrue("Unexpected exception: " + ex,
ex.getMessage().contains("lease"));
}
assertEquals(1, AzureMetricsTestUtil.getLongCounterValue(getInstrumentation(), WASB_CLIENT_ERRORS));
assertEquals(0, AzureMetricsTestUtil.getLongCounterValue(getInstrumentation(), WASB_SERVER_ERRORS));
} finally {
testAccount.releaseLease(leaseID, directoryName);
}
}
@Test
public void testCreateFsWithAuthorityMissingCreds() throws Exception {
String uriString = String.format("%s://[email protected]/testDir", scheme);
final URI uri = URI.create(uriString);
exception.expect(AzureException.class);
AbstractAzureFSFactory factory = getFactory(scheme);
Configuration config = new Configuration();
config.setInteger("fs.azure.io.retry.max.retries", 0);
factory.configure(config);
factory.create(uri);
}
/**
* Read "size" bytes of data and verify that what was read and what was written
* are the same.
*/
private void readRandomDataAndVerify(int size) throws AzureException, IOException {
byte[] b = new byte[size];
FSDataInputStream stream = fs.open(PATH);
int bytesRead = stream.read(b);
stream.close();
assertEquals(bytesRead, size);
// compare the data read to the data written
assertTrue(comparePrefix(randomData, b, size));
}
/**
* Read "size" bytes of data and verify that what was read and what was written
* are the same.
*/
private void readRandomDataAndVerify(int size) throws AzureException, IOException {
byte[] b = new byte[size];
FSDataInputStream stream = fs.open(PATH);
int bytesRead = stream.read(b);
stream.close();
assertEquals(bytesRead, size);
// compare the data read to the data written
assertTrue(comparePrefix(randomData, b, size));
}
@Test
public void testCreateFsWithAuthorityMissingCreds() throws Exception {
String uriString = String.format("%s://[email protected]/testDir", scheme);
final URI uri = URI.create(uriString);
exception.expect(AzureException.class);
AbstractAzureFSFactory factory = getFactory(scheme);
Configuration config = new Configuration();
config.setInteger("fs.azure.io.retry.max.retries", 0);
factory.configure(config);
factory.create(uri);
}
/**
* Get a self-renewing lease on the specified file.
*/
public SelfRenewingLease acquireLease(Path path) throws AzureException {
String fullKey = pathToKey(makeAbsolute(path));
return getStore().acquireLease(fullKey);
}
/**
* Get a self-renewing Azure blob lease on the source folder zero-byte file.
*/
private SelfRenewingLease leaseSourceFolder(String srcKey)
throws AzureException {
return store.acquireLease(srcKey);
}
/**
* Get a self-renewing lease on the specified file.
*/
public SelfRenewingLease acquireLease(Path path) throws AzureException {
String fullKey = pathToKey(makeAbsolute(path));
return getStore().acquireLease(fullKey);
}
/**
* Get a self-renewing Azure blob lease on the source folder zero-byte file.
*/
private SelfRenewingLease leaseSourceFolder(String srcKey)
throws AzureException {
return store.acquireLease(srcKey);
}