use of com.yahoo.test.ManualClock in project vespa by vespa-engine.
the class RedeployTest method testPurgingOfOldNonActiveDeployments.
@Test
public void testPurgingOfOldNonActiveDeployments() {
ManualClock clock = new ManualClock(Instant.now());
ConfigserverConfig configserverConfig = new ConfigserverConfig(new ConfigserverConfig.Builder().configServerDBDir(Files.createTempDir().getAbsolutePath()).configDefinitionsDir(Files.createTempDir().getAbsolutePath()).sessionLifetime(60));
DeployTester tester = new DeployTester("src/test/apps/app", configserverConfig, clock);
// session 2 (numbering starts at 2)
tester.deployApp("myapp", Instant.now());
clock.advance(Duration.ofSeconds(10));
Optional<com.yahoo.config.provision.Deployment> deployment2 = tester.redeployFromLocalActive();
assertTrue(deployment2.isPresent());
// session 3
deployment2.get().activate();
long activeSessionId = tester.tenant().getApplicationRepo().getSessionIdForApplication(tester.applicationId());
clock.advance(Duration.ofSeconds(10));
Optional<com.yahoo.config.provision.Deployment> deployment3 = tester.redeployFromLocalActive();
assertTrue(deployment3.isPresent());
// session 4 (not activated)
deployment3.get().prepare();
LocalSession deployment3session = ((Deployment) deployment3.get()).session();
assertNotEquals(activeSessionId, deployment3session);
// No change to active session id
assertEquals(activeSessionId, tester.tenant().getApplicationRepo().getSessionIdForApplication(tester.applicationId()));
assertEquals(3, tester.tenant().getLocalSessionRepo().listSessions().size());
// longer than session lifetime
clock.advance(Duration.ofHours(1));
// All sessions except 3 should be removed after the call to purgeOldSessions
tester.tenant().getLocalSessionRepo().purgeOldSessions();
final Collection<LocalSession> sessions = tester.tenant().getLocalSessionRepo().listSessions();
assertEquals(1, sessions.size());
assertEquals(3, new ArrayList<>(sessions).get(0).getSessionId());
}
use of com.yahoo.test.ManualClock in project vespa by vespa-engine.
the class LocalSessionRepoTest method setupSessions.
private void setupSessions(TenantName tenantName, boolean createInitialSessions) throws Exception {
GlobalComponentRegistry globalComponentRegistry = new TestComponentRegistry.Builder().curator(curator).build();
TenantFileSystemDirs tenantFileSystemDirs = TenantFileSystemDirs.createTestDirs(tenantName);
if (createInitialSessions) {
IOUtils.copyDirectory(testApp, new File(tenantFileSystemDirs.sessionsPath(), "1"));
IOUtils.copyDirectory(testApp, new File(tenantFileSystemDirs.sessionsPath(), "2"));
IOUtils.copyDirectory(testApp, new File(tenantFileSystemDirs.sessionsPath(), "3"));
}
clock = new ManualClock(Instant.ofEpochSecond(1));
LocalSessionLoader loader = new SessionFactoryImpl(globalComponentRegistry, new SessionCounter(globalComponentRegistry.getConfigCurator(), tenantName), new MemoryTenantApplications(), tenantFileSystemDirs, new HostRegistry<>(), tenantName);
repo = new LocalSessionRepo(tenantFileSystemDirs, loader, clock, 5);
}
use of com.yahoo.test.ManualClock in project vespa by vespa-engine.
the class TimeoutBudgetTest method testTimeLeft.
@Test
public void testTimeLeft() {
ManualClock clock = new ManualClock();
TimeoutBudget budget = new TimeoutBudget(clock, Duration.ofMillis(7));
assertThat(budget.timeLeft().toMillis(), is(7l));
clock.advance(Duration.ofMillis(1));
assertThat(budget.timeLeft().toMillis(), is(6l));
clock.advance(Duration.ofMillis(5));
assertThat(budget.timeLeft().toMillis(), is(1l));
assertThat(budget.timeLeft().toMillis(), is(1l));
clock.advance(Duration.ofMillis(1));
assertThat(budget.timeLeft().toMillis(), is(0l));
clock.advance(Duration.ofMillis(5));
assertThat(budget.timeLeft().toMillis(), is(0l));
clock.advance(Duration.ofMillis(1));
assertThat(budget.timesUsed(), is("[0 ms, 1 ms, 5 ms, 0 ms, 1 ms, 5 ms, total: 13 ms]"));
}
use of com.yahoo.test.ManualClock in project vespa by vespa-engine.
the class HostedDeployTest method testRedeployAfterExpiredValidationOverride.
@Test
public void testRedeployAfterExpiredValidationOverride() {
// Old version of model fails, but application disables loading old models until 2016-10-10, so deployment works
ManualClock clock = new ManualClock("2016-10-09T00:00:00");
List<ModelFactory> modelFactories = new ArrayList<>();
modelFactories.add(DeployTester.createModelFactory(clock));
// older than default
modelFactories.add(DeployTester.createFailingModelFactory(Version.fromIntValues(1, 0, 0)));
DeployTester tester = new DeployTester("src/test/apps/validationOverride/", modelFactories, createConfigserverConfig());
tester.deployApp("myApp", clock.instant());
// Redeployment from local active works
{
Optional<com.yahoo.config.provision.Deployment> deployment = tester.redeployFromLocalActive();
assertTrue(deployment.isPresent());
deployment.get().prepare();
deployment.get().activate();
}
// validation override expires
clock.advance(Duration.ofDays(2));
// Redeployment from local active also works after the validation override expires
{
Optional<com.yahoo.config.provision.Deployment> deployment = tester.redeployFromLocalActive();
assertTrue(deployment.isPresent());
deployment.get().prepare();
deployment.get().activate();
}
// However, redeployment from the outside fails after this date
{
try {
tester.deployApp("myApp", Instant.now());
fail("Expected redeployment to fail");
} catch (Exception expected) {
// success
}
}
}
use of com.yahoo.test.ManualClock in project vespa by vespa-engine.
the class UpgraderTest method testBlockVersionChangeHalfwayThoughThenNewVersion.
/**
* Tests the scenario where a release is deployed to 2 of 3 production zones, then blocked,
* followed by timeout of the upgrade and a new release.
* In this case, the blocked production zone should not progress with upgrading to the previous version,
* and should not upgrade to the new version until the other production zones have it
* (expected behavior; both requirements are debatable).
*/
@Test
public void testBlockVersionChangeHalfwayThoughThenNewVersion() {
// Friday, 16:00
ManualClock clock = new ManualClock(Instant.parse("2017-09-29T16:00:00.00Z"));
DeploymentTester tester = new DeploymentTester(new ControllerTester(clock));
Version version = Version.fromString("5.0");
tester.updateVersionStatus(version);
ApplicationPackage applicationPackage = new ApplicationPackageBuilder().upgradePolicy("canary").blockChange(false, true, "mon-fri", "00-09,17-23", "UTC").blockChange(false, true, "sat-sun", "00-23", "UTC").region("us-west-1").region("us-central-1").region("us-east-3").build();
Application app = tester.createAndDeploy("app1", 1, applicationPackage);
// New version is released
version = Version.fromString("5.1");
tester.updateVersionStatus(version);
// Application upgrade starts
tester.upgrader().maintain();
tester.readyJobTrigger().maintain();
tester.deployAndNotify(app, applicationPackage, true, systemTest);
tester.deployAndNotify(app, applicationPackage, true, DeploymentJobs.JobType.stagingTest);
tester.deployAndNotify(app, applicationPackage, true, productionUsWest1);
// Entering block window after prod job is triggered
clock.advance(Duration.ofHours(1));
tester.deployAndNotify(app, applicationPackage, true, DeploymentJobs.JobType.productionUsCentral1);
// Next job not triggered due to being in the block window
assertTrue(tester.deploymentQueue().jobs().isEmpty());
// A day passes and we get a new version
tester.clock().advance(Duration.ofDays(1));
version = Version.fromString("5.2");
tester.updateVersionStatus(version);
tester.upgrader().maintain();
tester.readyJobTrigger().maintain();
assertTrue("Nothing is scheduled", tester.deploymentQueue().jobs().isEmpty());
// Monday morning: We are not blocked
// Sunday, 17:00
tester.clock().advance(Duration.ofDays(1));
// Monday, 10:00
tester.clock().advance(Duration.ofHours(17));
tester.upgrader().maintain();
tester.readyJobTrigger().maintain();
// We proceed with the new version in the expected order, not starting with the previously blocked version:
// Test jobs are run with the new version, but not production as we are in the block window
tester.deployAndNotify(app, applicationPackage, true, systemTest);
tester.deployAndNotify(app, applicationPackage, true, DeploymentJobs.JobType.stagingTest);
tester.deployAndNotify(app, applicationPackage, true, productionUsWest1);
tester.deployAndNotify(app, applicationPackage, true, DeploymentJobs.JobType.productionUsCentral1);
tester.deployAndNotify(app, applicationPackage, true, DeploymentJobs.JobType.productionUsEast3);
assertTrue("All jobs consumed", tester.deploymentQueue().jobs().isEmpty());
// App is completely upgraded to the latest version
for (Deployment deployment : tester.applications().require(app.id()).deployments().values()) assertEquals(version, deployment.version());
}
Aggregations