// Path: cloud-vmware-server/src/test/java/jetbrains/buildServer/clouds/vmware/stubs/FakeModel.java
// public static final ThreadFactory FAKE_MODEL_THREAD_FACTORY = r -> {
//   Thread th = new Thread(r);
//   th.setDaemon(true);
//   return th;
// };


import com.vmware.vim25.*;
import com.vmware.vim25.mo.*;
import java.rmi.RemoteException;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import jetbrains.buildServer.serverSide.TeamCityProperties;
import org.jetbrains.annotations.NotNull;
import static jetbrains.buildServer.clouds.vmware.stubs.FakeModel.FAKE_MODEL_THREAD_FACTORY;
    newVm.setParentFolder(folder.getName());
    final VirtualMachineConfigInfo oldConfig = newVm.myConfigInfoRef.get();
    newVm.myConfigInfoRef.set(null);
    newVm.myCustomizationSpec = spec.getCustomization();
    final CountDownLatch latch = new CountDownLatch(1);
    new Thread(){
      @Override
      public void run() {
        try {sleep(100);} catch (InterruptedException e) {}
        latch.countDown();
        newVm.myConfigInfoRef.set(oldConfig);

        if (spec.isPowerOn()){
          if (!newVm.myIsStarted.compareAndSet(false, true)){
            //throw new RemoteException("Already started");
          }
        }
      }
    }.start();
    return longTask(latch);
  }

  @Override
  public Task powerOffVM_Task() throws RemoteException {
    FakeModel.instance().publishEvent(getName(), "powerOffVM_Task");
    if (!myIsStarted.get()){
      throw new RemoteException("Already stopped");
    }
    final TaskInfo taskInfo = new TaskInfo();

// Path: cloud-vmware-server/src/test/java/jetbrains/buildServer/clouds/vmware/stubs/FakeModel.java
// public static final ThreadFactory FAKE_MODEL_THREAD_FACTORY = r -> {
//   Thread th = new Thread(r);
//   th.setDaemon(true);
//   return th;
// };


// Path: cloud-vmware-server/src/test/java/jetbrains/buildServer/clouds/vmware/stubs/FakeVirtualMachine.java
import com.vmware.vim25.*;
import com.vmware.vim25.mo.*;
import java.rmi.RemoteException;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import jetbrains.buildServer.serverSide.TeamCityProperties;
import org.jetbrains.annotations.NotNull;
import static jetbrains.buildServer.clouds.vmware.stubs.FakeModel.FAKE_MODEL_THREAD_FACTORY;

    newVm.setParentFolder(folder.getName());
    final VirtualMachineConfigInfo oldConfig = newVm.myConfigInfoRef.get();
    newVm.myConfigInfoRef.set(null);
    newVm.myCustomizationSpec = spec.getCustomization();
    final CountDownLatch latch = new CountDownLatch(1);
    new Thread(){
      @Override
      public void run() {
        try {sleep(100);} catch (InterruptedException e) {}
        latch.countDown();
        newVm.myConfigInfoRef.set(oldConfig);

        if (spec.isPowerOn()){
          if (!newVm.myIsStarted.compareAndSet(false, true)){
            //throw new RemoteException("Already started");
          }
        }
      }
    }.start();
    return longTask(latch);
  }

  @Override
  public Task powerOffVM_Task() throws RemoteException {
    FakeModel.instance().publishEvent(getName(), "powerOffVM_Task");
    if (!myIsStarted.get()){
      throw new RemoteException("Already stopped");
    }
    final TaskInfo taskInfo = new TaskInfo();

    final Thread thread = FAKE_MODEL_THREAD_FACTORY.newThread(() -> {