com.intellij.util.WaitFor Java Examples
The following examples show how to use
com.intellij.util.WaitFor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VmwareCloudInstanceTest.java From teamcity-vmware-plugin with Apache License 2.0 | 6 votes |
public void do_not_make_instance_start_date_earlier(){ final CloudInstanceUserData data = new CloudInstanceUserData("aaa", "bbbb", "localhost", 10000l, "profileDescr", Collections.<String, String>emptyMap()); final VmwareCloudInstance instance = myImage.startNewInstance(data); new WaitFor(5 * 1000){ @Override protected boolean condition() { return instance.getStatus() == InstanceStatus.RUNNING; } }; FakeVirtualMachine fakeVM = FakeModel.instance().getVirtualMachine(instance.getName()); final Calendar calendarInstance = Calendar.getInstance(); calendarInstance.set(2001, 1, 1); fakeVM.setBootTime(calendarInstance); calendarInstance.set(2001, 1, 1); final Calendar instance2 = Calendar.getInstance(); instance2.set(2002, 1, 1); assertTrue(instance.getStartedTime().after(instance2.getTime())); }
Example #2
Source File: TreeUiTest.java From consulo with Apache License 2.0 | 6 votes |
private void assertCallbackOnce(final TreeAction action) { final int[] notifyCount = new int[1]; final boolean[] done = new boolean[1]; invokeLaterIfNeeded(new Runnable() { @Override public void run() { action.run(new Runnable() { @Override public void run() { notifyCount[0]++; done[0] = true; } }); } }); new WaitFor(60000) { @Override protected boolean condition() { return done[0] && getMyBuilder().getUi().isReady(); } }; assertTrue(done[0]); assertEquals(1, notifyCount[0]); }
Example #3
Source File: VmwareCloudImageTest.java From teamcity-vmware-plugin with Apache License 2.0 | 6 votes |
@TestFor(issues = "TW-54729") public void check_name_generator_doesnt_use_disk() throws IOException, InterruptedException { final Set<String> generatedNames = new HashSet<>(); Thread nameGenerator = new Thread(()->{ for (int i=0; i<10000; i++){ if (Thread.currentThread().isInterrupted()) break; generatedNames.add(myImage.generateNewVmName()); } }); nameGenerator.start(); new WaitFor(500){ @Override protected boolean condition() { return generatedNames.size() == 10000; } }; assertEquals(10000, generatedNames.size()); nameGenerator.join(); assertEquals("1", FileUtil.readText(new File(myIdxStorage, myImage.getImageDetails().getSourceId() + ".idx"))); myImage.storeIdx(); assertEquals("10001", FileUtil.readText(new File(myIdxStorage, myImage.getImageDetails().getSourceId() + ".idx"))); }
Example #4
Source File: BaseTreeTestCase.java From consulo with Apache License 2.0 | 6 votes |
@Override protected void tearDown() throws Exception { invokeLaterIfNeeded(new Runnable() { @Override public void run() { if (getBuilder() != null) { Disposer.dispose(getBuilder()); } } }); new WaitFor(6000) { @Override protected boolean condition() { return getBuilder() == null || getBuilder().getUi() == null; } }; super.tearDown(); }
Example #5
Source File: VmwareCloudIntegrationTest.java From teamcity-vmware-plugin with Apache License 2.0 | 6 votes |
public void sync_start_stop_instance_status() throws RemoteException { final VmwareCloudImage img1 = getImageByName("image1"); assertEquals(1, img1.getInstances().size()); final VmwareCloudInstance inst1 = img1.getInstances().iterator().next(); assertEquals(InstanceStatus.STOPPED, inst1.getStatus()); startNewInstanceAndWait("image1"); assertEquals(InstanceStatus.RUNNING, inst1.getStatus()); FakeModel.instance().getVirtualMachine("image1").shutdownGuest(); new WaitFor(3000){ protected boolean condition() { return img1.getInstances().iterator().next().getStatus() == InstanceStatus.STOPPED; } }.assertCompleted("Should have caught the stopped status"); FakeModel.instance().getVirtualMachine("image1").powerOnVM_Task(null); new WaitFor(3000){ protected boolean condition() { return img1.getInstances().iterator().next().getStatus() == InstanceStatus.RUNNING; } }.assertCompleted("Should have caught the running status"); }
Example #6
Source File: VmwareCloudIntegrationTest.java From teamcity-vmware-plugin with Apache License 2.0 | 6 votes |
public void sync_clone_status() throws RemoteException { final VmwareCloudImage img1 = getImageByName("image_template"); assertEquals(0, img1.getInstances().size()); final VmwareCloudInstance inst = startNewInstanceAndWait("image_template"); assertEquals(InstanceStatus.RUNNING, inst.getStatus()); FakeModel.instance().getVirtualMachine(inst.getName()).shutdownGuest(); new WaitFor(3000){ protected boolean condition() { return img1.getInstances().iterator().next().getStatus() == InstanceStatus.STOPPED; } }.assertCompleted("Should have caught the stopped status"); FakeModel.instance().getVirtualMachine(inst.getName()).powerOnVM_Task(null); new WaitFor(3000){ protected boolean condition() { return img1.getInstances().iterator().next().getStatus() == InstanceStatus.RUNNING; } }.assertCompleted("Should have caught the running status"); }
Example #7
Source File: AbstractTreeBuilderTest.java From consulo with Apache License 2.0 | 6 votes |
void hideTree() throws Exception { Assert.assertFalse(getMyBuilder().myWasCleanedUp); invokeLaterIfNeeded(new Runnable() { @Override public void run() { getBuilder().getUi().deactivate(); } }); final WaitFor waitFor = new WaitFor() { @Override protected boolean condition() { return getMyBuilder().myWasCleanedUp || myCancelRequest != null; } }; if (myCancelRequest != null) { throw new Exception(myCancelRequest); } waitFor.assertCompleted("Tree cleanup was not performed. isCancelledReadyState=" + getBuilder().getUi().isCancelledReady()); Assert.assertTrue(getMyBuilder().myWasCleanedUp); }
Example #8
Source File: VmwareCloudIntegrationTest.java From teamcity-vmware-plugin with Apache License 2.0 | 6 votes |
public void check_same_datacenter() throws InterruptedException { FakeModel.instance().addDatacenter("dc2"); FakeModel.instance().addFolder("cf2").setParent("dc2", Datacenter.class); FakeModel.instance().addResourcePool("rp2").setParentFolder("cf2"); FakeModel.instance().addVM("image3").setParentFolder("cf"); updateClientParameters(VmwareTestUtils.getImageParameters(PROJECT_ID, "[{sourceVmName:'image1', behaviour:'START_STOP'}," + "{sourceVmName:'image2',snapshot:'snap*',folder:'cf',pool:'rp',maxInstances:3,behaviour:'ON_DEMAND_CLONE'}," + "{sourceVmName:'image_template', snapshot:'" + VmwareConstants.CURRENT_STATE + "',folder:'cf',pool:'rp',maxInstances:3,behaviour:'FRESH_CLONE'}, " + "{sourceVmName:'image3',snapshot:'" + VmwareConstants.CURRENT_STATE + "'," + "folder:'cf2',pool:'rp2',maxInstances:3,behaviour:'ON_DEMAND_CLONE'}]")); recreateClient(); final CloudInstanceUserData userData = createUserData("image3_agent"); final VmwareCloudInstance vmwareCloudInstance = myClient.startNewInstance(getImageByName("image3"), userData); new WaitFor(10 * 1000) { @Override protected boolean condition() { return vmwareCloudInstance.getStatus() == InstanceStatus.ERROR && vmwareCloudInstance.getErrorInfo() != null; } }.assertCompleted(); final String msg = vmwareCloudInstance.getErrorInfo().getMessage(); assertContains(msg, "Unable to find folder cf2 in datacenter dc"); }
Example #9
Source File: VmwareCloudIntegrationTest.java From teamcity-vmware-plugin with Apache License 2.0 | 6 votes |
@TestFor(issues = "TW-47486") public void shouldnt_throw_error_when_stopping_nonexisting_instance(){ setInternalProperty("teamcity.vsphere.instance.status.update.delay.ms", "250000"); recreateClient(); final VmwareCloudInstance startedInstance = startNewInstanceAndWait("image_template"); final FakeVirtualMachine vm = FakeModel.instance().getVirtualMachine(startedInstance.getName()); assertNotNull(vm); FakeModel.instance().removeVM(vm.getName()); final VmwareCloudImage image = startedInstance.getImage(); assertContains(image.getInstances(), startedInstance); myClient.terminateInstance(startedInstance); new WaitFor(1000) { @Override protected boolean condition() { return !image.getInstances().contains(startedInstance); } }; assertNotContains(image.getInstances(), startedInstance); }
Example #10
Source File: VmwareCloudIntegrationTest.java From teamcity-vmware-plugin with Apache License 2.0 | 6 votes |
private VMWareCloudClient recreateClient(final VMWareCloudClient oldClient, final CloudClientParameters parameters, long updateTime, boolean waitForInitialization){ if (oldClient != null) { oldClient.dispose(); } myProfile = VmwareTestUtils.createProfileFromProps(parameters); final VMWareCloudClient newClient = new VMWareCloudClient(myProfile, myFakeApi, myTaskManager, myIdxStorage); final Collection<VmwareCloudImageDetails> images = VMWareCloudClientFactory.parseImageDataInternal(parameters); newClient.populateImagesData(images, updateTime, updateTime); if (waitForInitialization) { new WaitFor(5000) { @Override protected boolean condition() { return newClient.isInitialized(); } }.assertCompleted("Must be initialized"); } return newClient; }
Example #11
Source File: VmwareCloudIntegrationTest.java From teamcity-vmware-plugin with Apache License 2.0 | 6 votes |
private void terminateAndDeleteIfNecessary(final boolean shouldBeDeleted, final VmwareCloudInstance instance) throws CheckedCloudException { myClient.terminateInstance(instance); new WaitFor(5*1000){ protected boolean condition() { return instance.getStatus()==InstanceStatus.STOPPED; } }.assertCompleted(); final String name = instance.getName(); final WaitFor waitFor = new WaitFor(10 * 1000) { @Override protected boolean condition() { try { if (shouldBeDeleted) { return (myFakeApi.getAllVMsMap(false).get(name) == null); } else { return myFakeApi.getInstanceDetails(name).getInstanceStatus() == InstanceStatus.STOPPED; } } catch (CheckedCloudException e) { return false; } } }; waitFor.assertCompleted("template clone should be deleted after execution"); }
Example #12
Source File: AndroidUtils.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static void runAfterSyncFinishes(@NotNull Project project, @NotNull Consumer<Project> runnable) { new WaitFor(GRADLE_SYNC_TIMEOUT, () -> runnable.accept(project)) { @Override public boolean condition() { return !GradleSyncState.getInstance(project).isSyncInProgress(); } }; }
Example #13
Source File: WeaksTestCase.java From consulo with Apache License 2.0 | 5 votes |
private static void waitFor(final Condition<Void> condition) { new WaitFor(10000) { @Override protected boolean condition() { gc(); return condition.value(null); } }.assertCompleted(condition.toString()); }
Example #14
Source File: TreeUiTest.java From consulo with Apache License 2.0 | 5 votes |
private void assertReleaseDuringBuilding(final String actionAction, final Object actionElement, Runnable buildAction) throws Exception { buildStructure(myRoot); myElementUpdateHook = new ElementUpdateHook() { @Override public void onElementAction(String action, Object element) { if (!element.toString().equals(actionElement.toString())) return; Runnable runnable = new Runnable() { @Override public void run() { myReadyRequest = true; Disposer.dispose(getBuilder()); } }; if (actionAction.equals(action)) { if (getBuilder().getUi().isPassthroughMode()) { runnable.run(); } else { //noinspection SSBasedInspection SwingUtilities.invokeLater(runnable); } } } }; buildAction.run(); boolean released = new WaitFor(15000) { @Override protected boolean condition() { return getBuilder().getUi() == null; } }.isConditionRealized(); assertTrue(released); }
Example #15
Source File: BaseTreeTestCase.java From consulo with Apache License 2.0 | 5 votes |
void waitBuilderToCome(final Condition<Object> condition) throws Exception { boolean success = new WaitFor(60000) { @Override protected boolean condition() { final boolean[] ready = {false}; invokeAndWaitIfNeeded(new Runnable() { @Override public void run() { AbstractTreeUi ui = getBuilder().getUi(); if (ui == null) { ready[0] = true; return; } ready[0] = myCancelRequest != null || myReadyRequest || condition.value(null) && ui.isReady(); } }); return ready[0]; } }.isConditionRealized(); if (myCancelRequest != null) { throw new Exception(myCancelRequest); } if (!myReadyRequest) { if (!getBuilder().isDisposed()) { Assert.assertTrue(getBuilder().getUi().getNodeActions().isEmpty()); } } Assert.assertTrue(success); }
Example #16
Source File: MergingUpdateQueueTest.java From consulo with Apache License 2.0 | 5 votes |
private void waitForExecution(final MyQueue queue) { queue.onTimer(); new WaitFor(5000) { @Override protected boolean condition() { return queue.wasExecuted(); } }; }
Example #17
Source File: VmwareCloudIntegrationTest.java From teamcity-vmware-plugin with Apache License 2.0 | 5 votes |
@TestFor(issues = "TW-55838") public void should_poweroff_when_instance_doesnt_stop_in_time() throws MalformedURLException { setInternalProperty("teamcity.vmware.guest.shutdown.timeout", "1000"); final VmwareCloudInstance startedInstance = startNewInstanceAndWait("image_template"); final FakeVirtualMachine vm = FakeModel.instance().getVirtualMachine(startedInstance.getName()); final AtomicLong powerOffCalled = new AtomicLong(); final AtomicLong guestShutdownCalled = new AtomicLong(); assertNotNull(vm); FakeModel.instance().getEvents().forEach(event->{ if (event.second.equals("powerOffVM_Task") && event.first.equals(startedInstance.getName())){ assertTrue(powerOffCalled.compareAndSet(0, event.third)); } if (event.second.equals("shutdownGuest") && event.first.equals(startedInstance.getName())){ assertTrue(guestShutdownCalled.compareAndSet(0, event.third)); } }); assertEquals(0, powerOffCalled.get() + guestShutdownCalled.get()); setInternalProperty("test.guest.shutdown.sleep.interval", "3000"); myClient.terminateInstance(startedInstance); new WaitFor(2*1000){ @Override protected boolean condition() { return FakeModel.instance().getVirtualMachine(startedInstance.getName()) == null; } }; FakeModel.instance().getEvents().forEach(event->{ if (event.second.equals("powerOffVM_Task") && event.first.equals(startedInstance.getName())){ assertTrue(powerOffCalled.compareAndSet(0, event.third)); } if (event.second.equals("shutdownGuest") && event.first.equals(startedInstance.getName())){ assertTrue(guestShutdownCalled.compareAndSet(0, event.third)); } }); assertTrue(guestShutdownCalled.get() > 0); long diff = powerOffCalled.get() - guestShutdownCalled.get(); assertTrue( diff > 0 && diff < 2000 ); }
Example #18
Source File: VmwareCloudIntegrationTest.java From teamcity-vmware-plugin with Apache License 2.0 | 5 votes |
public void enforce_change_of_stuck_instance_status() throws RemoteException, ExecutionException, InterruptedException { myStuckTime.set(3*1000); recreateClient(250); final VmwareCloudInstance instance = startNewInstanceAndWait("image1"); FakeModel.instance().getVms().get(instance.getName()).shutdownGuest(); instance.setStatus(InstanceStatus.STOPPING); new WaitFor(6*1000){ @Override protected boolean condition() { return instance.getStatus() == InstanceStatus.STOPPED; } }.assertCompleted("should have changed the status"); }
Example #19
Source File: VmwareCloudIntegrationTest.java From teamcity-vmware-plugin with Apache License 2.0 | 5 votes |
public void should_power_off_if_no_guest_tools_avail() throws InterruptedException { final VmwareCloudImage image_template = getImageByName("image_template"); final VmwareCloudInstance instance = startNewInstanceAndWait("image_template"); assertContains(image_template.getInstances(), instance); FakeModel.instance().getVirtualMachine(instance.getName()).disableGuestTools(); myClient.terminateInstance(instance); new WaitFor(2000) { @Override protected boolean condition() { return instance.getStatus() == InstanceStatus.STOPPED && !image_template.getInstances().contains(instance); } }; assertNull(FakeModel.instance().getVirtualMachine(instance.getName())); assertNotContains(image_template.getInstances(), instance); }
Example #20
Source File: VmwareCloudImageTest.java From teamcity-vmware-plugin with Apache License 2.0 | 5 votes |
public void should_store_idx_on_dispose() throws IOException { new WaitFor(500){ @Override protected boolean condition() { return myCloudClient.isInitialized(); } }; VmwareCloudImage img = myCloudClient.getImages().iterator().next(); assertEquals("imageNickname-1", img.generateNewVmName()); File file = new File(myIdxStorage, img.getImageDetails().getSourceId() + ".idx"); assertEquals("1", FileUtil.readText(file)); myCloudClient.dispose(); assertEquals( "2", FileUtil.readText(file)); }
Example #21
Source File: VmwareCloudImageTest.java From teamcity-vmware-plugin with Apache License 2.0 | 5 votes |
public void terminate_instance_if_cant_reconfigure() throws IOException { final CloudInstanceUserData data = new CloudInstanceUserData("aaa", "bbbb", "localhost", 10000l, "profileDescr", Collections.<String, String>emptyMap()); final AtomicBoolean stopInstanceCalled = new AtomicBoolean(); myApiConnector = new FakeApiConnector(VmwareCloudIntegrationTest.TEST_SERVER_UUID, VmwareCloudIntegrationTest.PROFILE_ID){ @Override public Task reconfigureInstance(@NotNull final VmwareCloudInstance instance, @NotNull final String agentName, @NotNull final CloudInstanceUserData userData) throws VmwareCheckedCloudException { return FakeVirtualMachine.failureTask(); } @Override public Task stopInstance(@NotNull final VmwareCloudInstance instance) { stopInstanceCalled.set(true); return super.stopInstance(instance); } }; myImage = new VmwareCloudImage(myApiConnector, myImageDetails, myTaskExecutor, myIdxStorage, myProfile); myCloudClient = new VMWareCloudClient(myProfile, myApiConnector, new VmwareUpdateTaskManager(), createTempDir()); myCloudClient.populateImagesData(Collections.singletonList(myImageDetails)); myImage.startNewInstance(data); new WaitFor(1000){ @Override protected boolean condition() { return stopInstanceCalled.get(); } }; assertTrue("Should have stopped if can't reconfigure", stopInstanceCalled.get()); }
Example #22
Source File: VmwareCloudImageTest.java From teamcity-vmware-plugin with Apache License 2.0 | 5 votes |
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()); }
Example #23
Source File: AndroidUtils.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static void runAfterSyncFinishes(@NotNull Project project, @NotNull Consumer<Project> runnable) { new WaitFor(GRADLE_SYNC_TIMEOUT, () -> runnable.accept(project)) { @Override public boolean condition() { return !GradleSyncState.getInstance(project).isSyncInProgress(); } }; }
Example #24
Source File: VmwareCloudIntegrationTest.java From teamcity-vmware-plugin with Apache License 2.0 | 4 votes |
@TestFor(issues = "TW-61456") public void recover_if_cant_connect_on_start() throws MalformedURLException { final AtomicBoolean failure = new AtomicBoolean(false); final AtomicLong lastApiCallTime = new AtomicLong(0); myFakeApi = new FakeApiConnector(TEST_SERVER_UUID, PROFILE_ID){ @Override protected <T extends ManagedEntity> Collection<T> findAllEntitiesOld(final Class<T> instanceType) throws VmwareCheckedCloudException { lastApiCallTime.set(System.currentTimeMillis()); if (failure.get()){ throw new VmwareCheckedCloudException("Cannot connect"); } return super.findAllEntitiesOld(instanceType); } @Override protected <T extends ManagedEntity> Map<String, T> findAllEntitiesAsMapOld(final Class<T> instanceType) throws VmwareCheckedCloudException { lastApiCallTime.set(System.currentTimeMillis()); if (failure.get()){ throw new VmwareCheckedCloudException("Cannot connect"); } return super.findAllEntitiesAsMapOld(instanceType); } @Override protected <T extends ManagedEntity> Pair<T,Datacenter> findEntityByIdNameOld(final String name, final Class<T> instanceType) throws VmwareCheckedCloudException { lastApiCallTime.set(System.currentTimeMillis()); if (failure.get()){ throw new VmwareCheckedCloudException("Cannot connect"); } return super.findEntityByIdNameOld(name, instanceType); } @Override protected Map<String, VirtualMachine> searchVMsByNames(@NotNull Collection<String> names, @Nullable Datacenter dc) throws VmwareCheckedCloudException { lastApiCallTime.set(System.currentTimeMillis()); if (failure.get()){ throw new VmwareCheckedCloudException("Cannot connect"); } return super.searchVMsByNames(names, dc); } }; failure.set(true); recreateClient(250); new WaitFor(1000){ @Override protected boolean condition() { return myClient.isInitialized(); } }; myClient.getImages().forEach(img-> assertNotNull(img.getErrorInfo())); failure.set(false); new WaitFor(1000){ @Override protected boolean condition() { AtomicBoolean result = new AtomicBoolean(true); myClient.getImages().forEach(img-> result.compareAndSet(true, img.getErrorInfo()==null)); return result.get(); } }; myClient.getImages().forEach(img-> assertNull(img.getErrorInfo())); }
Example #25
Source File: VmwareCloudIntegrationTest.java From teamcity-vmware-plugin with Apache License 2.0 | 4 votes |
@TestFor(issues = "TW-56632") public void should_poweroff_and_delete_when_instance_doesnt_stop_in_time(){ setInternalProperty("teamcity.vmware.guest.shutdown.timeout.seconds", "1"); final VmwareCloudInstance startedInstance = startNewInstanceAndWait("image_template"); final FakeVirtualMachine vm = FakeModel.instance().getVirtualMachine(startedInstance.getName()); final AtomicLong powerOffCalled = new AtomicLong(); final AtomicLong guestShutdownCalled = new AtomicLong(); final AtomicLong destroyCalled = new AtomicLong(); assertNotNull(vm); FakeModel.instance().getEvents().forEach(event->{ if (event.second.equals("powerOffVM_Task") && event.first.equals(startedInstance.getName())){ assertTrue(powerOffCalled.compareAndSet(0, event.third)); } if (event.second.equals("shutdownGuest") && event.first.equals(startedInstance.getName())){ assertTrue(guestShutdownCalled.compareAndSet(0, event.third)); } }); assertEquals(0, powerOffCalled.get() + guestShutdownCalled.get()); setInternalProperty("test.guest.shutdown.sleep.interval", "3000"); myClient.terminateInstance(startedInstance); new WaitFor(2*1000){ @Override protected boolean condition() { return FakeModel.instance().getVirtualMachine(startedInstance.getName()) == null; } }; assertTrue(FakeModel.instance().getVirtualMachine(startedInstance.getName()) == null); FakeModel.instance().getEvents().forEach(event->{ if (event.second.equals("powerOffVM_Task") && event.first.equals(startedInstance.getName())){ assertTrue(powerOffCalled.compareAndSet(0, event.third)); } if (event.second.equals("shutdownGuest") && event.first.equals(startedInstance.getName())){ assertTrue(guestShutdownCalled.compareAndSet(0, event.third)); } if (event.second.equals("destroy_Task") && event.first.equals(startedInstance.getName())){ assertTrue(destroyCalled.compareAndSet(0, event.third)); } }); assertTrue(guestShutdownCalled.get() > 0); long diff = powerOffCalled.get() - guestShutdownCalled.get(); assertTrue( diff > 0 && diff < 2000 ); assertTrue( destroyCalled.get() > 0 ); }
Example #26
Source File: VmwareCloudIntegrationTest.java From teamcity-vmware-plugin with Apache License 2.0 | 4 votes |
private VmwareCloudInstance startNewInstanceAndCheck(VMWareCloudClient client, String imageName, Map<String, String> parameters, boolean instanceShouldStart, boolean waitForInstance2Start) { final CloudInstanceUserData userData = createUserData(imageName + "_agent", parameters); final VmwareCloudImage image = getImageByName(client, imageName); final Collection<VmwareCloudInstance> runningInstances = image .getInstances() .stream() .filter(i->i.getStatus() == InstanceStatus.RUNNING) .collect(Collectors.toList()); final VmwareCloudInstance vmwareCloudInstance = client.startNewInstance(image, userData); final boolean ready = vmwareCloudInstance.isReady(); System.out.printf("Instance '%s'. Ready: %b%n", vmwareCloudInstance.getName(), ready); if (!waitForInstance2Start) return vmwareCloudInstance; final WaitFor waitFor = new WaitFor(2 * 1000) { @Override protected boolean condition() { if (ready) { return vmwareCloudInstance.getStatus() == InstanceStatus.RUNNING; } else { return image .getInstances() .stream() .anyMatch(i->i.getStatus() == InstanceStatus.RUNNING && !runningInstances.contains(i)); } } }; if (instanceShouldStart) { waitFor.assertCompleted(); if (!ready) { final VmwareCloudInstance startedInstance = image .getInstances() .stream() .filter(i -> i.getStatus() == InstanceStatus.RUNNING && !runningInstances.contains(i)).findAny().get(); assertNotNull(startedInstance); return startedInstance; } else { return vmwareCloudInstance; } } else { assertFalse(waitFor.isConditionRealized()); return null; } }
Example #27
Source File: VmwareCloudIntegrationTest.java From teamcity-vmware-plugin with Apache License 2.0 | 4 votes |
public void do_not_clear_image_instances_list_on_error() throws ExecutionException, InterruptedException, MalformedURLException { final AtomicBoolean failure = new AtomicBoolean(false); final AtomicLong lastApiCallTime = new AtomicLong(0); myFakeApi = new FakeApiConnector(TEST_SERVER_UUID, PROFILE_ID){ @Override protected <T extends ManagedEntity> Collection<T> findAllEntitiesOld(final Class<T> instanceType) throws VmwareCheckedCloudException { lastApiCallTime.set(System.currentTimeMillis()); if (failure.get()){ throw new VmwareCheckedCloudException("Cannot connect"); } return super.findAllEntitiesOld(instanceType); } @Override protected <T extends ManagedEntity> Map<String, T> findAllEntitiesAsMapOld(final Class<T> instanceType) throws VmwareCheckedCloudException { lastApiCallTime.set(System.currentTimeMillis()); if (failure.get()){ throw new VmwareCheckedCloudException("Cannot connect"); } return super.findAllEntitiesAsMapOld(instanceType); } @Override protected <T extends ManagedEntity> Pair<T,Datacenter> findEntityByIdNameOld(final String name, final Class<T> instanceType) throws VmwareCheckedCloudException { lastApiCallTime.set(System.currentTimeMillis()); if (failure.get()){ throw new VmwareCheckedCloudException("Cannot connect"); } return super.findEntityByIdNameOld(name, instanceType); } }; recreateClient(250); startNewInstanceAndWait("image2"); startNewInstanceAndWait("image2"); startNewInstanceAndWait("image2"); Thread.sleep(5*1000); failure.set(true); final long problemStart = System.currentTimeMillis(); new WaitFor(5*1000){ @Override protected boolean condition() { return myLastRunTime.get() > problemStart; } }.assertCompleted("Should have been checked at least once - delay set to 2 sec"); assertEquals(3, getImageByName("image2").getInstances().size()); }
Example #28
Source File: TreeUiTest.java From consulo with Apache License 2.0 | 4 votes |
public void testDeferredSelection() throws Exception { buildStructure(myRoot, false); final Ref<Boolean> queued = new Ref<Boolean>(false); final Ref<Boolean> intellijSelected = new Ref<Boolean>(false); final Ref<Boolean> jetbrainsSelected = new Ref<Boolean>(false); invokeLaterIfNeeded(new Runnable() { @Override public void run() { try { getBuilder().select(new NodeElement("intellij"), new Runnable() { @Override public void run() { intellijSelected.set(true); } }, true); queued.set(true); } catch (Exception e) { e.printStackTrace(); fail(); } } }); new WaitFor() { @Override protected boolean condition() { return queued.get(); } }; assertTrue(getBuilder().getUi().isIdle()); assertTreeNow("+null\n"); assertNull(((DefaultMutableTreeNode)notNull(getBuilder().getTreeModel()).getRoot()).getUserObject()); invokeLaterIfNeeded(new Runnable() { @Override public void run() { getBuilder().getUi().activate(true); getBuilder().select(new NodeElement("jetbrains"), new Runnable() { @Override public void run() { jetbrainsSelected.set(true); } }, true); } }); waitBuilderToCome(new Condition<Object>() { @Override public boolean value(Object object) { return intellijSelected.get() && jetbrainsSelected.get(); } }); assertTree("-/\n" + " -com\n" + " +[intellij]\n" + " +[jetbrains]\n" + " +org\n" + " +xUnit\n"); }
Example #29
Source File: PlaybackDebugger.java From consulo with Apache License 2.0 | 4 votes |
private void startWhenFrameActive() { myLog.setText(null); addInfo("Waiting for IDE frame activation", -1, MESSAGE_COLOR, 0); myRunner = new PlaybackRunner(myCodeEditor.getText(), this, false, true, false); VirtualFile file = pathToFile(); if (file != null) { VirtualFile scriptDir = file.getParent(); if (scriptDir != null) { myRunner.setScriptDir(new File(scriptDir.getPresentableUrl())); } } new Thread() { @Override public void run() { new WaitFor() { @Override protected boolean condition() { java.awt.Window window = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow(); return window != null && TargetAWT.from(window).getUserData(IdeFrame.KEY) != null || myRunner == null; } }; if (myRunner == null) { message(null, "Script stopped", -1, Type.message, true); return; } message(null, "Starting script...", -1, Type.message, true); try { sleep(1000); } catch (InterruptedException e) { } if (myRunner == null) { message(null, "Script stopped", -1, Type.message, true); return; } final PlaybackRunner runner = myRunner; myRunner.run().doWhenProcessed(new Runnable() { @Override public void run() { if (runner == myRunner) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { myRunner = null; } }); } } }); } }.start(); }