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);
}
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);
}
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());
}
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);
}
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();
}
Aggregations