package org.apache.mesos.logstash.systemtest;

import org.apache.mesos.logstash.scheduler.Scheduler;
import org.apache.mesos.mini.MesosCluster;
import org.apache.mesos.mini.MesosClusterConfig;
import org.junit.ClassRule;
import org.junit.Test;

import java.net.Inet4Address;
import java.net.Socket;

/**
 * Created by peldan on 07/07/15.
 */
public class MessageTest {

    // Creates a destination where we can instruct logstash to forward the logs
//    private Socket createLogstashBackend() {
//        Inet4Address inet4addr = new Inet4Address();
//        return new Socket(inet4addr, rand);
//    }

    @ClassRule
    public static MesosCluster cluster = new MesosCluster(MesosClusterConfig.builder()
            .numberOfSlaves(1)
            .slaveResources(new String[]{"ports(*):[9200-9200,9300-9300]"})
            .dockerInDockerImages(new String[]{"epeld/logstash-executor"}).build());

    @Test
    public void schedulerStarts() throws Exception {

        System.out.println("HELLO WORLD");
        //Scheduler scheduler = new Scheduler(cluster.getMasterUrl(), "epeld/logstash-executor");
        //scheduler.run();

        //
    }

}

@@ -36,24 +36,71 @@
 ystemtest;%0A%0A
+import com.github.dockerjava.api.DockerClient;%0A
 import org.a
@@ -248,23 +248,41 @@
 org.
-junit.ClassRule
+apache.mesos.mini.util.DockerUtil
 ;%0Aim
@@ -300,22 +300,18 @@
 nit.
-Test;%0A
+*;
 %0Aimport 
 java
@@ -310,30 +310,76 @@
 ort 
-java.net.Inet4Address;
+org.junit.rules.ExternalResource;%0Aimport org.junit.rules.RuleChain;%0A
 %0Aimp
@@ -391,18 +391,15 @@
 ava.
-net.Socket
+io.File
 ;%0A%0A/
@@ -475,196 +475,255 @@
     
-// Creates a destination where we can instruct logstash to forward the logs%0A//    private Socket createLogstashBackend() %7B%0A//        Inet4Address inet4addr = new Inet4Address();%0A//
+public static class SmallInnerClass extends ExternalResource %7B%0A        // For usage as JUnit rule...%0A        @Override%0A        protected void before() throws Throwable %7B%0A            DockerUtil utils = new DockerUtil(CONFIG.dockerClient);%0A%0A
         
 retu
@@ -722,67 +722,102 @@
     
-return new Socket(inet4addr, rand);%0A//
+    utils.buildImageFromFolder(new File(%22../executor%22), %22logstash-executor%22);%0A    
     %7D%0A
-%0A
     
-@ClassRule
+%7D%0A
 %0A   
@@ -831,16 +831,22 @@
  static 
+final 
 MesosClu
@@ -853,256 +853,1307 @@
 ster
- cluster = new MesosCluster(MesosClusterConfig.builder()%0A            .numberOfSlaves(1)%0A            .slaveResources(new String%5B%5D%7B%22ports(*):%5B9200-9200,9300-9300%5D%22%7D)%0A            .dockerInDockerImages(new String%5B%5D%7B%22epeld/logstash-executor%22%7D).build());
+Config CONFIG = MesosClusterConfig.builder()%0A            // Note: Logstash-mesos uses container discovery, and mesos-local runs all%0A            // the executors in the same docker host. So it is safest to just use 1 slave for now..%0A            .numberOfSlaves(1)%0A            .slaveResources(new String%5B%5D%7B%22ports(*):%5B9200-9200,9300-9300%5D%22%7D)%0A            .dockerInDockerImages(new String%5B%5D%7B%22logstash-executor%22%7D).build();%0A%0A    public static MesosCluster cluster = new MesosCluster(CONFIG);%0A%0A    @ClassRule%0A    public static RuleChain chain= RuleChain%0A            .outerRule(new SmallInnerClass()).around(cluster);%0A%0A%0A    @BeforeClass%0A    public static void startScheduler() %7B%0A        Thread t = new Thread(new Runnable() %7B%0A            @Override%0A            public void run() %7B%0A                new Scheduler(cluster.getMesosMasterURL(), %22logstash-executor%22).run();%0A            %7D%0A        %7D);%0A        t.setDaemon(true);%0A        t.start();%0A    %7D%0A%0A    @AfterClass%0A    public static void stopScheduler() %7B%0A        // TODO%0A    %7D%0A%0A    @Test%0A    public void schedulerStarts() throws Exception %7B%0A%0A        cluster.getStateInfo();%0A%0A        System.out.println(%22HELLO WORLD%22);%0A        //Scheduler scheduler = new Scheduler(cluster.getMasterUrl(), %22epeld/logstash-executor%22);%0A        //scheduler.run();%0A%0A        //%0A    %7D
 %0A%0A  
@@ -2183,32 +2183,33 @@
  schedulerStarts
+2
 () throws Except
@@ -2207,32 +2207,65 @@
 ws Exception %7B%0A%0A
+        cluster.getStateInfo();%0A%0A
         System.o
@@ -2279,32 +2279,33 @@
 tln(%22HELLO WORLD
+2
 %22);%0A        //Sc

Create test-class that uses mini-mesos to run a scheduler