Logo AND Algorithmique Numérique Distribuée

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