Search in sources :

Example 6 with ManualClock

use of com.yahoo.test.ManualClock in project vespa by vespa-engine.

the class AthenzIdentityProviderImplTest method metrics_updated_on_refresh.

@Test
public void metrics_updated_on_refresh() {
    IdentityDocumentService identityDocumentService = mock(IdentityDocumentService.class);
    AthenzService athenzService = mock(AthenzService.class);
    ManualClock clock = new ManualClock(Instant.EPOCH);
    Metric metric = mock(Metric.class);
    when(identityDocumentService.getSignedIdentityDocument()).thenReturn(getIdentityDocument());
    when(athenzService.sendInstanceRegisterRequest(any(), any())).then(new Answer<InstanceIdentity>() {

        @Override
        public InstanceIdentity answer(InvocationOnMock invocationOnMock) throws Throwable {
            return new InstanceIdentity(getCertificate(getExpirationSupplier(clock)), "TOKEN");
        }
    });
    when(athenzService.sendInstanceRefreshRequest(anyString(), anyString(), anyString(), anyString(), any(), any(), any(), any())).thenThrow(new RuntimeException("#1")).thenThrow(new RuntimeException("#2")).thenReturn(new InstanceIdentity(getCertificate(getExpirationSupplier(clock)), "TOKEN"));
    AthenzCredentialsService credentialService = new AthenzCredentialsService(IDENTITY_CONFIG, identityDocumentService, athenzService, clock);
    AthenzIdentityProviderImpl identityProvider = new AthenzIdentityProviderImpl(IDENTITY_CONFIG, metric, credentialService, mock(ScheduledExecutorService.class), clock);
    identityProvider.reportMetrics();
    verify(metric).set(eq(AthenzIdentityProviderImpl.CERTIFICATE_EXPIRY_METRIC_NAME), eq(certificateValidity.getSeconds()), any());
    // Advance 1 day, refresh fails, cert is 1 day old
    clock.advance(Duration.ofDays(1));
    identityProvider.refreshCertificate();
    identityProvider.reportMetrics();
    verify(metric).set(eq(AthenzIdentityProviderImpl.CERTIFICATE_EXPIRY_METRIC_NAME), eq(certificateValidity.minus(Duration.ofDays(1)).getSeconds()), any());
    // Advance 1 more day, refresh fails, cert is 2 days old
    clock.advance(Duration.ofDays(1));
    identityProvider.refreshCertificate();
    identityProvider.reportMetrics();
    verify(metric).set(eq(AthenzIdentityProviderImpl.CERTIFICATE_EXPIRY_METRIC_NAME), eq(certificateValidity.minus(Duration.ofDays(2)).getSeconds()), any());
    // Advance 1 more day, refresh succeds, cert is new
    clock.advance(Duration.ofDays(1));
    identityProvider.refreshCertificate();
    identityProvider.reportMetrics();
    verify(metric).set(eq(AthenzIdentityProviderImpl.CERTIFICATE_EXPIRY_METRIC_NAME), eq(certificateValidity.getSeconds()), any());
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ManualClock(com.yahoo.test.ManualClock) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Metric(com.yahoo.jdisc.Metric) Test(org.junit.Test)

Example 7 with ManualClock

use of com.yahoo.test.ManualClock in project vespa by vespa-engine.

the class TimeoutBudgetTest method testHasTimeLeft.

@Test
public void testHasTimeLeft() {
    ManualClock clock = new ManualClock();
    TimeoutBudget budget = new TimeoutBudget(clock, Duration.ofMillis(7));
    assertThat(budget.hasTimeLeft(), is(true));
    clock.advance(Duration.ofMillis(1));
    assertThat(budget.hasTimeLeft(), is(true));
    clock.advance(Duration.ofMillis(5));
    assertThat(budget.hasTimeLeft(), is(true));
    assertThat(budget.hasTimeLeft(), is(true));
    clock.advance(Duration.ofMillis(1));
    assertThat(budget.hasTimeLeft(), is(false));
    clock.advance(Duration.ofMillis(5));
    assertThat(budget.hasTimeLeft(), is(false));
    clock.advance(Duration.ofMillis(1));
    assertThat(budget.timesUsed(), is("[0 ms, 1 ms, 5 ms, 0 ms, 1 ms, 5 ms, total: 13 ms]"));
}
Also used : ManualClock(com.yahoo.test.ManualClock) Test(org.junit.Test)

Example 8 with ManualClock

use of com.yahoo.test.ManualClock in project vespa by vespa-engine.

the class HostedDeployTest method testDeployMultipleVersions.

@Test
public void testDeployMultipleVersions() {
    ManualClock clock = new ManualClock("2016-10-09T00:00:00");
    List<ModelFactory> modelFactories = new ArrayList<>();
    modelFactories.add(DeployTester.createModelFactory(Version.fromString("6.1.0"), clock));
    modelFactories.add(DeployTester.createModelFactory(Version.fromString("6.2.0"), clock));
    modelFactories.add(DeployTester.createModelFactory(Version.fromString("7.0.0"), clock));
    DeployTester tester = new DeployTester("src/test/apps/hosted/", modelFactories, createConfigserverConfig());
    ApplicationId app = tester.deployApp("myApp", Instant.now());
    assertEquals(3, tester.getAllocatedHostsOf(app).getHosts().size());
}
Also used : ManualClock(com.yahoo.test.ManualClock) ArrayList(java.util.ArrayList) ModelFactory(com.yahoo.config.model.api.ModelFactory) ApplicationId(com.yahoo.config.provision.ApplicationId) Test(org.junit.Test)

Example 9 with ManualClock

use of com.yahoo.test.ManualClock in project vespa by vespa-engine.

the class AthenzIdentityProviderImplTest method component_creation_fails_when_credentials_not_found.

@Test(expected = AthenzIdentityProviderException.class)
public void component_creation_fails_when_credentials_not_found() {
    AthenzCredentialsService credentialService = mock(AthenzCredentialsService.class);
    when(credentialService.registerInstance()).thenThrow(new RuntimeException("athenz unavailable"));
    new AthenzIdentityProviderImpl(IDENTITY_CONFIG, mock(Metric.class), credentialService, mock(ScheduledExecutorService.class), new ManualClock(Instant.EPOCH));
}
Also used : ManualClock(com.yahoo.test.ManualClock) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Metric(com.yahoo.jdisc.Metric) Test(org.junit.Test)

Example 10 with ManualClock

use of com.yahoo.test.ManualClock in project vespa by vespa-engine.

the class RateLimitingSearcherTestCase method testRateLimiting.

@Test
public void testRateLimiting() {
    RateLimitingConfig.Builder rateLimitingConfig = new RateLimitingConfig.Builder();
    rateLimitingConfig.maxAvailableCapacity(4);
    rateLimitingConfig.capacityIncrement(2);
    rateLimitingConfig.recheckForCapacityProbability(1.0);
    ClusterInfoConfig.Builder clusterInfoConfig = new ClusterInfoConfig.Builder();
    clusterInfoConfig.clusterId("testCluster");
    clusterInfoConfig.nodeCount(4);
    ManualClock clock = new ManualClock();
    MetricReceiver.MockReceiver metric = new MetricReceiver.MockReceiver();
    Chain<Searcher> chain = new Chain<Searcher>("test", new RateLimitingSearcher(new RateLimitingConfig(rateLimitingConfig), new ClusterInfoConfig(clusterInfoConfig), metric, clock), new CostSettingSearcher());
    assertEquals("'rate' request are available initially", 2, tryRequests(chain, "id1"));
    assertTrue("However, don't reject if we dryRun", executeWasAllowed(chain, "id1", true));
    // causes 2 new requests to become available
    clock.advance(Duration.ofMillis(1500));
    assertEquals("'rate' new requests became available", 2, tryRequests(chain, "id1"));
    assertEquals("Another id", 2, tryRequests(chain, "id2"));
    clock.advance(Duration.ofMillis(1000000));
    assertEquals("'maxAvailableCapacity' request became available", 4, tryRequests(chain, "id2"));
    assertFalse("If quota is set to 0, all requests are rejected, even initially", executeWasAllowed(chain, "id3", 0));
    clock.advance(Duration.ofMillis(1000000));
    assertTrue("A single query which costs more than capacity is allowed as cost is calculated after allowing it", executeWasAllowed(chain, "id1", 8, 8, false));
    assertFalse("capacity is -4: disallowing", executeWasAllowed(chain, "id1"));
    clock.advance(Duration.ofMillis(1000));
    assertFalse("capacity is -2: disallowing", executeWasAllowed(chain, "id1"));
    clock.advance(Duration.ofMillis(1000));
    assertFalse("capacity is 0: disallowing", executeWasAllowed(chain, "id1"));
    clock.advance(Duration.ofMillis(1000));
    assertTrue(executeWasAllowed(chain, "id1"));
    // check metrics
    Map<Point, UntypedMetric> map = metric.getSnapshot().getMapForMetric("requestsOverQuota");
    assertEquals(requestsToTry - 2 + 1 + requestsToTry - 2 + 3, map.get(metric.point("id", "id1")).getCount());
    assertEquals(requestsToTry - 2 + requestsToTry - 4, map.get(metric.point("id", "id2")).getCount());
}
Also used : Chain(com.yahoo.component.chain.Chain) MetricReceiver(com.yahoo.metrics.simple.MetricReceiver) RateLimitingSearcher(com.yahoo.search.searchers.RateLimitingSearcher) Searcher(com.yahoo.search.Searcher) Point(com.yahoo.metrics.simple.Point) RateLimitingConfig(com.yahoo.search.config.RateLimitingConfig) RateLimitingSearcher(com.yahoo.search.searchers.RateLimitingSearcher) UntypedMetric(com.yahoo.metrics.simple.UntypedMetric) ManualClock(com.yahoo.test.ManualClock) ClusterInfoConfig(com.yahoo.cloud.config.ClusterInfoConfig) Test(org.junit.Test)

Aggregations

ManualClock (com.yahoo.test.ManualClock)18 Test (org.junit.Test)16 Version (com.yahoo.component.Version)4 Application (com.yahoo.vespa.hosted.controller.Application)4 ControllerTester (com.yahoo.vespa.hosted.controller.ControllerTester)4 ApplicationPackage (com.yahoo.vespa.hosted.controller.application.ApplicationPackage)4 JobType.stagingTest (com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.stagingTest)4 JobType.systemTest (com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.systemTest)4 DockerImage (com.yahoo.config.provision.DockerImage)3 ApplicationPackageBuilder (com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder)3 DeploymentTester (com.yahoo.vespa.hosted.controller.deployment.DeploymentTester)3 VespaVersion (com.yahoo.vespa.hosted.controller.versions.VespaVersion)3 NodeRepository (com.yahoo.vespa.hosted.provision.NodeRepository)3 MockNameResolver (com.yahoo.vespa.hosted.provision.testutils.MockNameResolver)3 ArrayList (java.util.ArrayList)3 ModelFactory (com.yahoo.config.model.api.ModelFactory)2 ApplicationId (com.yahoo.config.provision.ApplicationId)2 Zone (com.yahoo.config.provision.Zone)2 Metric (com.yahoo.jdisc.Metric)2 Curator (com.yahoo.vespa.curator.Curator)2