From bb619bfaf1fbe8b7c6f20dd74a688631e31e2c54 Mon Sep 17 00:00:00 2001 From: Winston Li Date: Tue, 5 Apr 2016 04:17:15 +0100 Subject: [PATCH] Add tests that reproduce #1384. --- .../snapshot/push/PostbackManagerTest.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/snapshot/push/PostbackManagerTest.java diff --git a/services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/snapshot/push/PostbackManagerTest.java b/services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/snapshot/push/PostbackManagerTest.java new file mode 100644 index 0000000000..f552a4a82a --- /dev/null +++ b/services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/snapshot/push/PostbackManagerTest.java @@ -0,0 +1,41 @@ +package uk.ac.ic.wlgitbridge.snapshot.push; + +import org.junit.Assert; +import org.junit.Test; +import uk.ac.ic.wlgitbridge.snapshot.push.exception.InternalErrorException; +import uk.ac.ic.wlgitbridge.snapshot.push.exception.SnapshotPostException; +import uk.ac.ic.wlgitbridge.snapshot.push.exception.UnexpectedPostbackException; + +/** + * Created by winston on 05/04/2016. + */ +public class PostbackManagerTest { + + private final PostbackManager postbackManager = new PostbackManager(); + + @Test + public void testRaceWithVersionId() + throws UnexpectedPostbackException, + SnapshotPostException { + String key = postbackManager.makeKeyForProject("proj"); + postbackManager.postVersionIDForProject("proj", 1, key); + int versionId = postbackManager.waitForVersionIdOrThrow("proj"); + Assert.assertEquals("Version id didn't match posted", 1, versionId); + } + + @Test + public void testRaceWithException() throws UnexpectedPostbackException, + SnapshotPostException { + String key = postbackManager.makeKeyForProject("proj"); + InternalErrorException ex = new InternalErrorException(); + postbackManager.postExceptionForProject("proj", ex, key); + try { + postbackManager.waitForVersionIdOrThrow("proj"); + } catch (InternalErrorException e) { + Assert.assertSame("Wrong exception was thrown", ex, e); + return; + } + Assert.fail("Exception wasn't thrown as required"); + } + +}