@BeforeClass
  public static void setup() throws Exception {
    registry = Registry.getNewInstanceForTestOnly();
    hub = Hub.getNewInstanceForTest(PortProber.findFreePort(), registry);

    status = new URL("http://" + hub.getHost() + ":" + hub.getPort() + "/grid/status");
    host = new HttpHost(hub.getHost(), hub.getPort());

    hub.start();

    p1 = RemoteProxyFactory.getNewBasicRemoteProxy("app1", "http://machine1:4444/");
    p2 = RemoteProxyFactory.getNewBasicRemoteProxy("app1", "http://machine2:4444/");
    p3 = RemoteProxyFactory.getNewBasicRemoteProxy("app1", "http://machine3:4444/");
    p4 = RemoteProxyFactory.getNewBasicRemoteProxy("app1", "http://machine4:4444/");

    RegistrationRequest req = new RegistrationRequest();
    Map<String, Object> capability = new HashMap<String, Object>();
    capability.put("applicationName", "custom app");
    req.addDesiredCapabilitiy(capability);

    Map<String, Object> config = new HashMap<String, Object>();
    config.put("url", "http://machine5:4444/");
    req.setConfiguration(config);
    customProxy = new MyCustomProxy(req);

    registry.add(p1);
    registry.add(p2);
    registry.add(p3);
    registry.add(p4);
    registry.add(customProxy);
  }
Beispiel #2
0
 @Override
 public void launch(String[] args, Logger log) throws Exception {
   log.info("Launching a Selenium Grid node");
   RegistrationRequest c = RegistrationRequest.build(args);
   SelfRegisteringRemote remote = new SelfRegisteringRemote(c);
   remote.setRemoteServer(new SeleniumServer(c.getConfiguration()));
   remote.startRemoteServer();
   log.info("Selenium Grid node is up and ready to register to the hub");
   remote.startRegistrationProcess();
 }
  @Test(expected = IllegalArgumentException.class)
  public void invalidNodePollingValue() {
    Map<String, Object> config = new HashMap<String, Object>();
    config.put(ID, "abc");
    config.put(RegistrationRequest.NODE_POLLING, "abc");

    RegistrationRequest req = new RegistrationRequest();
    req.setConfiguration(config);

    new DefaultRemoteProxy(req, Registry.newInstance());
  }
  public DefaultRemoteProxy(RegistrationRequest request, Registry registry) {
    super(request, registry);

    pollingInterval =
        request.getConfigAsInt(RegistrationRequest.NODE_POLLING, DEFAULT_POLLING_INTERVAL);
    unregisterDelay =
        request.getConfigAsInt(
            RegistrationRequest.UNREGISTER_IF_STILL_DOWN_AFTER, DEFAULT_UNREGISTER_DELAY);
    downPollingLimit =
        request.getConfigAsInt(RegistrationRequest.DOWN_POLLING_LIMIT, DEFAULT_DOWN_POLLING_LIMIT);
  }
  @Test(expected = IllegalArgumentException.class)
  public void invalidUnregisterIfStillDownValue() {
    Map<String, Object> config = new HashMap<String, Object>();
    config.put(ID, "abc");
    config.put(RegistrationRequest.NODE_POLLING, 100);
    config.put(RegistrationRequest.UNREGISTER_IF_STILL_DOWN_AFTER, "abc");

    RegistrationRequest req = new RegistrationRequest();
    req.setConfiguration(config);

    new DefaultRemoteProxy(req, Registry.newInstance());
  }
  @Test(expected = InvalidParameterException.class)
  public void notExtendingProxyExisting() {
    Map<String, Object> app1 = new HashMap<>();
    GridNodeConfiguration config = new GridNodeConfiguration();
    app1.put(CapabilityType.APPLICATION_NAME, "app1");
    config.proxy = "java.lang.String";

    RegistrationRequest req = new RegistrationRequest();
    req.addDesiredCapability(app1);
    req.setConfiguration(config);

    BaseRemoteProxy.getNewInstance(req, registry);
  }
  // when some mandatory param are missing -> InvalidParameterException
  @Test(expected = InvalidParameterException.class)
  public void badConfig() {
    Map<String, Object> app1 = new HashMap<>();
    GridNodeConfiguration config = new GridNodeConfiguration();
    app1.put(CapabilityType.APPLICATION_NAME, "app1");
    config.proxy = "I Don't exist";

    RegistrationRequest req = new RegistrationRequest();
    req.addDesiredCapability(app1);
    req.setConfiguration(config);

    // requires Custom1 & Custom1 set in config to work.
    BaseRemoteProxy.getNewInstance(req, registry);
  }
  @Test
  public void proxyTimeout() throws InterruptedException {
    Registry registry = Registry.newInstance();
    registry.getConfiguration().getAllParams().put(RegistrationRequest.TIME_OUT, 1);
    RegistrationRequest req = RegistrationRequest.build("-role", "webdriver", "-A", "valueA");
    req.getConfiguration().put(ID, "abc");
    req.getConfiguration().put(RegistrationRequest.PROXY_CLASS, DefaultRemoteProxy.class.getName());

    BaseRemoteProxy p = BaseRemoteProxy.getNewInstance(req, registry);
    TestSession newSession = p.getNewSession(new HashMap<String, Object>());
    assertNotNull(newSession);
    Thread.sleep(2);
    p.forceSlotCleanerRun();
    assertTrue(p.getRegistry().getActiveSessions().isEmpty());
  }
  @BeforeClass
  public static void setup() {
    registry = Registry.getNewInstanceForTestOnly();
    // A request that will create a proxy with 5 slots. Each slot can host a
    // firefox.
    Map<String, Object> config = new HashMap<String, Object>();
    ff.put(APP, "firefox");
    ff.put(MAX_INSTANCES, 5);
    request.addDesiredCapabilitiy(ff);

    config.put(MAX_SESSION, 5);

    // add 5 proxies. Total = 5 proxies * 5 slots each = 25 firefox.
    for (int i = 0; i < 5; i++) {
      config.put(REMOTE_URL, "http://machine" + i + ":4444");
      request.setConfiguration(config);
      registry.add(new RemoteProxy(request));
    }
  }
  // because this method is called asynchronously and no one waits for the completion,
  // exception needs to be reported explicitly.
  public Void call() throws Exception {
    try {
      RegistrationRequest c = RegistrationRequest.build(args);
      for (DesiredCapabilities dc : c.getCapabilities()) {
        JenkinsCapabilityMatcher.enhanceCapabilities(dc, nodeName);
      }
      SelfRegisteringRemote remote = new SelfRegisteringRemote(c);
      PropertyUtils.setProperty(SeleniumConstants.PROPERTY_INSTANCE, remote);
      remote.startRemoteServer();
      remote.startRegistrationProcess();

      Channel.current().waitForProperty(SeleniumConstants.PROPERTY_LOCK);
      return null;
    } catch (Exception e) {
      e.printStackTrace();
      throw e;
    } catch (Error e) {
      e.printStackTrace();
      throw e;
    }
  }
  @Test
  public void existing() {
    Map<String, Object> app1 = new HashMap<>();
    GridNodeConfiguration config = new GridNodeConfiguration();
    app1.put(CapabilityType.APPLICATION_NAME, "app1");
    config.proxy = "org.openqa.grid.plugin.MyRemoteProxy";

    config.custom.put("Custom1", "A");
    config.custom.put("Custom2", "B");

    RegistrationRequest req = new RegistrationRequest();
    req.addDesiredCapability(app1);
    req.setConfiguration(config);

    RemoteProxy p = BaseRemoteProxy.getNewInstance(req, registry);

    assertEquals(p.getClass(), MyRemoteProxy.class);
    MyRemoteProxy myRemoteProxy = (MyRemoteProxy) p;
    assertEquals("A", myRemoteProxy.getCustom1());
    assertEquals("B", myRemoteProxy.getCustom2());
    assertEquals("A", myRemoteProxy.getConfig().custom.get("Custom1"));
    assertEquals("B", myRemoteProxy.getConfig().custom.get("Custom2"));
  }
  @Test
  public void defaultToRemoteProxy() {
    GridNodeConfiguration nodeConfiguration = new GridNodeConfiguration();
    new JCommander(nodeConfiguration, "-role", "webdriver", "-host", "localhost");
    RegistrationRequest res = RegistrationRequest.build(nodeConfiguration);
    res.getCapabilities().clear();
    RegistrationRequest req = res;

    Map<String, Object> app1 = new HashMap<>();
    GridNodeConfiguration config = new GridNodeConfiguration();
    app1.put(CapabilityType.APPLICATION_NAME, "app1");

    req.addDesiredCapability(app1);
    req.setConfiguration(config);

    // requires Custom1 & Custom1 set in config to work.
    RemoteProxy p = BaseRemoteProxy.getNewInstance(req, registry);
    assertEquals(BaseRemoteProxy.class, p.getClass());
  }