Skip to content

Commit 2280569

Browse files
steveloughranarjun4084346
authored andcommitted
HADOOP-17325. WASB Test Failures
Contributed by Ayush Saxena and Steve Loughran Change-Id: I4bb76815bc1d11d1804dc67bafde68b6a995b974 (cherry picked from commit 07b7d07)
1 parent 7843368 commit 2280569

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/InMemoryBlockBlobStore.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import java.util.HashMap;
2626
import java.util.Map;
2727

28+
import static java.util.Objects.requireNonNull;
29+
2830
/**
2931
* A simple memory key-value store to help mock the Windows Azure Storage
3032
* implementation for unit testing.
@@ -163,7 +165,10 @@ public synchronized boolean exists(String key) {
163165

164166
@SuppressWarnings("unchecked")
165167
public synchronized HashMap<String, String> getMetadata(String key) {
166-
return (HashMap<String, String>) blobs.get(key).metadata.clone();
168+
Entry entry = requireNonNull(blobs.get(key), "entry for " + key);
169+
return (HashMap<String, String>) requireNonNull(entry.metadata,
170+
"metadata for " + key)
171+
.clone();
167172
}
168173

169174
public synchronized HashMap<String, String> getContainerMetadata() {

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/MockStorageInterface.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.apache.commons.codec.DecoderException;
3838
import org.apache.commons.codec.net.URLCodec;
3939
import org.apache.commons.lang.NotImplementedException;
40+
import org.apache.hadoop.fs.Path;
4041
import org.apache.http.client.utils.URIBuilder;
4142

4243
import com.microsoft.azure.storage.AccessCondition;
@@ -80,7 +81,7 @@ public InMemoryBlockBlobStore getBackingStore() {
8081
* Mocks the situation where a container already exists before WASB comes in,
8182
* i.e. the situation where a user creates a container then mounts WASB on the
8283
* pre-existing container.
83-
*
84+
*
8485
* @param uri
8586
* The URI of the container.
8687
* @param metadata
@@ -137,9 +138,20 @@ private static String convertUriToDecodedString(URI uri) {
137138

138139
private static URI convertKeyToEncodedUri(String key) {
139140
try {
140-
return new URIBuilder().setPath(key).build();
141+
Path p = new Path(key);
142+
URI unEncodedURI = p.toUri();
143+
return new URIBuilder().setPath(unEncodedURI.getPath())
144+
.setScheme(unEncodedURI.getScheme()).build();
141145
} catch (URISyntaxException e) {
142-
throw new AssertionError("Failed to encode key: " + key);
146+
int i = e.getIndex();
147+
String details;
148+
if (i >= 0) {
149+
details = " -- \"" + e.getInput().charAt(i) + "\"";
150+
} else {
151+
details = "";
152+
}
153+
throw new AssertionError("Failed to encode key: " + key
154+
+ ": " + e + details);
143155
}
144156
}
145157

@@ -148,8 +160,8 @@ public CloudBlobContainerWrapper getContainerReference(String name)
148160
throws URISyntaxException, StorageException {
149161
String fullUri;
150162
URIBuilder builder = new URIBuilder(baseUriString);
151-
fullUri = builder.setPath(builder.getPath() + "/" + name).toString();
152-
163+
String path = builder.getPath() == null ? "" : builder.getPath() + "/";
164+
fullUri = builder.setPath(path + name).toString();
153165
MockCloudBlobContainerWrapper container = new MockCloudBlobContainerWrapper(
154166
fullUri, name);
155167
// Check if we have a pre-existing container with that name, and prime
@@ -354,11 +366,11 @@ protected MockCloudBlobWrapper(URI uri, HashMap<String, String> metadata,
354366
this.uri = uri;
355367
this.metadata = metadata;
356368
this.properties = new BlobProperties();
357-
369+
358370
this.properties=updateLastModifed(this.properties);
359371
this.properties=updateLength(this.properties,length);
360372
}
361-
373+
362374
protected BlobProperties updateLastModifed(BlobProperties properties){
363375
try{
364376
Method setLastModified =properties.getClass().
@@ -371,7 +383,7 @@ protected BlobProperties updateLastModifed(BlobProperties properties){
371383
}
372384
return properties;
373385
}
374-
386+
375387
protected BlobProperties updateLength(BlobProperties properties,int length) {
376388
try{
377389
Method setLength =properties.getClass().
@@ -383,7 +395,7 @@ protected BlobProperties updateLength(BlobProperties properties,int length) {
383395
}
384396
return properties;
385397
}
386-
398+
387399
protected void refreshProperties(boolean getMetadata) {
388400
if (backingStore.exists(convertUriToDecodedString(uri))) {
389401
byte[] content = backingStore.getContent(convertUriToDecodedString(uri));

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/TestBlobMetadata.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,10 @@ public void testPermissionMetadata() throws Exception {
202202
Path selfishFile = new Path("/noOneElse");
203203
fs.create(selfishFile, justMe, true, 4096, fs.getDefaultReplication(),
204204
fs.getDefaultBlockSize(), null).close();
205+
String mockUri = AzureBlobStorageTestAccount.toMockUri(selfishFile);
206+
assertNotNull("converted URI", mockUri);
205207
HashMap<String, String> metadata = backingStore
206-
.getMetadata(AzureBlobStorageTestAccount.toMockUri(selfishFile));
208+
.getMetadata(mockUri);
207209
assertNotNull(metadata);
208210
String storedPermission = metadata.get("hdi_permission");
209211
assertEquals(getExpectedPermissionString("rw-------"), storedPermission);

0 commit comments

Comments
 (0)