Skip to content

Commit

Permalink
Merge pull request #631 from apache/parallel-tests
Browse files Browse the repository at this point in the history
Enables parallel testing for UTs and ITs
  • Loading branch information
bdemers authored Jul 30, 2024
2 parents a1a0235 + cce2ce2 commit 0d7c6fc
Show file tree
Hide file tree
Showing 15 changed files with 198 additions and 107 deletions.
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,12 @@
<include>**/*Tests.java</include>
<include>**/*TestCase.java</include>
</includes>
<properties>
<configurationParameters>
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent
</configurationParameters>
</properties>
</configuration>
</plugin>
<plugin>
Expand All @@ -594,6 +600,12 @@
<dependenciesToScan>
<dependency>org.apache.directory.scimple:scim-compliance-tests</dependency>
</dependenciesToScan>
<properties>
<configurationParameters>
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent
</configurationParameters>
</properties>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ public class MockServerClientTestRunner implements ParameterResolver, BeforeEach

private final List<Class<?>> supportedClasses = List.of(MockWebServer.class, ScimUserClient.class, Client.class);

private final static Weld WELD = new Weld();
static {
// Use single instance of Weld for all tests using this runner
WELD.initialize();
Runtime.getRuntime().addShutdownHook(new Thread(WELD::shutdown));
}

@Override
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
return supportedClasses.contains(parameterContext.getParameter().getType());
Expand All @@ -59,9 +66,6 @@ public Object resolveParameter(ParameterContext parameterContext, ExtensionConte
@Override
public void beforeEach(ExtensionContext context) throws Exception {

Weld weld = new Weld();
getStore(context).put(Weld.class, weld);

MockWebServer server = new MockWebServer();
getStore(context).put(MockWebServer.class, server);

Expand All @@ -79,11 +83,6 @@ public void beforeTestExecution(ExtensionContext context) throws Exception {
if (server != null) {
server.start();
}

Weld weld = fromStore(Weld.class, context);
if (weld != null) {
weld.initialize();
}
}

@Override
Expand All @@ -93,11 +92,6 @@ public void afterEach(ExtensionContext context) throws Exception {
server.shutdown();
}

Weld weld = fromStore(Weld.class, context);
if (weld != null) {
weld.shutdown();
}

Client client = fromStore(Client.class, context);
if (client != null) {
client.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
package org.apache.directory.scim.compliance.junit;

import org.apache.commons.lang3.reflect.FieldUtils;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestInstantiationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -39,22 +38,41 @@
import java.util.List;
import java.util.ServiceLoader;

public class EmbeddedServerExtension implements BeforeAllCallback, BeforeEachCallback, AfterAllCallback {
public class EmbeddedServerExtension implements BeforeEachCallback {

private static final Logger logger = LoggerFactory.getLogger(EmbeddedServerExtension.class);

private ScimTestServer server;
private URI uri;
private static ScimTestServer server;
private static URI uri;

@Override
public void beforeAll(ExtensionContext context) throws Exception {
static {
// Start a single instance of the ScimTestServer
// this instance is shared for all tests using this extension
setupServer();
}

private static void setupServer() {
ServiceLoader<ScimTestServer> serviceLoader = ServiceLoader.load(ScimTestServer.class);
if (serviceLoader.findFirst().isPresent()) {
server = serviceLoader.findFirst().get();
uri = server.start(randomPort());
} else {
logger.info("Could not find implementation of ScimTestServer via ServiceLoader, assuming server is started using different technique");
}
serviceLoader.findFirst()
.ifPresentOrElse(testServer -> {
try {
server = testServer;
uri = server.start(randomPort());

Runtime.getRuntime().addShutdownHook(new Thread(() -> {
if (server != null) {
try {
server.shutdown();
} catch (Exception e) {
logger.warn("Failed to shutdown test server", e);
}
}
}));

} catch (Exception e) {
throw new TestInstantiationException("Failed to start test server: "+ testServer, e);
}
}, () -> logger.info("Could not find implementation of ScimTestServer via ServiceLoader, assuming server is started using different technique"));
}

@Override
Expand All @@ -76,13 +94,6 @@ public void beforeEach(ExtensionContext context) throws Exception {
}
}

@Override
public void afterAll(ExtensionContext context) throws Exception {
if (server != null) {
server.shutdown();
}
}

private static int randomPort() {
try (ServerSocket socket = new ServerSocket(0)) {
return socket.getLocalPort();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,38 @@

package org.apache.directory.scim.example.jersey.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;

import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.inject.Named;

import jakarta.ws.rs.core.Response;
import org.apache.directory.scim.core.repository.ETag;
import org.apache.directory.scim.core.repository.PatchHandler;
import org.apache.directory.scim.core.repository.Repository;
import org.apache.directory.scim.core.schema.SchemaRegistry;
import org.apache.directory.scim.example.jersey.extensions.LuckyNumberExtension;
import org.apache.directory.scim.server.exception.UnableToCreateResourceException;
import org.apache.directory.scim.core.repository.Repository;
import org.apache.directory.scim.spec.exception.ResourceException;
import org.apache.directory.scim.spec.extension.EnterpriseExtension;
import org.apache.directory.scim.spec.filter.Filter;
import org.apache.directory.scim.spec.filter.FilterExpressions;
import org.apache.directory.scim.spec.filter.FilterResponse;
import org.apache.directory.scim.spec.filter.Filter;
import org.apache.directory.scim.spec.filter.PageRequest;
import org.apache.directory.scim.spec.filter.SortRequest;
import org.apache.directory.scim.spec.filter.attribute.AttributeReference;
import org.apache.directory.scim.spec.patch.PatchOperation;
import org.apache.directory.scim.spec.resources.*;
import org.apache.directory.scim.core.schema.SchemaRegistry;
import org.apache.directory.scim.spec.resources.Email;
import org.apache.directory.scim.spec.resources.Name;
import org.apache.directory.scim.spec.resources.ScimExtension;
import org.apache.directory.scim.spec.resources.ScimResource;
import org.apache.directory.scim.spec.resources.ScimUser;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

/**
* Creates a singleton (effectively) Repository<ScimUser> with a memory-based
Expand All @@ -66,7 +69,7 @@ public class InMemoryUserService implements Repository<ScimUser> {
static final String DEFAULT_USER_EMAIL_TYPE = "work";
static final int DEFAULT_USER_LUCKY_NUMBER = 7;

private final Map<String, ScimUser> users = new HashMap<>();
private final Map<String, ScimUser> users = new ConcurrentHashMap<>();

private SchemaRegistry schemaRegistry;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
import org.apache.directory.scim.spec.resources.ScimGroup;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import jakarta.enterprise.context.ApplicationScoped;
Expand All @@ -54,7 +54,7 @@
@ApplicationScoped
public class InMemoryGroupService implements Repository<ScimGroup> {

private final Map<String, ScimGroup> groups = new HashMap<>();
private final Map<String, ScimGroup> groups = new ConcurrentHashMap<>();

private SchemaRegistry schemaRegistry;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,38 @@

package org.apache.directory.scim.example.memory.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;

import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.inject.Named;

import jakarta.ws.rs.core.Response;
import org.apache.directory.scim.core.repository.ETag;
import org.apache.directory.scim.core.repository.PatchHandler;
import org.apache.directory.scim.core.repository.Repository;
import org.apache.directory.scim.core.schema.SchemaRegistry;
import org.apache.directory.scim.example.memory.extensions.LuckyNumberExtension;
import org.apache.directory.scim.server.exception.UnableToCreateResourceException;
import org.apache.directory.scim.core.repository.Repository;
import org.apache.directory.scim.spec.exception.ResourceException;
import org.apache.directory.scim.spec.extension.EnterpriseExtension;
import org.apache.directory.scim.spec.filter.Filter;
import org.apache.directory.scim.spec.filter.FilterExpressions;
import org.apache.directory.scim.spec.filter.FilterResponse;
import org.apache.directory.scim.spec.filter.Filter;
import org.apache.directory.scim.spec.filter.PageRequest;
import org.apache.directory.scim.spec.filter.SortRequest;
import org.apache.directory.scim.spec.filter.attribute.AttributeReference;
import org.apache.directory.scim.spec.patch.PatchOperation;
import org.apache.directory.scim.spec.resources.*;
import org.apache.directory.scim.core.schema.SchemaRegistry;
import org.apache.directory.scim.spec.resources.Email;
import org.apache.directory.scim.spec.resources.Name;
import org.apache.directory.scim.spec.resources.ScimExtension;
import org.apache.directory.scim.spec.resources.ScimResource;
import org.apache.directory.scim.spec.resources.ScimUser;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

/**
* Creates a singleton (effectively) Repository<ScimUser> with a memory-based
Expand All @@ -66,7 +69,7 @@ public class InMemoryUserService implements Repository<ScimUser> {
static final String DEFAULT_USER_EMAIL_TYPE = "work";
static final int DEFAULT_USER_LUCKY_NUMBER = 7;

private final Map<String, ScimUser> users = new HashMap<>();
private final Map<String, ScimUser> users = new ConcurrentHashMap<>();

private SchemaRegistry schemaRegistry;

Expand Down
15 changes: 15 additions & 0 deletions scim-server-examples/scim-server-quarkus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,21 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<properties>
<configurationParameters>
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent

# Looks like there is race condition, disable the logger callback
junit.quarkus.enable-basic-logging=false
</configurationParameters>
</properties>
</configuration>
</plugin>
<plugin>
<groupId>io.quarkus.platform</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@
package org.apache.directory.scim.example.quarkus.service;

import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import jakarta.ws.rs.core.Response;
import org.apache.commons.lang3.StringUtils;
import org.apache.directory.scim.core.repository.ETag;
import org.apache.directory.scim.core.repository.PatchHandler;
import org.apache.directory.scim.server.exception.UnableToCreateResourceException;
import org.apache.directory.scim.core.repository.Repository;
import org.apache.directory.scim.core.schema.SchemaRegistry;
import org.apache.directory.scim.server.exception.UnableToCreateResourceException;
import org.apache.directory.scim.spec.exception.ResourceException;
import org.apache.directory.scim.spec.filter.Filter;
import org.apache.directory.scim.spec.filter.FilterExpressions;
import org.apache.directory.scim.spec.filter.FilterResponse;
import org.apache.directory.scim.spec.filter.Filter;
import org.apache.directory.scim.spec.filter.PageRequest;
import org.apache.directory.scim.spec.filter.SortRequest;
import org.apache.directory.scim.spec.filter.attribute.AttributeReference;
Expand All @@ -39,22 +42,18 @@
import org.apache.directory.scim.spec.resources.ScimGroup;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Named;
import org.apache.directory.scim.core.schema.SchemaRegistry;

@Named
@ApplicationScoped
public class InMemoryGroupService implements Repository<ScimGroup> {

private final Map<String, ScimGroup> groups = new HashMap<>();
private final Map<String, ScimGroup> groups = new ConcurrentHashMap<>();

private SchemaRegistry schemaRegistry;

Expand Down
Loading

0 comments on commit 0d7c6fc

Please sign in to comment.