package org.apache.hadoop.tools.posum.test;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.tools.posum.common.util.PosumConfiguration;
import org.apache.hadoop.tools.posum.data.master.DataMasterContext;
import org.apache.hadoop.tools.posum.data.monitor.cluster.ClusterMonitor;
import org.apache.hadoop.tools.posum.data.core.DataStoreImpl;
import org.junit.Ignore;
import org.junit.Test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class ManualTests {
    @Test
    @Ignore
    public void checkRegistration() {
        System.out.println(NetUtils.createSocketAddr("0.0.0.0", 7000));
    }

    @Test
    @Ignore
    public void testMongoRunner() throws IOException, InterruptedException {
        String scriptLocation = getClass().getClassLoader().getResource("run-mongo.sh").getFile();
        Process process = Runtime.getRuntime().exec("/bin/bash " + scriptLocation);
        process.waitFor();
        if (process.exitValue() != 0) {
            System.out.println("Error running Mongo database:");
            String s;
            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            while ((s = reader.readLine()) != null)
                System.out.println(s);
            reader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
            while ((s = reader.readLine()) != null)
                System.out.println(s);
            throw new RuntimeException("Could not run MongoDB");
        }
    }

    @Test
    @Ignore
    public void testMongoStopper() throws IOException, InterruptedException {
        String scriptLocation = getClass().getClassLoader().getResource("run-mongo.sh").getFile();
        Process process = Runtime.getRuntime().exec("/bin/bash " + scriptLocation + " --stop");
        process.waitFor();
        if (process.exitValue() != 0) {
            System.out.println("Error stopping Mongo database:");
            String s;
            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            while ((s = reader.readLine()) != null)
                System.out.println(s);
            reader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
            while ((s = reader.readLine()) != null)
                System.out.println(s);
            throw new RuntimeException("Could not stop MongoDB");
        }
    }

//    @Test
//    @Ignore
//    public void testHadoopAPIClient() {
//        HadoopAPIClient apiClient = new HadoopAPIClient();
//        List<AppProfile> apps = apiClient.getAppsInfo();
//        System.out.println(apps);
//        for (AppProfile app : apps) {
//            if (RestClient.TrackingUI.AM.equals(app.getTrackingUI())) {
//                System.out.println("For job: " + app.getId());
//                Map<String, String> requested = new HashMap<>(2);
//                requested.put("mapreduce.input.fileinputformat.inputdir", "inputdir");
//                requested.put("mapreduce.input.fileinputformat.numinputfiles", "numinputfiles");
//                Map<String, String> properties = apiClient.getJobConfProperties(app.getId(), app.getId(), requested);
//                System.out.println("Input dir is: " + properties.get("inputdir"));
//                System.out.println("Input files are: " + properties.get("numinputfiles"));
//            }
//        }
//    }

    @Test
    @Ignore
    public void checkDatabaseFeeding() {
        Configuration conf = PosumConfiguration.newInstance();
        DataStoreImpl dataStore = new DataStoreImpl(conf);
        DataMasterContext context = new DataMasterContext();
        context.setDataStore(dataStore);
        ClusterMonitor monitor = new ClusterMonitor(context);
        monitor.start();
        try {
            Thread.sleep(100000);
            monitor.stop();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}

@@ -183,32 +183,94 @@
 mConfiguration;%0A
+import org.apache.hadoop.tools.posum.data.core.DataStoreImpl;%0A
 import org.apach
@@ -410,3160 +410,205 @@
 org.
-apache.hadoop.tools.posum.data.core.DataStoreImpl;%0Aimport org.junit.Ignore;%0Aimport org.junit.Test;%0A%0Aimport java.io.BufferedReader;%0Aimport java.io.IOException;%0Aimport java.io.InputStreamReader;%0A%0Apublic class ManualTests %7B%0A    @Test%0A    @Ignore%0A    public void checkRegistration() %7B%0A        System.out.println(NetUtils.createSocketAddr(%220.0.0.0%22, 7000));%0A    %7D%0A%0A    @Test%0A    @Ignore%0A    public void testMongoRunner() throws IOException, InterruptedException %7B%0A        String scriptLocation = getClass().getClassLoader().getResource(%22run-mongo.sh%22).getFile();%0A        Process process = Runtime.getRuntime().exec(%22/bin/bash %22 + scriptLocation);%0A        process.waitFor();%0A        if (process.exitValue() != 0) %7B%0A            System.out.println(%22Error running Mongo database:%22);%0A            String s;%0A            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));%0A            while ((s = reader.readLine()) != null)%0A                System.out.println(s);%0A            reader = new BufferedReader(new InputStreamReader(process.getErrorStream()));%0A            while ((s = reader.readLine()) != null)%0A                System.out.println(s);%0A            throw new RuntimeException(%22Could not run MongoDB%22);%0A        %7D%0A    %7D%0A%0A    @Test%0A    @Ignore%0A    public void testMongoStopper() throws IOException, InterruptedException %7B%0A        String scriptLocation = getClass().getClassLoader().getResource(%22run-mongo.sh%22).getFile();%0A        Process process = Runtime.getRuntime().exec(%22/bin/bash %22 + scriptLocation + %22 --stop%22);%0A        process.waitFor();%0A        if (process.exitValue() != 0) %7B%0A            System.out.println(%22Error stopping Mongo database:%22);%0A            String s;%0A            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));%0A            while ((s = reader.readLine()) != null)%0A                System.out.println(s);%0A            reader = new BufferedReader(new InputStreamReader(process.getErrorStream()));%0A            while ((s = reader.readLine()) != null)%0A                System.out.println(s);%0A            throw new RuntimeException(%22Could not stop MongoDB%22);%0A        %7D%0A    %7D%0A%0A//    @Test%0A//    @Ignore%0A//    public void testHadoopAPIClient() %7B%0A//        HadoopAPIClient apiClient = new HadoopAPIClient();%0A//        List%3CAppProfile%3E apps = apiClient.getAppsInfo();%0A//        System.out.println(apps);%0A//        for (AppProfile app : apps) %7B%0A//            if (RestClient.TrackingUI.AM.equals(app.getTrackingUI())) %7B%0A//                System.out.println(%22For job: %22 + app.getId());%0A//                Map%3CString, String%3E requested = new HashMap%3C%3E(2);%0A//                requested.put(%22mapreduce.input.fileinputformat.inputdir%22, %22inputdir%22);%0A//                requested.put(%22mapreduce.input.fileinputformat.numinputfiles%22, %22numinputfiles%22);%0A//                Map%3CString, String%3E properties = apiClient.getJobConfProperties(app.getId(), app.getId(), requested);%0A//                System.out.println(%22Input dir is: %22 + properties.get(%22inputdir%22));%0A//                System.out.println(%22Input files are: %22 + properties.get(%22numinputfiles%22));%0A//            %7D%0A//        %7D%0A//
+junit.Ignore;%0Aimport org.junit.Test;%0A%0Apublic class ManualTests %7B%0A    @Test%0A    @Ignore%0A    public void checkRegistration() %7B%0A        System.out.println(NetUtils.createSocketAddr(%220.0.0.0%22, 7000));%0A
     

remove old manual tests