forked from eclipse/microprofile-fault-tolerance
-
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.
#microprofile-fault-tolerance-182 Add more configuration based TCK tests
Solve eclipse#182 Signed-off-by: Antoine Sabot-Durand <antoine@sabot-durand.net>
- Loading branch information
Showing
9 changed files
with
782 additions
and
0 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
tck/src/main/java/org/eclipse/microprofile/fault/tolerance/tck/TimeoutGlobalConfigTest.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,80 @@ | ||
/* | ||
******************************************************************************* | ||
* Copyright (c) 2016-2017 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* You may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*******************************************************************************/ | ||
package org.eclipse.microprofile.fault.tolerance.tck; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.eclipse.microprofile.fault.tolerance.tck.timeout.clientserver.TimeoutClient; | ||
import org.eclipse.microprofile.faulttolerance.exceptions.TimeoutException; | ||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.testng.Arquillian; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.EmptyAsset; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
/** | ||
* Tests to exercise Fault Tolerance Timeouts. | ||
* | ||
* @author <a href="mailto:neil_young@uk.ibm.com">Neil Young</a> | ||
*/ | ||
public class TimeoutGlobalConfigTest extends Arquillian { | ||
|
||
@Deployment | ||
public static WebArchive deploy() { | ||
JavaArchive testJar = ShrinkWrap | ||
.create(JavaArchive.class, "ftTimeout.jar") | ||
.addClasses(TimeoutClient.class) | ||
.addAsManifestResource(new StringAsset( | ||
"Timeout/value=200"), "microprofile-config.properties") | ||
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml").as(JavaArchive.class); | ||
|
||
WebArchive war = ShrinkWrap.create(WebArchive.class, "ftTimeout.war").addAsLibrary(testJar); | ||
return war; | ||
} | ||
|
||
/** | ||
* A test to override timeout value by global config. | ||
* Default timeout is 1 second. We override its value with global property config. | ||
* The code below will timeout thanks to config | ||
*/ | ||
@Test | ||
public void testTimeout() { | ||
try { | ||
clientForTimeout.serviceA(500); | ||
Assert.fail("serviceA should throw a TimeoutException in testTimeout"); | ||
} | ||
catch (TimeoutException ex) { | ||
// Expected | ||
} | ||
catch (RuntimeException ex) { | ||
// Not Expected | ||
Assert.fail("serviceA should throw a TimeoutException in testTimeout not a RuntimeException"); | ||
} | ||
} | ||
|
||
private @Inject | ||
TimeoutClient clientForTimeout; | ||
|
||
|
||
} |
82 changes: 82 additions & 0 deletions
82
tck/src/main/java/org/eclipse/microprofile/fault/tolerance/tck/TimeoutMethodConfigTest.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,82 @@ | ||
/* | ||
******************************************************************************* | ||
* Copyright (c) 2016-2017 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* You may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*******************************************************************************/ | ||
package org.eclipse.microprofile.fault.tolerance.tck; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.eclipse.microprofile.fault.tolerance.tck.timeout.clientserver.TimeoutClient; | ||
import org.eclipse.microprofile.faulttolerance.exceptions.TimeoutException; | ||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.testng.Arquillian; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.EmptyAsset; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
/** | ||
* Tests to exercise Fault Tolerance Timeouts. | ||
* | ||
* @author <a href="mailto:neil_young@uk.ibm.com">Neil Young</a> | ||
*/ | ||
public class TimeoutMethodConfigTest extends Arquillian { | ||
|
||
@Deployment | ||
public static WebArchive deploy() { | ||
JavaArchive testJar = ShrinkWrap | ||
.create(JavaArchive.class, "ftTimeout.jar") | ||
.addClasses(TimeoutClient.class) | ||
.addAsManifestResource(new StringAsset( | ||
"org.eclipse.microprofile.fault.tolerance.tck.timeout.clientserver.TimeoutClient/" + | ||
"serviceA/Timeout/value=200") | ||
, "microprofile-config.properties") | ||
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml").as(JavaArchive.class); | ||
|
||
WebArchive war = ShrinkWrap.create(WebArchive.class, "ftTimeout.war").addAsLibrary(testJar); | ||
return war; | ||
} | ||
|
||
/** | ||
* A test to override timeout value by method config. | ||
* Default timeout is 1 second. We override its value with method property config. | ||
* The code below will timeout thanks to config | ||
*/ | ||
@Test | ||
public void testTimeout() { | ||
try { | ||
clientForTimeout.serviceA(500); | ||
Assert.fail("serviceA should throw a TimeoutException in testTimeout"); | ||
} | ||
catch (TimeoutException ex) { | ||
// Expected | ||
} | ||
catch (RuntimeException ex) { | ||
// Not Expected | ||
Assert.fail("serviceA should throw a TimeoutException in testTimeout not a RuntimeException"); | ||
} | ||
} | ||
|
||
private @Inject | ||
TimeoutClient clientForTimeout; | ||
|
||
|
||
} |
123 changes: 123 additions & 0 deletions
123
...n/java/org/eclipse/microprofile/fault/tolerance/tck/bulkhead/BulkheadSynchConfigTest.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,123 @@ | ||
/* | ||
******************************************************************************* | ||
* Copyright (c) 2017 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* You may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*******************************************************************************/ | ||
package org.eclipse.microprofile.fault.tolerance.tck.bulkhead; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.Future; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.eclipse.microprofile.fault.tolerance.tck.bulkhead.clientserver.BulkheadClassSemaphore3Bean; | ||
import org.eclipse.microprofile.fault.tolerance.tck.bulkhead.clientserver.BulkheadClassSemaphoreDefaultBean; | ||
import org.eclipse.microprofile.fault.tolerance.tck.bulkhead.clientserver.BulkheadTestBackend; | ||
import org.eclipse.microprofile.fault.tolerance.tck.bulkhead.clientserver.ParrallelBulkheadTest; | ||
import org.eclipse.microprofile.fault.tolerance.tck.bulkhead.clientserver.TestData; | ||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.testng.Arquillian; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.EmptyAsset; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.testng.ITestContext; | ||
import org.testng.annotations.BeforeTest; | ||
import org.testng.annotations.Test; | ||
|
||
//import org.jboss.arquillian.core.api.Asynchronousing.ExecutorService; | ||
|
||
/** | ||
* @author Gordon Hutchison | ||
*/ | ||
public class BulkheadSynchConfigTest extends Arquillian { | ||
|
||
/** | ||
* This is the Arquillian deploy method that controls the contents of the | ||
* war that contains all the tests. | ||
* | ||
* @return the test war "ftBulkheadSynchTest.war" | ||
*/ | ||
@Deployment | ||
public static WebArchive deploy() { | ||
JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, "ftBulkheadSynchTest.jar") | ||
.addPackage(BulkheadClassSemaphoreDefaultBean.class.getPackage()).addClass(Utils.class) | ||
.addAsManifestResource(new StringAsset( | ||
"Bulkhead/value=5"), "microprofile-config.properties") | ||
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml").as(JavaArchive.class); | ||
WebArchive war = ShrinkWrap.create(WebArchive.class, "ftBulkheadSynchTest.war").addAsLibrary(testJar); | ||
return war; | ||
} | ||
|
||
@BeforeTest | ||
public void beforeTest(final ITestContext testContext) { | ||
Utils.log("Testmethod: " + testContext.getName()); | ||
} | ||
|
||
/** | ||
* Tests taking Bulkhead3 waiting for 3 and no more workers and change its configuration by propoerty | ||
* to switch to 5 workers. Test wouldn't pass without property config working | ||
*/ | ||
@Test() | ||
public void testBulkheadClassSemaphore3() { | ||
TestData td = new TestData(new CountDownLatch(3)); | ||
threads(20, bhBeanClassSemaphore3, 5, td); | ||
td.check(); | ||
} | ||
|
||
/** | ||
* Run a number of Callable's in parallel | ||
* | ||
* @param number | ||
* @param test | ||
* @param maxSimultaneousWorkers | ||
*/ | ||
private void threads(int number, BulkheadTestBackend test, int maxSimultaneousWorkers, TestData td) { | ||
|
||
td.setExpectedMaxSimultaneousWorkers(maxSimultaneousWorkers); | ||
td.setExpectedInstances(number); | ||
Future[] results = new Future[number]; | ||
for (int i = 0; i < number; i++) { | ||
Utils.log("Starting test " + i); | ||
results[i] = xService.submit(new ParrallelBulkheadTest(test, td)); | ||
} | ||
|
||
Utils.handleResults(number, results); | ||
} | ||
|
||
/* | ||
* We use an executer service to simulate the parallelism of multiple | ||
* simultaneous requests | ||
*/ | ||
private static final int THREADPOOL_SIZE = 30; | ||
|
||
private ExecutorService xService = Executors.newFixedThreadPool(THREADPOOL_SIZE); | ||
|
||
/* | ||
* As the FaultTolerance annotation only work on business methods of | ||
* injected objects we need to inject a variety of these for use by the | ||
* tests below. The naming convention indicates if the annotation is on a | ||
* class or method, asynchronous or semaphore based, the size/value of | ||
* the {@code @Bulkhead} and whether we have queueing or not. | ||
*/ | ||
@Inject | ||
private BulkheadClassSemaphore3Bean bhBeanClassSemaphore3; | ||
|
||
} |
Oops, something went wrong.