Thomas Vachuska | f9c8436 | 2015-04-15 11:20:45 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onlab.stc; |
| 17 | |
HIGUCHI Yuta | d9c6117 | 2016-01-04 23:31:13 -0800 | [diff] [blame] | 18 | import org.junit.AfterClass; |
Thomas Vachuska | f9c8436 | 2015-04-15 11:20:45 -0700 | [diff] [blame] | 19 | import org.junit.BeforeClass; |
| 20 | import org.junit.Test; |
Thomas Vachuska | 0ec6ff4 | 2015-07-17 11:00:02 -0700 | [diff] [blame] | 21 | import org.onlab.util.Tools; |
Thomas Vachuska | f9c8436 | 2015-04-15 11:20:45 -0700 | [diff] [blame] | 22 | |
Thomas Vachuska | f9c8436 | 2015-04-15 11:20:45 -0700 | [diff] [blame] | 23 | import java.io.IOException; |
| 24 | |
| 25 | import static org.onlab.stc.CompilerTest.getStream; |
| 26 | import static org.onlab.stc.Coordinator.print; |
| 27 | import static org.onlab.stc.Scenario.loadScenario; |
| 28 | |
| 29 | /** |
| 30 | * Test of the test coordinator. |
| 31 | */ |
| 32 | public class CoordinatorTest { |
| 33 | |
| 34 | private Coordinator coordinator; |
| 35 | private StepProcessListener listener = new Listener(); |
| 36 | |
| 37 | @BeforeClass |
| 38 | public static void setUpClass() throws IOException { |
| 39 | CompilerTest.setUpClass(); |
Thomas Vachuska | 0ec6ff4 | 2015-07-17 11:00:02 -0700 | [diff] [blame] | 40 | |
Thomas Vachuska | f9c8436 | 2015-04-15 11:20:45 -0700 | [diff] [blame] | 41 | StepProcessor.launcher = "true "; |
| 42 | } |
| 43 | |
HIGUCHI Yuta | d9c6117 | 2016-01-04 23:31:13 -0800 | [diff] [blame] | 44 | @AfterClass |
| 45 | public static void tearDownClass() throws IOException { |
| 46 | CompilerTest.tearDownClass(); |
| 47 | } |
| 48 | |
Thomas Vachuska | f9c8436 | 2015-04-15 11:20:45 -0700 | [diff] [blame] | 49 | @Test |
Thomas Vachuska | 0ec6ff4 | 2015-07-17 11:00:02 -0700 | [diff] [blame] | 50 | public void simple() throws IOException, InterruptedException { |
Thomas Vachuska | f9c8436 | 2015-04-15 11:20:45 -0700 | [diff] [blame] | 51 | executeTest("simple-scenario.xml"); |
| 52 | } |
| 53 | |
| 54 | @Test |
Thomas Vachuska | 0ec6ff4 | 2015-07-17 11:00:02 -0700 | [diff] [blame] | 55 | public void complex() throws IOException, InterruptedException { |
Thomas Vachuska | f9c8436 | 2015-04-15 11:20:45 -0700 | [diff] [blame] | 56 | executeTest("scenario.xml"); |
| 57 | } |
| 58 | |
Thomas Vachuska | 0ec6ff4 | 2015-07-17 11:00:02 -0700 | [diff] [blame] | 59 | private void executeTest(String name) throws IOException, InterruptedException { |
Thomas Vachuska | f9c8436 | 2015-04-15 11:20:45 -0700 | [diff] [blame] | 60 | Scenario scenario = loadScenario(getStream(name)); |
| 61 | Compiler compiler = new Compiler(scenario); |
| 62 | compiler.compile(); |
Thomas Vachuska | 0ec6ff4 | 2015-07-17 11:00:02 -0700 | [diff] [blame] | 63 | Tools.removeDirectory(compiler.logDir()); |
Thomas Vachuska | f9c8436 | 2015-04-15 11:20:45 -0700 | [diff] [blame] | 64 | coordinator = new Coordinator(scenario, compiler.processFlow(), compiler.logDir()); |
| 65 | coordinator.addListener(listener); |
Thomas Vachuska | 50ec1af | 2015-06-02 00:42:52 -0700 | [diff] [blame] | 66 | coordinator.reset(); |
Thomas Vachuska | f9c8436 | 2015-04-15 11:20:45 -0700 | [diff] [blame] | 67 | coordinator.start(); |
| 68 | coordinator.waitFor(); |
| 69 | coordinator.removeListener(listener); |
| 70 | } |
| 71 | |
| 72 | private class Listener implements StepProcessListener { |
| 73 | @Override |
Thomas Vachuska | b51b8bc | 2015-07-27 08:37:12 -0700 | [diff] [blame] | 74 | public void onStart(Step step, String command) { |
| 75 | print("> %s: started; %s", step.name(), command); |
Thomas Vachuska | f9c8436 | 2015-04-15 11:20:45 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | @Override |
Thomas Vachuska | 8643937 | 2015-06-05 09:21:32 -0700 | [diff] [blame] | 79 | public void onCompletion(Step step, Coordinator.Status status) { |
| 80 | print("< %s: %s", step.name(), status == Coordinator.Status.SUCCEEDED ? "completed" : "failed"); |
Thomas Vachuska | f9c8436 | 2015-04-15 11:20:45 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public void onOutput(Step step, String line) { |
| 85 | print(" %s: %s", step.name(), line); |
| 86 | } |
| 87 | } |
| 88 | } |