Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
che
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
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
Administrator
che
Commits
a82e1091
Unverified
Commit
a82e1091
authored
5 years ago
by
Sergii Kabashniuk
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Do not use spy in ServerCheckerTest (#14975)
Signed-off-by:
Sergii Kabashniuk
<
skabashniuk@redhat.com
>
parent
5d38d7a7
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/hc/ServerCheckerTest.java
+35
-28
35 additions, 28 deletions
...clipse/che/api/workspace/server/hc/ServerCheckerTest.java
with
35 additions
and
28 deletions
wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/hc/ServerCheckerTest.java
+
35
−
28
View file @
a82e1091
...
@@ -12,11 +12,7 @@
...
@@ -12,11 +12,7 @@
package
org.eclipse.che.api.workspace.server.hc
;
package
org.eclipse.che.api.workspace.server.hc
;
import
static
java
.
lang
.
String
.
format
;
import
static
java
.
lang
.
String
.
format
;
import
static
org
.
mockito
.
Mockito
.
atLeast
;
import
static
org
.
mockito
.
Mockito
.
spy
;
import
static
org
.
mockito
.
Mockito
.
timeout
;
import
static
org
.
mockito
.
Mockito
.
timeout
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
testng
.
Assert
.
assertEquals
;
import
static
org
.
testng
.
Assert
.
assertEquals
;
import
static
org
.
testng
.
Assert
.
assertFalse
;
import
static
org
.
testng
.
Assert
.
assertFalse
;
import
static
org
.
testng
.
Assert
.
assertTrue
;
import
static
org
.
testng
.
Assert
.
assertTrue
;
...
@@ -24,6 +20,7 @@ import static org.testng.Assert.fail;
...
@@ -24,6 +20,7 @@ import static org.testng.Assert.fail;
import
java.util.Timer
;
import
java.util.Timer
;
import
java.util.concurrent.CompletableFuture
;
import
java.util.concurrent.CompletableFuture
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
import
org.eclipse.che.api.workspace.server.spi.InfrastructureException
;
import
org.eclipse.che.api.workspace.server.spi.InfrastructureException
;
...
@@ -56,49 +53,47 @@ public class ServerCheckerTest {
...
@@ -56,49 +53,47 @@ public class ServerCheckerTest {
@Test
(
timeOut
=
TEST_TIMEOUT_MS
)
@Test
(
timeOut
=
TEST_TIMEOUT_MS
)
public
void
successfulCheckTest
()
throws
Exception
{
public
void
successfulCheckTest
()
throws
Exception
{
checker
=
checker
=
spy
(
new
TestServerChecker
(
new
TestServerChecker
(
MACHINE_NAME
,
MACHINE_NAME
,
SERVER_REF
,
SERVER_REF
,
PERIOD_MS
,
PERIOD_MS
,
CHECKER_TIMEOUT_MS
,
CHECKER_TIMEOUT_MS
,
SUCCESS_THRESHOLD
,
SUCCESS_THRESHOLD
,
TimeUnit
.
MILLISECONDS
,
TimeUnit
.
MILLISECONDS
,
timer
);
timer
));
CompletableFuture
<
String
>
reportCompFuture
=
checker
.
getReportCompFuture
();
CompletableFuture
<
String
>
reportCompFuture
=
checker
.
getReportCompFuture
();
// not considered as available before start
// not considered as available before start
assertFalse
(
reportCompFuture
.
isDone
());
assertFalse
(
reportCompFuture
.
isDone
());
// ensure server not available before start
// ensure server not available before start
when
(
checker
.
i
sAvailable
(
)).
thenReturn
(
false
);
CountDownLatch
isAvailableCountDownLatch
=
checker
.
s
et
Available
(
false
);
checker
.
start
();
checker
.
start
();
verify
(
checker
,
timeout
((
int
)
(
PERIOD_MS
*
2
)).
atLeastOnce
()).
isAvailable
(
);
isAvailableCountDownLatch
.
await
(
PERIOD_MS
*
2
,
TimeUnit
.
MILLISECONDS
);
// not considered as available after check
// not considered as available after check
assertFalse
(
reportCompFuture
.
isDone
());
assertFalse
(
reportCompFuture
.
isDone
());
// make server available
// make server available
when
(
checker
.
i
sAvailable
(
)).
thenReturn
(
true
);
isAvailableCountDownLatch
=
checker
.
s
et
Available
(
true
);
assertEquals
(
reportCompFuture
.
get
(),
SERVER_REF
);
assertEquals
(
reportCompFuture
.
get
(),
SERVER_REF
);
verify
(
checker
,
atLeast
(
2
)).
isAvailable
(
);
isAvailableCountDownLatch
.
await
(
PERIOD_MS
*
2
,
TimeUnit
.
MILLISECONDS
);
}
}
@Test
(
timeOut
=
TEST_TIMEOUT_MS
)
@Test
(
timeOut
=
TEST_TIMEOUT_MS
)
public
void
checkTimeoutTest
()
throws
Exception
{
public
void
checkTimeoutTest
()
throws
Exception
{
checker
=
checker
=
spy
(
new
TestServerChecker
(
new
TestServerChecker
(
MACHINE_NAME
,
MACHINE_NAME
,
SERVER_REF
,
SERVER_REF
,
PERIOD_MS
,
PERIOD_MS
,
PERIOD_MS
*
2
,
PERIOD_MS
*
2
,
SUCCESS_THRESHOLD
,
SUCCESS_THRESHOLD
,
TimeUnit
.
MILLISECONDS
,
TimeUnit
.
MILLISECONDS
,
timer
);
timer
));
// ensure server not available before start
// ensure server not available before start
when
(
checker
.
i
sAvailable
(
)).
thenReturn
(
false
);
checker
.
s
et
Available
(
false
);
checker
.
start
();
checker
.
start
();
CompletableFuture
<
String
>
reportCompFuture
=
checker
.
getReportCompFuture
();
CompletableFuture
<
String
>
reportCompFuture
=
checker
.
getReportCompFuture
();
...
@@ -119,6 +114,11 @@ public class ServerCheckerTest {
...
@@ -119,6 +114,11 @@ public class ServerCheckerTest {
}
}
private
static
class
TestServerChecker
extends
ServerChecker
{
private
static
class
TestServerChecker
extends
ServerChecker
{
private
boolean
isAvailable
;
private
CountDownLatch
isAvailableCountDownLatch
=
new
CountDownLatch
(
1
);
protected
TestServerChecker
(
protected
TestServerChecker
(
String
machineName
,
String
machineName
,
String
serverRef
,
String
serverRef
,
...
@@ -132,7 +132,14 @@ public class ServerCheckerTest {
...
@@ -132,7 +132,14 @@ public class ServerCheckerTest {
@Override
@Override
public
boolean
isAvailable
()
{
public
boolean
isAvailable
()
{
return
false
;
isAvailableCountDownLatch
.
countDown
();
return
isAvailable
;
}
public
CountDownLatch
setAvailable
(
boolean
isAvailable
)
{
this
.
isAvailable
=
isAvailable
;
this
.
isAvailableCountDownLatch
=
new
CountDownLatch
(
1
);
return
isAvailableCountDownLatch
;
}
}
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
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