blob: 1e5580a9600cd38d54e372cc1b024d8446d0edab [file] [log] [blame]
Thomas Vachuskaf9c84362015-04-15 11:20:45 -07001/*
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 */
16package org.onlab.stc;
17
HIGUCHI Yutad9c61172016-01-04 23:31:13 -080018import org.junit.AfterClass;
Thomas Vachuskaf9c84362015-04-15 11:20:45 -070019import org.junit.BeforeClass;
20import org.junit.Test;
Thomas Vachuska0ec6ff42015-07-17 11:00:02 -070021import org.onlab.util.Tools;
Thomas Vachuskaf9c84362015-04-15 11:20:45 -070022
Thomas Vachuskaf9c84362015-04-15 11:20:45 -070023import java.io.IOException;
24
25import static org.onlab.stc.CompilerTest.getStream;
26import static org.onlab.stc.Coordinator.print;
27import static org.onlab.stc.Scenario.loadScenario;
28
29/**
30 * Test of the test coordinator.
31 */
32public 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 Vachuska0ec6ff42015-07-17 11:00:02 -070040
Thomas Vachuskaf9c84362015-04-15 11:20:45 -070041 StepProcessor.launcher = "true ";
42 }
43
HIGUCHI Yutad9c61172016-01-04 23:31:13 -080044 @AfterClass
45 public static void tearDownClass() throws IOException {
46 CompilerTest.tearDownClass();
47 }
48
Thomas Vachuskaf9c84362015-04-15 11:20:45 -070049 @Test
Thomas Vachuska0ec6ff42015-07-17 11:00:02 -070050 public void simple() throws IOException, InterruptedException {
Thomas Vachuskaf9c84362015-04-15 11:20:45 -070051 executeTest("simple-scenario.xml");
52 }
53
54 @Test
Thomas Vachuska0ec6ff42015-07-17 11:00:02 -070055 public void complex() throws IOException, InterruptedException {
Thomas Vachuskaf9c84362015-04-15 11:20:45 -070056 executeTest("scenario.xml");
57 }
58
Thomas Vachuska0ec6ff42015-07-17 11:00:02 -070059 private void executeTest(String name) throws IOException, InterruptedException {
Thomas Vachuskaf9c84362015-04-15 11:20:45 -070060 Scenario scenario = loadScenario(getStream(name));
61 Compiler compiler = new Compiler(scenario);
62 compiler.compile();
Thomas Vachuska0ec6ff42015-07-17 11:00:02 -070063 Tools.removeDirectory(compiler.logDir());
Thomas Vachuskaf9c84362015-04-15 11:20:45 -070064 coordinator = new Coordinator(scenario, compiler.processFlow(), compiler.logDir());
65 coordinator.addListener(listener);
Thomas Vachuska50ec1af2015-06-02 00:42:52 -070066 coordinator.reset();
Thomas Vachuskaf9c84362015-04-15 11:20:45 -070067 coordinator.start();
68 coordinator.waitFor();
69 coordinator.removeListener(listener);
70 }
71
72 private class Listener implements StepProcessListener {
73 @Override
Thomas Vachuskab51b8bc2015-07-27 08:37:12 -070074 public void onStart(Step step, String command) {
75 print("> %s: started; %s", step.name(), command);
Thomas Vachuskaf9c84362015-04-15 11:20:45 -070076 }
77
78 @Override
Thomas Vachuska86439372015-06-05 09:21:32 -070079 public void onCompletion(Step step, Coordinator.Status status) {
80 print("< %s: %s", step.name(), status == Coordinator.Status.SUCCEEDED ? "completed" : "failed");
Thomas Vachuskaf9c84362015-04-15 11:20:45 -070081 }
82
83 @Override
84 public void onOutput(Step step, String line) {
85 print(" %s: %s", step.name(), line);
86 }
87 }
88}