Skip to content

Commit 3ba7d12

Browse files
authored
BXC-4569 - Use docker for Fedora in tests (#1729)
* Add docker compose to bring up a test instance of fcrepo docker to use in integration tests (which uses auth be default). Update StorageLocationTestHelper to work with a shared path for storing binaries with fedora also allows as a external binary source. Update BinaryTransferServiceImplIT to work with this setup * Bring up fedora in gh actions. Only running persistence tests for now * Address config via mounted volume * Enable logging for fedora * Debugging config * Use env variable * Reenable tests and cleanup * Check on bxc storage * Cleanup build.yml * Sort IDs as part of formatting member order validation messages, to resolve flapping tests which fail if the HashSet happens to return a different order * Update readme with instructions for running integration tests * Update all of the operations integration tests to use external fedora * Update web-access IT, fix some incorrect assumptions and a file path issue that caused tests to flap * Cleanup dependencies * Updated tests in services-api app. Running redis in docker now instead of using embedded. Cleanup fedora and redis after tests. Switched to using MvcTestHelpers for some methods that were being provided by AbstractAPIIT * Add servlet-api for tests * Change servlet-api to being both provided and test scope. Remove unneeded CommonsMultipartResolver which was requiring web dependencies in the operations module * More fixes to servlet-api dependency. Fixed includes that were using the incorrect dependency as their source, since they failed after removing fedora dependencies * Add helper methods for getting base location for a storage area (or generate a storage uri in the default storage area), to fix issue of tests failing when files were being written to the storage root. Get web-access-app tests to work in ghactions * Upgrade jedis to version that supports redis 5 and 7 * Switch to using JedisPooled for managing resources. Set redis at version 7. * More jedis fixes, and update jesque * Utility for cleaning up repo. Updating deposit tests * Revert "Switch to using JedisPooled for managing resources. Set redis at version 7." This reverts commit 41385d4. * Downgrade to jedis 3.10 since jesque does not support 4. Switch to redis 6 since that is the highest version supported by jedis 3 * Update services camel app tests * Try using fuseki as a container * Add fuseki to gh actions * Update integration test module. Remove fedora server dependency everywhere * Increase message count * Cleanup files from the shared storage location * Fix visibility * Fix test that was failing due to timezones
1 parent 17b3896 commit 3ba7d12

File tree

148 files changed

+1262
-2815
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+1262
-2815
lines changed

.github/workflows/build.yml

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,46 @@ jobs:
1515

1616
services:
1717
redis:
18-
image: redis
18+
image: redis:6
1919
ports:
20-
- 6379/tcp
20+
- 46380:6379
21+
fedora:
22+
image: fcrepo/fcrepo:5.1.1
23+
ports:
24+
- 48085:8080
25+
volumes:
26+
- ${{ github.workspace }}/it_config:/config
27+
- /tmp/boxc_test_storage:/tmp/boxc_test_storage
28+
env:
29+
CATALINA_OPTS: "-Djava.awt.headless=true -server -Xms512m -Xmx1024m -XX:NewSize=256m -XX:MaxNewSize=256m -Dfcrepo.external.content.allowed=/config/allowed_external_paths.txt"
2130

2231
steps:
32+
- name: Change permissions of /tmp/boxc_test_storage
33+
run: sudo chmod 2777 /tmp/boxc_test_storage
34+
2335
- name: Checkout repository
2436
uses: actions/checkout@v2
37+
38+
- name: Get Container ID of fedora service
39+
id: get_container_id
40+
run: |
41+
CONTAINER_ID=$(docker ps --format "{{.ID}}" -f "ancestor=fcrepo/fcrepo:5.1.1")
42+
echo "CONTAINER_ID=$CONTAINER_ID" >> $GITHUB_ENV
43+
- name: Restart fedora now that the repository has been checked out so config files are available
44+
run: docker restart ${{ env.CONTAINER_ID }}
45+
46+
- name: Run Fuseki container as command to pass in extra dataset name argument
47+
run: |
48+
docker run -d --rm -p 43030:3030 atomgraph/fuseki --mem /test
49+
2550
- name: Checkout submodules
2651
run: git submodule update --init --recursive
52+
2753
- name: Set up JDK 11
2854
uses: actions/setup-java@v1
2955
with:
3056
java-version: 11
57+
3158
- name: Cache Maven packages
3259
uses: actions/cache@v2
3360
with:
@@ -36,9 +63,6 @@ jobs:
3663
restore-keys: ${{ runner.os }}-m2
3764
- name: Build with Maven
3865
run: mvn -B -U -pl '!integration' clean install -DskipTests
39-
- name: Package integration module with Maven
40-
run: mvn -B -U -pl integration clean package -DskipTests
41-
4266
- name: Set up nodejs
4367
uses: actions/setup-node@v2
4468
with:
@@ -69,3 +93,8 @@ jobs:
6993
${{github.workspace}}/**/target/site/jacoco-it/jacoco.xml:jacoco
7094
${{github.workspace}}/static/js/vue-cdr-access/coverage/lcov.info:lcov
7195
${{github.workspace}}/static/js/admin/vue-permissions-editor/coverage/lcov.info:lcov
96+
97+
- name: View fedora service logs
98+
if: always()
99+
run: |
100+
docker logs ${{ env.CONTAINER_ID }}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ services-worker
4141
.sass-cache
4242
*.css.map
4343
dependency-reduced-pom.xml
44-
etc/solr-config/access/data/
44+
etc/solr-config/access/data/
45+
it_config/logs/*

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,25 @@ All tests run automatically in Github Actions.
6161
All Java tests run automatically when building the project, unless skipped.
6262
JavaScript test don't run on a maven build, but can be run manually using the NPM command below.
6363

64+
### Running java unit tests
6465
```
6566
# Java Unit Tests (skipping tests from external modules)
6667
mvn -pl '!clamav-java' test
68+
```
69+
70+
### Running java unit and integration tests
71+
To run the integration tests locally, you will first need to start external dependencies such as Fedora. Do to this, from the root directory of this project, run the following command:
72+
```
73+
docker-compose up
74+
```
75+
And then run the integration tests from within your IDE or via the following:
76+
```
6777
# Java unit and integration tests
6878
mvn -pl '!clamav-java' verify
79+
```
6980

81+
### Running JavaScript tests
82+
```
7083
# JavaScript Tests
7184
npm --prefix static/js/admin/vue-permissions-editor run test
7285
npm --prefix static/js/vue-cdr-access run test

deposit-app/pom.xml

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -163,59 +163,6 @@
163163
<groupId>gov.loc</groupId>
164164
<artifactId>bagit</artifactId>
165165
</dependency>
166-
<!-- integration testing -->
167-
<dependency>
168-
<groupId>org.fcrepo</groupId>
169-
<artifactId>fcrepo-http-commons</artifactId>
170-
<scope>test</scope>
171-
<type>test-jar</type>
172-
</dependency>
173-
<dependency>
174-
<groupId>org.fcrepo</groupId>
175-
<artifactId>fcrepo-auth-common</artifactId>
176-
</dependency>
177-
<dependency>
178-
<groupId>org.glassfish.grizzly</groupId>
179-
<artifactId>grizzly-http-servlet</artifactId>
180-
</dependency>
181-
<dependency>
182-
<groupId>org.glassfish.jersey.core</groupId>
183-
<artifactId>jersey-common</artifactId>
184-
</dependency>
185-
<dependency>
186-
<groupId>org.glassfish.jersey.ext</groupId>
187-
<artifactId>jersey-spring5</artifactId>
188-
</dependency>
189-
<dependency>
190-
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
191-
<artifactId>jersey-test-framework-provider-grizzly2</artifactId>
192-
</dependency>
193-
<dependency>
194-
<groupId>org.fcrepo</groupId>
195-
<artifactId>fcrepo-kernel-modeshape</artifactId>
196-
<scope>test</scope>
197-
<classifier>tests</classifier>
198-
</dependency>
199-
<dependency>
200-
<groupId>org.fcrepo</groupId>
201-
<artifactId>fcrepo-http-api</artifactId>
202-
</dependency>
203-
<dependency>
204-
<groupId>javax.xml.bind</groupId>
205-
<artifactId>jaxb-api</artifactId>
206-
</dependency>
207-
<dependency>
208-
<groupId>com.sun.xml.bind</groupId>
209-
<artifactId>jaxb-core</artifactId>
210-
</dependency>
211-
<dependency>
212-
<groupId>com.sun.xml.bind</groupId>
213-
<artifactId>jaxb-impl</artifactId>
214-
</dependency>
215-
<dependency>
216-
<groupId>it.ozimov</groupId>
217-
<artifactId>embedded-redis</artifactId>
218-
</dependency>
219166
</dependencies>
220167

221168
<build>

deposit-app/src/test/java/edu/unc/lib/boxc/deposit/fcrepo4/AbstractFedoraDepositJobIT.java

Lines changed: 26 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,5 @@
11
package edu.unc.lib.boxc.deposit.fcrepo4;
22

3-
import java.io.File;
4-
import java.io.IOException;
5-
import java.net.URI;
6-
import java.nio.file.Path;
7-
import java.util.List;
8-
import java.util.UUID;
9-
10-
import org.apache.http.HttpStatus;
11-
import org.fcrepo.client.FcrepoClient;
12-
import org.fcrepo.client.FcrepoOperationFailedException;
13-
import org.fcrepo.client.FcrepoResponse;
14-
import org.junit.jupiter.api.AfterEach;
15-
import org.junit.jupiter.api.AfterAll;
16-
import org.junit.jupiter.api.BeforeEach;
17-
import org.junit.jupiter.api.extension.ExtendWith;
18-
import org.junit.jupiter.api.io.TempDir;
19-
import org.springframework.beans.factory.annotation.Autowired;
20-
import org.springframework.test.context.ContextConfiguration;
21-
import org.springframework.test.context.ContextHierarchy;
22-
import org.springframework.test.context.junit.jupiter.SpringExtension;
23-
243
import edu.unc.lib.boxc.deposit.api.RedisWorkerConstants.DepositState;
254
import edu.unc.lib.boxc.deposit.impl.model.ActivityMetricsClient;
265
import edu.unc.lib.boxc.deposit.impl.model.DepositModelManager;
@@ -35,12 +14,30 @@
3514
import edu.unc.lib.boxc.model.fcrepo.ids.RepositoryPaths;
3615
import edu.unc.lib.boxc.model.fcrepo.services.RepositoryInitializer;
3716
import edu.unc.lib.boxc.model.fcrepo.test.TestHelper;
17+
import edu.unc.lib.boxc.model.fcrepo.test.TestRepositoryDeinitializer;
3818
import edu.unc.lib.boxc.operations.api.events.PremisLoggerFactory;
3919
import edu.unc.lib.boxc.persist.api.storage.StorageLocationManager;
4020
import edu.unc.lib.boxc.persist.api.transfer.BinaryTransferService;
21+
import edu.unc.lib.boxc.persist.impl.storage.StorageLocationTestHelper;
22+
import org.apache.http.HttpStatus;
23+
import org.fcrepo.client.FcrepoClient;
24+
import org.fcrepo.client.FcrepoOperationFailedException;
25+
import org.fcrepo.client.FcrepoResponse;
26+
import org.junit.jupiter.api.AfterEach;
27+
import org.junit.jupiter.api.BeforeEach;
28+
import org.junit.jupiter.api.extension.ExtendWith;
29+
import org.junit.jupiter.api.io.TempDir;
30+
import org.springframework.beans.factory.annotation.Autowired;
31+
import org.springframework.test.context.ContextConfiguration;
32+
import org.springframework.test.context.ContextHierarchy;
33+
import org.springframework.test.context.junit.jupiter.SpringExtension;
4134
import redis.clients.jedis.Jedis;
4235
import redis.clients.jedis.JedisPool;
43-
import redis.embedded.RedisServer;
36+
37+
import java.io.File;
38+
import java.nio.file.Path;
39+
import java.util.List;
40+
import java.util.UUID;
4441

4542
/**
4643
*
@@ -49,7 +46,6 @@
4946
*/
5047
@ExtendWith(SpringExtension.class)
5148
@ContextHierarchy({
52-
@ContextConfiguration("/spring-test/test-fedora-container.xml"),
5349
@ContextConfiguration("/spring-test/cdr-client-container.xml")
5450
})
5551
public abstract class AbstractFedoraDepositJobIT {
@@ -76,6 +72,10 @@ public abstract class AbstractFedoraDepositJobIT {
7672
protected BinaryTransferService binaryTransferService;
7773
@Autowired
7874
protected StorageLocationManager storageLocationManager;
75+
@Autowired
76+
protected StorageLocationTestHelper storageLocationTestHelper;
77+
@Autowired
78+
protected FcrepoClient fcrepoClient;
7979
@TempDir
8080
public Path tmpFolder;
8181
@Autowired
@@ -93,23 +93,6 @@ public abstract class AbstractFedoraDepositJobIT {
9393

9494
protected ContentRootObject rootObj;
9595

96-
private static final RedisServer redisServer;
97-
98-
static {
99-
try {
100-
redisServer = new RedisServer(46380);
101-
redisServer.start();
102-
} catch (Exception e) {
103-
throw new RuntimeException(e);
104-
}
105-
106-
}
107-
108-
@AfterAll
109-
public static void afterAll() throws Exception {
110-
redisServer.stop();
111-
}
112-
11396
@BeforeEach
11497
public void initBase() throws Exception {
11598
TestHelper.setContentBase(baseAddress);
@@ -130,24 +113,12 @@ public void initBase() throws Exception {
130113
}
131114

132115
@AfterEach
133-
public void cleanupRedis() throws Exception {
116+
public void cleanupDatastores() throws Exception {
134117
try (Jedis jedis = jedisPool.getResource()) {
135118
jedis.flushDB();
136119
}
137-
}
138-
139-
protected URI createBaseContainer(String name) throws IOException, FcrepoOperationFailedException {
140-
URI baseUri = URI.create(serverAddress + name);
141-
// Create a parent object to put the binary into
142-
try (FcrepoResponse response = client.put(baseUri).perform()) {
143-
return response.getLocation();
144-
} catch (FcrepoOperationFailedException e) {
145-
// Eat conflict exceptions since this will run multiple times
146-
if (e.getStatusCode() != HttpStatus.SC_CONFLICT) {
147-
throw e;
148-
}
149-
return baseUri;
150-
}
120+
TestRepositoryDeinitializer.cleanup(fcrepoClient);
121+
storageLocationTestHelper.cleanupStorageLocations();
151122
}
152123

153124
protected ContentObject findContentObjectByPid(List<ContentObject> objs, final PID pid) {

deposit-app/src/test/java/edu/unc/lib/boxc/deposit/fcrepo4/IngestContentObjectsJobIT.java

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.jdom2.output.XMLOutputter;
4545
import org.junit.jupiter.api.Assertions;
4646
import org.junit.jupiter.api.BeforeEach;
47+
import org.junit.jupiter.api.Disabled;
4748
import org.junit.jupiter.api.Test;
4849
import org.slf4j.Logger;
4950
import org.springframework.beans.factory.annotation.Autowired;
@@ -96,10 +97,6 @@ public class IngestContentObjectsJobIT extends AbstractFedoraDepositJobIT {
9697

9798
private static final Logger log = getLogger(IngestContentObjectsJobIT.class);
9899

99-
static {
100-
System.setProperty("fcrepo.properties.management", "relaxed");
101-
}
102-
103100
private static final String INGESTOR_PRINC = "ingestor";
104101
private static final String DEPOSITOR_NAME = "boxy_depositor";
105102

@@ -460,10 +457,12 @@ public void ingestWorkObjectWithModsHistoryTest() throws Exception {
460457
Path modsPath = job.getModsPath(workPid, true);
461458
var originalModsPath = Path.of("src/test/resources/simpleMods.xml");
462459
Files.copy(originalModsPath, modsPath);
463-
Path modsHistoryPath = depositDirManager.getHistoryFile(workPid, DatastreamType.MD_DESCRIPTIVE_HISTORY);
460+
var modsPid = DatastreamPids.getMdDescriptivePid(workPid);
461+
var modsHistoryStorageUri = storageLocationTestHelper.makeTestStorageUri(DatastreamPids.getDatastreamHistoryPid(modsPid));
462+
Path modsHistoryPath = Paths.get(modsHistoryStorageUri);
464463
FileUtils.writeStringToFile(modsHistoryPath.toFile(), "History content", UTF_8);
465464
String modsHistorySha1 = getSha1(modsHistoryPath);
466-
historyResc.addProperty(CdrDeposit.storageUri, modsHistoryPath.toUri().toString());
465+
historyResc.addProperty(CdrDeposit.storageUri, modsHistoryStorageUri.toString());
467466
historyResc.addLiteral(CdrDeposit.sha1sum, modsHistorySha1);
468467

469468
job.closeModel();
@@ -508,7 +507,8 @@ public void ingestWorkObjectWithFITSHistoryTest() throws Exception {
508507
PID fitsPid = DatastreamPids.getTechnicalMetadataPid(mainPid);
509508
PID historyPid = DatastreamPids.getDatastreamHistoryPid(fitsPid);
510509
Resource historyResc = DepositModelHelpers.addDatastream(mainResc, DatastreamType.TECHNICAL_METADATA_HISTORY);
511-
Path historyPath = depositDirManager.getHistoryFile(fitsPid, DatastreamType.TECHNICAL_METADATA_HISTORY);
510+
var historyUri = storageLocationTestHelper.makeTestStorageUri(historyPid);
511+
Path historyPath = Path.of(historyUri);
512512
FileUtils.writeStringToFile(historyPath.toFile(), "History content", UTF_8);
513513
String historySha1 = getSha1(historyPath);
514514
historyResc.addProperty(CdrDeposit.storageUri, historyPath.toUri().toString());
@@ -714,6 +714,7 @@ public void resumeIngestFolderTest() throws Exception {
714714
model = job.getWritableModel();
715715
Resource file2Resc = model.getResource(file2Pid.getRepositoryPath());
716716
Resource orig2Resc = DepositModelHelpers.getDatastream(file2Resc);
717+
setupStorageUriForResource(FILE2_LOC, orig2Resc, file2Resc, file2Pid);
717718
orig2Resc.addProperty(CdrDeposit.storageUri, Paths.get(depositDir.getAbsolutePath(),
718719
FILE2_LOC).toUri().toString());
719720
job.closeModel();
@@ -1100,6 +1101,7 @@ public void fromMultipleDepositsTest() throws Exception {
11001101
private final static Date CREATED_DATE = DateTimeUtil.parseUTCToDate(CREATED_STRING);
11011102
private final static Date LAST_MODIFIED_DATE = DateTimeUtil.parseUTCToDate(LAST_MODIFIED_STRING);
11021103

1104+
@Disabled("This test only works if fedora is in 'relaxed' mode, which is not the case on our servers or in docker")
11031105
@Test
11041106
public void overrideTimestampsTest() throws Exception {
11051107
Map<String, String> status = new HashMap<>();
@@ -1271,9 +1273,7 @@ private PID addFileObject(Bag parent, String stagingLocation,
12711273

12721274
Resource origResc = DepositModelHelpers.addDatastream(fileResc, ORIGINAL_FILE);
12731275
if (stagingLocation != null) {
1274-
origResc.addProperty(CdrDeposit.storageUri, Paths.get(depositDir.getAbsolutePath(),
1275-
stagingLocation).toUri().toString());
1276-
fileResc.addLiteral(Cdr.storageLocation, LOC1_ID);
1276+
setupStorageUriForResource(stagingLocation, origResc, fileResc, filePid);
12771277
}
12781278
origResc.addProperty(CdrDeposit.mimetype, mimetype);
12791279
if (sha1 != null) {
@@ -1286,15 +1286,26 @@ private PID addFileObject(Bag parent, String stagingLocation,
12861286
parent.add(fileResc);
12871287

12881288
// Create the accompanying fake premis report file
1289-
Path fitsPath = job.getTechMdPath(filePid, true);
1289+
var fitsStorageUri = storageLocationTestHelper.makeTestStorageUri(DatastreamPids.getTechnicalMetadataPid(filePid));
1290+
Path fitsPath = Path.of(fitsStorageUri);
12901291
Files.createFile(fitsPath);
12911292
Resource fitsResc = DepositModelHelpers.addDatastream(fileResc, TECHNICAL_METADATA);
1292-
fitsResc.addProperty(CdrDeposit.storageUri, fitsPath.toUri().toString());
1293+
fitsResc.addProperty(CdrDeposit.storageUri, fitsStorageUri.toString());
12931294
fitsResc.addLiteral(CdrDeposit.sha1sum, getSha1(fitsPath));
12941295

12951296
return filePid;
12961297
}
12971298

1299+
private void setupStorageUriForResource(String stagingLocation, Resource origResc, Resource fileResc, PID filePid) throws Exception {
1300+
var fileStagingPath = Paths.get(depositDir.getAbsolutePath(), stagingLocation);
1301+
var storageUri = storageLocationTestHelper.makeTestStorageUri(DatastreamPids.getOriginalFilePid(filePid));
1302+
var storagePath = Path.of(storageUri);
1303+
Files.copy(fileStagingPath, storagePath);
1304+
origResc.addProperty(CdrDeposit.storageUri, storageUri.toString());
1305+
fileResc.addLiteral(Cdr.storageLocation, LOC1_ID);
1306+
fileResc.addLiteral(CdrDeposit.label, stagingLocation);
1307+
}
1308+
12981309
private List<PID> addWorkWithFileObject(Bag parent, String stagingLocation,
12991310
String mimetype, String sha1, String md5) throws Exception {
13001311
Model model = parent.getModel();

0 commit comments

Comments
 (0)