Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.

Commit 9248873

Browse files
committed
Merge pull request #51 from emgerner-msft/master
Java Storage Client Library 3.1.0
2 parents 71a603d + 6ac4a02 commit 9248873

29 files changed

+530
-775
lines changed

ChangeLog.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2015.09.16 Version 3.1.0
2+
* Fixed a bug in table where a select on a non-existent field resulted in a null reference exception if the corresponding field in the TableEntity was not nullable.
3+
* Fixed a bug in table where JsonParser was automatically closing the response stream before it was completely drained causing socket exhaustion.
4+
* Fixed a bug in StorageCredentialsAccountAndKey.updateKey(String) which prevented valid keys from being set.
5+
* Added CloudBlobContainer.listBlobs(final String, final boolean) method.
6+
* Fixed a bug in blob where using AccessConditions on block blob uploads larger than 64MB done with the upload* methods or block blob uploads done openOutputStream with would fail if the blob did not already exist.
7+
* Added support for setting a proxy per request. Proxy can be set on an OperationContext instance and will be used when that instance is passed to the request method.
8+
19
2015.08.04 Version 3.0.0
210
* Added support for SAS to the Azure File service.
311
* Added support for Append Blob.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ To get the binaries of this library as distributed by Microsoft, ready for use w
3030
<dependency>
3131
<groupId>com.microsoft.azure</groupId>
3232
<artifactId>azure-storage</artifactId>
33-
<version>3.0.0</version>
33+
<version>3.1.0</version>
3434
</dependency>
3535
```
3636

microsoft-azure-storage-samples/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<dependency>
2727
<groupId>com.microsoft.azure</groupId>
2828
<artifactId>azure-storage</artifactId>
29-
<version>3.0.0</version>
29+
<version>3.1.0</version>
3030
</dependency>
3131
</dependencies>
3232
</project>

microsoft-azure-storage-test/src/com/microsoft/azure/storage/StorageAccountTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,24 @@ public void testStorageCredentialsSharedKey() throws URISyntaxException, Storage
7575
cred = new StorageCredentialsAccountAndKey(ACCOUNT_NAME, base64EncodedDummyKey);
7676
assertEquals(base64EncodedDummyKey, cred.exportBase64EncodedKey());
7777
}
78+
79+
@Test
80+
public void testStorageCredentialsSharedKeyUpdateKey() throws URISyntaxException, StorageException {
81+
StorageCredentialsAccountAndKey cred = new StorageCredentialsAccountAndKey(ACCOUNT_NAME, ACCOUNT_KEY);
82+
assertEquals(ACCOUNT_KEY, cred.exportBase64EncodedKey());
83+
84+
// Validate update with byte array
85+
byte[] dummyKey = { 0, 1, 2 };
86+
cred.updateKey(dummyKey);
87+
String base64EncodedDummyKey = Base64.encode(dummyKey);
88+
assertEquals(base64EncodedDummyKey, cred.exportBase64EncodedKey());
89+
90+
// Validate update with string
91+
dummyKey[0] = 3;
92+
base64EncodedDummyKey = Base64.encode(dummyKey);
93+
cred.updateKey(base64EncodedDummyKey);
94+
assertEquals(base64EncodedDummyKey, cred.exportBase64EncodedKey());
95+
}
7896

7997
@Test
8098
public void testStorageCredentialsSAS() throws URISyntaxException, StorageException {

microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/BlobOutputStreamTests.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.net.HttpURLConnection;
2222
import java.net.URISyntaxException;
2323
import java.util.ArrayList;
24+
import java.util.Date;
2425
import java.util.concurrent.Callable;
2526
import java.util.concurrent.ExecutorCompletionService;
2627
import java.util.concurrent.ExecutorService;
@@ -32,6 +33,7 @@
3233
import org.junit.Test;
3334
import org.junit.experimental.categories.Category;
3435

36+
import com.microsoft.azure.storage.AccessCondition;
3537
import com.microsoft.azure.storage.Constants;
3638
import com.microsoft.azure.storage.OperationContext;
3739
import com.microsoft.azure.storage.ResponseReceivedEvent;
@@ -100,6 +102,36 @@ public void testClose() throws URISyntaxException, StorageException, IOException
100102
assertEquals(1, blocks.size());
101103
}
102104

105+
@Test
106+
public void testWithAccessCondition() throws URISyntaxException, StorageException, IOException {
107+
int blobLengthToUse = 8 * 512;
108+
byte[] buffer = BlobTestHelper.getRandomBuffer(blobLengthToUse);
109+
String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testblob");
110+
AccessCondition accessCondition = AccessCondition.generateIfNotModifiedSinceCondition(new Date());
111+
112+
CloudBlockBlob blockBlob = this.container.getBlockBlobReference(blobName);
113+
BlobOutputStream blobOutputStream = blockBlob.openOutputStream(accessCondition, null, null);
114+
ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer);
115+
blobOutputStream.write(inputStream, 512);
116+
117+
inputStream = new ByteArrayInputStream(buffer, 512, 3 * 512);
118+
blobOutputStream.write(inputStream, 3 * 512);
119+
120+
blobOutputStream.close();
121+
122+
byte[] result = new byte[blobLengthToUse];
123+
blockBlob.downloadToByteArray(result, 0);
124+
125+
int i = 0;
126+
for (; i < 4 * 512; i++) {
127+
assertEquals(buffer[i], result[i]);
128+
}
129+
130+
for (; i < 8 * 512; i++) {
131+
assertEquals(0, result[i]);
132+
}
133+
}
134+
103135
@Test
104136
public void testWriteStream() throws URISyntaxException, StorageException, IOException {
105137
int blobLengthToUse = 8 * 512;

microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/CloudBlobContainerTests.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,46 @@ public void testCloudBlobContainerListBlobs() throws StorageException, IOExcepti
449449
assertTrue(blobNames.size() == 0);
450450
}
451451

452+
/**
453+
* List the blobs in a container with a prefix
454+
*
455+
* @throws URISyntaxException
456+
* @throws StorageException
457+
* @throws IOException
458+
*/
459+
@Test
460+
@Category({ DevFabricTests.class, DevStoreTests.class })
461+
public void testCloudBlobContainerListBlobsPrefix() throws StorageException, IOException, URISyntaxException {
462+
this.container.create();
463+
int numBlobs = 2;
464+
List<String> blobNames = BlobTestHelper
465+
.uploadNewBlobs(this.container, BlobType.BLOCK_BLOB, numBlobs, 128, null);
466+
467+
BlobTestHelper.uploadNewBlob(this.container, BlobType.BLOCK_BLOB, "pref/blob1", 128, null);
468+
blobNames.add("pref/blob1");
469+
470+
BlobTestHelper.uploadNewBlob(this.container, BlobType.BLOCK_BLOB, "pref/blob2", 128, null);
471+
blobNames.add("pref/blob2");
472+
473+
// Flat listing false
474+
int count = 0;
475+
for (ListBlobItem blob : this.container.listBlobs("pref")) {
476+
assertEquals(CloudBlobDirectory.class, blob.getClass());
477+
assertTrue(((CloudBlobDirectory)blob).getPrefix().startsWith("pref"));
478+
count++;
479+
}
480+
assertEquals(1, count);
481+
482+
// Flat listing true
483+
count = 0;
484+
for (ListBlobItem blob : this.container.listBlobs("pref", true)) {
485+
assertEquals(CloudBlockBlob.class, blob.getClass());
486+
assertTrue(((CloudBlockBlob)blob).getName().startsWith("pref/blob"));
487+
count++;
488+
}
489+
assertEquals(2, count);
490+
}
491+
452492
/**
453493
* List the blobs in a container with next(). This tests for the item in the changelog: "Fixed a bug for all
454494
* listing API's where next() would sometimes throw an exception if hasNext() had not been called even if

microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/CloudBlockBlobTests.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,27 @@ public void testBlobUploadFromStreamTest() throws URISyntaxException, StorageExc
899899
blockBlobRef.download(dstStream);
900900
BlobTestHelper.assertStreamsAreEqual(srcStream, new ByteArrayInputStream(dstStream.toByteArray()));
901901
}
902+
903+
@Test
904+
public void testBlobUploadFromStreamAccessConditionTest() throws URISyntaxException, StorageException, IOException {
905+
final String blockBlobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testBlockBlob");
906+
final CloudBlockBlob blockBlobRef = this.container.getBlockBlobReference(blockBlobName);
907+
AccessCondition accessCondition = AccessCondition.generateIfNotModifiedSinceCondition(new Date());
908+
909+
int length = 2 * 1024;
910+
ByteArrayInputStream srcStream = BlobTestHelper.getRandomDataStream(length);
911+
blockBlobRef.upload(srcStream, -1, accessCondition, null, null);
912+
ByteArrayOutputStream dstStream = new ByteArrayOutputStream();
913+
blockBlobRef.download(dstStream);
914+
BlobTestHelper.assertStreamsAreEqual(srcStream, new ByteArrayInputStream(dstStream.toByteArray()));
915+
916+
length = 5 * 1024 * 1024;
917+
srcStream = BlobTestHelper.getRandomDataStream(length);
918+
blockBlobRef.upload(srcStream, length);
919+
dstStream = new ByteArrayOutputStream();
920+
blockBlobRef.download(dstStream);
921+
BlobTestHelper.assertStreamsAreEqual(srcStream, new ByteArrayInputStream(dstStream.toByteArray()));
922+
}
902923

903924
@Test
904925
@Category({ DevFabricTests.class, DevStoreTests.class })

microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,8 +1488,7 @@ private void doCloudFileCopy(boolean sourceIsSas, boolean destinationIsSas)
14881488

14891489
// Get destination file reference
14901490
StorageCredentialsSharedAccessSignature credentials = new StorageCredentialsSharedAccessSignature(sasToken);
1491-
copyDestination = new CloudFile(destination.getUri(),
1492-
destination.getServiceClient().getCredentials());
1491+
copyDestination = new CloudFile(destination.getUri(), credentials);
14931492
}
14941493

14951494
// Start copy and wait for completion

microsoft-azure-storage-test/src/com/microsoft/azure/storage/table/TableQueryTests.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Arrays;
2323
import java.util.Date;
2424
import java.util.HashMap;
25+
import java.util.List;
2526
import java.util.UUID;
2627

2728
import org.junit.AfterClass;
@@ -133,6 +134,70 @@ private void testTableWithSelectOnMissingFields(TableRequestOptions options) thr
133134
assertEquals(EdmType.STRING, ent.getProperties().get("F").getEdmType());
134135
}
135136

137+
@SuppressWarnings("deprecation")
138+
@Test
139+
public void testTableQueryProjectionWithNull() throws URISyntaxException, StorageException {
140+
CloudTable table = TableTestHelper.getRandomTableReference();
141+
try {
142+
// Create a new table so we don't pollute the main query table
143+
table.createIfNotExists();
144+
145+
// Insert an entity which is missing String and IntegerPrimitive
146+
DynamicTableEntity entity = new DynamicTableEntity(UUID.randomUUID().toString(), UUID.randomUUID()
147+
.toString());
148+
table.execute(TableOperation.insert(entity));
149+
150+
testTableQueryProjectionWithSpecialCases(table, TablePayloadFormat.Json);
151+
testTableQueryProjectionWithSpecialCases(table, TablePayloadFormat.AtomPub);
152+
}
153+
finally {
154+
table.deleteIfExists();
155+
}
156+
}
157+
158+
@SuppressWarnings("deprecation")
159+
@Test
160+
public void testTableQueryProjectionWithIncorrectTypes() throws URISyntaxException, StorageException {
161+
CloudTable table = TableTestHelper.getRandomTableReference();
162+
try {
163+
// Create a new table so we don't pollute the main query table
164+
table.createIfNotExists();
165+
166+
// Insert an entity with String as an int, and IntegerPrimitive as a bool
167+
DynamicTableEntity entity = new DynamicTableEntity(UUID.randomUUID().toString(), UUID.randomUUID()
168+
.toString());
169+
entity.getProperties().put("String", new EntityProperty(1234));
170+
entity.getProperties().put("IntegerPrimitive", new EntityProperty(true));
171+
table.execute(TableOperation.insert(entity));
172+
173+
testTableQueryProjectionWithSpecialCases(table, TablePayloadFormat.Json);
174+
testTableQueryProjectionWithSpecialCases(table, TablePayloadFormat.AtomPub);
175+
}
176+
finally {
177+
table.deleteIfExists();
178+
}
179+
}
180+
181+
private void testTableQueryProjectionWithSpecialCases(CloudTable table, TablePayloadFormat format) {
182+
table.getServiceClient().getDefaultRequestOptions().setTablePayloadFormat(format);
183+
184+
// Query on String and IntegerPrimitive
185+
TableQuery<ComplexEntity> query = TableQuery.from(ComplexEntity.class).select(
186+
new String[] { "String", "IntegerPrimitive"});
187+
Iterable<ComplexEntity> iterable = table.execute(query);
188+
189+
List<ComplexEntity> entities = new ArrayList<ComplexEntity>();
190+
for (ComplexEntity entity : iterable) {
191+
entities.add(entity);
192+
}
193+
194+
// Verify A has a set value and B and E have class defaults
195+
assertEquals(1, entities.size());
196+
ComplexEntity entity = entities.get(0);
197+
assertNull(entity.getString());
198+
assertEquals(-1, entity.getIntegerPrimitive());
199+
}
200+
136201
@Test
137202
public void testTableQueryWithSpecialChars() throws StorageException, URISyntaxException {
138203
CloudTable table = TableTestHelper.getRandomTableReference();

microsoft-azure-storage/src/com/microsoft/azure/storage/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ public static class HeaderConstants {
550550
/**
551551
* Specifies the value to use for UserAgent header.
552552
*/
553-
public static final String USER_AGENT_VERSION = "3.0.0";
553+
public static final String USER_AGENT_VERSION = "3.1.0";
554554

555555
/**
556556
* The default type for content-type and accept

0 commit comments

Comments
 (0)