diff options
author | Harald Musum <musum@verizonmedia.com> | 2020-05-30 20:36:48 +0200 |
---|---|---|
committer | Harald Musum <musum@verizonmedia.com> | 2020-05-30 21:29:44 +0200 |
commit | 514160d72b3a19890ed4fc911d1f8b58c1e87b06 (patch) | |
tree | 539c8783e00374fa7805fc4d51e14feece3dc1b0 /configserver | |
parent | 2e3d463d90a4834b65446415e1f92389091716ab (diff) |
Move two tests
Diffstat (limited to 'configserver')
3 files changed, 44 insertions, 27 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/Deployment.java b/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/Deployment.java index e7161d1d1d3..b7555ee3bfb 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/Deployment.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/Deployment.java @@ -131,8 +131,11 @@ public class Deployment implements com.yahoo.config.provision.Deployment { try (ActionTimer timer = applicationRepository.timerFor(session.getApplicationId(), "deployment.activateMillis")) { TimeoutBudget timeoutBudget = new TimeoutBudget(clock, timeout); - ApplicationId applicationId = session.getApplicationId(); + + if ( ! timeoutBudget.hasTimeLeft()) throw new RuntimeException("Timeout exceeded when trying to activate '" + applicationId + "'"); + + RemoteSession previousActiveSession; try (Lock lock = tenant.getApplicationRepo().lock(applicationId)) { validateSessionStatus(session); diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java index f37f4b79f99..c4de563e068 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java @@ -28,6 +28,7 @@ import com.yahoo.vespa.config.server.session.LocalSession; import com.yahoo.vespa.config.server.session.LocalSessionRepo; import com.yahoo.vespa.config.server.session.PrepareParams; import com.yahoo.vespa.config.server.session.RemoteSession; +import com.yahoo.vespa.config.server.session.Session; import com.yahoo.vespa.config.server.session.SilentDeployLogger; import com.yahoo.vespa.config.server.tenant.ApplicationRolesStore; import com.yahoo.vespa.config.server.tenant.Tenant; @@ -37,6 +38,7 @@ import com.yahoo.vespa.curator.mock.MockCurator; import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import java.io.File; @@ -53,6 +55,7 @@ import java.util.Map; import java.util.Optional; import java.util.Set; +import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -87,6 +90,9 @@ public class ApplicationRepositoryTest { @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder(); + @Rule + public ExpectedException exceptionRule = ExpectedException.none(); + @Before public void setup() { Curator curator = new MockCurator(); @@ -443,6 +449,40 @@ public class ApplicationRepositoryTest { assertThat(portsCopy.get().allocations(), is(list)); } + @Test + public void testActivationOfUnpreparedSession() { + // Needed so we can test that the original active session is still active after a failed activation + PrepareResult result = deployApp(testApp); + long firstSession = result.sessionId(); + + TimeoutBudget timeoutBudget = new TimeoutBudget(clock, Duration.ofSeconds(10)); + long sessionId = applicationRepository.createSession(applicationId(), timeoutBudget, testAppJdiscOnly); + exceptionRule.expect(IllegalStateException.class); + exceptionRule.expectMessage(containsString("tenant:test1 Session 3 is not prepared")); + applicationRepository.activate(tenantRepository.getTenant(tenant1), sessionId, timeoutBudget, false); + + RemoteSession activeSession = applicationRepository.getActiveSession(applicationId()); + assertEquals(firstSession, activeSession.getSessionId()); + assertEquals(Session.Status.ACTIVATE, activeSession.getStatus()); + } + + @Test + public void testActivationTimesOut() { + // Needed so we can test that the original active session is still active after a failed activation + PrepareResult result = deployApp(testAppJdiscOnly); + long firstSession = result.sessionId(); + + long sessionId = applicationRepository.createSession(applicationId(), timeoutBudget, testAppJdiscOnly); + applicationRepository.prepare(tenantRepository.getTenant(tenant1), sessionId, prepareParams(), clock.instant()); + exceptionRule.expect(RuntimeException.class); + exceptionRule.expectMessage(containsString("Timeout exceeded when trying to activate 'test1.testapp'")); + applicationRepository.activate(tenantRepository.getTenant(tenant1), sessionId, new TimeoutBudget(clock, Duration.ofSeconds(0)), false); + + RemoteSession activeSession = applicationRepository.getActiveSession(applicationId()); + assertEquals(firstSession, activeSession.getSessionId()); + assertEquals(Session.Status.ACTIVATE, activeSession.getStatus()); + } + private ApplicationRepository createApplicationRepository() { return new ApplicationRepository(tenantRepository, provisioner, diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionActiveHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionActiveHandlerTest.java index e1805272379..0c7b9697e3c 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionActiveHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionActiveHandlerTest.java @@ -58,13 +58,11 @@ import java.util.Set; import static com.yahoo.jdisc.Response.Status.BAD_REQUEST; import static com.yahoo.jdisc.Response.Status.CONFLICT; -import static com.yahoo.jdisc.Response.Status.INTERNAL_SERVER_ERROR; import static com.yahoo.jdisc.Response.Status.METHOD_NOT_ALLOWED; import static com.yahoo.jdisc.Response.Status.NOT_FOUND; import static com.yahoo.jdisc.Response.Status.OK; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; @@ -130,16 +128,6 @@ public class SessionActiveHandlerTest extends SessionHandlerTest { } @Test - public void testActivationWithBarrierTimeout() throws Exception { - // Needed so we can test that previous active session is still active after a failed activation - activateAndAssertOK(90, 0); - ((MockCurator) curator).timeoutBarrierOnEnter(true); - ActivateRequest activateRequest = new ActivateRequest(91, 90, "").invoke(); - HttpResponse actResponse = activateRequest.getActResponse(); - assertThat(actResponse.getStatus(), Is.is(INTERNAL_SERVER_ERROR)); - } - - @Test public void require_that_session_created_from_active_that_is_no_longer_active_cannot_be_activated() throws Exception { long sessionId = 1; activateAndAssertOK(1, 0); @@ -178,20 +166,6 @@ public class SessionActiveHandlerTest extends SessionHandlerTest { } @Test - public void testActivationOfUnpreparedSession() throws Exception { - // Needed so we can test that previous active session is still active after a failed activation - RemoteSession firstSession = activateAndAssertOK(90, 0); - long sessionId = 91L; - ActivateRequest activateRequest = new ActivateRequest(sessionId, 0, Session.Status.NEW, "").invoke(); - HttpResponse actResponse = activateRequest.getActResponse(); - RemoteSession session = activateRequest.getSession(); - assertThat(actResponse.getStatus(), is(Response.Status.BAD_REQUEST)); - assertThat(getRenderedString(actResponse), is("{\"error-code\":\"BAD_REQUEST\",\"message\":\"tenant:"+ tenantName +" app:default:default Session " + sessionId + " is not prepared\"}")); - assertThat(session.getStatus(), is(not(Session.Status.ACTIVATE))); - assertThat(firstSession.getStatus(), is(Session.Status.ACTIVATE)); - } - - @Test public void require_that_handler_gives_error_for_unsupported_methods() throws Exception { testUnsupportedMethod(SessionHandlerTest.createTestRequest(pathPrefix, HttpRequest.Method.POST, Cmd.PREPARED, 1L)); testUnsupportedMethod(SessionHandlerTest.createTestRequest(pathPrefix, HttpRequest.Method.DELETE, Cmd.PREPARED, 1L)); |