Last active
November 20, 2015 01:19
-
-
Save lwoodson/8f22be5e720ea3e946c5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| public class AttemptAssertion { | |
| public static void attempt(timeout, wait, Callable testBody) { | |
| int elapsed = 0; | |
| Exception exception = null; | |
| while (true) { | |
| Thread.sleep(wait * 1000); | |
| elapsed++; | |
| try { | |
| return testBody.call(); | |
| } catch (Exception e) { | |
| exception = e; | |
| } | |
| if (elapsed > timeout) { | |
| if (exception != null) { | |
| throw exception; | |
| } else { | |
| throw new TimeoutException("Exceeded " + timeout + " seconds"); | |
| } | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or 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
| import static AttemptAssertion.attempt; | |
| public class CountTest { | |
| private DBI dbi; | |
| private CountDAO countDao; | |
| @BeforeMethod | |
| public void setUp() { | |
| // setup dbi | |
| dao = dbi.onDemand(CountDAO.class); | |
| } | |
| @Test | |
| public void testCounts() { | |
| // make request to kick off process | |
| attempt(60, 1, () -> { | |
| int count = dao.getCountForRelationAndType( | |
| JobStatusItem.class.simpleName(), id, "products"); | |
| assertEquals(count, 12345); | |
| }); | |
| } | |
| } |
This file contains hidden or 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
| import static AttemptAssertion.attempt; | |
| public class CountTest { | |
| private CatalogProcessConfigFetcher configFetcher; | |
| private Poller poller; | |
| private CatalogProcessConfig syntheticConfig; | |
| @BeforeMethod | |
| public void setUp() { | |
| configFetcher = // code to create our DAL layer config fetcher | |
| } | |
| @Test | |
| public void testCounts() { | |
| // make request to generate a config | |
| attempt(60, 1, () -> { | |
| syntheticConfig = configFetcher.fetchCatalogProcessConfig( | |
| "higdonoutdoors", CatalogProcessType.SYNTHETIC_CATALOG); | |
| assertEquals(syntheticConfig.getClientName(), "higdonoutdoors"); | |
| // other assertions... | |
| }); | |
| callSomethingElse(syntheticConfig); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment