Search in sources :

Example 1 with ProcessedCapabilities

use of de.zalando.ep.zalenium.util.ProcessedCapabilities in project zalenium by zalando.

the class DockerSeleniumStarterRemoteProxyTest method noContainerIsStartedForAlreadyProcessedRequest.

@Test
public void noContainerIsStartedForAlreadyProcessedRequest() {
    Map<String, Object> requestedCapability = new HashMap<>();
    requestedCapability.put(CapabilityType.BROWSER_NAME, BrowserType.CHROME);
    requestedCapability.put(CapabilityType.PLATFORM_NAME, Platform.LINUX);
    ProcessedCapabilities processedCapabilities = new ProcessedCapabilities(requestedCapability, System.identityHashCode(requestedCapability));
    DockerSeleniumStarterRemoteProxy.processedCapabilitiesList.add(processedCapabilities);
    TestSession testSession = spyProxy.getNewSession(requestedCapability);
    Assert.assertNull(testSession);
    verify(spyProxy, times(0)).startDockerSeleniumContainer(timeZone, screenSize);
}
Also used : ProcessedCapabilities(de.zalando.ep.zalenium.util.ProcessedCapabilities) HashMap(java.util.HashMap) TestSession(org.openqa.grid.internal.TestSession) Test(org.junit.Test)

Example 2 with ProcessedCapabilities

use of de.zalando.ep.zalenium.util.ProcessedCapabilities in project zalenium by zalando.

the class DockerSeleniumStarterRemoteProxy method getNewSession.

/**
 * Receives a request to create a new session, but instead of accepting it, it will create a
 * docker-selenium container which will register to the hub, then reject the request and the hub
 * will assign the request to the new registered node.
 */
@Override
public TestSession getNewSession(Map<String, Object> requestedCapability) {
    if (!hasCapability(requestedCapability)) {
        LOGGER.debug(String.format("%s Capability not supported %s", getId(), requestedCapability));
        return null;
    }
    if (!requestedCapability.containsKey(CapabilityType.BROWSER_NAME)) {
        LOGGER.debug(String.format("%s Capability %s does not contain %s key, a docker-selenium " + "node cannot be started without it", getId(), requestedCapability, CapabilityType.BROWSER_NAME));
        return null;
    }
    // Check and configure specific screen resolution capabilities when they have been passed in the test config.
    Dimension screenSize = getConfiguredScreenResolutionFromCapabilities(requestedCapability);
    // Check and configure time zone capabilities when they have been passed in the test config.
    TimeZone timeZone = getConfiguredTimeZoneFromCapabilities(requestedCapability);
    /*
            Reusing nodes, rejecting requests when a node is cleaning up and will be ready again soon.
         */
    if (nodesAvailable(requestedCapability)) {
        LOGGER.debug(String.format("%s A node is coming up soon for %s, won't start a new node yet.", getId(), requestedCapability));
        return null;
    }
    // Checking if this request has been processed based on its id, contents, and attempts
    if (hasRequestBeenProcessed(requestedCapability)) {
        LOGGER.debug(String.format("%s Request %s, has been processed and it is waiting for a node.", getId(), requestedCapability));
        return null;
    }
    ProcessedCapabilities processedCapabilities = new ProcessedCapabilities(requestedCapability, System.identityHashCode(requestedCapability));
    processedCapabilitiesList.add(processedCapabilities);
    LOGGER.debug(String.format("%s Starting new node for %s.", getId(), requestedCapability));
    poolExecutor.execute(() -> startDockerSeleniumContainer(timeZone, screenSize));
    cleanProcessedCapabilities();
    return null;
}
Also used : ProcessedCapabilities(de.zalando.ep.zalenium.util.ProcessedCapabilities) TimeZone(java.util.TimeZone) Dimension(org.openqa.selenium.Dimension)

Example 3 with ProcessedCapabilities

use of de.zalando.ep.zalenium.util.ProcessedCapabilities in project zalenium by zalando.

the class DockerSeleniumStarterRemoteProxy method hasRequestBeenProcessed.

private boolean hasRequestBeenProcessed(Map<String, Object> requestedCapability) {
    int requestedCapabilityHashCode = System.identityHashCode(requestedCapability);
    for (ProcessedCapabilities processedCapability : processedCapabilitiesList) {
        LOGGER.debug(getId() + "System.identityHashCode(requestedCapability) -> " + System.identityHashCode(requestedCapability) + ", " + requestedCapability);
        LOGGER.debug(getId() + "processedCapability.getIdentityHashCode() -> " + processedCapability.getIdentityHashCode() + ", " + processedCapability.getRequestedCapability());
        if (processedCapability.getIdentityHashCode() == requestedCapabilityHashCode) {
            processedCapability.setLastProcessedTime(System.currentTimeMillis());
            int processedTimes = processedCapability.getProcessedTimes() + 1;
            processedCapability.setProcessedTimes(processedTimes);
            if (processedTimes >= 30) {
                processedCapability.setProcessedTimes(1);
                LOGGER.info(String.format("%s Request has waited 30 attempts for a node, something " + "went wrong with the previous attempts, creating a new node for %s.", getId(), requestedCapability));
                return false;
            }
            return true;
        }
    }
    return false;
}
Also used : ProcessedCapabilities(de.zalando.ep.zalenium.util.ProcessedCapabilities)

Example 4 with ProcessedCapabilities

use of de.zalando.ep.zalenium.util.ProcessedCapabilities in project zalenium by zalando.

the class DockerSeleniumStarterRemoteProxyTest method containerIsStartedForRequestProcessedMoreThan30Times.

@Test
public void containerIsStartedForRequestProcessedMoreThan30Times() {
    Map<String, Object> requestedCapability = new HashMap<>();
    requestedCapability.put(CapabilityType.BROWSER_NAME, BrowserType.FIREFOX);
    requestedCapability.put(CapabilityType.PLATFORM_NAME, Platform.LINUX);
    ProcessedCapabilities processedCapabilities = new ProcessedCapabilities(requestedCapability, System.identityHashCode(requestedCapability));
    processedCapabilities.setProcessedTimes(31);
    DockerSeleniumStarterRemoteProxy.processedCapabilitiesList.add(processedCapabilities);
    TestSession testSession = spyProxy.getNewSession(requestedCapability);
    Assert.assertNull(testSession);
    verify(spyProxy, timeout(1000).atLeastOnce()).startDockerSeleniumContainer(timeZone, screenSize);
}
Also used : ProcessedCapabilities(de.zalando.ep.zalenium.util.ProcessedCapabilities) HashMap(java.util.HashMap) TestSession(org.openqa.grid.internal.TestSession) Test(org.junit.Test)

Example 5 with ProcessedCapabilities

use of de.zalando.ep.zalenium.util.ProcessedCapabilities in project zalenium by zalando.

the class DockerSeleniumStarterRemoteProxy method cleanProcessedCapabilities.

private void cleanProcessedCapabilities() {
    /*
            Cleaning processed capabilities to reduce the risk of having two objects with the same
            identityHashCode after the garbage collector did its job.
            Not a silver bullet solution, but should be good enough.
         */
    List<ProcessedCapabilities> processedCapabilitiesToRemove = new ArrayList<>();
    for (ProcessedCapabilities processedCapability : processedCapabilitiesList) {
        long timeSinceLastProcess = System.currentTimeMillis() - processedCapability.getLastProcessedTime();
        long maximumLastProcessedTime = 1000 * 60;
        if (timeSinceLastProcess >= maximumLastProcessedTime) {
            processedCapabilitiesToRemove.add(processedCapability);
        }
    }
    processedCapabilitiesList.removeAll(processedCapabilitiesToRemove);
}
Also used : ProcessedCapabilities(de.zalando.ep.zalenium.util.ProcessedCapabilities) ArrayList(java.util.ArrayList)

Aggregations

ProcessedCapabilities (de.zalando.ep.zalenium.util.ProcessedCapabilities)5 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 TestSession (org.openqa.grid.internal.TestSession)2 ArrayList (java.util.ArrayList)1 TimeZone (java.util.TimeZone)1 Dimension (org.openqa.selenium.Dimension)1