-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
48 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
logicaldoc-util/src/main/java/com/logicaldoc/util/time/Pause.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.logicaldoc.util.time; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* A simple class to pause the current thread | ||
* | ||
* @author Marco Meschieri - LogicalDOC | ||
* @since 9.0.1 | ||
*/ | ||
public abstract class Pause { | ||
|
||
private Pause() { | ||
// Empty | ||
} | ||
|
||
public static void doPause(long ms) throws InterruptedException { | ||
CountDownLatch latch = new CountDownLatch(1); | ||
if (latch.await(ms, TimeUnit.MILLISECONDS)) | ||
throw new IllegalStateException("Unexpected latch status"); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
logicaldoc-util/src/test/java/com/logicaldoc/util/time/PauseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.logicaldoc.util.time; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.util.Date; | ||
|
||
import org.junit.Test; | ||
|
||
import com.logicaldoc.util.junit.AbstractTestCase; | ||
import com.logicaldoc.util.time.TimeDiff.TimeField; | ||
|
||
public class PauseTest extends AbstractTestCase { | ||
|
||
@Test | ||
public void testDoPause() throws InterruptedException { | ||
Date date1 = new Date(); | ||
Pause.doPause(2000); | ||
Date date2 = new Date(); | ||
|
||
assertEquals(2L, TimeDiff.getTimeDifference(date1, date2, TimeField.SECOND)); | ||
} | ||
} |