Search in sources :

Example 1 with ServerSetup

use of org.keycloak.testsuite.crossdc.ServerSetup in project keycloak by keycloak.

the class CrossDCTestEnricher method beforeTest.

public void beforeTest(@Observes(precedence = -2) Before event) {
    if (!suiteContext.isAuthServerCrossDc())
        return;
    // if annotation is present on method
    InitialDcState annotation = event.getTestMethod().getAnnotation(InitialDcState.class);
    // annotation not present on method, taking it from class
    if (annotation == null) {
        Class<?> annotatedClass = getNearestSuperclassWithAnnotation(event.getTestClass().getJavaClass(), InitialDcState.class);
        annotation = annotatedClass == null ? null : annotatedClass.getAnnotation(InitialDcState.class);
    }
    if (annotation == null) {
        log.debug("No environment preparation requested, not changing auth/cache server run status.");
        // Test does not specify its environment, so it's on its own
        return;
    }
    ServerSetup cacheServers = annotation.cacheServers();
    ServerSetup authServers = annotation.authServers();
    // Stop auth servers that otherwise could be hang connecting to a cache server stopped next
    switch(authServers) {
        case ALL_NODES_IN_EVERY_DC:
            break;
        case FIRST_NODE_IN_EVERY_DC:
            DC.validDcsStream().forEach((DC dc) -> stopAuthServerBackendNode(dc, 1));
            break;
        case FIRST_NODE_IN_FIRST_DC:
            stopAuthServerBackendNode(DC.FIRST, 1);
            forAllBackendNodesInDc(DC.SECOND, CrossDCTestEnricher::stopAuthServerBackendNode);
            break;
        case ALL_NODES_IN_FIRST_DC_FIRST_NODE_IN_SECOND_DC:
            stopAuthServerBackendNode(DC.SECOND, 1);
            break;
        case ALL_NODES_IN_FIRST_DC_NO_NODES_IN_SECOND_DC:
            forAllBackendNodesInDc(DC.SECOND, CrossDCTestEnricher::stopAuthServerBackendNode);
            break;
    }
    switch(cacheServers) {
        case ALL_NODES_IN_EVERY_DC:
        // the same as ALL_NODES_IN_EVERY_DC as there is only one cache server per DC
        case FIRST_NODE_IN_EVERY_DC:
        case ALL_NODES_IN_FIRST_DC_FIRST_NODE_IN_SECOND_DC:
            DC.validDcsStream().forEach(CrossDCTestEnricher::startCacheServer);
            break;
        case FIRST_NODE_IN_FIRST_DC:
        case ALL_NODES_IN_FIRST_DC_NO_NODES_IN_SECOND_DC:
            startCacheServer(DC.FIRST);
            stopCacheServer(DC.SECOND);
            break;
    }
    switch(authServers) {
        case ALL_NODES_IN_EVERY_DC:
            forAllBackendNodes(CrossDCTestEnricher::startAuthServerBackendNode);
            break;
        case FIRST_NODE_IN_EVERY_DC:
            DC.validDcsStream().forEach((DC dc) -> startAuthServerBackendNode(dc, 0));
            break;
        case FIRST_NODE_IN_FIRST_DC:
            startAuthServerBackendNode(DC.FIRST, 0);
            break;
        case ALL_NODES_IN_FIRST_DC_FIRST_NODE_IN_SECOND_DC:
            forAllBackendNodesInDc(DC.FIRST, CrossDCTestEnricher::startAuthServerBackendNode);
            startAuthServerBackendNode(DC.SECOND, 0);
            break;
        case ALL_NODES_IN_FIRST_DC_NO_NODES_IN_SECOND_DC:
            forAllBackendNodesInDc(DC.FIRST, CrossDCTestEnricher::startAuthServerBackendNode);
            break;
    }
    suspendPeriodicTasks();
}
Also used : ServerSetup(org.keycloak.testsuite.crossdc.ServerSetup) InitialDcState(org.keycloak.testsuite.arquillian.annotation.InitialDcState) DC(org.keycloak.testsuite.crossdc.DC)

Aggregations

InitialDcState (org.keycloak.testsuite.arquillian.annotation.InitialDcState)1 DC (org.keycloak.testsuite.crossdc.DC)1 ServerSetup (org.keycloak.testsuite.crossdc.ServerSetup)1