@BeforeMethod public void setUp() throws Exception { super.setUp(); FakeModel.instance().clear(); myTaskExecutor = new CloudAsyncTaskExecutor("Test-vmware"); myApiConnector = new FakeApiConnector(); myIdxStorage = createTempDir(); myImageDetails = new VmwareCloudImageDetails( "imageNickname", "srcVM", "srcVMSnap", "folderId", "rpId", CloneBehaviour.FRESH_CLONE, 5); FakeModel.instance().addVM("srcVM"); FakeModel.instance().addFolder("folderId"); FakeModel.instance().addResourcePool("rpId"); FakeModel.instance().addVMSnapshot("srcVM", "srcVMSnap"); myImage = new VmwareCloudImage(myApiConnector, myImageDetails, myTaskExecutor, myIdxStorage); myCloudClient = new VMWareCloudClient(new CloudClientParameters(), myApiConnector, createTempDir()); myCloudClient.populateImagesDataAsync(Collections.singletonList(myImageDetails)); myUpdateTask = new UpdateInstancesTask<VmwareCloudInstance, VmwareCloudImage, VMWareCloudClient>( myApiConnector, myCloudClient, 10 * 1000); }
public void check_can_start_new_instance_limits() throws RemoteException, InterruptedException { final CloudInstanceUserData data = new CloudInstanceUserData( "aaa", "bbbb", "localhost", 10000l, "profileDescr", Collections.<String, String>emptyMap()); assertTrue(myImage.canStartNewInstance()); myImage.startNewInstance(data); assertTrue(myImage.canStartNewInstance()); myImage.startNewInstance(data); assertTrue(myImage.canStartNewInstance()); myImage.startNewInstance(data); assertTrue(myImage.canStartNewInstance()); myImage.startNewInstance(data); assertTrue(myImage.canStartNewInstance()); final VmwareCloudInstance instance2Stop = myImage.startNewInstance(data); assertFalse(myImage.canStartNewInstance()); new WaitFor(5 * 1000) { @Override protected boolean condition() { return instance2Stop.getStatus() == InstanceStatus.RUNNING; } }; final FakeVirtualMachine vm2Stop = FakeModel.instance().getVirtualMachine(instance2Stop.getName()); final String result = vm2Stop.powerOffVM_Task().waitForTask(); assertEquals(Task.SUCCESS, result); instance2Stop.setStatus(InstanceStatus.STOPPED); assertTrue(myImage.canStartNewInstance()); System.setProperty(VmwareConstants.CONSIDER_STOPPED_VMS_LIMIT, "true"); assertFalse(myImage.canStartNewInstance()); System.getProperties().remove(VmwareConstants.CONSIDER_STOPPED_VMS_LIMIT); assertTrue(myImage.canStartNewInstance()); }