Skip to content

Commit 21d51b2

Browse files
committed
test(discovery-v1): increase timout on createCollection and output transaction id
1 parent ab1458b commit 21d51b2

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

discovery/src/test/java/com/ibm/watson/discovery/v1/DiscoveryServiceIT.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.google.gson.internal.LazilyParsedNumber;
2525
import com.ibm.cloud.sdk.core.http.HttpConfigOptions;
2626
import com.ibm.cloud.sdk.core.http.HttpMediaType;
27+
import com.ibm.cloud.sdk.core.http.Response;
2728
import com.ibm.cloud.sdk.core.security.Authenticator;
2829
import com.ibm.cloud.sdk.core.security.BasicAuthenticator;
2930
import com.ibm.cloud.sdk.core.security.BearerTokenAuthenticator;
@@ -37,6 +38,8 @@
3738
import com.ibm.watson.discovery.query.Operator;
3839
import com.ibm.watson.discovery.v1.model.*;
3940
import com.ibm.watson.discovery.v1.model.NormalizationOperation.Operation;
41+
42+
import java.awt.*;
4043
import java.io.ByteArrayInputStream;
4144
import java.io.FileInputStream;
4245
import java.io.FileNotFoundException;
@@ -2134,7 +2137,21 @@ private Configuration createTestConfig() {
21342137
}
21352138

21362139
private Collection createCollection(CreateCollectionOptions createOptions) {
2137-
Collection createResponse = discovery.createCollection(createOptions).execute().getResult();
2140+
2141+
Collection createResponse = null;
2142+
try {
2143+
// In a successful case, you can grab the ID with the following code.
2144+
Response<Collection> collectionResponse = discovery.createCollection(createOptions).execute();
2145+
createResponse = collectionResponse.getResult();
2146+
2147+
String transactionId = collectionResponse.getHeaders().values("x-global-transaction-id").get(0);
2148+
System.out.println("x-global-transcation-id: "+transactionId);
2149+
} catch (ServiceResponseException e) {
2150+
// This is how you get the ID from a failed request.
2151+
// Make sure to use the ServiceResponseException class or one of its subclasses!
2152+
String transactionId = e.getHeaders().values("x-global-transaction-id").get(0);
2153+
System.out.println("x-global-transcation-id: "+transactionId);
2154+
}
21382155
collectionIds.add(createResponse.getCollectionId());
21392156
return createResponse;
21402157
}
@@ -2179,7 +2196,7 @@ private DocumentAccepted createTestDocument(String json, String filename, String
21792196
DocumentAccepted createResponse = discovery.addDocument(builder.build()).execute().getResult();
21802197
WaitFor.Condition documentAccepted =
21812198
new WaitForDocumentAccepted(environmentId, collectionId, createResponse.getDocumentId());
2182-
WaitFor.waitFor(documentAccepted, 5, TimeUnit.SECONDS, 500);
2199+
WaitFor.waitFor(documentAccepted, 10, TimeUnit.SECONDS, 500);
21832200
return createResponse;
21842201
}
21852202

@@ -2205,7 +2222,7 @@ private synchronized String setupTestDocuments() {
22052222

22062223
WaitFor.Condition collectionAvailable =
22072224
new WaitForCollectionAvailable(environmentId, collectionId);
2208-
WaitFor.waitFor(collectionAvailable, 5, TimeUnit.SECONDS, 500);
2225+
WaitFor.waitFor(collectionAvailable, 10, TimeUnit.SECONDS, 500);
22092226

22102227
return collectionId;
22112228
}

0 commit comments

Comments
 (0)