Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
adapt these tests to the fact that the hosts are now multicores
[simgrid.git] / examples / java / energy / vm / EnergyVMRunner.java
1 /* Copyright (c) 2016. 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 energy.vm;
7
8 import org.simgrid.msg.Host;
9 import org.simgrid.msg.HostFailureException;
10 import org.simgrid.msg.HostNotFoundException;
11 import org.simgrid.msg.Msg;
12 import org.simgrid.msg.Process;
13 import org.simgrid.msg.Task;
14 import org.simgrid.msg.TaskCancelledException;
15 import org.simgrid.msg.VM;
16
17 /* This class is a process in charge of running the test. It creates and starts the VMs, and fork processes within VMs */
18 public class EnergyVMRunner extends Process {
19
20   public class DummyProcess extends Process {
21     public  DummyProcess (Host host, String name) {
22       super(host, name); 
23     }
24
25     @Override
26     public void main(String[] strings) {
27       Task  task = new Task(this.getHost().getName()+"-task", 300E6 , 0);
28       try {
29         task.execute();
30       } catch (HostFailureException | TaskCancelledException e) {
31         Msg.error(e.getMessage());
32         e.printStackTrace();
33       } 
34       Msg.info("This worker is done."); 
35     }
36   }
37
38   EnergyVMRunner(Host host, String name, String[] args) throws HostNotFoundException {
39     super(host, name, args);
40   }
41
42   @Override
43   public void main(String[] strings) throws HostNotFoundException, HostFailureException {
44     /* get hosts */
45     Host host1 = Host.getByName("MyHost1");
46     Host host2 = Host.getByName("MyHost2");
47     Host host3 = Host.getByName("MyHost3");
48
49     Msg.info("Creating and starting two VMs");
50     VM vmHost1 = new VM(host1, "vmHost1", 2048, 10, 50);
51     vmHost1.start();
52
53     VM vmHost2 = new VM(host2, "vmHost3", 2048, 10, 50);
54     vmHost2.start();
55
56     Msg.info("Create two tasks on Host1: one inside a VM, the other directly on the host");
57     new DummyProcess (vmHost1, "p11").start(); 
58     new DummyProcess (vmHost1, "p12").start(); 
59
60     Msg.info("Create two tasks on Host2: both directly on the host");
61     new DummyProcess (vmHost2, "p21").start(); 
62     new DummyProcess (host2, "p22").start(); 
63
64     Msg.info("Create two tasks on Host3: both inside a VM");
65     new DummyProcess (host3, "p31").start(); 
66     new DummyProcess (host3, "p312").start(); 
67
68     Msg.info("Wait 5 seconds. The tasks are still running (they run for 3 seconds, but 2 tasks are co-located, "
69              + "so they run for 6 seconds)"); 
70     waitFor(5); 
71     Msg.info("Wait another 5 seconds. The tasks stop at some point in between"); 
72     waitFor(5); 
73
74     vmHost1.destroy(); 
75     vmHost2.destroy(); 
76   }
77 }