Пример #1
0
 protected List<Container> listContainers(final DockerClient dockerClient, final String needle)
     throws DockerException, InterruptedException {
   final List<Container> containers = dockerClient.listContainers();
   final List<Container> matches = Lists.newArrayList();
   for (final Container container : containers) {
     if (container.names() != null) {
       for (final String name : container.names()) {
         if (name.contains(needle)) {
           matches.add(container);
           break;
         }
       }
     }
   }
   return matches;
 }
Пример #2
0
  @After
  public void baseTeardown() throws Exception {
    for (final HeliosClient client : clients) {
      client.close();
    }
    clients.clear();

    for (Service service : services) {
      try {
        service.stopAsync();
      } catch (Exception e) {
        log.error("Uncaught exception", e);
      }
    }
    for (Service service : services) {
      try {
        service.awaitTerminated();
      } catch (Exception e) {
        log.error("Service failed", e);
      }
    }
    services.clear();

    // Clean up docker
    try (final DockerClient dockerClient = getNewDockerClient()) {
      final List<Container> containers = dockerClient.listContainers();
      for (final Container container : containers) {
        for (final String name : container.names()) {
          if (name.contains(testTag)) {
            try {
              dockerClient.killContainer(container.id());
            } catch (DockerException e) {
              e.printStackTrace();
            }
            break;
          }
        }
      }
    } catch (Exception e) {
      log.error("Docker client exception", e);
    }

    if (zk != null) {
      zk.close();
    }

    listThreads();
  }