Skip to content
This repository was archived by the owner on Mar 11, 2022. It is now read-only.

Commit db6b3fe

Browse files
authored
Merge pull request #491 from cloudant/sync-session-renewal
Session renewal improvements
2 parents f409553 + ddb31ab commit db6b3fe

16 files changed

Lines changed: 604 additions & 508 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ language: java
22
sudo: false
33

44
jdk:
5-
- oraclejdk8
5+
- openjdk8
66

77
services:
88
- couchdb

CHANGES.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Unreleased
2-
- [UPGRADED] Optional OkHttp dependency to version 3.12.2.
32
- [FIXED] Create an array of strings for QueryBuilder.fields() when a single field is provided.
3+
- [IMPROVED] Return exceptions directly from IAM token request failures instead of logging and
4+
deferring the request to the service with no credentials. The exception type is the same, but
5+
the message and cause are more clear and a round trip is avoided.
6+
- [IMPROVED] Prevent multiple session renewal requests happening simultaneously because some auth
7+
types apply limits to the number of requests that can be made.
8+
- [UPGRADED] Optional OkHttp dependency to version 3.12.5.
49

510
# 2.17.0 (2019-05-23)
611
- [NEW] Added `com.cloudant.client.api.model.DbInfo#getDocDelCountLong()` to return

cloudant-client/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ dependencies {
2020
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.1.0'
2121
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.1.0'
2222
testCompile group: 'org.hamcrest', name: 'hamcrest-library', version: '1.3'
23-
testCompile group: 'com.squareup.okhttp3', name: 'mockwebserver', version: '3.12.2'
23+
testCompile group: 'com.squareup.okhttp3', name: 'mockwebserver', version: '3.12.5'
2424
testCompile group: 'org.jmockit', name: 'jmockit', version: '1.34'
2525
testCompile group: 'org.littleshoot', name: 'littleproxy', version: '1.1.0'
2626
}

cloudant-client/src/main/java/com/cloudant/client/org/lightcouch/CouchDbClient.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,9 +551,10 @@ public HttpConnection execute(HttpConnection connection) {
551551
try {
552552
connection = connection.execute();
553553
} catch (HttpConnectionInterceptorException e) {
554-
CouchDbException exception = new CouchDbException(connection.getConnection()
555-
.getResponseMessage(), connection.getConnection().getResponseCode());
554+
CouchDbException exception;
556555
if (e.deserialize) {
556+
exception = new CouchDbException(connection.getConnection()
557+
.getResponseMessage(), connection.getConnection().getResponseCode());
557558
try {
558559
JsonObject errorResponse = new Gson().fromJson(e.error, JsonObject
559560
.class);
@@ -563,6 +564,7 @@ public HttpConnection execute(HttpConnection connection) {
563564
exception.error = e.error;
564565
}
565566
} else {
567+
exception = new CouchDbException(e.getMessage(), e);
566568
exception.error = e.error;
567569
exception.reason = e.reason;
568570
}

cloudant-client/src/test/java/com/cloudant/tests/CloudFoundryServiceTest.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package com.cloudant.tests;
1616

17+
import static com.cloudant.http.internal.interceptors.IamCookieInterceptor.IAM_TOKEN_SERVER_URL_PROPERTY_KEY;
1718
import static com.cloudant.tests.util.MockWebServerResources.IAM_API_KEY;
1819
import static com.cloudant.tests.util.MockWebServerResources.IAM_TOKEN;
1920
import static com.cloudant.tests.util.MockWebServerResources.OK_IAM_COOKIE;
@@ -23,12 +24,11 @@
2324
import com.cloudant.client.api.ClientBuilder;
2425
import com.cloudant.client.api.CloudantClient;
2526
import com.cloudant.tests.extensions.MockWebServerExtension;
26-
import com.cloudant.tests.util.IamSystemPropertyMock;
2727
import com.cloudant.tests.util.MockWebServerResources;
2828
import com.google.gson.GsonBuilder;
2929

30+
import org.junit.jupiter.api.AfterEach;
3031
import org.junit.jupiter.api.Assertions;
31-
import org.junit.jupiter.api.BeforeAll;
3232
import org.junit.jupiter.api.BeforeEach;
3333
import org.junit.jupiter.api.Test;
3434
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -46,8 +46,6 @@
4646

4747
public class CloudFoundryServiceTest {
4848

49-
public static IamSystemPropertyMock iamSystemPropertyMock;
50-
5149
private static String TEST_HOST = "https://cloudant.example";
5250
private static String TEST_USER = "user";
5351
private static String TEST_PASSWORD = "pass";
@@ -63,25 +61,23 @@ public class CloudFoundryServiceTest {
6361
public MockWebServer server;
6462
public MockWebServer mockIamServer;
6563

66-
/**
67-
* Before running this test class setup the property mock.
68-
*/
69-
@BeforeAll
70-
public static void setupIamSystemPropertyMock() {
71-
iamSystemPropertyMock = new IamSystemPropertyMock();
72-
}
73-
7464
@BeforeEach
7565
public void beforeEach() {
7666
server = mockWebServerExt.get();
7767
server.useHttps(MockWebServerResources.getSSLSocketFactory(), false);
7868
mockServerHostPort = String.format("%s:%s/", server.getHostName(), server.getPort());
7969
//setup mock IAM server
8070
mockIamServer = mockIamServerExt.get();
81-
iamSystemPropertyMock.setMockIamTokenEndpointUrl(mockIamServer.url(iamTokenEndpoint)
71+
// Override the default IAM token server with our test mock server
72+
System.setProperty(IAM_TOKEN_SERVER_URL_PROPERTY_KEY, mockIamServer.url(iamTokenEndpoint)
8273
.toString());
8374
}
8475

76+
@AfterEach
77+
public void clearIAMMock() {
78+
System.clearProperty(IAM_TOKEN_SERVER_URL_PROPERTY_KEY);
79+
}
80+
8581
private static class VCAPGenerator {
8682

8783
private Map<String, Object> vcap;

0 commit comments

Comments
 (0)