Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Register
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSDU
OSDU Data Platform
System
Register
Commits
702cc402
Commit
702cc402
authored
2 years ago
by
preeti singh[Microsoft]
Committed by
Harshika Dhoot
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Adding retry for transient server errors and socket timeout exception from client
parent
20602750
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!273
Adding retry for transient server errors and socket timeout exception from client
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
testing/register-test-core/src/main/java/org/opengroup/osdu/register/util/TestUtils.java
+27
-2
27 additions, 2 deletions
...main/java/org/opengroup/osdu/register/util/TestUtils.java
with
27 additions
and
2 deletions
testing/register-test-core/src/main/java/org/opengroup/osdu/register/util/TestUtils.java
+
27
−
2
View file @
702cc402
...
...
@@ -26,6 +26,8 @@ import javax.net.ssl.SSLContext;
import
javax.net.ssl.TrustManager
;
import
javax.net.ssl.X509TrustManager
;
import
javax.ws.rs.core.MediaType
;
import
javax.ws.rs.core.Response
;
import
java.net.SocketTimeoutException
;
import
java.net.URL
;
import
java.security.SecureRandom
;
import
java.security.cert.X509Certificate
;
...
...
@@ -104,6 +106,7 @@ public abstract class TestUtils {
Map
<
String
,
String
>
headers
,
boolean
isHttp
)
throws
Exception
{
ClientResponse
response
;
Client
client
=
getClient
();
client
.
setConnectTimeout
(
300000
);
client
.
setReadTimeout
(
300000
);
...
...
@@ -116,14 +119,36 @@ public abstract class TestUtils {
System
.
out
.
println
(
httpMethod
);
System
.
out
.
println
(
requestBody
);
System
.
out
.
println
(
headers
);
int
retryCount
=
2
;
WebResource
webResource
=
client
.
resource
(
url
);
final
WebResource
.
Builder
builder
=
webResource
.
type
(
MediaType
.
APPLICATION_JSON
)
.
header
(
"Authorization"
,
token
);
headers
.
forEach
((
k
,
v
)
->
builder
.
header
(
k
,
v
));
return
builder
.
method
(
httpMethod
,
ClientResponse
.
class
,
requestBody
);
try
{
response
=
builder
.
method
(
httpMethod
,
ClientResponse
.
class
,
requestBody
);
while
(
retryCount
>
0
)
{
if
(
response
.
getStatusInfo
().
getFamily
().
equals
(
Response
.
Status
.
Family
.
valueOf
(
"SERVER_ERROR"
)))
{
System
.
out
.
println
(
"got resoponse : "
+
response
.
getStatusInfo
());
Thread
.
sleep
(
5000
);
System
.
out
.
println
(
"Retrying.. "
);
response
=
builder
.
method
(
httpMethod
,
ClientResponse
.
class
,
requestBody
);
}
else
break
;
retryCount
--;
}
System
.
out
.
println
(
"sending response from TestUtils send method"
);
return
response
;
}
catch
(
Exception
e
)
{
if
(
e
.
getCause
()
instanceof
SocketTimeoutException
)
{
System
.
out
.
println
(
"Retrying in case of socket timeout exception"
);
return
builder
.
method
(
httpMethod
,
ClientResponse
.
class
,
requestBody
);
}
e
.
printStackTrace
();
throw
new
AssertionError
(
"Error: Send request error"
,
e
);
}
}
@SuppressWarnings
(
"unchecked"
)
public
static
<
T
>
T
getResult
(
ClientResponse
response
,
int
exepectedStatus
,
Class
<
T
>
classOfT
)
{
String
json
=
response
.
getEntity
(
String
.
class
);
...
...
This diff is collapsed.
Click to expand it.
preeti singh[Microsoft]
@preeti
mentioned in commit
c5df6b13
·
2 years ago
mentioned in commit
c5df6b13
mentioned in commit c5df6b13e28f14f1e8eac97987a8c2c5e5fb205c
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment