Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix leak of memory caused to some Events
[simgrid.git] / teshsuite / java / SleepHostOff / 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 SleepHostOff;
8
9 import org.simgrid.msg.*;
10 import org.simgrid.msg.Process;
11
12 class Sleeper extends Process {
13   public Sleeper(Host host, String name, String[] args) {
14     super(host,name,args);
15   }
16   public void main(String[] args) {
17     boolean stillAlive = true;
18     while (stillAlive) {
19       Msg.info("I'm not dead");
20       try {
21         Process.sleep(10);
22         stillAlive = true;
23       } catch (HostFailureException e) {
24         stillAlive = false;
25         Msg.info("catch HostException: "+e.getLocalizedMessage());
26       }
27     }
28   }
29 }
30
31 class TestRunner extends Process {
32   public TestRunner(Host host, String name, String[] args) {
33     super(host,name,args);
34   }
35
36   public void main(String[] strings) throws MsgException {
37     Host host = Host.getByName("Tremblay");
38
39     Msg.info("**** **** **** ***** ***** Test Sleep ***** ***** **** **** ****");
40     Msg.info("Test sleep: Create a process on "+host.getName()+" that simply make periodic sleep, turn off "
41              +host.getName());
42     new Sleeper(host, "Sleeper", null).start();
43
44     waitFor(0.02);
45     Msg.info("Stop "+host.getName());
46     host.off();
47     Msg.info(host.getName()+" has been stopped");
48     waitFor(0.3);
49     Msg.info("Test sleep seems ok, cool! (number of Process : " + Process.getCount() 
50              + ", it should be 1 (i.e. the Test one))");
51   }
52 }
53
54 public class SleepHostOff {
55   public static void main(String[] args) throws Exception {
56     Msg.init(args);
57
58     if (args.length < 1) {
59       Msg.info("Usage: java -cp simgrid.jar:. sleep_host_off.SleepHostOff <platform.xml>");
60       System.exit(1);
61     }
62
63     Msg.createEnvironment(args[0]);
64
65     new TestRunner(Host.getByName("Fafard"), "TestRunner", null).start();
66
67     Msg.run();
68   }
69 }