Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
a few more cosmetics
[simgrid.git] / teshsuite / java / sleep_host_off / SleepHostOff.java
1 /* Copyright (c) 2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 package sleep_host_off;
8
9 import org.simgrid.msg.*;
10
11 class Sleeper extends Process {
12   public Sleeper(Host host, String name, String[] args) {
13     super(host,name,args);
14   }
15   public void main(String[] args) {
16     while (true) {
17       Msg.info("I'm not dead");
18       try {
19         Process.sleep(10);
20       } catch (HostFailureException e) {
21         Msg.info("catch HostException: "+e.getLocalizedMessage());
22         break; //Break is needed to finalize the endless loop 
23       }
24     }
25   }
26 }
27
28 class TestRunner extends Process {
29   public TestRunner(Host host, String name, String[] args) {
30     super(host,name,args);
31   }
32
33   public void main(String[] strings) throws MsgException {
34     Host host = Host.all()[1];
35
36     Msg.info("**** **** **** ***** ***** Test Sleep ***** ***** **** **** ****");
37     Msg.info("Test sleep: Create a process on "+host.getName()+" that simply make periodic sleep, turn off "
38              +host.getName());
39     new Sleeper(host, "Sleeper", null).start();
40
41     waitFor(0.02);
42     Msg.info("Stop "+host.getName());
43     host.off();
44     Msg.info(host.getName()+" has been stopped");
45     waitFor(0.3);
46     Msg.info("Test sleep seems ok, cool! (number of Process : " + Process.getCount() 
47              + ", it should be 1 (i.e. the Test one))");
48   }
49 }
50
51 public class SleepHostOff {
52   public static void main(String[] args) throws Exception {
53     Msg.init(args);
54
55     if (args.length < 1) {
56       Msg.info("Usage: java -cp simgrid.jar:. sleep_host_off.SleepHostOff <platform.xml>");
57       System.exit(1);
58     }
59
60     Msg.createEnvironment(args[0]);
61
62     Host[] hosts = Host.all();
63     new TestRunner(hosts[0], "TestRunner", null).start();
64
65     Msg.run();
66   }
67 }