forked from payara/Payara
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request payara#5315 from Pandrex247/FISH-758
FISH-758 Fault Tolerance Annotations Not Applied to Rest Client Interfaces
- Loading branch information
1 parent
c57d009
commit 80590c9
Showing
16 changed files
with
829 additions
and
82 deletions.
There are no files selected for viewing
382 changes: 346 additions & 36 deletions
382
...ce/src/main/java/fish/payara/microprofile/faulttolerance/cdi/FaultToleranceExtension.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
.../test/java/fish/payara/microprofile/faulttolerance/cdi/DetermineInterceptorIndexTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | ||
* | ||
* Copyright (c) 2021 Payara Foundation and/or its affiliates. All rights reserved. | ||
* | ||
* The contents of this file are subject to the terms of either the GNU | ||
* General Public License Version 2 only ("GPL") or the Common Development | ||
* and Distribution License("CDDL") (collectively, the "License"). You | ||
* may not use this file except in compliance with the License. You can | ||
* obtain a copy of the License at | ||
* https://github.com/payara/Payara/blob/master/LICENSE.txt | ||
* See the License for the specific | ||
* language governing permissions and limitations under the License. | ||
* | ||
* When distributing the software, include this License Header Notice in each | ||
* file and include the License file at glassfish/legal/LICENSE.txt. | ||
* | ||
* GPL Classpath Exception: | ||
* The Payara Foundation designates this particular file as subject to the "Classpath" | ||
* exception as provided by the Payara Foundation in the GPL Version 2 section of the License | ||
* file that accompanied this code. | ||
* | ||
* Modifications: | ||
* If applicable, add the following below the License Header, with the fields | ||
* enclosed by brackets [] replaced by your own identifying information: | ||
* "Portions Copyright [year] [name of copyright owner]" | ||
* | ||
* Contributor(s): | ||
* If you wish your version of this file to be governed by only the CDDL or | ||
* only the GPL Version 2, indicate your decision by adding "[Contributor] | ||
* elects to include this software in this distribution under the [CDDL or GPL | ||
* Version 2] license." If you don't indicate a single choice of license, a | ||
* recipient has the option to distribute your version of this file under | ||
* either the CDDL, the GPL Version 2 or to extend the choice of license to | ||
* its licensees as provided above. However, if you add GPL Version 2 code | ||
* and therefore, elected the GPL Version 2 license, then the option applies | ||
* only if the new code is made subject to such option by the copyright | ||
* holder. | ||
*/ | ||
|
||
package fish.payara.microprofile.faulttolerance.cdi; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Tests for the {@link FaultToleranceExtension#determineInterceptorIndex(List, int)} method. | ||
*/ | ||
public class DetermineInterceptorIndexTest { | ||
|
||
@Test | ||
public void determineInterceptorIndex() { | ||
List<Class<?>> interceptors = new ArrayList<>(); | ||
interceptors.add(DummyInterceptor1k.class); | ||
interceptors.add(DummyInterceptor2k.class); | ||
interceptors.add(DummyInterceptor3k.class); | ||
interceptors.add(DummyInterceptor4k.class); | ||
interceptors.add(DummyInterceptor5k.class); | ||
|
||
int index = FaultToleranceExtension.determineInterceptorIndex(interceptors, 3700); | ||
Assert.assertTrue(index == 3); | ||
|
||
index = FaultToleranceExtension.determineInterceptorIndex(interceptors, 6000); | ||
Assert.assertTrue(index == 4); | ||
|
||
index = FaultToleranceExtension.determineInterceptorIndex(interceptors, 5000); | ||
Assert.assertTrue(index == 4); | ||
|
||
index = FaultToleranceExtension.determineInterceptorIndex(interceptors, 2000); | ||
Assert.assertTrue(index == 1); | ||
|
||
index = FaultToleranceExtension.determineInterceptorIndex(interceptors, 500); | ||
Assert.assertTrue(index == 0); | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
...lerance/src/test/java/fish/payara/microprofile/faulttolerance/cdi/DummyInterceptor1k.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package fish.payara.microprofile.faulttolerance.cdi; | ||
|
||
import javax.annotation.Priority; | ||
|
||
@Priority(1000) | ||
public class DummyInterceptor1k { | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
...lerance/src/test/java/fish/payara/microprofile/faulttolerance/cdi/DummyInterceptor2k.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package fish.payara.microprofile.faulttolerance.cdi; | ||
|
||
import javax.annotation.Priority; | ||
|
||
@Priority(2000) | ||
public class DummyInterceptor2k { | ||
} |
7 changes: 7 additions & 0 deletions
7
...lerance/src/test/java/fish/payara/microprofile/faulttolerance/cdi/DummyInterceptor3k.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package fish.payara.microprofile.faulttolerance.cdi; | ||
|
||
import javax.annotation.Priority; | ||
|
||
@Priority(3000) | ||
public class DummyInterceptor3k { | ||
} |
7 changes: 7 additions & 0 deletions
7
...lerance/src/test/java/fish/payara/microprofile/faulttolerance/cdi/DummyInterceptor4k.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package fish.payara.microprofile.faulttolerance.cdi; | ||
|
||
import javax.annotation.Priority; | ||
|
||
@Priority(4000) | ||
public class DummyInterceptor4k { | ||
} |
7 changes: 7 additions & 0 deletions
7
...lerance/src/test/java/fish/payara/microprofile/faulttolerance/cdi/DummyInterceptor5k.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package fish.payara.microprofile.faulttolerance.cdi; | ||
|
||
import javax.annotation.Priority; | ||
|
||
@Priority(5000) | ||
public class DummyInterceptor5k { | ||
} |
36 changes: 36 additions & 0 deletions
36
appserver/tests/payara-samples/samples/microprofile-rc-ft/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>payara-samples-profiled-tests</artifactId> | ||
<groupId>fish.payara.samples</groupId> | ||
<version>5.2021.5-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>microprofile-rc-ft</artifactId> | ||
|
||
<name>Payara Samples - Payara - Microprofile Rest Client Fault Tolerance</name> | ||
<packaging>war</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>fish.payara.samples</groupId> | ||
<artifactId>samples-test-utils</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>jakarta.platform</groupId> | ||
<artifactId>jakarta.jakartaee-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.microprofile.rest.client</groupId> | ||
<artifactId>microprofile-rest-client-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.microprofile.fault-tolerance</groupId> | ||
<artifactId>microprofile-fault-tolerance-api</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
.../java/fish/payara/samples/microprofile/restclient/faulttolerance/HelloRemoteResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | ||
* | ||
* Copyright (c) 2021 Payara Foundation and/or its affiliates. All rights reserved. | ||
* | ||
* The contents of this file are subject to the terms of either the GNU | ||
* General Public License Version 2 only ("GPL") or the Common Development | ||
* and Distribution License("CDDL") (collectively, the "License"). You | ||
* may not use this file except in compliance with the License. You can | ||
* obtain a copy of the License at | ||
* https://github.com/payara/Payara/blob/master/LICENSE.txt | ||
* See the License for the specific | ||
* language governing permissions and limitations under the License. | ||
* | ||
* When distributing the software, include this License Header Notice in each | ||
* file and include the License file at glassfish/legal/LICENSE.txt. | ||
* | ||
* GPL Classpath Exception: | ||
* The Payara Foundation designates this particular file as subject to the "Classpath" | ||
* exception as provided by the Payara Foundation in the GPL Version 2 section of the License | ||
* file that accompanied this code. | ||
* | ||
* Modifications: | ||
* If applicable, add the following below the License Header, with the fields | ||
* enclosed by brackets [] replaced by your own identifying information: | ||
* "Portions Copyright [year] [name of copyright owner]" | ||
* | ||
* Contributor(s): | ||
* If you wish your version of this file to be governed by only the CDDL or | ||
* only the GPL Version 2, indicate your decision by adding "[Contributor] | ||
* elects to include this software in this distribution under the [CDDL or GPL | ||
* Version 2] license." If you don't indicate a single choice of license, a | ||
* recipient has the option to distribute your version of this file under | ||
* either the CDDL, the GPL Version 2 or to extend the choice of license to | ||
* its licensees as provided above. However, if you add GPL Version 2 code | ||
* and therefore, elected the GPL Version 2 license, then the option applies | ||
* only if the new code is made subject to such option by the copyright | ||
* holder. | ||
*/ | ||
package fish.payara.samples.microprofile.restclient.faulttolerance; | ||
|
||
import javax.ws.rs.*; | ||
import javax.ws.rs.core.MediaType; | ||
import java.util.logging.Logger; | ||
|
||
@Path("/hello") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
@Consumes(MediaType.TEXT_PLAIN) | ||
public class HelloRemoteResource { | ||
|
||
private static int counter = 0; | ||
private static final Logger LOGGER = Logger.getLogger(HelloRemoteResource.class.getName()); | ||
|
||
@Path("{name}") | ||
@GET | ||
public String hello(@PathParam("name") String name) { | ||
// check if we're down | ||
LOGGER.info(() -> String.format("Counter value: %s", counter)); | ||
if (isDown()) { | ||
LOGGER.warning(() -> String.format("Service unavailable, name: %s", name)); | ||
throw new ServiceUnavailableException(); | ||
} | ||
LOGGER.info(() -> String.format("Service available, name: %s", name)); | ||
return "Hello " + name + "!"; | ||
} | ||
|
||
private boolean isDown() { | ||
|
||
return counter++ % 2 == 1; | ||
} | ||
} |
Oops, something went wrong.