Java Process - Too short lifetime of the process. (Less than 1s...) -


problem:

this.proc.isalive in function make_test return false... don't know why... waits user command... (in case of console)

external program: -> l10_z1_external_test

target: process should life...

l10_z1__test__core.java

package bst_test;  import java.io.ioexception;  public class l10_z1__test__core {     public static void main(string[] args) {         // build proccess         processbuilder pr_1 = new processbuilder("java", "-jar", "../bst.jar");         try {             process proc = pr_1.start();             l10_z1__test__c_tester test_engine = new l10_z1__test__c_tester(                     proc);             string[] cmd;             string[] result;             cmd = new string[] { "add", "remove" };             result = new string[] { "sucess (add) | ", "sucess (remove) | ",                     "sucess (add) | ", "sucess (remove) | ",                     "sucess (add) - duplicate | ",                     "error (remove) - not found | ",                     "error (parse) - invalid integer or overflow | ",                     "error (remove) - not found | ", "sucess (add) | ",                     "sucess (remove) | ", "sucess (add) | ",                     "sucess (remove) | ", "sucess (add) | ",                     "sucess (remove) | ", "sucess (add) | ",                     "sucess (remove) | ", "sucess (add) | ",                     "sucess (remove) | ", "sucess (add) | ",                     "sucess (remove) | ",                     "error (parse) - invalid integer or overflow | ",                     "error (remove) - not found | " };             test_engine.make_test("add & search",                     "this test check - how work add & remove", cmd, result,                     new string[] { "-3", "4", "-3", "aa", "12", "5", "12", "7",                             "-12", "-50", "-999999999" });              // stop test;             test_engine.stop();         } catch (ioexception ex) {             system.out.println("error - problem init | java -jar "                     + "../bst.jar");         }     } } 

l10_z1__test__c_tester.java

package bst_test;  import java.io.bufferedreader; import java.io.bufferedwriter; import java.io.ioexception; import java.io.inputstreamreader; import java.io.outputstreamwriter;  public class l10_z1__test__c_tester{      private boolean is_run; /** information victim of test ;) */     private process pr_proc; /** victim process */      private bufferedreader processout;     private bufferedwriter processin;      /**      * default construtor invoke test subject.      * @prog_name {string} name of test_subject (program name: eg. closure.java)      */     l10_z1__test__c_tester (process in){         this.is_run = false;         this.pr_proc = in;         if(this.pr_proc.isalive()){             this.processout = new bufferedreader(new inputstreamreader(this.pr_proc.getinputstream()));             this.processin = new bufferedwriter(new outputstreamwriter(this.pr_proc.getoutputstream()));             this.is_run = true;         }     }       /**      * method create test , invoke. while test runing -> program send cmd process, result , validate it. (for multi arguments      * @param name {string} name of test      * @param desc {string} description of test      * @param cmd {string[]} commands sent program.      * @param c_res {string[]} correct output.      * @param data  {string[]} test data.      */     public void make_test(string name, string desc, string[] cmd, string[] c_res, string[] data){         if(this.is_run && this.pr_proc.isalive()){             system.out.println("/********************** [" + name + "] - #start **********************/");             system.out.println("desc: " + desc);             int j;             string out;             for(int = 1; <= data.length; i++){                 system.out.println("\n\nloop - " + i);                 for(j = 1; j <= cmd.length && this.pr_proc.isalive(); j++){                     try {                         system.out.println("in: - " + cmd[(j - 1)] + " " + data[(i - 1)]);                         this.processin.write(cmd[(j - 1)] + " " + data[(i - 1)]);                         this.processin.flush();                         out = this.processout.readline();                         system.out.println("out: - " + out +                                        "----------------------------------" +                                        "status: - " + this.check(out, c_res[(i - 1) * (j - 1)] + data[(i - 1)]));                     } catch (ioexception ex) {                         system.out.println("error - problem reader/writte buffer");                     }                 }             }             system.out.println("/********************** [" + name + "] - #end **********************/");         }     }     /**      * method create test , invoke. while test runing -> program send cmd process, result , validate it. (for 1 argument)      * @param name {string} name of test      * @param desc {string} description of test      * @param cmd {string[]} commands sent program.      * @param c_res {string[]} correct output.      */     public void make_test(string name, string desc, string[] cmd, string[] c_res){         if(this.is_run){             system.out.println("/********************** [" + name + "] - #start **********************/");             system.out.println("desc: " + desc);             int count = cmd.length;             string out;             for(int = 0; < count; i++){                 system.out.println("\n\nloop - " + i);                 try {                     system.out.println("in: - " + cmd[i]);                     this.processin.write(cmd[i]);                     out = this.processout.readline();                     system.out.println("out: - " + out +                                    "----------------------------------" +                                    "status: - " + this.check(out, c_res[i]));                     this.processin.flush();                 } catch (ioexception ex) {                     system.out.println("error - problem reader/writte buffer");                 }             }             system.out.println("/********************** [" + name + "] - #end **********************/");         }     }      /**      * function validate output test subject      * @param out {string} out compare cp      * @param cp {string} correct template      * @return {string} status of test.      */     public string check(string out, string cp){         if(out.equals(cp))             return "ok";         else             return "fail";     }      /**      * stop operation -> stop process, close buffer...      */     public void stop(){         if(this.is_run && this.pr_proc.isalive() ){             try {                 this.processin.close();                 this.processout.close();             } catch (ioexception ex) {                 system.out.println("error - problem closing i/o buffers");             }             this.pr_proc.destroy();         }     } } 

l10_z1_external_test.java

package bst;  import java.io.bufferedreader; import java.io.ioexception; import java.io.inputstreamreader;   public class l10_z1_external_test {       private l10_z1__bst bst;      /**      * default constructor l_10_z1__bst init;      */     l10_z1_external_test()     {         this.bst = new l10_z1__bst();     }      /**      * class nitialize, line reader , controler.      */     public void init()     {         bufferedreader br = new bufferedreader(new inputstreamreader(system.in));         string s = null;          try {             while((s = br.readline()) != null && !s.equals("quit"))             {                 this.switch_f(s.split(" "));             }         } catch (ioexception ex) {             system.out.println("error - unknow i/o problem.");         }           system.out.println("bye");      }      /**      * method procces user request bst - tree functions or specyfied errors      * @param in {string} - request, string format (<command> <number>)      */     public void switch_f(string[] in)     {          string text = null, error_text = "error - unknow command";           if(in.length == 2)         {              int number = 0;             boolean op_status = true;              try             {                 number = integer.parseint(in[1]);             }             catch (numberformatexception e)             {                 op_status = false;                 system.out.println("error (parse) - invalid integer or overflow | " + in[1]);             }              if(op_status)                 if( in[0].equals("add"))                 {                     text = "add";                      try {                         this.bst.add(number);                         system.out.println("sucess (" + text + ") | " + number);                     } catch (l10_z1__bst_exception ex) {                         system.out.println("error (" + text + ") - " + ex.getmessage() + " | " + number);                     }                 }                 else if( in[0].equals("remove"))                 {                     text = "remove";                      try {                         this.bst.remove(number);                         system.out.println("sucess (" + text + ") | " + number);                     } catch (l10_z1__bst_exception ex) {                         system.out.println("error (" + text + ") - " + ex.getmessage() + " | " + number);                     }                 }                 else if( in[0].equals("search"))                 {                     text = "search";                      if(this.bst.search(number))                         system.out.println("sucess (" + text + ") | " + number);                     else                         system.out.println("error (" + text + ") - | " + number);                 }                 else                     system.out.println(error_text);          }         else if(in.length == 1)             if( in[0].equals("list"))             {                 text = "list";                  try {                        this.bst.print_list(this.bst.list_in_order());                 } catch (l10_z1__bst_exception ex) {                     system.out.println("error (" + text + ") - " + ex.getmessage());                 }             }             else                 system.out.println(error_text);         else             system.out.println(error_text);      }     } 

are checking process started using process monitor? isolate problem going through series of steps:

  1. make sure simple command create starting processbuilder process spawns process in operating system. if not, perhaps there problem related concurrency or command syntax.
  2. if able start process, start 1 can see not terminating in process monitor , call isalive on process. if can true returned that, should @ architecture of testing framework make sure working intended.

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -