Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openbis
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sispub
openbis
Commits
e62a12ce
Commit
e62a12ce
authored
13 years ago
by
brinn
Browse files
Options
Downloads
Patches
Plain Diff
Improve test case for server-side timeout.
SVN: 24033
parent
ff81abf2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
common/sourceTest/java/ch/systemsx/cisd/common/serviceconversation/ServiceConversationTest.java
+38
-58
38 additions, 58 deletions
...d/common/serviceconversation/ServiceConversationTest.java
with
38 additions
and
58 deletions
common/sourceTest/java/ch/systemsx/cisd/common/serviceconversation/ServiceConversationTest.java
+
38
−
58
View file @
e62a12ce
...
@@ -54,7 +54,7 @@ public class ServiceConversationTest
...
@@ -54,7 +54,7 @@ public class ServiceConversationTest
}
}
/**
/**
* This object encapsulates the client server connection for test purposes.
* This object encapsulates the client server connection for test purposes.
*/
*/
private
static
class
TestClientServerConnection
implements
IRemoteServiceConversationServer
,
private
static
class
TestClientServerConnection
implements
IRemoteServiceConversationServer
,
IServiceMessageTransport
IServiceMessageTransport
...
@@ -69,25 +69,25 @@ public class ServiceConversationTest
...
@@ -69,25 +69,25 @@ public class ServiceConversationTest
void
setResponseMessageTransport
(
final
IServiceMessageTransport
responseMessageTransport
)
void
setResponseMessageTransport
(
final
IServiceMessageTransport
responseMessageTransport
)
{
{
server
.
addClientResponseTransport
(
"dummyClient"
,
new
IServiceMessageTransport
()
server
.
addClientResponseTransport
(
"dummyClient"
,
new
IServiceMessageTransport
()
{
public
void
send
(
ServiceMessage
message
)
{
{
int
attempt
=
0
;
public
void
send
(
ServiceMessage
message
)
while
(
attempt
++
<
10
)
{
{
try
int
attempt
=
0
;
while
(
attempt
++
<
10
)
{
{
// Send all messages twice to test detection of duplicate messages.
try
responseMessageTransport
.
send
(
message
);
{
responseMessageTransport
.
send
(
message
);
// Send all messages twice to test detection of duplicate messages.
break
;
responseMessageTransport
.
send
(
message
);
}
catch
(
Exception
ex
)
responseMessageTransport
.
send
(
message
);
{
break
;
ConcurrencyUtilities
.
sleep
(
10
);
}
catch
(
Exception
ex
)
{
ConcurrencyUtilities
.
sleep
(
10
);
}
}
}
}
}
}
});
});
}
}
...
@@ -230,8 +230,7 @@ public class ServiceConversationTest
...
@@ -230,8 +230,7 @@ public class ServiceConversationTest
assertEquals
(
"Three"
,
conversation
.
receive
(
String
.
class
));
assertEquals
(
"Three"
,
conversation
.
receive
(
String
.
class
));
conversation
.
terminate
();
conversation
.
terminate
();
for
(
int
i
=
0
;
i
<
100
for
(
int
i
=
0
;
i
<
100
&&
holder
.
server
.
hasConversation
(
conversation
.
getId
());
++
i
)
&&
holder
.
server
.
hasConversation
(
conversation
.
getId
());
++
i
)
{
{
ConcurrencyUtilities
.
sleep
(
10L
);
ConcurrencyUtilities
.
sleep
(
10L
);
}
}
...
@@ -288,53 +287,34 @@ public class ServiceConversationTest
...
@@ -288,53 +287,34 @@ public class ServiceConversationTest
@Test
@Test
public
void
testEchoServiceTimeout
()
throws
Exception
public
void
testEchoServiceTimeout
()
throws
Exception
{
{
final
ServiceConversationServer
conversations
=
new
ServiceConversationServer
(
100
);
final
ServiceConversationServerAndClientHolder
holder
=
conversations
.
addServiceType
(
new
IServiceFactory
()
createServerAndClient
(
EchoService
.
createFactory
());
{
final
IServiceConversation
conversation
=
holder
.
client
.
startConversation
(
"echo"
);
public
IService
create
()
assertTrue
(
holder
.
server
.
hasConversation
(
conversation
.
getId
()));
{
return
new
EchoService
();
}
public
int
getClientTimeoutMillis
()
{
return
100
;
}
public
String
getServiceTypeId
()
conversation
.
send
(
"One"
);
{
assertEquals
(
"One"
,
conversation
.
receive
(
String
.
class
));
return
"echo"
;
conversation
.
send
(
"Two"
);
}
});
final
BlockingQueue
<
ServiceMessage
>
messageQueue
=
new
LinkedBlockingQueue
<
ServiceMessage
>();
conversations
.
addClientResponseTransport
(
"dummyClient"
,
new
IServiceMessageTransport
()
{
public
void
send
(
ServiceMessage
message
)
{
messageQueue
.
add
(
message
);
}
});
final
String
id
=
conversations
.
startConversation
(
"echo"
,
"dummyClient"
).
getServiceConversationId
();
assertTrue
(
conversations
.
hasConversation
(
id
));
int
messageIdx
=
0
;
conversations
.
getIncomingMessageTransport
().
send
(
new
ServiceMessage
(
id
,
0
,
false
,
"One"
));
ServiceMessage
m
=
messageQueue
.
take
();
assertEquals
(
id
,
m
.
getConversationId
());
assertEquals
(
messageIdx
++,
m
.
getMessageIdx
());
assertEquals
(
"One"
,
m
.
getPayload
());
// Wait for timeout to happen.
// Wait for timeout to happen.
for
(
int
i
=
0
;
i
<
100
&&
conversations
.
hasConversation
(
id
);
++
i
)
for
(
int
i
=
0
;
i
<
100
&&
holder
.
server
.
hasConversation
(
conversation
.
getId
()
);
++
i
)
{
{
ConcurrencyUtilities
.
sleep
(
10L
);
ConcurrencyUtilities
.
sleep
(
10L
);
}
}
assertFalse
(
conversations
.
hasConversation
(
id
));
assertFalse
(
holder
.
server
.
hasConversation
(
conversation
.
getId
()));
m
=
messageQueue
.
take
();
assertTrue
(
m
.
isException
());
conversation
.
send
(
"Three"
);
assertTrue
(
m
.
tryGetExceptionDescription
().
startsWith
(
try
"ch.systemsx.cisd.base.exceptions.TimeoutExceptionUnchecked:"
));
{
conversation
.
receive
(
String
.
class
);
fail
(
"Server timeout not signaled to client"
);
}
catch
(
ServiceExecutionException
ex
)
{
assertTrue
(
ex
.
getDescription
(),
ex
.
getDescription
().
startsWith
(
"ch.systemsx.cisd.base.exceptions.TimeoutExceptionUnchecked:"
));
}
}
}
@Test
(
expectedExceptions
=
UnknownServiceTypeException
.
class
)
@Test
(
expectedExceptions
=
UnknownServiceTypeException
.
class
)
...
...
This diff is collapsed.
Click to expand it.
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