Skip to content

Commit 71e5ba6

Browse files
committed
Merge pull request #47 from shellygms/master
DocumentDB JavaSDK version 1.7.1 Release
2 parents 7f01748 + 0d1d3b8 commit 71e5ba6

40 files changed

+1308
-846
lines changed

.classpath

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<attribute name="maven.pomderived" value="true"/>
77
</attributes>
88
</classpathentry>
9+
<classpathentry kind="src" output="target/classes" path="test"/>
910
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
1011
<attributes>
1112
<attribute name="maven.pomderived" value="true"/>
@@ -17,4 +18,4 @@
1718
</attributes>
1819
</classpathentry>
1920
<classpathentry kind="output" path="target/classes"/>
20-
</classpath>
21+
</classpath>

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ To get the binaries of this library as distributed by Microsoft, ready for use w
1414
<dependency>
1515
<groupId>com.microsoft.azure</groupId>
1616
<artifactId>azure-documentdb</artifactId>
17-
<version>1.7.0</version>
17+
<version>1.7.1</version>
1818
</dependency>
1919

2020
###Option 2: Source Via Git
@@ -39,6 +39,7 @@ To download a copy of the source code, click "Download ZIP" on the right side of
3939
* Jackson Data Mapper 1.8 (org.codehaus.jackson / jackson-mapper-asl / 1.8.5)
4040
* JSON 20140107 (org.json / json / 20140107)
4141
* JUnit 4.11 (junit / junit / 4.11)
42+
* mockito 1.10.19 (org.mockito / mockito-core / 1.10.19)
4243

4344
Dependencies will be added automatically if Maven is used. Otherwise, please download the jars and add them to your build path.
4445

changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## Changes in 1.7.1 : ##
2+
3+
- Setting Cookie policy on httpclient to ignoring server cookies as we don't use them.
4+
- Added support to retry on throttled requests.
5+
- Removed e.printstacktrace from source code and replaced with Logger operations as appropriate.
6+
- Changed test code structure and added mocking framework for unit testing.
7+
18
## Changes in 1.7.0 : ##
29

310
- Added support for expiring documents by setting the default time-to-live on collections and time-to-live override on documents.

pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.microsoft.azure</groupId>
55
<artifactId>azure-documentdb</artifactId>
6-
<version>1.7.0</version>
6+
<version>1.7.1</version>
77
<name>${project.groupId}:${project.artifactId}</name>
88
<description>Java SDK for Microsoft Azure DocumentDB</description>
99
<url>http://azure.microsoft.com/en-us/services/documentdb/</url>
@@ -166,6 +166,11 @@
166166
<artifactId>httpcore</artifactId>
167167
<version>4.2.5</version>
168168
</dependency>
169+
<dependency>
170+
<groupId>org.mockito</groupId>
171+
<artifactId>mockito-core</artifactId>
172+
<version>1.10.19</version>
173+
</dependency>
169174
</dependencies>
170175
<distributionManagement>
171176
<snapshotRepository>

src/com/microsoft/azure/documentdb/BackoffRetryUtility.java

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,70 @@
11
package com.microsoft.azure.documentdb;
22

3+
/**
4+
* A utility class to manage retries for resource throttled errors. It invokes a
5+
* delegate function to execute the target operation. Upon error, it waits a
6+
* period of time as defined in the ResourceThrottleRetryPolicy instance before
7+
* re-issuing the same request. The ResourceThrottleRetryPolicy object decides
8+
* the wait period based on the 'x-ms-retry-after-ms' response header sent by server.
9+
*
10+
*/
311
class BackoffRetryUtility {
412

513
/**
6-
* Executes the code block in the delegate and maybe retries.
14+
* Executes the code block in the delegate and retry if needed.
715
*
8-
* @param delegate the delegate to execute.
9-
* @param retryPolicy the retry policy.
16+
* @param delegate
17+
* the delegate to execute.
18+
* @param request
19+
* the request parameter for the execution.
20+
* @param maxRetryAttempts
21+
* the max number of retries.
22+
* @throws DocumentClientException
23+
* the original exception if retry is not applicable or if number of retries
24+
* exceeded maxRetryAttempts.
1025
*/
11-
public static void execute(BackoffRetryUtilityDelegate delegate, ResourceThrottleRetryPolicy retryPolicy) {
26+
public static DocumentServiceResponse execute(BackoffRetryUtilityDelegate delegate, DocumentServiceRequest request,
27+
int maxRetryAttempts) throws DocumentClientException {
28+
DocumentServiceResponse response = null;
29+
ResourceThrottleRetryPolicy retryPolicy = new ResourceThrottleRetryPolicy(maxRetryAttempts);
30+
while (true) {
31+
try {
32+
response = delegate.apply(request);
33+
break;
34+
} catch (DocumentClientException e) {
35+
boolean retry = retryPolicy.shouldRetry(e);
36+
if (!retry) {
37+
throw e;
38+
}
39+
40+
BackoffRetryUtility.delayForRetry(retryPolicy);
41+
}
42+
}
43+
44+
return response;
45+
}
46+
47+
/**
48+
* Executes the code block in the delegate and retry if needed.
49+
*
50+
* @param delegate
51+
* the delegate to execute.
52+
* @param maxRetryAttempts
53+
* the max number of retries.
54+
*/
55+
public static void execute(QueryBackoffRetryUtilityDelegate delegate, int maxRetryAttempts) {
56+
ResourceThrottleRetryPolicy retryPolicy = new ResourceThrottleRetryPolicy(maxRetryAttempts);
1257
while (true) {
1358
try {
1459
delegate.apply();
15-
break; // Break from the while loop if no exception happened.
60+
break;
1661
} catch (Exception e) {
17-
boolean retry = retryPolicy.shouldRetry(e);
62+
boolean retry = false;
63+
if (DocumentClientException.class == e.getClass()) {
64+
retry = retryPolicy.shouldRetry((DocumentClientException) e);
65+
}
66+
1867
if (!retry) {
19-
e.printStackTrace();
2068
throw new IllegalStateException("Exception not retriable", e);
2169
}
2270

@@ -32,7 +80,6 @@ private static void delayForRetry(ResourceThrottleRetryPolicy retryPolicy) {
3280
Thread.sleep(delay);
3381
} catch (InterruptedException e) {
3482
// Ignore the interruption.
35-
e.printStackTrace();
3683
}
3784
}
3885
}
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
package com.microsoft.azure.documentdb;
22

33
/**
4-
* The delegate class of the BackoffRetryUtility class.
4+
* Define a delegate used by the BackoffRetryUtility to retry throttled requests
5+
* other than query.
56
*
7+
* @param request
8+
* the request to be issued.
9+
* @throws DocumentClientException
610
*/
711
abstract interface BackoffRetryUtilityDelegate {
12+
abstract DocumentServiceResponse apply(DocumentServiceRequest request) throws DocumentClientException;
13+
}
14+
15+
/**
16+
* Define a delegate used by the BackoffRetryUtility to retry throttled requests
17+
* for QueryIterable.
18+
*
19+
* @param request
20+
* the request to be issued.
21+
* @throws DocumentClientException
22+
*/
23+
abstract interface QueryBackoffRetryUtilityDelegate {
824
abstract void apply() throws Exception;
925
}

0 commit comments

Comments
 (0)