Search in sources :

Example 11 with MockCurator

use of com.yahoo.vespa.curator.mock.MockCurator in project vespa by vespa-engine.

the class CuratorDatabaseTest method testTransactionsWithDeactivatedCache.

@Test
public void testTransactionsWithDeactivatedCache() throws Exception {
    MockCurator curator = new MockCurator();
    CuratorDatabase database = new CuratorDatabase(curator, Path.fromString("/"), false);
    assertEquals(0L, (long) curator.counter("/changeCounter").get().get().postValue());
    commitCreate("/1", database);
    commitCreate("/2", database);
    commitCreate("/1/1", database);
    commitCreate("/2/1", database);
    assertEquals(4L, (long) curator.counter("/changeCounter").get().get().postValue());
    // prime the db; this call returns a different instance
    List<String> children1Call0 = database.getChildren(Path.fromString("/1"));
    List<String> children1Call1 = database.getChildren(Path.fromString("/1"));
    List<String> children1Call2 = database.getChildren(Path.fromString("/1"));
    assertTrue("No cache, no reused data", children1Call1 != children1Call2);
}
Also used : MockCurator(com.yahoo.vespa.curator.mock.MockCurator) Test(org.junit.Test)

Example 12 with MockCurator

use of com.yahoo.vespa.curator.mock.MockCurator in project vespa by vespa-engine.

the class CuratorDatabaseTest method testTransactionsIncreaseTimer.

@Test
public void testTransactionsIncreaseTimer() throws Exception {
    MockCurator curator = new MockCurator();
    CuratorDatabase database = new CuratorDatabase(curator, Path.fromString("/"), true);
    assertEquals(0L, (long) curator.counter("/changeCounter").get().get().postValue());
    commitCreate("/1", database);
    commitCreate("/2", database);
    commitCreate("/1/1", database);
    commitCreate("/2/1", database);
    assertEquals(4L, (long) curator.counter("/changeCounter").get().get().postValue());
    // prime the db; this call returns a different instance
    List<String> children1Call0 = database.getChildren(Path.fromString("/1"));
    List<String> children1Call1 = database.getChildren(Path.fromString("/1"));
    List<String> children1Call2 = database.getChildren(Path.fromString("/1"));
    assertTrue("We reuse cached data when there are no commits", children1Call1 == children1Call2);
    assertEquals(1, database.getChildren(Path.fromString("/2")).size());
    commitCreate("/2/2", database);
    List<String> children1Call3 = database.getChildren(Path.fromString("/1"));
    assertEquals(2, database.getChildren(Path.fromString("/2")).size());
    assertFalse("We do not reuse cached data in different parts of the tree when there are commits", children1Call3 == children1Call2);
}
Also used : MockCurator(com.yahoo.vespa.curator.mock.MockCurator) Test(org.junit.Test)

Example 13 with MockCurator

use of com.yahoo.vespa.curator.mock.MockCurator in project vespa by vespa-engine.

the class CuratorDatabaseTest method testThatCounterIncreasesAlsoOnCommitFailureFromExistingTransaction.

@Test
public void testThatCounterIncreasesAlsoOnCommitFailureFromExistingTransaction() throws Exception {
    MockCurator curator = new MockCurator();
    CuratorDatabase database = new CuratorDatabase(curator, Path.fromString("/"), true);
    assertEquals(0L, (long) curator.counter("/changeCounter").get().get().postValue());
    try {
        NestedTransaction t = new NestedTransaction();
        CuratorTransaction separateC = new CuratorTransaction(curator);
        // fail as parent does not exist
        separateC.add(CuratorOperations.create("/1/2"));
        t.add(separateC);
        CuratorTransaction c = database.newCuratorTransactionIn(t);
        // does not fail
        c.add(CuratorOperations.create("/1"));
        t.commit();
        fail("Expected exception");
    } catch (Exception expected) {
    // expected because the parent does not exist
    }
    assertEquals(1L, (long) curator.counter("/changeCounter").get().get().postValue());
}
Also used : CuratorTransaction(com.yahoo.vespa.curator.transaction.CuratorTransaction) NestedTransaction(com.yahoo.transaction.NestedTransaction) MockCurator(com.yahoo.vespa.curator.mock.MockCurator) Test(org.junit.Test)

Example 14 with MockCurator

use of com.yahoo.vespa.curator.mock.MockCurator in project vespa by vespa-engine.

the class MetricsReporterTest method test_registered_metric.

@Test
public void test_registered_metric() throws Exception {
    NodeFlavors nodeFlavors = FlavorConfigBuilder.createDummies("default");
    Curator curator = new MockCurator();
    NodeRepository nodeRepository = new NodeRepository(nodeFlavors, curator, Clock.systemUTC(), Zone.defaultZone(), new MockNameResolver().mockAnyLookup(), new DockerImage("docker-registry.domain.tld:8080/dist/vespa"), true);
    Node node = nodeRepository.createNode("openStackId", "hostname", Optional.empty(), nodeFlavors.getFlavorOrThrow("default"), NodeType.tenant);
    nodeRepository.addNodes(Collections.singletonList(node));
    Node hostNode = nodeRepository.createNode("openStackId2", "parent", Optional.empty(), nodeFlavors.getFlavorOrThrow("default"), NodeType.proxy);
    nodeRepository.addNodes(Collections.singletonList(hostNode));
    Map<String, Number> expectedMetrics = new HashMap<>();
    expectedMetrics.put("hostedVespa.provisionedHosts", 1L);
    expectedMetrics.put("hostedVespa.parkedHosts", 0L);
    expectedMetrics.put("hostedVespa.readyHosts", 0L);
    expectedMetrics.put("hostedVespa.reservedHosts", 0L);
    expectedMetrics.put("hostedVespa.activeHosts", 0L);
    expectedMetrics.put("hostedVespa.inactiveHosts", 0L);
    expectedMetrics.put("hostedVespa.dirtyHosts", 0L);
    expectedMetrics.put("hostedVespa.failedHosts", 0L);
    expectedMetrics.put("hostedVespa.docker.totalCapacityDisk", 0.0);
    expectedMetrics.put("hostedVespa.docker.totalCapacityMem", 0.0);
    expectedMetrics.put("hostedVespa.docker.totalCapacityCpu", 0.0);
    expectedMetrics.put("hostedVespa.docker.freeCapacityDisk", 0.0);
    expectedMetrics.put("hostedVespa.docker.freeCapacityMem", 0.0);
    expectedMetrics.put("hostedVespa.docker.freeCapacityCpu", 0.0);
    expectedMetrics.put("wantedRebootGeneration", 0L);
    expectedMetrics.put("currentRebootGeneration", 0L);
    expectedMetrics.put("wantToReboot", 0);
    expectedMetrics.put("wantToRetire", 0);
    expectedMetrics.put("wantToDeprovision", 0);
    expectedMetrics.put("hardwareFailure", 0);
    expectedMetrics.put("hardwareDivergence", 0);
    expectedMetrics.put("allowedToBeDown", 0);
    expectedMetrics.put("numberOfServices", 0L);
    Orchestrator orchestrator = mock(Orchestrator.class);
    ServiceMonitor serviceMonitor = mock(ServiceMonitor.class);
    when(orchestrator.getNodeStatus(any())).thenReturn(HostStatus.NO_REMARKS);
    ServiceModel serviceModel = mock(ServiceModel.class);
    when(serviceMonitor.getServiceModelSnapshot()).thenReturn(serviceModel);
    when(serviceModel.getServiceInstancesByHostName()).thenReturn(Collections.emptyMap());
    TestMetric metric = new TestMetric();
    MetricsReporter metricsReporter = new MetricsReporter(nodeRepository, metric, orchestrator, serviceMonitor, Duration.ofMinutes(1), new JobControl(nodeRepository.database()));
    metricsReporter.maintain();
    assertEquals(expectedMetrics, metric.values);
}
Also used : MockNameResolver(com.yahoo.vespa.hosted.provision.testutils.MockNameResolver) HashMap(java.util.HashMap) Node(com.yahoo.vespa.hosted.provision.Node) JobControl(com.yahoo.vespa.hosted.provision.maintenance.JobControl) Curator(com.yahoo.vespa.curator.Curator) MockCurator(com.yahoo.vespa.curator.mock.MockCurator) Orchestrator(com.yahoo.vespa.orchestrator.Orchestrator) ServiceMonitor(com.yahoo.vespa.service.monitor.ServiceMonitor) NodeFlavors(com.yahoo.config.provision.NodeFlavors) ServiceModel(com.yahoo.vespa.service.monitor.ServiceModel) MetricsReporter(com.yahoo.vespa.hosted.provision.maintenance.MetricsReporter) NodeRepository(com.yahoo.vespa.hosted.provision.NodeRepository) DockerImage(com.yahoo.config.provision.DockerImage) MockCurator(com.yahoo.vespa.curator.mock.MockCurator) Test(org.junit.Test)

Example 15 with MockCurator

use of com.yahoo.vespa.curator.mock.MockCurator in project vespa by vespa-engine.

the class TestWithCurator method setupZKProvider.

@Before
public void setupZKProvider() throws Exception {
    curator = new MockCurator();
    configCurator = ConfigCurator.create(curator);
    curatorFramework = curator.framework();
}
Also used : MockCurator(com.yahoo.vespa.curator.mock.MockCurator) Before(org.junit.Before)

Aggregations

MockCurator (com.yahoo.vespa.curator.mock.MockCurator)29 Test (org.junit.Test)16 Before (org.junit.Before)11 Curator (com.yahoo.vespa.curator.Curator)6 ConfigCurator (com.yahoo.vespa.config.server.zookeeper.ConfigCurator)5 MockNameResolver (com.yahoo.vespa.hosted.provision.testutils.MockNameResolver)5 DockerImage (com.yahoo.config.provision.DockerImage)4 NodeRepository (com.yahoo.vespa.hosted.provision.NodeRepository)4 File (java.io.File)4 NullConfigModelRegistry (com.yahoo.config.model.NullConfigModelRegistry)3 NodeFlavors (com.yahoo.config.provision.NodeFlavors)3 Zone (com.yahoo.config.provision.Zone)3 Path (com.yahoo.path.Path)3 ModelFactoryRegistry (com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry)3 VespaModelFactory (com.yahoo.vespa.model.VespaModelFactory)3 ConfigserverConfig (com.yahoo.cloud.config.ConfigserverConfig)2 ManualClock (com.yahoo.test.ManualClock)2 TestComponentRegistry (com.yahoo.vespa.config.server.TestComponentRegistry)2 MemoryTenantApplications (com.yahoo.vespa.config.server.application.MemoryTenantApplications)2 SessionHandlerTest (com.yahoo.vespa.config.server.http.SessionHandlerTest)2