-
Notifications
You must be signed in to change notification settings - Fork 7
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
Eric Kerwin
committed
May 25, 2021
1 parent
a1cf424
commit f3d128b
Showing
8 changed files
with
175 additions
and
90 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
30 changes: 30 additions & 0 deletions
30
src/main/java/com/synopsys/integration/exception/IntegrationTimeoutException.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,30 @@ | ||
/* | ||
* integration-common | ||
* | ||
* Copyright (c) 2021 Synopsys, Inc. | ||
* | ||
* Use subject to the terms and conditions of the Synopsys End User Software License and Maintenance Agreement. All rights reserved worldwide. | ||
*/ | ||
package com.synopsys.integration.exception; | ||
|
||
public class IntegrationTimeoutException extends IntegrationException { | ||
public IntegrationTimeoutException() { | ||
} | ||
|
||
public IntegrationTimeoutException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { | ||
super(message, cause, enableSuppression, writableStackTrace); | ||
} | ||
|
||
public IntegrationTimeoutException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public IntegrationTimeoutException(String message) { | ||
super(message); | ||
} | ||
|
||
public IntegrationTimeoutException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/synopsys/integration/wait/BooleanWaitJobCompleter.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,24 @@ | ||
/* | ||
* integration-common | ||
* | ||
* Copyright (c) 2021 Synopsys, Inc. | ||
* | ||
* Use subject to the terms and conditions of the Synopsys End User Software License and Maintenance Agreement. All rights reserved worldwide. | ||
*/ | ||
package com.synopsys.integration.wait; | ||
|
||
import com.synopsys.integration.exception.IntegrationException; | ||
import com.synopsys.integration.exception.IntegrationTimeoutException; | ||
|
||
public class BooleanWaitJobCompleter implements WaitJobCompleter<Boolean> { | ||
@Override | ||
public Boolean complete() throws IntegrationException { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Boolean handleTimeout() throws IntegrationTimeoutException { | ||
return false; | ||
} | ||
|
||
} |
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
18 changes: 18 additions & 0 deletions
18
src/main/java/com/synopsys/integration/wait/WaitJobCompleter.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,18 @@ | ||
/* | ||
* integration-common | ||
* | ||
* Copyright (c) 2021 Synopsys, Inc. | ||
* | ||
* Use subject to the terms and conditions of the Synopsys End User Software License and Maintenance Agreement. All rights reserved worldwide. | ||
*/ | ||
package com.synopsys.integration.wait; | ||
|
||
import com.synopsys.integration.exception.IntegrationException; | ||
import com.synopsys.integration.exception.IntegrationTimeoutException; | ||
|
||
public interface WaitJobCompleter<T extends Object> { | ||
T complete() throws IntegrationException; | ||
|
||
T handleTimeout() throws IntegrationTimeoutException; | ||
|
||
} |
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
59 changes: 41 additions & 18 deletions
59
src/test/java/com/synopsys/integration/wait/WaitJobTest.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 |
---|---|---|
@@ -1,43 +1,66 @@ | ||
package com.synopsys.integration.wait; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
||
import com.synopsys.integration.exception.IntegrationException; | ||
import com.synopsys.integration.log.BufferedIntLogger; | ||
import com.synopsys.integration.log.LogLevel; | ||
|
||
import org.junit.Assert; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class WaitJobTest { | ||
private final BufferedIntLogger testingLogger = new BufferedIntLogger(); | ||
private final WaitJobConfig waitJobConfig = new WaitJobConfig(testingLogger, "holypants", 5, WaitJobConfig.CURRENT_TIME_SUPPLIER, 1); | ||
|
||
@Test | ||
public void testTaskNameLogged() throws IntegrationException, InterruptedException { | ||
BufferedIntLogger testingLogger = new BufferedIntLogger(); | ||
public void testTaskCompletesImmediately() throws IntegrationException, InterruptedException { | ||
WaitJobCondition waitJobCondition = () -> true; | ||
WaitJob<Boolean> waitJob = new WaitJob(waitJobConfig, waitJobCondition, WaitJob.BOOLEAN_COMPLETER); | ||
boolean completed = waitJob.waitFor(); | ||
|
||
WaitJob waitJob = WaitJob.createUsingSystemTimeWhenInvoked(testingLogger, 5, 1, "holypants", createTask()); | ||
waitJob.waitFor(); | ||
assertTrue(completed); | ||
|
||
String output = testingLogger.getOutputString(LogLevel.INFO); | ||
Assert.assertTrue(output.contains("holypants")); | ||
assertTrue(output.contains("holypants")); | ||
assertTrue(output.contains("complete!")); | ||
assertFalse(output.contains("not done yet")); | ||
} | ||
|
||
@Test | ||
public void testTaskNameNotLogged() throws IntegrationException, InterruptedException { | ||
BufferedIntLogger testingLogger = new BufferedIntLogger(); | ||
public void testTaskCompletesEventually() throws IntegrationException, InterruptedException { | ||
WaitJobCondition waitJobCondition = new WaitJobCondition() { | ||
private int count = 0; | ||
|
||
@Override | ||
public boolean isComplete() { | ||
return ++count > 2; | ||
} | ||
}; | ||
WaitJob<Boolean> waitJob = new WaitJob(waitJobConfig, waitJobCondition, WaitJob.BOOLEAN_COMPLETER); | ||
boolean completed = waitJob.waitFor(); | ||
|
||
WaitJob waitJob = WaitJob.createUsingSystemTimeWhenInvoked(testingLogger, 5, 1, createTask()); | ||
waitJob.waitFor(); | ||
assertTrue(completed); | ||
|
||
String output = testingLogger.getOutputString(LogLevel.INFO); | ||
Assert.assertFalse(output.contains("holypants")); | ||
assertTrue(output.contains("holypants")); | ||
assertTrue(output.contains("complete!")); | ||
assertTrue(output.contains("not done yet")); | ||
} | ||
|
||
private WaitJobTask createTask() { | ||
return new WaitJobTask() { | ||
private int count = 0; | ||
@Test | ||
public void testTaskCompletesNever() throws IntegrationException, InterruptedException { | ||
WaitJobCondition waitJobCondition = () -> false; | ||
WaitJob<Boolean> waitJob = new WaitJob(waitJobConfig, waitJobCondition, WaitJob.BOOLEAN_COMPLETER); | ||
boolean completed = waitJob.waitFor(); | ||
|
||
@Override | ||
public boolean isComplete() throws IntegrationException { | ||
return ++count > 1; | ||
} | ||
}; | ||
assertFalse(completed); | ||
|
||
String output = testingLogger.getOutputString(LogLevel.INFO); | ||
assertTrue(output.contains("holypants")); | ||
assertFalse(output.contains("complete!")); | ||
assertTrue(output.contains("not done yet")); | ||
} | ||
|
||
} |