2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.openflowplugin.openflow.md.it;
10 import java.util.concurrent.ExecutionException;
11 import java.util.concurrent.ThreadPoolExecutor;
12 import java.util.concurrent.TimeUnit;
13 import java.util.concurrent.TimeoutException;
15 import org.junit.Assert;
16 import org.opendaylight.openflowjava.protocol.impl.clients.SimpleClient;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
23 public abstract class SimulatorAssistant {
25 private static final Logger LOG = LoggerFactory
26 .getLogger(SimulatorAssistant.class);
30 * @throws InterruptedException
32 public static void waitForSwitchSimulatorOn(SimpleClient switchSim) {
34 switchSim.getIsOnlineFuture().get(6, TimeUnit.SECONDS); // intentionally ignoring future inner value
35 } catch (TimeoutException | ExecutionException | InterruptedException e) {
36 LOG.error("failed to start switch simulator: {}", e.getMessage(), e);
37 Assert.fail("failed to start switch simulator");
44 * @param failsafeTimeout
46 public static void tearDownSwitchSimulatorAfterScenario(SimpleClient switchSim, ThreadPoolExecutor scenarioPool, long failsafeTimeout) {
48 LOG.debug("tearing down simulator");
49 switchSim.getScenarioDone().get(failsafeTimeout, TimeUnit.MILLISECONDS);
50 } catch (Exception e) {
51 String msg = "waiting for scenario to finish failed: "+e.getMessage();
55 scenarioPool.shutdownNow();
60 LOG.debug("checking if simulator succeeded to connect to controller");
61 boolean simulatorWasOnline = switchSim.getIsOnlineFuture().get(100, TimeUnit.MILLISECONDS);
62 Assert.assertTrue("simulator failed to connect to controller", simulatorWasOnline);
63 } catch (Exception e) {
64 String message = "simulator probably failed to connect to controller";
65 LOG.error(message, e);