Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cebf7afe77596f29fda3c77e812250bc0d85901d
[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 import org.simgrid.msg.Process;
11 import org.simgrid.trace.Trace;
12
13 import java.util.ArrayList;
14 import java.util.List;
15 import java.util.Random;
16
17 class Sleeper extends Process {
18         public Sleeper(Host host, String name, String[] args) {
19                 super(host,name,args);
20         }
21         public void main(String[] args) {
22                 while (true) {
23                         Msg.info("I'm not dead");
24                         try {
25                                 Process.sleep(10);
26                         } catch (HostFailureException e) {
27                                 Msg.info("catch HostException: "+e.getLocalizedMessage());
28                                 break; //Break is needed to finalize the endless loop 
29                         }
30                 }
31         }       
32 }
33
34 class TestRunner extends Process {
35
36         public TestRunner(Host host, String name, String[] args) {
37                 super(host,name,args);
38         }
39
40         public void main(String[] strings) throws MsgException {
41                 Host host = Host.all()[1];
42
43
44                 Msg.info("**** **** **** ***** ***** Test Sleep ***** ***** **** **** ****");
45                 Msg.info("Test sleep: Create a process on "+host.getName()+" that simply make periodic sleep, turn off "+host.getName());
46                 new Sleeper(host, "Sleeper", null).start();
47
48                 waitFor(0.02);
49                 Msg.info("Stop "+host.getName());
50                 host.off();
51                 Msg.info(host.getName()+" has been stopped");
52                 waitFor(0.3);
53                 Msg.info("Test sleep seems ok, cool! (number of Process : " + Process.getCount() + ", it should be 1 (i.e. the Test one))");
54         }
55 }
56
57 public class SleepHostOff {
58
59         public static void main(String[] args) throws Exception {
60                 /* Init. internal values */
61                 Msg.init(args);
62
63                 if (args.length < 1) {
64                         Msg.info("Usage: java -cp simgrid.jar:. sleep_host_off.SleepHostOff <platform.xml>");
65                         System.exit(1);
66                 }
67
68                 /* construct the platform and deploy the application */
69                 Msg.createEnvironment(args[0]);
70
71                 Host[] hosts = Host.all();
72                 new TestRunner(hosts[0], "TestRunner", null).start();
73
74                 Msg.run();
75         }
76 }