@Test
    public void testCreateOnlyNeededModelVersions() {
        List<Host> hosts = createHosts(9, "6.0.0", "6.1.0", null, "6.1.0"); // Use a host without a version as well.

        CountingModelFactory factory600 = createHostedModelFactory(Version.fromString("6.0.0"));
        CountingModelFactory factory610 = createHostedModelFactory(Version.fromString("6.1.0"));
        CountingModelFactory factory620 = createHostedModelFactory(Version.fromString("6.2.0"));
        CountingModelFactory factory700 = createHostedModelFactory(Version.fromString("7.0.0"));
        CountingModelFactory factory710 = createHostedModelFactory(Version.fromString("7.1.0"));
        CountingModelFactory factory720 = createHostedModelFactory(Version.fromString("7.2.0"));
        List<ModelFactory> modelFactories = List.of(factory600, factory610, factory620,
                                                    factory700, factory710, factory720);

        DeployTester tester = createTester(hosts, modelFactories, prodZone);
        // Deploy with version that does not exist on hosts, the model for this version should also be created
        tester.deployApp("src/test/apps/hosted/", "7.0.0");
        assertEquals(9, tester.getAllocatedHostsOf(tester.applicationId()).getHosts().size());

        // Check >0 not ==0 as the session watcher thread is running and will redeploy models in the background
        assertTrue(factory600.creationCount() > 0);
        assertTrue(factory610.creationCount() > 0);
        assertFalse(factory620.creationCount() > 0); // Latest model version on a major, but not for the latest major
        assertTrue(factory700.creationCount() > 0);  // Wanted version, also needs to be built
        assertFalse(factory710.creationCount() > 0);
        assertTrue("Newest is always included", factory720.creationCount() > 0);
    }
Test that only the minimal set of models are created (model versions used on hosts, the wanted version
and the latest version for the latest major)
configserver/src/test/java/com/yahoo/vespa/config/server/deploy/HostedDeployTest.java