Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
briar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julian Dehm
briar
Commits
c054e1c0
Commit
c054e1c0
authored
13 years ago
by
akwizgran
Browse files
Options
Downloads
Patches
Plain Diff
Replaced some sleeps with latches.
parent
9464e29d
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
test/net/sf/briar/db/H2DatabaseTest.java
+10
-14
10 additions, 14 deletions
test/net/sf/briar/db/H2DatabaseTest.java
with
10 additions
and
14 deletions
test/net/sf/briar/db/H2DatabaseTest.java
+
10
−
14
View file @
c054e1c0
...
...
@@ -10,6 +10,8 @@ import java.util.Iterator;
import
java.util.Map
;
import
java.util.Random
;
import
java.util.TreeMap
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
junit.framework.TestCase
;
...
...
@@ -910,8 +912,8 @@ public class H2DatabaseTest extends TestCase {
@Test
public
void
testCloseWaitsForCommit
()
throws
Exception
{
final
CountDownLatch
latch
=
new
CountDownLatch
(
1
);
final
AtomicBoolean
transactionFinished
=
new
AtomicBoolean
(
false
);
final
AtomicBoolean
closed
=
new
AtomicBoolean
(
false
);
final
AtomicBoolean
error
=
new
AtomicBoolean
(
false
);
final
Database
<
Connection
>
db
=
open
(
false
);
...
...
@@ -922,8 +924,8 @@ public class H2DatabaseTest extends TestCase {
public
void
run
()
{
try
{
db
.
close
();
closed
.
set
(
true
);
if
(!
transactionFinished
.
get
())
error
.
set
(
true
);
latch
.
countDown
();
}
catch
(
Exception
e
)
{
error
.
set
(
true
);
}
...
...
@@ -932,24 +934,21 @@ public class H2DatabaseTest extends TestCase {
t
.
start
();
// Do whatever the transaction needs to do
try
{
Thread
.
sleep
(
10
0
);
Thread
.
sleep
(
10
);
}
catch
(
InterruptedException
ignored
)
{}
transactionFinished
.
set
(
true
);
// Commit the transaction
db
.
commitTransaction
(
txn
);
// The other thread should now terminate
try
{
t
.
join
(
10
*
1000
);
}
catch
(
InterruptedException
ignored
)
{}
assertTrue
(
closed
.
get
());
assertTrue
(
latch
.
await
(
5
,
TimeUnit
.
SECONDS
));
// Check that the other thread didn't encounter an error
assertFalse
(
error
.
get
());
}
@Test
public
void
testCloseWaitsForAbort
()
throws
Exception
{
final
CountDownLatch
latch
=
new
CountDownLatch
(
1
);
final
AtomicBoolean
transactionFinished
=
new
AtomicBoolean
(
false
);
final
AtomicBoolean
closed
=
new
AtomicBoolean
(
false
);
final
AtomicBoolean
error
=
new
AtomicBoolean
(
false
);
final
Database
<
Connection
>
db
=
open
(
false
);
...
...
@@ -960,8 +959,8 @@ public class H2DatabaseTest extends TestCase {
public
void
run
()
{
try
{
db
.
close
();
closed
.
set
(
true
);
if
(!
transactionFinished
.
get
())
error
.
set
(
true
);
latch
.
countDown
();
}
catch
(
Exception
e
)
{
error
.
set
(
true
);
}
...
...
@@ -970,16 +969,13 @@ public class H2DatabaseTest extends TestCase {
t
.
start
();
// Do whatever the transaction needs to do
try
{
Thread
.
sleep
(
10
0
);
Thread
.
sleep
(
10
);
}
catch
(
InterruptedException
ignored
)
{}
transactionFinished
.
set
(
true
);
// Abort the transaction
db
.
abortTransaction
(
txn
);
// The other thread should now terminate
try
{
t
.
join
(
10000
);
}
catch
(
InterruptedException
ignored
)
{}
assertTrue
(
closed
.
get
());
assertTrue
(
latch
.
await
(
5
,
TimeUnit
.
SECONDS
));
// Check that the other thread didn't encounter an error
assertFalse
(
error
.
get
());
}
...
...
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