// Path: src/test/java/org/jenkinsci/plugins/mesos/fixture/AgentSpecMother.java
// public class AgentSpecMother {
// 
//   public static final MesosAgentSpecTemplate simple =
//       new MesosAgentSpecTemplate(
//           "label",
//           Mode.EXCLUSIVE,
//           "0.1",
//           "32",
//           1,
//           1,
//           1,
//           "0",
//           "",
//           "",
//           Collections.emptyList(),
//           null,
//           null,
//           null);
// 
//   public static final MesosAgentSpecTemplate docker =
//       new MesosAgentSpecTemplate(
//           "label",
//           Mode.EXCLUSIVE,
//           "0.5",
//           "512",
//           3,
//           1,
//           1,
//           "1",
//           "",
//           "",
//           Collections.emptyList(),
//           new ContainerInfo(
//               "DOCKER",
//               "jeschkies/jenkins-simple-agent:testing",
//               false,
//               false,
//               true,
//               Collections.emptyList(),
//               Network.HOST),
//           null,
//           null);
// }


import static org.awaitility.Awaitility.await;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertThrows;
import akka.actor.ActorSystem;
import akka.stream.ActorMaterializer;
import com.mesosphere.utils.mesos.MesosClusterExtension;
import com.mesosphere.utils.zookeeper.ZookeeperServerExtension;
import hudson.model.Slave;
import hudson.slaves.SlaveComputer;
import java.time.Duration;
import java.util.Collections;
import java.util.concurrent.*;
import jenkins.model.Jenkins;
import org.jenkinsci.plugins.mesos.*;
import org.jenkinsci.plugins.mesos.fixture.AgentSpecMother;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;
    final String name = "jenkins-lifecycle";
    final MesosAgentSpecTemplate spec = AgentSpecMother.simple;
    MesosJenkinsAgent agent = (MesosJenkinsAgent) cloud.startAgent(name, spec).get();
    agent.waitUntilOnlineAsync(materializer).get();

    // verify slave is running when the future completes;
    assertThat(agent.isRunning(), is(true));

    assertThat(Jenkins.getInstanceOrNull().getNodes(), hasSize(1));

    agent.terminate();
    await().atMost(10, TimeUnit.SECONDS).until(agent::isKilled);
    assertThat(agent.isKilled(), is(true));

    assertThat(Jenkins.getInstanceOrNull().getNodes(), hasSize(0));
  }

  @Test
  public void testComputerNodeTermination(TestUtils.JenkinsRule j) throws Exception {
    MesosCloud cloud =
        new MesosCloud(
            mesosCluster.getMesosUrl().toString(),
            "MesosTest",
            null,
            "*",
            System.getProperty("user.name"),
            j.getURL().toString(),
            Collections.emptyList());

    final String name = "jenkins-node-terminate";
// Path: src/test/java/org/jenkinsci/plugins/mesos/fixture/AgentSpecMother.java
// public class AgentSpecMother {
// 
//   public static final MesosAgentSpecTemplate simple =
//       new MesosAgentSpecTemplate(
//           "label",
//           Mode.EXCLUSIVE,
//           "0.1",
//           "32",
//           1,
//           1,
//           1,
//           "0",
//           "",
//           "",
//           Collections.emptyList(),
//           null,
//           null,
//           null);
// 
//   public static final MesosAgentSpecTemplate docker =
//       new MesosAgentSpecTemplate(
//           "label",
//           Mode.EXCLUSIVE,
//           "0.5",
//           "512",
//           3,
//           1,
//           1,
//           "1",
//           "",
//           "",
//           Collections.emptyList(),
//           new ContainerInfo(
//               "DOCKER",
//               "jeschkies/jenkins-simple-agent:testing",
//               false,
//               false,
//               true,
//               Collections.emptyList(),
//               Network.HOST),
//           null,
//           null);
// }


// Path: src/test/java/org/jenkinsci/plugins/mesos/integration/MesosJenkinsAgentLifecycleTest.java
import static org.awaitility.Awaitility.await;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertThrows;
import akka.actor.ActorSystem;
import akka.stream.ActorMaterializer;
import com.mesosphere.utils.mesos.MesosClusterExtension;
import com.mesosphere.utils.zookeeper.ZookeeperServerExtension;
import hudson.model.Slave;
import hudson.slaves.SlaveComputer;
import java.time.Duration;
import java.util.Collections;
import java.util.concurrent.*;
import jenkins.model.Jenkins;
import org.jenkinsci.plugins.mesos.*;
import org.jenkinsci.plugins.mesos.fixture.AgentSpecMother;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;

    final String name = "jenkins-lifecycle";
    final MesosAgentSpecTemplate spec = AgentSpecMother.simple;
    MesosJenkinsAgent agent = (MesosJenkinsAgent) cloud.startAgent(name, spec).get();
    agent.waitUntilOnlineAsync(materializer).get();

    // verify slave is running when the future completes;
    assertThat(agent.isRunning(), is(true));

    assertThat(Jenkins.getInstanceOrNull().getNodes(), hasSize(1));

    agent.terminate();
    await().atMost(10, TimeUnit.SECONDS).until(agent::isKilled);
    assertThat(agent.isKilled(), is(true));

    assertThat(Jenkins.getInstanceOrNull().getNodes(), hasSize(0));
  }

  @Test
  public void testComputerNodeTermination(TestUtils.JenkinsRule j) throws Exception {
    MesosCloud cloud =
        new MesosCloud(
            mesosCluster.getMesosUrl().toString(),
            "MesosTest",
            null,
            "*",
            System.getProperty("user.name"),
            j.getURL().toString(),
            Collections.emptyList());

    final String name = "jenkins-node-terminate";
    final MesosAgentSpecTemplate spec = AgentSpecMother.simple;