-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ACS-6151 - Create ATS liveness/readiness probes tests #892
Changes from 8 commits
d833b8e
99d31ee
6b4e3e1
f5ce966
85fc677
314453f
8631773
9519a7f
51062f4
85c838d
4b9a0ea
7682a66
c31cc1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* #%L | ||
* Alfresco Transform Core | ||
* %% | ||
* Copyright (C) 2005 - 2023 Alfresco Software Limited | ||
* %% | ||
* This file is part of the Alfresco software. | ||
* - | ||
* If the software was purchased under a paid Alfresco license, the terms of | ||
* the paid license agreement will prevail. Otherwise, the software is | ||
* provided under the following open source license terms: | ||
* - | ||
* Alfresco is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* - | ||
* Alfresco is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* - | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. | ||
* #L% | ||
*/ | ||
|
||
package org.alfresco.transform.aio; | ||
|
||
import org.alfresco.transform.base.LivenessReadinessProbeTest; | ||
|
||
public class AIOLivenessReadinessProbeTest extends LivenessReadinessProbeTest { | ||
@Override | ||
protected LivenessReadinessProbeTest.ImagesForTests getImageForTest() { | ||
return new ImagesForTests("alfresco-transform-core-aio", "text/plain", "text/plain", "original.txt"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package org.alfresco.transform.base; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import org.springframework.core.io.ClassPathResource; | ||
|
||
import org.springframework.http.client.MultipartBodyBuilder; | ||
import org.springframework.test.web.reactive.server.WebTestClient; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.wait.strategy.Wait; | ||
|
||
import java.net.URISyntaxException; | ||
|
||
import java.util.Objects; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import static org.springframework.http.HttpStatus.OK; | ||
import static org.springframework.http.HttpStatus.TOO_MANY_REQUESTS; | ||
|
||
import org.springframework.web.reactive.function.client.WebClient; | ||
|
||
public abstract class LivenessReadinessProbeTest | ||
{ | ||
@Test | ||
public void readinessShouldReturnAn429ErrorAfterReachingMaxTransforms() throws URISyntaxException | ||
{ | ||
final ImagesForTests testData = getImageForTest(); | ||
|
||
try (final var env = createEnv(testData.image)) | ||
{ | ||
env.start(); | ||
var url = "http://localhost:" + env.getFirstMappedPort(); | ||
|
||
int max_transforms = 11; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved this value to a constant and used in both places |
||
for (int i = 0; i<max_transforms; i++) { | ||
sendTransformRequest(url, testData.sourceMimetype, testData.targetMimetype, testData.filename); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be good to add an assertion that probe is successful before sending transformation request There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added an assertion before sending each request |
||
} | ||
|
||
assertProbeDied(url); | ||
|
||
final String logs = env.getLogs(); | ||
System.out.println(logs); | ||
} | ||
} | ||
|
||
protected abstract ImagesForTests getImageForTest(); | ||
|
||
private GenericContainer<?> createEnv(String image) throws URISyntaxException | ||
{ | ||
System.out.println(image); | ||
final GenericContainer<?> transformCore = new GenericContainer<>("alfresco/"+image+":latest"); | ||
|
||
return transformCore.withEnv("livenessTransformEnabled", "true") | ||
.withEnv("maxTransforms", "10") | ||
.withNetworkAliases(image) | ||
.withExposedPorts(8090) | ||
.waitingFor(Wait.forListeningPort()); | ||
} | ||
|
||
protected static class ImagesForTests | ||
{ | ||
private final String image; | ||
private final String sourceMimetype; | ||
private final String targetMimetype; | ||
private final String filename; | ||
|
||
public ImagesForTests(String image, String sourceMimetype, String targetMimetype, String filename) | ||
{ | ||
this.image = Objects.requireNonNull(image); | ||
this.sourceMimetype = Objects.requireNonNull(sourceMimetype); | ||
this.targetMimetype = Objects.requireNonNull(targetMimetype); | ||
this.filename = Objects.requireNonNull(filename); | ||
} | ||
} | ||
|
||
private void sendTransformRequest(String url, String sourceMimetype, String targetMimetype, String filename) | ||
{ | ||
var builder = createRequestBuilder(sourceMimetype, targetMimetype, filename); | ||
WebClient client = WebClient.create(); | ||
WebClient.ResponseSpec responseSpec = client.post() | ||
.uri(url + "/test") | ||
.bodyValue(builder.build()) | ||
.retrieve(); | ||
|
||
System.out.println(responseSpec.toBodilessEntity().block()); | ||
assertEquals(OK, responseSpec.toBodilessEntity().block().getStatusCode()); | ||
} | ||
|
||
private MultipartBodyBuilder createRequestBuilder(String sourceMimetype, String targetMimetype, String filename) | ||
{ | ||
MultipartBodyBuilder builder = new MultipartBodyBuilder(); | ||
builder.part("_sourceMimetype", sourceMimetype); | ||
builder.part("_targetMimetype", targetMimetype); | ||
builder.part("file", new ClassPathResource(filename)); | ||
|
||
return builder; | ||
} | ||
|
||
private static void assertProbeDied(String url) | ||
{ | ||
WebTestClient client = WebTestClient.bindToServer().baseUrl(url+"/ready").build(); | ||
client.get() | ||
.exchange() | ||
.expectStatus().isEqualTo(TOO_MANY_REQUESTS); | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this file be moved to the concrete TEngine using it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of moving this file I used existing quick.jpg and quick.pdf files for ImageMagick and PdfRenderer tests. Removed my test files. |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this file be moved to the concrete TEngine using it? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* #%L | ||
* Alfresco Transform Core | ||
* %% | ||
* Copyright (C) 2005 - 2023 Alfresco Software Limited | ||
* %% | ||
* This file is part of the Alfresco software. | ||
* - | ||
* If the software was purchased under a paid Alfresco license, the terms of | ||
* the paid license agreement will prevail. Otherwise, the software is | ||
* provided under the following open source license terms: | ||
* - | ||
* Alfresco is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* - | ||
* Alfresco is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* - | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. | ||
* #L% | ||
*/ | ||
|
||
package org.alfresco.transform.imagemagick; | ||
|
||
import org.alfresco.transform.base.LivenessReadinessProbeTest; | ||
|
||
public class ImageMagickLivenessReadinessProbeTest extends LivenessReadinessProbeTest { | ||
@Override | ||
protected ImagesForTests getImageForTest() { | ||
return new ImagesForTests("alfresco-imagemagick", "image/jpeg", "image/png", "test.jpeg"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* #%L | ||
* Alfresco Transform Core | ||
* %% | ||
* Copyright (C) 2005 - 2023 Alfresco Software Limited | ||
* %% | ||
* This file is part of the Alfresco software. | ||
* - | ||
* If the software was purchased under a paid Alfresco license, the terms of | ||
* the paid license agreement will prevail. Otherwise, the software is | ||
* provided under the following open source license terms: | ||
* - | ||
* Alfresco is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* - | ||
* Alfresco is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* - | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. | ||
* #L% | ||
*/ | ||
|
||
package org.alfresco.transform.libreoffice; | ||
|
||
import org.alfresco.transform.base.LivenessReadinessProbeTest; | ||
|
||
public class LibreOfficeLivenessReadinessProbeTest extends LivenessReadinessProbeTest { | ||
@Override | ||
protected ImagesForTests getImageForTest() { | ||
return new ImagesForTests("alfresco-libreoffice", "text/plain", "application/pdf", "original.txt"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* #%L | ||
* Alfresco Transform Core | ||
* %% | ||
* Copyright (C) 2005 - 2023 Alfresco Software Limited | ||
* %% | ||
* This file is part of the Alfresco software. | ||
* - | ||
* If the software was purchased under a paid Alfresco license, the terms of | ||
* the paid license agreement will prevail. Otherwise, the software is | ||
* provided under the following open source license terms: | ||
* - | ||
* Alfresco is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* - | ||
* Alfresco is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* - | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. | ||
* #L% | ||
*/ | ||
|
||
package org.alfresco.transform.misc; | ||
|
||
import org.alfresco.transform.base.LivenessReadinessProbeTest; | ||
|
||
public class MiscLivenessReadinessProbeTest extends LivenessReadinessProbeTest { | ||
@Override | ||
protected ImagesForTests getImageForTest() { | ||
return new ImagesForTests("alfresco-transform-misc", "text/plain", "text/plain", "original.txt"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* #%L | ||
* Alfresco Transform Core | ||
* %% | ||
* Copyright (C) 2005 - 2023 Alfresco Software Limited | ||
* %% | ||
* This file is part of the Alfresco software. | ||
* - | ||
* If the software was purchased under a paid Alfresco license, the terms of | ||
* the paid license agreement will prevail. Otherwise, the software is | ||
* provided under the following open source license terms: | ||
* - | ||
* Alfresco is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* - | ||
* Alfresco is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* - | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. | ||
* #L% | ||
*/ | ||
|
||
package org.alfresco.transform.pdfrenderer; | ||
|
||
import org.alfresco.transform.base.LivenessReadinessProbeTest; | ||
|
||
public class PdfRendererLivenessReadinessProbeTest extends LivenessReadinessProbeTest { | ||
@Override | ||
protected ImagesForTests getImageForTest() { | ||
return new ImagesForTests("alfresco-pdf-renderer", "application/pdf", "image/png", "test.pdf"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* #%L | ||
* Alfresco Transform Core | ||
* %% | ||
* Copyright (C) 2005 - 2023 Alfresco Software Limited | ||
* %% | ||
* This file is part of the Alfresco software. | ||
* - | ||
* If the software was purchased under a paid Alfresco license, the terms of | ||
* the paid license agreement will prevail. Otherwise, the software is | ||
* provided under the following open source license terms: | ||
* - | ||
* Alfresco is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* - | ||
* Alfresco is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* - | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. | ||
* #L% | ||
*/ | ||
|
||
package org.alfresco.transform.tika; | ||
|
||
import org.alfresco.transform.base.LivenessReadinessProbeTest; | ||
|
||
|
||
public class TikaLivenessReadinessProbeTest extends LivenessReadinessProbeTest { | ||
@Override | ||
protected ImagesForTests getImageForTest() { | ||
return new ImagesForTests("alfresco-tika", "text/plain", "text/plain", "original.txt"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<scope>test</scope>
seems to be missing hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added missing scope
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update: after adding the scope all tests has failed:
TestEngine with ID 'junit-jupiter' failed to discover tests