FixedListMachineProvisioningLocation extends AbstractLocation implements MachineProvisioningLocation<T>, Closeable { public T obtain() throws NoMachinesAvailableException { return obtain(Maps.<String,Object>newLinkedHashMap()); } FixedListMachineProvisioningLocation();  FixedListMachineProvisioningLocation(Map<?,?> properties); @Override void init(); @Override String toVerboseString(); @Override AbstractLocation configure(Map<?,?> properties); @Override @SuppressWarnings("unchecked") FixedListMachineProvisioningLocation<T> newSubLocation(Map<?,?> newFlags); @Override void close(); void addMachine(T machine); void removeMachine(T machine); Set<T> getAvailable(); Set<T> getInUse(); Set<T> getAllMachines(); @Override void addChild(Location child); @Override boolean removeChild(Location child); T obtain(); @SuppressWarnings("unchecked") @Override T obtain(Map<?,?> flags); @Override void release(T machine); @Override Map<String,Object> getProvisioningFlags(Collection<String> tags); @SuppressWarnings("serial")
    static final ConfigKey<Function<Iterable<? extends MachineLocation>, MachineLocation>> MACHINE_CHOOSER; static final ConfigKey<Collection<MachineLocationCustomizer>> MACHINE_LOCATION_CUSTOMIZERS; @Beta
    @SuppressWarnings("serial")
    static final ConfigKey<List<LocationSpec<? extends MachineLocation>>> MACHINE_SPECS; @Beta
    @SuppressWarnings("serial")
    static final ConfigKey<Supplier<? extends List<? extends MachineLocation>>> INITIAL_MACHINES_FACTORY; }
@Test public void testSetsChildLocations() throws NoMachinesAvailableException { assertEquals(ImmutableList.copyOf(provisioner.getChildren()), ImmutableList.of(machine)); provisioner.obtain(); assertEquals(ImmutableList.copyOf(provisioner.getChildren()), ImmutableList.of(machine)); }
@Test public void canObtainMachine() throws NoMachinesAvailableException { SshMachineLocation obtained = provisioner.obtain(); assertEquals(obtained, machine); }
@SuppressWarnings("unused") @Test(expectedExceptions = { NoMachinesAvailableException.class }) public void throwsExceptionIfNoMachinesAvailable() throws NoMachinesAvailableException { SshMachineLocation machine1 = provisioner.obtain(); SshMachineLocation machine2 = provisioner.obtain(); fail("Did not throw NoMachinesAvailableException as expected"); }
@Test public void theBuilder() throws NoMachinesAvailableException { provisioner2 = new FixedListMachineProvisioningLocation.Builder(mgmt.getLocationManager()). user("u1"). addAddress("192.168.0.1"). addAddress("u2@192.168.0.2"). addAddress("192.168.0.{3,4}"). addAddresses("192.168.0.{6-8}"). addAddressMultipleTimes("192.168.0.{8,7}", 2). addAddress("u3@192.168.0.{11-20}"). build(); assertUserAndHost(provisioner2.obtain(), "u1", "192.168.0.1"); assertUserAndHost(provisioner2.obtain(), "u2", "192.168.0.2"); for (int i=3; i<=4; i++) assertUserAndHost(provisioner2.obtain(), "u1", "192.168.0."+i); for (int i=6; i<=8; i++) assertUserAndHost(provisioner2.obtain(), "u1", "192.168.0."+i); for (int j=0; j<2; j++) for (int i=8; i>=7; i--) assertUserAndHost(provisioner2.obtain(), "u1", "192.168.0."+i); for (int i=11; i<=20; i++) assertUserAndHost(provisioner2.obtain(), "u3", "192.168.0."+i); try { provisioner2.obtain(); fail("Should not have obtained"); } catch (Exception e) { } }
@Test public void theBuilderLegacy() throws NoMachinesAvailableException { provisioner2 = new FixedListMachineProvisioningLocation.Builder(mgmt.getLocationManager()). user("u1"). addAddress("192.168.0.1"). addAddress("u2@192.168.0.2"). addAddress("192.168.0.{3,4}"). addAddresses("192.168.0.{6-8}"). addAddressMultipleTimes("192.168.0.{8,7}", 2). addAddress("u3@192.168.0.{11-20}"). build(); assertUserAndHost(provisioner2.obtain(), "u1", "192.168.0.1"); assertUserAndHost(provisioner2.obtain(), "u2", "192.168.0.2"); for (int i=3; i<=4; i++) assertUserAndHost(provisioner2.obtain(), "u1", "192.168.0."+i); for (int i=6; i<=8; i++) assertUserAndHost(provisioner2.obtain(), "u1", "192.168.0."+i); for (int j=0; j<2; j++) for (int i=8; i>=7; i--) assertUserAndHost(provisioner2.obtain(), "u1", "192.168.0."+i); for (int i=11; i<=20; i++) assertUserAndHost(provisioner2.obtain(), "u3", "192.168.0."+i); try { provisioner2.obtain(); fail("Should not have obtained"); } catch (Exception e) { } }
@Test public void testObtainDesiredMachineThrowsIfNotKnown() throws Exception { SshMachineLocation machine2 = new SshMachineLocation( MutableMap.of("address", Inet4Address.getByName("192.168.144.201"))); try { SshMachineLocation obtained = provisioner.obtain(MutableMap.of("desiredMachine", machine2)); fail("obtained="+obtained); } catch (IllegalStateException e) { if (!e.toString().contains("machine unknown")) throw e; } }
@Test public void testCanCreateWithAlreadyParentedMachine() throws UnknownHostException, NoMachinesAvailableException { machine = provisioner.obtain(); FixedListMachineProvisioningLocation<SshMachineLocation> provisioner2 = new FixedListMachineProvisioningLocation.Builder(mgmt.getLocationManager()) .add(machine) .build(); assertEquals(provisioner2.obtain(), machine); }