You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2018/08/28 22:59:23 UTC
[geode] 01/02: GEODE-5639: use AssertJ instead of CatchException
This is an automated email from the ASF dual-hosted git repository.
klund pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
commit f550cc48b15ccca2f4c91891b93adb16a044af06
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Mon Aug 27 11:47:47 2018 -0700
GEODE-5639: use AssertJ instead of CatchException
* Move PdxAttributesJUnitTest to distributedTest
---
.../connectors/jdbc/JdbcWriterIntegrationTest.java | 9 +-
...okenSerializationConsistencyRegressionTest.java | 12 +-
...ExceptionsIncludeLocalMemberRegressionTest.java | 54 +++++---
.../cache/execute/PRTransactionDUnitTest.java | 152 ++++++++++++---------
.../geode/pdx/PdxAttributesDistributedTest.java} | 88 +++++-------
.../test/dunit/tests/BasicDistributedTest.java | 73 +++++-----
.../LocatorLauncherIntegrationTest.java | 53 +++----
.../ServerLauncherBuilderIntegrationTest.java | 30 ++--
.../distributed/ServerLauncherIntegrationTest.java | 53 +++----
.../eviction/TransactionsWithOverflowTest.java | 43 +++---
.../FileProcessControllerIntegrationTest.java | 7 +-
.../pdx/PdxInstanceLoaderIntegrationTest.java | 30 ++--
.../apache/geode/distributed/LocatorStateTest.java | 34 ++---
.../cache/EntryEventSerializationTest.java | 6 +-
.../cache/xmlcache/CacheCreationJUnitTest.java | 15 +-
.../geode/internal/lang/ThrowableUtilsTest.java | 64 ++++-----
.../internal/offheap/FreeListManagerTest.java | 41 +++---
.../MemoryAllocatorFillPatternJUnitTest.java | 25 ++--
.../security/GemFireSecurityExceptionTest.java | 91 ++++++------
.../geode/security/NotAuthorizedExceptionTest.java | 97 ++++++-------
.../ParallelGatewaySenderOperationsDUnitTest.java | 11 +-
21 files changed, 481 insertions(+), 507 deletions(-)
diff --git a/geode-connectors/src/acceptanceTest/java/org/apache/geode/connectors/jdbc/JdbcWriterIntegrationTest.java b/geode-connectors/src/acceptanceTest/java/org/apache/geode/connectors/jdbc/JdbcWriterIntegrationTest.java
index 404d7c2..6f126be 100644
--- a/geode-connectors/src/acceptanceTest/java/org/apache/geode/connectors/jdbc/JdbcWriterIntegrationTest.java
+++ b/geode-connectors/src/acceptanceTest/java/org/apache/geode/connectors/jdbc/JdbcWriterIntegrationTest.java
@@ -14,9 +14,8 @@
*/
package org.apache.geode.connectors.jdbc;
-import static com.googlecode.catchexception.CatchException.catchException;
-import static com.googlecode.catchexception.CatchException.caughtException;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.catchThrowable;
import java.sql.Connection;
import java.sql.ResultSet;
@@ -58,7 +57,7 @@ public abstract class JdbcWriterIntegrationTest {
private Employee employee2;
@Before
- public void setup() throws Exception {
+ public void setUp() throws Exception {
cache = (InternalCache) new CacheFactory().set("locators", "").set("mcast-port", "0")
.setPdxReadSerialized(false).create();
employees = createRegionWithJDBCSynchronousWriter(REGION_TABLE_NAME);
@@ -138,8 +137,8 @@ public abstract class JdbcWriterIntegrationTest {
@Test
public void putNonPdxInstanceFails() {
Region nonPdxEmployees = this.employees;
- catchException(nonPdxEmployees).put("1", "non pdx instance");
- assertThat((Exception) caughtException()).isInstanceOf(IllegalArgumentException.class);
+ Throwable thrown = catchThrowable(() -> nonPdxEmployees.put("1", "non pdx instance"));
+ assertThat(thrown).isInstanceOf(IllegalArgumentException.class);
}
@Test
diff --git a/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/BrokenSerializationConsistencyRegressionTest.java b/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/BrokenSerializationConsistencyRegressionTest.java
index da6365b..be39bbd 100644
--- a/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/BrokenSerializationConsistencyRegressionTest.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/BrokenSerializationConsistencyRegressionTest.java
@@ -14,13 +14,12 @@
*/
package org.apache.geode.internal.cache;
-import static com.googlecode.catchexception.CatchException.catchException;
-import static com.googlecode.catchexception.CatchException.caughtException;
import static org.apache.geode.cache.RegionShortcut.REPLICATE;
import static org.apache.geode.internal.lang.SystemPropertyHelper.EARLY_ENTRY_EVENT_SERIALIZATION;
import static org.apache.geode.internal.lang.SystemPropertyHelper.GEODE_PREFIX;
import static org.apache.geode.test.dunit.VM.getVM;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.catchThrowable;
import java.io.DataInput;
import java.io.DataOutput;
@@ -109,9 +108,8 @@ public class BrokenSerializationConsistencyRegressionTest implements Serializabl
@Test
public void failureToDataSerializeFailsToPropagate() {
Region<String, DataSerializable> region = cacheRule.getCache().getRegion(REGION_NAME);
- catchException(region).put(KEY, valueFailsToSerialize);
+ Throwable caughtException = catchThrowable(() -> region.put(KEY, valueFailsToSerialize));
- Exception caughtException = caughtException();
assertThat(caughtException).isInstanceOf(ToDataException.class);
assertThat(caughtException.getCause()).isInstanceOf(IOException.class)
.hasMessage("FailsToSerialize");
@@ -131,9 +129,8 @@ public class BrokenSerializationConsistencyRegressionTest implements Serializabl
txManager.begin();
region2.put(KEY, stringValue);
region.put(KEY, valueFailsToSerialize);
- catchException(txManager).commit();
+ Throwable caughtException = catchThrowable(() -> txManager.commit());
- Exception caughtException = caughtException();
assertThat(caughtException).isInstanceOf(ToDataException.class);
assertThat(caughtException.getCause()).isInstanceOf(IOException.class)
.hasMessage("FailsToSerialize");
@@ -151,9 +148,8 @@ public class BrokenSerializationConsistencyRegressionTest implements Serializabl
@Test
public void failureToPdxSerializeFails() {
Region<String, PdxSerializable> region = cacheRule.getCache().getRegion(REGION_NAME);
- catchException(region).put(KEY, pdxValueFailsToSerialize);
+ Throwable caughtException = catchThrowable(() -> region.put(KEY, pdxValueFailsToSerialize));
- Exception caughtException = caughtException();
assertThat(caughtException).isInstanceOf(ToDataException.class);
assertThat(caughtException.getCause()).isInstanceOf(UncheckedIOException.class);
assertThat(caughtException.getCause().getCause()).isInstanceOf(IOException.class)
diff --git a/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/execute/FunctionExceptionsIncludeLocalMemberRegressionTest.java b/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/execute/FunctionExceptionsIncludeLocalMemberRegressionTest.java
index f128a86..eadc2ca 100644
--- a/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/execute/FunctionExceptionsIncludeLocalMemberRegressionTest.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/execute/FunctionExceptionsIncludeLocalMemberRegressionTest.java
@@ -14,12 +14,14 @@
*/
package org.apache.geode.internal.cache.execute;
-import static com.googlecode.catchexception.CatchException.catchException;
-import static com.googlecode.catchexception.CatchException.caughtException;
-import static org.apache.geode.test.dunit.Host.getHost;
+import static org.apache.geode.test.dunit.VM.getVM;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.catchThrowable;
+
+import java.io.Serializable;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -33,8 +35,10 @@ import org.apache.geode.cache.execute.FunctionException;
import org.apache.geode.cache.execute.FunctionService;
import org.apache.geode.cache.execute.ResultCollector;
import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.cache.CacheTestCase;
+import org.apache.geode.test.dunit.rules.CacheRule;
+import org.apache.geode.test.dunit.rules.DistributedRule;
import org.apache.geode.test.junit.categories.FunctionServiceTest;
+import org.apache.geode.test.junit.rules.serializable.SerializableTestName;
/**
* TRAC #41779: InternalExecution.setWaitOnExceptionFlag(true) does not add the exception from the
@@ -43,57 +47,63 @@ import org.apache.geode.test.junit.categories.FunctionServiceTest;
* <p>
* Extracted from {@link PRFunctionExecutionDUnitTest}.
*/
-@Category({FunctionServiceTest.class})
+@Category(FunctionServiceTest.class)
@SuppressWarnings("serial")
-public class FunctionExceptionsIncludeLocalMemberRegressionTest extends CacheTestCase {
+public class FunctionExceptionsIncludeLocalMemberRegressionTest implements Serializable {
private Execution execution;
+ @Rule
+ public DistributedRule distributedRule = new DistributedRule();
+
+ @Rule
+ public CacheRule cacheRule = new CacheRule();
+
+ @Rule
+ public SerializableTestName testName = new SerializableTestName();
+
@Before
public void setUp() {
- VM datastore1 = getHost(0).getVM(0);
- VM datastore2 = getHost(0).getVM(1);
- VM datastore3 = getHost(0).getVM(2);
- VM datastore4 = getHost(0).getVM(3);
+ VM datastore1 = getVM(0);
+ VM datastore2 = getVM(1);
- String regionName = getUniqueName();
+ String regionName = getClass().getSimpleName() + "_" + testName.getMethodName();
// create stores on all VMs including controller
datastore1.invoke(() -> createPartitionedRegion(regionName));
datastore2.invoke(() -> createPartitionedRegion(regionName));
- datastore3.invoke(() -> createPartitionedRegion(regionName));
- datastore4.invoke(() -> createPartitionedRegion(regionName));
createPartitionedRegion(regionName);
datastore1.invoke(() -> registerThrowsExceptionFunction());
datastore2.invoke(() -> registerThrowsExceptionFunction());
- datastore3.invoke(() -> registerThrowsExceptionFunction());
- datastore4.invoke(() -> registerThrowsExceptionFunction());
registerThrowsExceptionFunction();
- execution = FunctionService.onRegion(cache.getRegion(regionName));
+ execution = FunctionService.onRegion(cacheRule.getCache().getRegion(regionName));
((InternalExecution) execution).setWaitOnExceptionFlag(true);
}
@Test
- public void functionExceptionsIncludeLocalMember() throws Exception {
+ public void functionExceptionsIncludeLocalMember() {
ResultCollector resultCollector = execution.execute(ThrowsExceptionFunction.class.getName());
- catchException(resultCollector).getResult();
- assertThat((Exception) caughtException()).isInstanceOf(FunctionException.class);
+ Throwable thrown = catchThrowable(() -> resultCollector.getResult());
+ assertThat(thrown).isInstanceOf(FunctionException.class);
- FunctionException functionException = caughtException();
- assertThat(functionException.getExceptions()).hasSize(5);
+ FunctionException functionException = (FunctionException) thrown;
+ assertThat(functionException.getExceptions()).hasSize(3);
}
private void createPartitionedRegion(final String regionName) {
+ cacheRule.createCache();
+
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setLocalMaxMemory(10);
paf.setRedundantCopies(0);
- RegionFactory regionFactory = getCache().createRegionFactory(RegionShortcut.PARTITION);
+ RegionFactory regionFactory =
+ cacheRule.getCache().createRegionFactory(RegionShortcut.PARTITION);
regionFactory.setPartitionAttributes(paf.create());
regionFactory.create(regionName);
diff --git a/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/execute/PRTransactionDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/execute/PRTransactionDUnitTest.java
index 0575e6f..ef5a397 100644
--- a/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/execute/PRTransactionDUnitTest.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/execute/PRTransactionDUnitTest.java
@@ -14,8 +14,7 @@
*/
package org.apache.geode.internal.cache.execute;
-import static com.googlecode.catchexception.CatchException.catchException;
-import static com.googlecode.catchexception.CatchException.caughtException;
+import static org.assertj.core.api.Assertions.catchThrowable;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -74,35 +73,33 @@ import org.apache.geode.test.dunit.SerializableRunnable;
/**
* Test for co-located PR transactions. the test creates two data hosts and uses function execution
* to execute transactions.
- *
*/
-
public class PRTransactionDUnitTest extends PRColocationDUnitTest {
private static final Logger logger = LogService.getLogger();
- public static final int VERIFY_TX = 0;
+ static final int VERIFY_TX = 0;
- public static final int VERIFY_ROLLBACK = 1;
+ static final int VERIFY_ROLLBACK = 1;
- public static final int VERIFY_NON_COLOCATION = 2;
+ static final int VERIFY_NON_COLOCATION = 2;
- public static final int VERIFY_DESTROY = 4;
+ static final int VERIFY_DESTROY = 4;
- public static final int VERIFY_LISTENER_CALLBACK = 5;
+ static final int VERIFY_LISTENER_CALLBACK = 5;
- public static final int VERIFY_INVALIDATE = 6;
+ static final int VERIFY_INVALIDATE = 6;
- public static final int VERIFY_TXSTATE_CONFLICT = 7;
+ static final int VERIFY_TXSTATE_CONFLICT = 7;
- public static final int VERIFY_REP_READ = 8;
+ static final int VERIFY_REP_READ = 8;
- public static final int UPDATE_NON_COLOCATION = 9;
+ static final int UPDATE_NON_COLOCATION = 9;
- final int totalIterations = 50;
+ private final int totalIterations = 50;
- final int warmupIterations = 10;
+ private final int warmupIterations = 10;
- final int perfOrderShipmentPairs = 1;
+ private final int perfOrderShipmentPairs = 1;
public PRTransactionDUnitTest() {
super();
@@ -149,7 +146,7 @@ public class PRTransactionDUnitTest extends PRColocationDUnitTest {
*
* @param redundantBuckets redundant buckets for colocated PRs
*/
- protected void basicPRTXInNonColocatedFunction(int redundantBuckets) {
+ private void basicPRTXInNonColocatedFunction(int redundantBuckets) {
setupColocatedRegions(redundantBuckets);
dataStore1.invoke(() -> registerFunction());
@@ -212,7 +209,7 @@ public class PRTransactionDUnitTest extends PRColocationDUnitTest {
* @param redundantBuckets redundant buckets for colocated PRs
* @param populateData if false tests are carried out on empty colocated PRs
*/
- protected void basicPRTXInFunction(int redundantBuckets, boolean populateData) {
+ private void basicPRTXInFunction(int redundantBuckets, boolean populateData) {
if (populateData) {
createPopulateAndVerifyCoLocatedPRs(redundantBuckets);
@@ -225,7 +222,8 @@ public class PRTransactionDUnitTest extends PRColocationDUnitTest {
dataStore3.invoke(() -> registerFunction());
accessor.invoke(new SerializableCallable("run function") {
- public Object call() throws Exception {
+ @Override
+ public Object call() {
PartitionedRegion pr = (PartitionedRegion) basicGetCache()
.getRegion(Region.SEPARATOR + CustomerPartitionedRegionName);
PartitionedRegion orderpr = (PartitionedRegion) basicGetCache()
@@ -293,7 +291,7 @@ public class PRTransactionDUnitTest extends PRColocationDUnitTest {
});
}
- protected void createColocatedPRs(int redundantBuckets) {
+ private void createColocatedPRs(int redundantBuckets) {
createCacheInAllVms();
redundancy = new Integer(redundantBuckets);
@@ -323,13 +321,14 @@ public class PRTransactionDUnitTest extends PRColocationDUnitTest {
}
private SerializableCallable runGetCache = new SerializableCallable("runGetCache") {
- public Object call() throws Exception {
+ @Override
+ public Object call() {
getCache();
return null;
}
};
- protected void populateAndVerifyColocatedPRs(int redundantBuckets) {
+ private void populateAndVerifyColocatedPRs(int redundantBuckets) {
// Put the customer 1-10 in CustomerPartitionedRegion
accessor.invoke(
() -> PRColocationDUnitTest.putCustomerPartitionedRegion(CustomerPartitionedRegionName));
@@ -373,18 +372,18 @@ public class PRTransactionDUnitTest extends PRColocationDUnitTest {
}
- protected void createPopulateAndVerifyCoLocatedPRs(int redundantBuckets) {
+ private void createPopulateAndVerifyCoLocatedPRs(int redundantBuckets) {
createColocatedPRs(redundantBuckets);
populateAndVerifyColocatedPRs(redundantBuckets);
}
- protected void createPRWithCoLocation(String prName, String coLocatedWith) {
+ private void createPRWithCoLocation(String prName, String coLocatedWith) {
setAttributes(prName, coLocatedWith);
createPartitionedRegion(attributeObjects);
}
- protected void setAttributes(String prName, String coLocatedWith) {
+ private void setAttributes(String prName, String coLocatedWith) {
this.regionName = prName;
this.colocatedWith = coLocatedWith;
this.isPartitionResolver = new Boolean(true);
@@ -402,7 +401,7 @@ public class PRTransactionDUnitTest extends PRColocationDUnitTest {
*
* @param bucketRedundancy redundancy for the colocated PRs
*/
- protected void basicPRTXWithNonColocatedGet(int bucketRedundancy) {
+ private void basicPRTXWithNonColocatedGet(int bucketRedundancy) {
setupColocatedRegions(bucketRedundancy);
dataStore1.invoke(verifyNonColocated);
@@ -541,7 +540,7 @@ public class PRTransactionDUnitTest extends PRColocationDUnitTest {
* @param bucketRedundancy redundancy for the colocated PRs
*/
@SuppressWarnings("unchecked")
- protected void basicPRTXWithOpOnMovedBucket(Op op, int bucketRedundancy, DistributedMember dm1,
+ private void basicPRTXWithOpOnMovedBucket(Op op, int bucketRedundancy, DistributedMember dm1,
DistributedMember dm2) {
// First transaction.
TransactionId txId = dataStore1.invoke(() -> beginTx(false));
@@ -594,10 +593,6 @@ public class PRTransactionDUnitTest extends PRColocationDUnitTest {
};
}
- enum Op {
- GET, CONTAINSVALUEFORKEY, CONTAINSKEY, CREATE, PUT, INVALIDATE, DESTROY, GETENTRY;
- }
-
private void _resumeTx(Op op, TransactionId txId, PartitionedRegion pr,
CacheTransactionManager mgr) {
CustId cust1 = new CustId(1);
@@ -686,6 +681,7 @@ public class PRTransactionDUnitTest extends PRColocationDUnitTest {
private void setBucketReadHook(OrderId order1, DistributedMember source,
DistributedMember destination, PartitionedRegion prOrder) {
prOrder.getDataStore().setBucketReadHook(new Runnable() {
+ @Override
@SuppressWarnings("unchecked")
public void run() {
LogService.getLogger().info("In bucketReadHook");
@@ -735,7 +731,7 @@ public class PRTransactionDUnitTest extends PRColocationDUnitTest {
*
* @param bucketRedundancy redundancy for the colocated PRs
*/
- protected void basicPRTXWithNonColocatedOp(Op op, int bucketRedundancy) {
+ private void basicPRTXWithNonColocatedOp(Op op, int bucketRedundancy) {
dataStore1.invoke(verifyNonColocated);
dataStore2.invoke(verifyNonColocated);
@@ -819,7 +815,7 @@ public class PRTransactionDUnitTest extends PRColocationDUnitTest {
}
}
- private boolean useBucketReadHook = false;
+ private boolean useBucketReadHook;
@SuppressWarnings("unchecked")
@Test
@@ -869,7 +865,7 @@ public class PRTransactionDUnitTest extends PRColocationDUnitTest {
*
* @param bucketRedundancy redundancy for the colocated PRs
*/
- protected void basicPRTXInCacheListener(int bucketRedundancy) {
+ private void basicPRTXInCacheListener(int bucketRedundancy) {
createCacheInAllVms();
redundancy = new Integer(bucketRedundancy);
localMaxmemory = new Integer(50);
@@ -879,7 +875,8 @@ public class PRTransactionDUnitTest extends PRColocationDUnitTest {
createPRWithCoLocation(OrderPartitionedRegionName, CustomerPartitionedRegionName);
// register Cache Listeners
SerializableCallable registerListeners = new SerializableCallable() {
- public Object call() throws Exception {
+ @Override
+ public Object call() {
Region custRegion =
basicGetCache().getRegion(Region.SEPARATOR + CustomerPartitionedRegionName);
custRegion.getAttributesMutator().addCacheListener(new TransactionListener());
@@ -905,7 +902,7 @@ public class PRTransactionDUnitTest extends PRColocationDUnitTest {
* verify that 10 orders are created for each customer
*
*/
- public static void validatePRTXInCacheListener() throws ClassNotFoundException {
+ private static void validatePRTXInCacheListener() {
PartitionedRegion customerPartitionedregion = null;
PartitionedRegion orderPartitionedregion = null;
try {
@@ -954,7 +951,8 @@ public class PRTransactionDUnitTest extends PRColocationDUnitTest {
createPopulateAndVerifyCoLocatedPRs(1);
SerializableCallable registerListeners = new SerializableCallable() {
- public Object call() throws Exception {
+ @Override
+ public Object call() {
Region custRegion =
basicGetCache().getRegion(Region.SEPARATOR + CustomerPartitionedRegionName);
custRegion.getAttributesMutator().addCacheListener(new TransactionListener2());
@@ -968,7 +966,8 @@ public class PRTransactionDUnitTest extends PRColocationDUnitTest {
dataStore3.invoke(registerListeners);
accessor.invoke(new SerializableCallable("run function") {
- public Object call() throws Exception {
+ @Override
+ public Object call() {
PartitionedRegion pr = (PartitionedRegion) basicGetCache()
.getRegion(Region.SEPARATOR + CustomerPartitionedRegionName);
PartitionedRegion orderpr = (PartitionedRegion) basicGetCache()
@@ -1002,7 +1001,7 @@ public class PRTransactionDUnitTest extends PRColocationDUnitTest {
}
@Test
- public void testRepeatableRead() throws Exception {
+ public void testRepeatableRead() {
createColocatedPRs(1);
dataStore1.invoke(() -> registerFunction());
@@ -1010,7 +1009,8 @@ public class PRTransactionDUnitTest extends PRColocationDUnitTest {
dataStore3.invoke(() -> registerFunction());
accessor.invoke(new SerializableCallable("run function") {
- public Object call() throws Exception {
+ @Override
+ public Object call() {
PartitionedRegion pr = (PartitionedRegion) basicGetCache()
.getRegion(Region.SEPARATOR + CustomerPartitionedRegionName);
PartitionedRegion orderpr = (PartitionedRegion) basicGetCache()
@@ -1042,14 +1042,15 @@ public class PRTransactionDUnitTest extends PRColocationDUnitTest {
}
@Test
- public void testPRTXPerformance() throws Exception {
+ public void testPRTXPerformance() {
PRColocationDUnitTestHelper.defaultStringSize = 1024;
createPopulateAndVerifyCoLocatedPRs(1);
// register functions
SerializableCallable registerPerfFunctions = new SerializableCallable("register Fn") {
- public Object call() throws Exception {
+ @Override
+ public Object call() {
Function perfFunction = new PerfFunction();
FunctionService.registerFunction(perfFunction);
Function perfTxFunction = new PerfTxFunction();
@@ -1064,7 +1065,8 @@ public class PRTransactionDUnitTest extends PRColocationDUnitTest {
accessor.invoke(registerPerfFunctions);
SerializableCallable runPerfFunction = new SerializableCallable("runPerfFunction") {
- public Object call() throws Exception {
+ @Override
+ public Object call() {
long perfTime = 0;
Region customerPR = basicGetCache().getRegion(CustomerPartitionedRegionName);
Execution execution = FunctionService.onRegion(customerPR);
@@ -1102,7 +1104,8 @@ public class PRTransactionDUnitTest extends PRColocationDUnitTest {
Long perfTime = (Long) accessor.invoke(runPerfFunction);
SerializableCallable runPerfTxFunction = new SerializableCallable("runPerfTxFunction") {
- public Object call() throws Exception {
+ @Override
+ public Object call() {
long perfTime = 0;
Region customerPR = basicGetCache().getRegion(CustomerPartitionedRegionName);
Execution execution = FunctionService.onRegion(customerPR);
@@ -1161,7 +1164,7 @@ public class PRTransactionDUnitTest extends PRColocationDUnitTest {
*
* @param redundantBuckets redundant buckets for colocated PRs
*/
- protected void basicPRTXCommitToFailAfterPrimaryBucketMoved(int redundantBuckets) {
+ private void basicPRTXCommitToFailAfterPrimaryBucketMoved(int redundantBuckets) {
setupColocatedRegions(redundantBuckets);
InternalDistributedMember dm1 = (InternalDistributedMember) dataStore1.invoke(getDM());
@@ -1200,66 +1203,76 @@ public class PRTransactionDUnitTest extends PRColocationDUnitTest {
mgr.resume(txId);
- catchException(mgr).commit();
- assertTrue(caughtException() instanceof TransactionDataRebalancedException);
+ Throwable thrown = catchThrowable(() -> mgr.commit());
+ assertTrue(thrown instanceof TransactionDataRebalancedException);
}
// Don't want to run the test twice
+ @Override
@Test
- public void testColocatedPartitionedRegion() throws Throwable {}
+ public void testColocatedPartitionedRegion() {}
+ @Override
@Test
- public void testColocationPartitionedRegion() throws Throwable {}
+ public void testColocationPartitionedRegion() {}
+ @Override
@Test
- public void testColocationPartitionedRegionWithRedundancy() throws Throwable {}
+ public void testColocationPartitionedRegionWithRedundancy() {}
+ @Override
@Test
- public void testPartitionResolverPartitionedRegion() throws Throwable {}
+ public void testPartitionResolverPartitionedRegion() {}
+ @Override
@Test
public void testColocationPartitionedRegionWithNullColocationSpecifiedOnOneNode() {}
@Override
@Test
- public void testColocatedPRRedundancyRecovery() throws Throwable {}
+ public void testColocatedPRRedundancyRecovery() {}
@Override
@Test
- public void testColocatedPRWithAccessorOnDifferentNode1() throws Throwable {}
+ public void testColocatedPRWithAccessorOnDifferentNode1() {}
@Override
@Test
- public void testColocatedPRWithAccessorOnDifferentNode2() throws Throwable {}
+ public void testColocatedPRWithAccessorOnDifferentNode2() {}
@Override
@Test
- public void testColocatedPRWithDestroy() throws Throwable {}
+ public void testColocatedPRWithDestroy() {}
@Override
@Test
- public void testColocatedPRWithLocalDestroy() throws Throwable {}
+ public void testColocatedPRWithLocalDestroy() {}
@Override
@Test
- public void testColocatedPRWithPROnDifferentNode1() throws Throwable {}
+ public void testColocatedPRWithPROnDifferentNode1() {}
@Override
- public final void preTearDownCacheTestCase() throws Exception {
+ public final void preTearDownCacheTestCase() {
Invoke.invokeInEveryVM(verifyNoTxState);
}
- SerializableCallable verifyNoTxState = new SerializableCallable() {
+ private SerializableCallable verifyNoTxState = new SerializableCallable() {
@Override
- public Object call() throws Exception {
+ public Object call() {
TXManagerImpl mgr = getGemfireCache().getTxManager();
assertEquals(0, mgr.hostedTransactionsInProgressForTest());
return null;
}
};
- class TransactionListener extends CacheListenerAdapter {
+ enum Op {
+ GET, CONTAINSVALUEFORKEY, CONTAINSKEY, CREATE, PUT, INVALIDATE, DESTROY, GETENTRY;
+ }
+
+ static class TransactionListener extends CacheListenerAdapter {
+ @Override
public void afterCreate(EntryEvent event) {
// for each customer, put 10 orders in a tx.
Region custPR = event.getRegion();
@@ -1285,41 +1298,46 @@ public class PRTransactionDUnitTest extends PRColocationDUnitTest {
}
static class TransactionListener2 extends CacheListenerAdapter {
- private int numberOfPutCallbacks = 0;
- private int numberOfDestroyCallbacks = 0;
- private int numberOfInvalidateCallbacks = 0;
+ private int numberOfPutCallbacks;
+ private int numberOfDestroyCallbacks;
+ private int numberOfInvalidateCallbacks;
+
+ @Override
public void afterCreate(EntryEvent event) {
synchronized (this) {
numberOfPutCallbacks++;
}
}
+ @Override
public void afterUpdate(EntryEvent event) {
afterCreate(event);
}
+ @Override
public void afterDestroy(EntryEvent event) {
synchronized (this) {
numberOfDestroyCallbacks++;
}
}
+ @Override
public void afterInvalidate(EntryEvent event) {
synchronized (this) {
numberOfInvalidateCallbacks++;
}
}
- public synchronized int getNumberOfPutCallbacks() {
+ synchronized int getNumberOfPutCallbacks() {
return numberOfPutCallbacks;
}
- public synchronized int getNumberOfDestroyCallbacks() {
+ synchronized int getNumberOfDestroyCallbacks() {
return numberOfDestroyCallbacks;
}
- public synchronized int getNumberOfInvalidateCallbacks() {
+ synchronized int getNumberOfInvalidateCallbacks() {
return numberOfInvalidateCallbacks;
}
}
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/pdx/PdxAttributesJUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/pdx/PdxAttributesDistributedTest.java
similarity index 81%
rename from geode-core/src/integrationTest/java/org/apache/geode/pdx/PdxAttributesJUnitTest.java
rename to geode-core/src/distributedTest/java/org/apache/geode/pdx/PdxAttributesDistributedTest.java
index 175af2a..8075486 100644
--- a/geode-core/src/integrationTest/java/org/apache/geode/pdx/PdxAttributesJUnitTest.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/pdx/PdxAttributesDistributedTest.java
@@ -1,30 +1,29 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You 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
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ * 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.apache.geode.pdx;
-import static com.googlecode.catchexception.CatchException.catchException;
-import static com.googlecode.catchexception.CatchException.caughtException;
import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.catchThrowable;
import static org.junit.Assert.assertEquals;
import java.io.File;
-import java.io.FilenameFilter;
import java.io.IOException;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import org.apache.commons.io.FileUtils;
@@ -41,7 +40,6 @@ import org.apache.geode.cache.CacheWriterException;
import org.apache.geode.cache.DataPolicy;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.RegionShortcut;
-import org.apache.geode.cache.asyncqueue.AsyncEvent;
import org.apache.geode.cache.asyncqueue.AsyncEventListener;
import org.apache.geode.cache.client.PoolManager;
import org.apache.geode.distributed.ConfigurationProperties;
@@ -57,8 +55,8 @@ import org.apache.geode.pdx.internal.PeerTypeRegistration;
import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase;
import org.apache.geode.test.junit.categories.SerializationTest;
-@Category({SerializationTest.class})
-public class PdxAttributesJUnitTest extends JUnit4CacheTestCase {
+@Category(SerializationTest.class)
+public class PdxAttributesDistributedTest extends JUnit4CacheTestCase {
private File diskDir;
@@ -81,12 +79,8 @@ public class PdxAttributesJUnitTest extends JUnit4CacheTestCase {
cache.close();
}
FileUtils.deleteDirectory(diskDir);
- File[] defaultStoreFiles = new File(".").listFiles(new FilenameFilter() {
-
- public boolean accept(File dir, String name) {
- return name.startsWith("BACKUPPDXAttributes");
- }
- });
+ File[] defaultStoreFiles = new File(".").listFiles(
+ (dir, name) -> name.startsWith("BACKUPPDXAttributes"));
for (File file : defaultStoreFiles) {
FileUtils.forceDelete(file);
@@ -296,9 +290,8 @@ public class PdxAttributesJUnitTest extends JUnit4CacheTestCase {
initCache(true, false, null);
Region region = createRegion(true, false);
- catchException(this).defineATypeNoEnum();
- assertThat((Exception) caughtException())
- .isExactlyInstanceOf(PdxInitializationException.class);
+ Throwable thrown = catchThrowable(() -> defineATypeNoEnum());
+ assertThat(thrown).isExactlyInstanceOf(PdxInitializationException.class);
// Drop partitioned region.
region.destroyRegion();
@@ -310,9 +303,8 @@ public class PdxAttributesJUnitTest extends JUnit4CacheTestCase {
{
initCache(true, false, null);
defineATypeNoEnum();
- catchException(this).createRegion(true, false);
- assertThat((Exception) caughtException())
- .isExactlyInstanceOf(PdxInitializationException.class);
+ Throwable thrown = catchThrowable(() -> createRegion(true, false));
+ assertThat(thrown).isExactlyInstanceOf(PdxInitializationException.class);
}
}
@@ -321,9 +313,8 @@ public class PdxAttributesJUnitTest extends JUnit4CacheTestCase {
{
initCache(true, false, null);
Region region = createRegion(true, true);
- catchException(this).defineATypeNoEnum();
- assertThat((Exception) caughtException())
- .isExactlyInstanceOf(PdxInitializationException.class);
+ Throwable thrown = catchThrowable(() -> defineATypeNoEnum());
+ assertThat(thrown).isExactlyInstanceOf(PdxInitializationException.class);
// Drop partitioned region.
region.destroyRegion();
@@ -336,9 +327,8 @@ public class PdxAttributesJUnitTest extends JUnit4CacheTestCase {
{
initCache(true, false, null);
defineATypeNoEnum();
- catchException(this).createRegion(true, true);
- assertThat((Exception) caughtException())
- .isExactlyInstanceOf(PdxInitializationException.class);
+ Throwable thrown = catchThrowable(() -> createRegion(true, true));
+ assertThat(thrown).isExactlyInstanceOf(PdxInitializationException.class);
}
}
@@ -364,9 +354,8 @@ public class PdxAttributesJUnitTest extends JUnit4CacheTestCase {
{
initCache(true, false, null);
definePersistentAEQ(cache, "aeq", true);
- catchException(this).defineATypeNoEnum();
- assertThat((Exception) caughtException())
- .isExactlyInstanceOf(PdxInitializationException.class);
+ Throwable thrown = catchThrowable(() -> defineATypeNoEnum());
+ assertThat(thrown).isExactlyInstanceOf(PdxInitializationException.class);
}
tearDown();
setUp();
@@ -374,9 +363,8 @@ public class PdxAttributesJUnitTest extends JUnit4CacheTestCase {
{
initCache(true, false, null);
defineATypeNoEnum();
- catchException(this).definePersistentAEQ(cache, "aeq", true);
- assertThat((Exception) caughtException())
- .isExactlyInstanceOf(PdxInitializationException.class);
+ Throwable thrown = catchThrowable(() -> definePersistentAEQ(cache, "aeq", true));
+ assertThat(thrown).isExactlyInstanceOf(PdxInitializationException.class);
}
}
@@ -401,18 +389,18 @@ public class PdxAttributesJUnitTest extends JUnit4CacheTestCase {
int port = AvailablePortHelper.getRandomAvailableTCPPort();
PoolManager.createFactory().addServer("localhost", port).create("pool");
- catchException(this).defineAType();
- assertThat((Exception) caughtException()).isExactlyInstanceOf(ToDataException.class);
+ Throwable thrown = catchThrowable(() -> defineAType());
+ assertThat(thrown).isExactlyInstanceOf(ToDataException.class);
}
}
- public void defineAType() throws IOException {
+ private void defineAType() throws IOException {
SimpleClass sc = new SimpleClass(1, (byte) 2);
HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT);
DataSerializer.writeObject(sc, out);
}
- public void defineATypeNoEnum() throws /* IO */ Exception {
+ private void defineATypeNoEnum() throws /* IO */ Exception {
SimpleClass sc = new SimpleClass(1, (byte) 2, null);
HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT);
DataSerializer.writeObject(sc, out);
@@ -441,7 +429,7 @@ public class PdxAttributesJUnitTest extends JUnit4CacheTestCase {
}
}
- public Region createRegion(boolean persistent, boolean pr) {
+ private Region createRegion(boolean persistent, boolean pr) {
Region region;
RegionShortcut rs;
@@ -458,14 +446,8 @@ public class PdxAttributesJUnitTest extends JUnit4CacheTestCase {
return region;
}
- public void definePersistentAEQ(Cache cache, String id, boolean persistent) {
- AsyncEventListener al = new AsyncEventListener() {
- public void close() {}
-
- public boolean processEvents(List<AsyncEvent> events) {
- return true;
- }
- };
+ private void definePersistentAEQ(Cache cache, String id, boolean persistent) {
+ AsyncEventListener al = events -> true;
cache.createAsyncEventQueueFactory().setPersistent(persistent).create(id, al);
}
diff --git a/geode-core/src/distributedTest/java/org/apache/geode/test/dunit/tests/BasicDistributedTest.java b/geode-core/src/distributedTest/java/org/apache/geode/test/dunit/tests/BasicDistributedTest.java
index af7d7b3..98af3d2 100644
--- a/geode-core/src/distributedTest/java/org/apache/geode/test/dunit/tests/BasicDistributedTest.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/test/dunit/tests/BasicDistributedTest.java
@@ -14,11 +14,8 @@
*/
package org.apache.geode.test.dunit.tests;
-import static com.googlecode.catchexception.CatchException.catchException;
-import static com.googlecode.catchexception.CatchException.caughtException;
-import static com.googlecode.catchexception.throwable.CatchThrowable.catchThrowable;
-import static com.googlecode.catchexception.throwable.CatchThrowable.caughtThrowable;
import static org.apache.geode.test.dunit.Invoke.invokeInEveryVM;
+import static org.assertj.core.api.Assertions.catchThrowable;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
@@ -41,7 +38,6 @@ import org.apache.geode.test.dunit.VM;
/**
* This class tests the basic functionality of the distributed unit test framework.
*/
-
@SuppressWarnings("serial")
public class BasicDistributedTest extends DistributedTestCase {
@@ -53,7 +49,7 @@ public class BasicDistributedTest extends DistributedTestCase {
private VM vm1;
@Override
- public final void postSetUp() throws Exception {
+ public final void postSetUp() {
bindings = new Properties();
invokeInEveryVM(() -> bindings = new Properties());
vm0 = Host.getHost(0).getVM(0);
@@ -61,25 +57,25 @@ public class BasicDistributedTest extends DistributedTestCase {
}
@Override
- public final void postTearDown() throws Exception {
+ public final void postTearDown() {
bindings = null;
invokeInEveryVM(() -> bindings = null);
}
@Test
- public void testPreconditions() throws Exception {
+ public void testPreconditions() {
invokeInEveryVM(
() -> assertThat("getUniqueName() must not return null", getUniqueName(), notNullValue()));
invokeInEveryVM(() -> assertThat("bindings must not be null", bindings, notNullValue()));
}
@Test
- public void testInvokeOnClassTargetWithEmptyArgs() throws Exception {
+ public void testInvokeOnClassTargetWithEmptyArgs() {
assertThat(vm0.invoke(BasicDistributedTest.class, "booleanValue", new Object[] {}), is(true));
}
@Test
- public void testInvokeOnObjectTargetWithEmptyArgs() throws Exception {
+ public void testInvokeOnObjectTargetWithEmptyArgs() {
assertThat(vm0.invoke(new BasicDistributedTest(), "booleanValue", new Object[] {}), is(true));
}
@@ -98,12 +94,12 @@ public class BasicDistributedTest extends DistributedTestCase {
}
@Test
- public void testInvokeOnClassTargetWithNullArgs() throws Exception {
+ public void testInvokeOnClassTargetWithNullArgs() {
assertThat(vm0.invoke(BasicDistributedTest.class, "booleanValue", null), is(true));
}
@Test
- public void testInvokeOnObjectTargetWithNullArgs() throws Exception {
+ public void testInvokeOnObjectTargetWithNullArgs() {
assertThat(vm0.invoke(new BasicDistributedTest(), "booleanValue", null), is(true));
}
@@ -122,23 +118,23 @@ public class BasicDistributedTest extends DistributedTestCase {
}
@Test
- public void testRemoteInvocationWithException() throws Exception {
- catchException(vm0).invoke(() -> remoteThrowException());
+ public void testRemoteInvocationWithException() {
+ Throwable thrown = catchThrowable(() -> vm0.invoke(() -> remoteThrowException()));
- assertThat(caughtException(), instanceOf(RMIException.class));
- assertThat(caughtException().getCause(), notNullValue());
- assertThat(caughtException().getCause(), instanceOf(BasicTestException.class));
- assertThat(caughtException().getCause().getMessage(), is(MESSAGE_FOR_remoteThrowException));
+ assertThat(thrown, instanceOf(RMIException.class));
+ assertThat(thrown.getCause(), notNullValue());
+ assertThat(thrown.getCause(), instanceOf(BasicTestException.class));
+ assertThat(thrown.getCause().getMessage(), is(MESSAGE_FOR_remoteThrowException));
}
@Test
- public void testInvokeWithLambda() throws Exception {
+ public void testInvokeWithLambda() {
assertThat(vm0.invoke(() -> DUnitEnv.get().getVMID()), is(0));
assertThat(vm1.invoke(() -> DUnitEnv.get().getVMID()), is(1));
}
@Test
- public void testInvokeLambdaAsync() throws Throwable {
+ public void testInvokeLambdaAsync() throws Exception {
assertThat(vm0.invokeAsync(() -> DUnitEnv.get().getVMID()).getResult(), is(0));
}
@@ -149,7 +145,7 @@ public class BasicDistributedTest extends DistributedTestCase {
}
@Test
- public void testInvokeNamedLambdaAsync() throws Throwable {
+ public void testInvokeNamedLambdaAsync() throws Exception {
assertThat(vm0.invokeAsync("getVMID", () -> DUnitEnv.get().getVMID()).getResult(), is(0));
}
@@ -169,38 +165,41 @@ public class BasicDistributedTest extends DistributedTestCase {
assertThat(async.exceptionOccurred(), is(true));
assertThat(async.getException(), instanceOf(BasicTestException.class));
- catchThrowable(async).checkException();
+ Throwable thrown = catchThrowable(() -> async.checkException());
- assertThat(caughtThrowable(), instanceOf(AssertionError.class));
- assertThat(caughtThrowable().getCause(), notNullValue());
- assertThat(caughtThrowable().getCause(), instanceOf(BasicTestException.class));
- assertThat(caughtThrowable().getCause().getMessage(), is(MESSAGE_FOR_remoteThrowException));
+ assertThat(thrown, instanceOf(AssertionError.class));
+ assertThat(thrown.getCause(), notNullValue());
+ assertThat(thrown.getCause(), instanceOf(BasicTestException.class));
+ assertThat(thrown.getCause().getMessage(), is(MESSAGE_FOR_remoteThrowException));
}
@Test
public void testInvokeNamedRunnableLambdaAsync() throws Exception {
- catchThrowable(vm0.invokeAsync("throwSomething", () -> throwException()).join())
- .checkException();
+ Throwable thrown =
+ catchThrowable(() -> vm0.invokeAsync("throwSomething", () -> throwException()).join()
+ .checkException());
- assertThat(caughtThrowable(), notNullValue());
- assertThat(caughtThrowable().getCause(), notNullValue());
- assertThat(caughtThrowable().getCause(), instanceOf(BasicDUnitException.class));
+ assertThat(thrown, notNullValue());
+ assertThat(thrown.getCause(), notNullValue());
+ assertThat(thrown.getCause(), instanceOf(BasicDUnitException.class));
}
@Test
- public void testInvokeNamedRunnableLambda() throws Exception {
- catchException(vm0).invoke("throwSomething", () -> throwException());
+ public void testInvokeNamedRunnableLambda() {
+ Throwable thrown = catchThrowable(() -> vm0.invoke("throwSomething", () -> throwException()));
- assertThat(caughtException(), notNullValue());
- assertThat(caughtException().getCause(), notNullValue());
- assertThat(caughtException().getCause(), instanceOf(BasicDUnitException.class));
- assertThat(caughtException().getCause().getMessage(), nullValue());
+ assertThat(thrown, notNullValue());
+ assertThat(thrown.getCause(), notNullValue());
+ assertThat(thrown.getCause(), instanceOf(BasicDUnitException.class));
+ assertThat(thrown.getCause().getMessage(), nullValue());
}
+ @SuppressWarnings("unused")
private static boolean booleanValue() { // invoked by reflection
return true;
}
+ @SuppressWarnings("unused")
private static boolean booleanValue(final boolean value) { // invoked by reflection
return value;
}
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/distributed/LocatorLauncherIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/distributed/LocatorLauncherIntegrationTest.java
index 20c157c..62772b7 100755
--- a/geode-core/src/integrationTest/java/org/apache/geode/distributed/LocatorLauncherIntegrationTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/distributed/LocatorLauncherIntegrationTest.java
@@ -14,13 +14,12 @@
*/
package org.apache.geode.distributed;
-import static com.googlecode.catchexception.apis.BDDCatchException.caughtException;
-import static com.googlecode.catchexception.apis.BDDCatchException.when;
import static org.apache.geode.distributed.ConfigurationProperties.NAME;
import static org.apache.geode.distributed.DistributedSystem.PROPERTIES_FILE_PROPERTY;
import static org.apache.geode.distributed.internal.DistributionConfig.GEMFIRE_PREFIX;
import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPort;
import static org.apache.geode.internal.DistributionLocator.TEST_OVERRIDE_DEFAULT_PORT_PROPERTY;
+import static org.assertj.core.api.Assertions.catchThrowable;
import static org.assertj.core.api.BDDAssertions.assertThat;
import static org.assertj.core.api.BDDAssertions.then;
@@ -50,16 +49,16 @@ public class LocatorLauncherIntegrationTest {
private static final String CURRENT_DIRECTORY = System.getProperty("user.dir");
@Rule
- public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
+ public RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
@Rule
- public final TemporaryFolder temporaryFolder = new TemporaryFolder();
+ public TemporaryFolder temporaryFolder = new TemporaryFolder();
@Rule
- public final TestName testName = new TestName();
+ public TestName testName = new TestName();
@Test
- public void buildWithMemberNameSetInGemFireProperties() throws Exception {
+ public void buildWithMemberNameSetInGemFireProperties() {
// given: gemfire.properties with a name
givenGemFirePropertiesFile(withMemberName());
@@ -71,29 +70,29 @@ public class LocatorLauncherIntegrationTest {
}
@Test
- public void buildWithNoMemberNameThrowsIllegalStateException() throws Exception {
+ public void buildWithNoMemberNameThrowsIllegalStateException() {
// given: gemfire.properties with no name
givenGemFirePropertiesFile(withoutMemberName());
// when: no MemberName is specified
- when(new Builder().setCommand(Command.START)).build();
+ Throwable thrown = catchThrowable(() -> new Builder().setCommand(Command.START).build());
// then: throw IllegalStateException
- then(caughtException()).isExactlyInstanceOf(IllegalStateException.class)
+ then(thrown).isExactlyInstanceOf(IllegalStateException.class)
.hasMessage(memberNameValidationErrorMessage());
}
@Test
- public void buildWithWorkingDirectoryNotEqualToCurrentDirectoryThrowsIllegalStateException()
- throws Exception {
+ public void buildWithWorkingDirectoryNotEqualToCurrentDirectoryThrowsIllegalStateException() {
// given: using LocatorLauncher in-process
// when: setting WorkingDirectory to non-current directory
- when(new Builder().setCommand(Command.START).setMemberName("memberOne")
- .setWorkingDirectory(getWorkingDirectoryPath())).build();
+ Throwable thrown =
+ catchThrowable(() -> new Builder().setCommand(Command.START).setMemberName("memberOne")
+ .setWorkingDirectory(getWorkingDirectoryPath()).build());
// then: throw IllegalStateException
- then(caughtException()).isExactlyInstanceOf(IllegalStateException.class)
+ then(thrown).isExactlyInstanceOf(IllegalStateException.class)
.hasMessage(workingDirectoryOptionNotValidErrorMessage());
}
@@ -121,7 +120,7 @@ public class LocatorLauncherIntegrationTest {
}
@Test
- public void parseArgumentsParsesValuesSeparatedByEquals() throws Exception {
+ public void parseArgumentsParsesValuesSeparatedByEquals() {
// given: a new builder
Builder builder = new Builder();
@@ -143,7 +142,7 @@ public class LocatorLauncherIntegrationTest {
}
@Test
- public void getWorkingDirectoryReturnsCurrentDirectoryByDefault() throws Exception {
+ public void getWorkingDirectoryReturnsCurrentDirectoryByDefault() {
// given:
// when: not setting WorkingDirectory
@@ -153,7 +152,7 @@ public class LocatorLauncherIntegrationTest {
}
@Test
- public void setWorkingDirectoryToNullUsesCurrentDirectory() throws Exception {
+ public void setWorkingDirectoryToNullUsesCurrentDirectory() {
// given: a new builder
Builder builder = new Builder();
@@ -165,7 +164,7 @@ public class LocatorLauncherIntegrationTest {
}
@Test
- public void setWorkingDirectoryToEmptyStringUsesCurrentDirectory() throws Exception {
+ public void setWorkingDirectoryToEmptyStringUsesCurrentDirectory() {
// given: a new builder
Builder builder = new Builder();
@@ -177,7 +176,7 @@ public class LocatorLauncherIntegrationTest {
}
@Test
- public void setWorkingDirectoryToBlankStringUsesCurrentDirectory() throws Exception {
+ public void setWorkingDirectoryToBlankStringUsesCurrentDirectory() {
// given: a new builder
Builder builder = new Builder();
@@ -189,7 +188,7 @@ public class LocatorLauncherIntegrationTest {
}
@Test
- public void setWorkingDirectoryToExistingDirectory() throws Exception {
+ public void setWorkingDirectoryToExistingDirectory() {
// given: a new builder
Builder builder = new Builder();
@@ -206,29 +205,31 @@ public class LocatorLauncherIntegrationTest {
File nonDirectory = temporaryFolder.newFile();
// when: setting WorkingDirectory to that file
- when(new Builder()).setWorkingDirectory(nonDirectory.getCanonicalPath());
+ Throwable thrown =
+ catchThrowable(() -> new Builder().setWorkingDirectory(nonDirectory.getCanonicalPath()));
// then: throw IllegalArgumentException
- then(caughtException()).isExactlyInstanceOf(IllegalArgumentException.class)
+ then(thrown).isExactlyInstanceOf(IllegalArgumentException.class)
.hasMessage(workingDirectoryNotFoundErrorMessage())
.hasCause(new FileNotFoundException(nonDirectory.getCanonicalPath()));
}
@Test
- public void setWorkingDirectoryToNonExistingDirectory() throws Exception {
+ public void setWorkingDirectoryToNonExistingDirectory() {
// given:
// when: setting WorkingDirectory to non-existing directory
- when(new Builder()).setWorkingDirectory("/path/to/non_existing/directory");
+ Throwable thrown =
+ catchThrowable(() -> new Builder().setWorkingDirectory("/path/to/non_existing/directory"));
// then: throw IllegalArgumentException
- then(caughtException()).isExactlyInstanceOf(IllegalArgumentException.class)
+ then(thrown).isExactlyInstanceOf(IllegalArgumentException.class)
.hasMessage(workingDirectoryNotFoundErrorMessage())
.hasCause(new FileNotFoundException("/path/to/non_existing/directory"));
}
@Test
- public void portCanBeOverriddenBySystemProperty() throws Exception {
+ public void portCanBeOverriddenBySystemProperty() {
// given: overridden default port
int overriddenPort = getRandomAvailableTCPPort();
System.setProperty(TEST_OVERRIDE_DEFAULT_PORT_PROPERTY, String.valueOf(overriddenPort));
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/distributed/ServerLauncherBuilderIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/distributed/ServerLauncherBuilderIntegrationTest.java
index acd2237..9631921 100755
--- a/geode-core/src/integrationTest/java/org/apache/geode/distributed/ServerLauncherBuilderIntegrationTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/distributed/ServerLauncherBuilderIntegrationTest.java
@@ -14,13 +14,12 @@
*/
package org.apache.geode.distributed;
-import static com.googlecode.catchexception.apis.BDDCatchException.caughtException;
-import static com.googlecode.catchexception.apis.BDDCatchException.when;
import static org.apache.geode.distributed.ConfigurationProperties.NAME;
import static org.apache.geode.distributed.DistributedSystem.PROPERTIES_FILE_PROPERTY;
import static org.apache.geode.distributed.internal.DistributionConfig.GEMFIRE_PREFIX;
import static org.apache.geode.internal.cache.AbstractCacheServer.TEST_OVERRIDE_DEFAULT_PORT_PROPERTY;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.catchThrowable;
import static org.assertj.core.api.BDDAssertions.then;
import java.io.File;
@@ -51,13 +50,13 @@ public class ServerLauncherBuilderIntegrationTest {
private static final String CURRENT_DIRECTORY = System.getProperty("user.dir");
@Rule
- public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
+ public RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
@Rule
- public final TemporaryFolder temporaryFolder = new TemporaryFolder();
+ public TemporaryFolder temporaryFolder = new TemporaryFolder();
@Rule
- public final TestName testName = new TestName();
+ public TestName testName = new TestName();
@Test
public void buildWithMemberNameSetInGemFireProperties() {
@@ -77,10 +76,10 @@ public class ServerLauncherBuilderIntegrationTest {
givenGemFirePropertiesFile(withoutMemberName());
// when: no MemberName is specified
- when(new Builder().setCommand(Command.START)).build();
+ Throwable thrown = catchThrowable(() -> new Builder().setCommand(Command.START).build());
// then: throw IllegalStateException
- then(caughtException()).isExactlyInstanceOf(IllegalStateException.class)
+ then(thrown).isExactlyInstanceOf(IllegalStateException.class)
.hasMessage(memberNameValidationErrorMessage());
}
@@ -89,11 +88,12 @@ public class ServerLauncherBuilderIntegrationTest {
// given: using LocatorLauncher in-process
// when: setting WorkingDirectory to non-current directory
- when(new Builder().setCommand(Command.START).setMemberName("memberOne")
- .setWorkingDirectory(getWorkingDirectoryPath())).build();
+ Throwable thrown =
+ catchThrowable(() -> new Builder().setCommand(Command.START).setMemberName("memberOne")
+ .setWorkingDirectory(getWorkingDirectoryPath()).build());
// then: throw IllegalStateException
- then(caughtException()).isExactlyInstanceOf(IllegalStateException.class)
+ then(thrown).isExactlyInstanceOf(IllegalStateException.class)
.hasMessage(workingDirectoryOptionNotValidErrorMessage());
}
@@ -220,10 +220,11 @@ public class ServerLauncherBuilderIntegrationTest {
File nonDirectory = temporaryFolder.newFile();
// when: setting WorkingDirectory to that file
- when(new Builder()).setWorkingDirectory(nonDirectory.getCanonicalPath());
+ Throwable thrown =
+ catchThrowable(() -> new Builder().setWorkingDirectory(nonDirectory.getCanonicalPath()));
// then: throw IllegalArgumentException
- then(caughtException()).isExactlyInstanceOf(IllegalArgumentException.class)
+ then(thrown).isExactlyInstanceOf(IllegalArgumentException.class)
.hasMessage(workingDirectoryNotFoundErrorMessage())
.hasCause(new FileNotFoundException(nonDirectory.getCanonicalPath()));
}
@@ -233,10 +234,11 @@ public class ServerLauncherBuilderIntegrationTest {
// given:
// when: setting WorkingDirectory to non-existing directory
- when(new Builder()).setWorkingDirectory("/path/to/non_existing/directory");
+ Throwable thrown =
+ catchThrowable(() -> new Builder().setWorkingDirectory("/path/to/non_existing/directory"));
// then: throw IllegalArgumentException
- then(caughtException()).isExactlyInstanceOf(IllegalArgumentException.class)
+ then(thrown).isExactlyInstanceOf(IllegalArgumentException.class)
.hasMessage(workingDirectoryNotFoundErrorMessage())
.hasCause(new FileNotFoundException("/path/to/non_existing/directory"));
}
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/distributed/ServerLauncherIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/distributed/ServerLauncherIntegrationTest.java
index 7302cda..83834bf 100755
--- a/geode-core/src/integrationTest/java/org/apache/geode/distributed/ServerLauncherIntegrationTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/distributed/ServerLauncherIntegrationTest.java
@@ -14,13 +14,12 @@
*/
package org.apache.geode.distributed;
-import static com.googlecode.catchexception.apis.BDDCatchException.caughtException;
-import static com.googlecode.catchexception.apis.BDDCatchException.when;
import static org.apache.geode.distributed.ConfigurationProperties.NAME;
import static org.apache.geode.distributed.DistributedSystem.PROPERTIES_FILE_PROPERTY;
import static org.apache.geode.distributed.internal.DistributionConfig.GEMFIRE_PREFIX;
import static org.apache.geode.internal.cache.AbstractCacheServer.TEST_OVERRIDE_DEFAULT_PORT_PROPERTY;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.catchThrowable;
import static org.assertj.core.api.BDDAssertions.then;
import java.io.File;
@@ -50,16 +49,16 @@ public class ServerLauncherIntegrationTest {
private static final String CURRENT_DIRECTORY = System.getProperty("user.dir");
@Rule
- public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
+ public RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
@Rule
- public final TemporaryFolder temporaryFolder = new TemporaryFolder();
+ public TemporaryFolder temporaryFolder = new TemporaryFolder();
@Rule
- public final TestName testName = new TestName();
+ public TestName testName = new TestName();
@Test
- public void buildWithMemberNameSetInGemFireProperties() throws Exception {
+ public void buildWithMemberNameSetInGemFireProperties() {
// given: gemfire.properties containing a name
givenGemFirePropertiesFile(withMemberName());
@@ -71,29 +70,29 @@ public class ServerLauncherIntegrationTest {
}
@Test
- public void buildWithoutMemberNameThrowsIllegalStateException() throws Exception {
+ public void buildWithoutMemberNameThrowsIllegalStateException() {
// given: gemfire.properties with no name
givenGemFirePropertiesFile(withoutMemberName());
// when: no MemberName is specified
- when(new Builder().setCommand(Command.START)).build();
+ Throwable thrown = catchThrowable(() -> new Builder().setCommand(Command.START).build());
// then: throw IllegalStateException
- then(caughtException()).isExactlyInstanceOf(IllegalStateException.class)
+ then(thrown).isExactlyInstanceOf(IllegalStateException.class)
.hasMessage(memberNameValidationErrorMessage());
}
@Test
- public void buildWithWorkingDirectoryNotEqualToCurrentDirectoryThrowsIllegalStateException()
- throws Exception {
+ public void buildWithWorkingDirectoryNotEqualToCurrentDirectoryThrowsIllegalStateException() {
// given: using LocatorLauncher in-process
// when: setting WorkingDirectory to non-current directory
- when(new Builder().setCommand(Command.START).setMemberName("memberOne")
- .setWorkingDirectory(getWorkingDirectoryPath())).build();
+ Throwable thrown =
+ catchThrowable(() -> new Builder().setCommand(Command.START).setMemberName("memberOne")
+ .setWorkingDirectory(getWorkingDirectoryPath()).build());
// then: throw IllegalStateException
- then(caughtException()).isExactlyInstanceOf(IllegalStateException.class)
+ then(thrown).isExactlyInstanceOf(IllegalStateException.class)
.hasMessage(workingDirectoryOptionNotValidErrorMessage());
}
@@ -121,7 +120,7 @@ public class ServerLauncherIntegrationTest {
}
@Test
- public void parseArgumentsParsesValuesSeparatedByEquals() throws Exception {
+ public void parseArgumentsParsesValuesSeparatedByEquals() {
// given: a new builder
Builder builder = new Builder();
@@ -143,7 +142,7 @@ public class ServerLauncherIntegrationTest {
}
@Test
- public void getWorkingDirectoryReturnsCurrentDirectoryByDefault() throws Exception {
+ public void getWorkingDirectoryReturnsCurrentDirectoryByDefault() {
// given:
// when: not setting WorkingDirectory
@@ -153,7 +152,7 @@ public class ServerLauncherIntegrationTest {
}
@Test
- public void setWorkingDirectoryToNullUsesCurrentDirectory() throws Exception {
+ public void setWorkingDirectoryToNullUsesCurrentDirectory() {
// given: a new builder
Builder builder = new Builder();
@@ -165,7 +164,7 @@ public class ServerLauncherIntegrationTest {
}
@Test
- public void setWorkingDirectoryToEmptyStringUsesCurrentDirectory() throws Exception {
+ public void setWorkingDirectoryToEmptyStringUsesCurrentDirectory() {
// given: a new builder
Builder builder = new Builder();
@@ -177,7 +176,7 @@ public class ServerLauncherIntegrationTest {
}
@Test
- public void setWorkingDirectoryToBlankStringUsesCurrentDirectory() throws Exception {
+ public void setWorkingDirectoryToBlankStringUsesCurrentDirectory() {
// given: a new builder
Builder builder = new Builder();
@@ -189,7 +188,7 @@ public class ServerLauncherIntegrationTest {
}
@Test
- public void setWorkingDirectoryToExistingDirectory() throws Exception {
+ public void setWorkingDirectoryToExistingDirectory() {
// given: a new builder
Builder builder = new Builder();
@@ -206,29 +205,31 @@ public class ServerLauncherIntegrationTest {
File nonDirectory = temporaryFolder.newFile();
// when: setting WorkingDirectory to that file
- when(new Builder()).setWorkingDirectory(nonDirectory.getCanonicalPath());
+ Throwable thrown =
+ catchThrowable(() -> new Builder().setWorkingDirectory(nonDirectory.getCanonicalPath()));
// then: throw IllegalArgumentException
- then(caughtException()).isExactlyInstanceOf(IllegalArgumentException.class)
+ then(thrown).isExactlyInstanceOf(IllegalArgumentException.class)
.hasMessage(workingDirectoryNotFoundErrorMessage())
.hasCause(new FileNotFoundException(nonDirectory.getCanonicalPath()));
}
@Test
- public void setWorkingDirectoryToNonExistingDirectory() throws Exception {
+ public void setWorkingDirectoryToNonExistingDirectory() {
// given:
// when: setting WorkingDirectory to non-existing directory
- when(new Builder()).setWorkingDirectory("/path/to/non_existing/directory");
+ Throwable thrown =
+ catchThrowable(() -> new Builder().setWorkingDirectory("/path/to/non_existing/directory"));
// then: throw IllegalArgumentException
- then(caughtException()).isExactlyInstanceOf(IllegalArgumentException.class)
+ then(thrown).isExactlyInstanceOf(IllegalArgumentException.class)
.hasMessage(workingDirectoryNotFoundErrorMessage())
.hasCause(new FileNotFoundException("/path/to/non_existing/directory"));
}
@Test
- public void serverPortCanBeOverriddenBySystemProperty() throws Exception {
+ public void serverPortCanBeOverriddenBySystemProperty() {
// given: overridden default port
int overriddenPort = AvailablePortHelper.getRandomAvailableTCPPort();
System.setProperty(TEST_OVERRIDE_DEFAULT_PORT_PROPERTY, String.valueOf(overriddenPort));
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/eviction/TransactionsWithOverflowTest.java b/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/eviction/TransactionsWithOverflowTest.java
index b0869df..ca4397b 100644
--- a/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/eviction/TransactionsWithOverflowTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/eviction/TransactionsWithOverflowTest.java
@@ -12,15 +12,12 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
-
package org.apache.geode.internal.cache.eviction;
-
-import static com.googlecode.catchexception.CatchException.catchException;
-import static com.googlecode.catchexception.CatchException.caughtException;
import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.catchThrowable;
import java.io.File;
import java.util.Properties;
@@ -44,6 +41,7 @@ import org.apache.geode.cache.Region;
import org.apache.geode.cache.RegionFactory;
import org.apache.geode.internal.cache.InternalRegion;
import org.apache.geode.internal.cache.VMLRURegionMap;
+import org.apache.geode.test.junit.rules.DiskDirRule;
/**
* Test for transactional operations on overflowed data
@@ -51,24 +49,15 @@ import org.apache.geode.internal.cache.VMLRURegionMap;
public class TransactionsWithOverflowTest {
@Rule
+ public DiskDirRule diskDirRule = new DiskDirRule();
+
+ @Rule
public TestName name = new TestName();
private Cache cache;
- private String createDiskStoreAndGetName() {
- Cache cache = getCache();
- File[] diskDirs = new File[1];
- diskDirs[0] = new File("diskRegionDirs/" + getClass().getCanonicalName());
- diskDirs[0].mkdirs();
- DiskStoreFactory diskStoreFactory = cache.createDiskStoreFactory();
- diskStoreFactory.setDiskDirs(diskDirs);
- String diskStoreName = getClass().getName();
- diskStoreFactory.create(diskStoreName);
- return diskStoreName;
- }
-
@Test
- public void testpartitionedRegionWithOverflow() {
+ public void testPartitionedRegionWithOverflow() {
Cache cache = getCache();
String diskStoreName = createDiskStoreAndGetName();
Region pr = createOverflowPR(cache, diskStoreName);
@@ -82,7 +71,7 @@ public class TransactionsWithOverflowTest {
}
@Test
- public void verifyThatTransactionalDestroysRemoveFromTheEvictionList() throws Exception {
+ public void verifyThatTransactionalDestroysRemoveFromTheEvictionList() {
Cache cache = getCache();
RegionFactory<?, ?> rf = cache.createRegionFactory();
rf.setDataPolicy(DataPolicy.REPLICATE);
@@ -103,7 +92,7 @@ public class TransactionsWithOverflowTest {
}
@Test
- public void verifyThatTransactionalDestroysRemoveFromExpiration() throws Exception {
+ public void verifyThatTransactionalDestroysRemoveFromExpiration() {
Cache cache = getCache();
RegionFactory<?, ?> rf = cache.createRegionFactory();
rf.setDataPolicy(DataPolicy.REPLICATE);
@@ -118,8 +107,20 @@ public class TransactionsWithOverflowTest {
mgr.commit();
}
- catchException(r).getEntryExpiryTask(0);
- assertThat((Exception) caughtException()).isExactlyInstanceOf(EntryNotFoundException.class);
+ Throwable thrown = catchThrowable(() -> r.getEntryExpiryTask(0));
+ assertThat(thrown).isExactlyInstanceOf(EntryNotFoundException.class);
+ }
+
+ private String createDiskStoreAndGetName() {
+ Cache cache = getCache();
+ File[] diskDirs = new File[1];
+ diskDirs[0] = new File("diskRegionDirs/" + getClass().getCanonicalName());
+ diskDirs[0].mkdirs();
+ DiskStoreFactory diskStoreFactory = cache.createDiskStoreFactory();
+ diskStoreFactory.setDiskDirs(diskDirs);
+ String diskStoreName = getClass().getName();
+ diskStoreFactory.create(diskStoreName);
+ return diskStoreName;
}
private Cache getCache() {
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/internal/process/FileProcessControllerIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/internal/process/FileProcessControllerIntegrationTest.java
index 41ea567..0706809 100755
--- a/geode-core/src/integrationTest/java/org/apache/geode/internal/process/FileProcessControllerIntegrationTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/internal/process/FileProcessControllerIntegrationTest.java
@@ -14,12 +14,11 @@
*/
package org.apache.geode.internal.process;
-import static com.googlecode.catchexception.CatchException.caughtException;
-import static com.googlecode.catchexception.CatchException.verifyException;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.MINUTES;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -101,10 +100,10 @@ public class FileProcessControllerIntegrationTest {
FileProcessController controller = new FileProcessController(params, pid, 10, MILLISECONDS);
// when:
- verifyException(controller).status();
+ Throwable thrown = catchThrowable(() -> controller.status());
// then: we expect TimeoutException to be thrown
- assertThat((Exception) caughtException()).isInstanceOf(TimeoutException.class)
+ assertThat(thrown).isInstanceOf(TimeoutException.class)
.hasMessageContaining("Timed out waiting for process to create").hasNoCause();
}
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/pdx/PdxInstanceLoaderIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/pdx/PdxInstanceLoaderIntegrationTest.java
index 2fa0cda..a19eee0 100644
--- a/geode-core/src/integrationTest/java/org/apache/geode/pdx/PdxInstanceLoaderIntegrationTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/pdx/PdxInstanceLoaderIntegrationTest.java
@@ -14,13 +14,11 @@
*/
package org.apache.geode.pdx;
-import static com.googlecode.catchexception.CatchException.catchException;
-import static com.googlecode.catchexception.CatchException.caughtException;
import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.catchThrowable;
import org.junit.After;
-import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -35,36 +33,23 @@ import org.apache.geode.internal.cache.CachedDeserializable;
import org.apache.geode.internal.cache.LocalRegion;
import org.apache.geode.test.junit.categories.SerializationTest;
-@Category({SerializationTest.class})
+@Category(SerializationTest.class)
public class PdxInstanceLoaderIntegrationTest {
private Cache cache;
- @Before
- public void setUp() {}
-
@After
public void tearDown() {
cache.close();
}
- private class PdxInstanceLoader implements CacheLoader {
- @Override
- public void close() {}
-
- @Override
- public Object load(LoaderHelper helper) throws CacheLoaderException {
- return cache.createPdxInstanceFactory("no class name").create();
- }
- }
-
@Test
public void loadOfPdxInstanceWithReadSerializedFalseAttemptsToDeserialize() {
cache = new CacheFactory().set(MCAST_PORT, "0").setPdxReadSerialized(false).create();
Region region = cache.createRegionFactory(RegionShortcut.LOCAL)
.setCacheLoader(new PdxInstanceLoader()).create("region");
- catchException(region).get("key");
- assertThat((Exception) caughtException()).isInstanceOf(PdxSerializationException.class);
+ Throwable thrown = catchThrowable(() -> region.get("key"));
+ assertThat(thrown).isInstanceOf(PdxSerializationException.class);
}
@Test
@@ -86,4 +71,11 @@ public class PdxInstanceLoaderIntegrationTest {
assertThat(obj).isInstanceOf(CachedDeserializable.class);
}
+
+ private class PdxInstanceLoader implements CacheLoader {
+ @Override
+ public Object load(LoaderHelper helper) throws CacheLoaderException {
+ return cache.createPdxInstanceFactory("no class name").create();
+ }
+ }
}
diff --git a/geode-core/src/test/java/org/apache/geode/distributed/LocatorStateTest.java b/geode-core/src/test/java/org/apache/geode/distributed/LocatorStateTest.java
index e9709ee..843f8b2 100755
--- a/geode-core/src/test/java/org/apache/geode/distributed/LocatorStateTest.java
+++ b/geode-core/src/test/java/org/apache/geode/distributed/LocatorStateTest.java
@@ -14,9 +14,8 @@
*/
package org.apache.geode.distributed;
-import static com.googlecode.catchexception.CatchException.caughtException;
-import static com.googlecode.catchexception.CatchException.verifyException;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.catchThrowable;
import java.util.ArrayList;
import java.util.HashMap;
@@ -54,7 +53,7 @@ public class LocatorStateTest {
private String workingDirectory;
@Before
- public void before() throws Exception {
+ public void setUp() {
classpath = "test_classpath";
gemFireVersion = "test_gemfireVersion";
host = "test_host";
@@ -73,47 +72,47 @@ public class LocatorStateTest {
}
@Test
- public void fromJsonWithEmptyStringThrowsIllegalArgumentException() throws Exception {
+ public void fromJsonWithEmptyStringThrowsIllegalArgumentException() {
// given: empty string
String emptyString = "";
// when: passed to fromJson
- verifyException(this).fromJson(emptyString);
+ Throwable thrown = catchThrowable(() -> fromJson(emptyString));
// then: throws IllegalArgumentException with cause of GfJsonException
- assertThat((Exception) caughtException()).isInstanceOf(IllegalArgumentException.class)
+ assertThat(thrown).isInstanceOf(IllegalArgumentException.class)
.hasCauseInstanceOf(GfJsonException.class);
- assertThat(caughtException().getCause()).isInstanceOf(GfJsonException.class).hasNoCause();
+ assertThat(thrown.getCause()).isInstanceOf(GfJsonException.class).hasNoCause();
}
@Test
- public void fromJsonWithWhiteSpaceStringThrowsIllegalArgumentException() throws Exception {
+ public void fromJsonWithWhiteSpaceStringThrowsIllegalArgumentException() {
// given: white space string
String whiteSpaceString = " ";
// when: passed to fromJson
- verifyException(this).fromJson(whiteSpaceString);
+ Throwable thrown = catchThrowable(() -> fromJson(whiteSpaceString));
// then: throws IllegalArgumentException with cause of GfJsonException
- assertThat((Exception) caughtException()).isInstanceOf(IllegalArgumentException.class)
+ assertThat(thrown).isInstanceOf(IllegalArgumentException.class)
.hasCauseInstanceOf(GfJsonException.class);
- assertThat(caughtException().getCause()).isInstanceOf(GfJsonException.class).hasNoCause();
+ assertThat(thrown.getCause()).isInstanceOf(GfJsonException.class).hasNoCause();
}
@Test
- public void fromJsonWithNullStringThrowsNullPointerException() throws Exception {
+ public void fromJsonWithNullStringThrowsNullPointerException() {
// given: null string
String nullString = null;
// when: passed to fromJson
- verifyException(this).fromJson(nullString);
+ Throwable thrown = catchThrowable(() -> fromJson(nullString));
// then: throws NullPointerException
- assertThat((Exception) caughtException()).isInstanceOf(NullPointerException.class).hasNoCause();
+ assertThat(thrown).isInstanceOf(NullPointerException.class).hasNoCause();
}
@Test
- public void fromJsonWithValidJsonStringReturnsLocatorState() throws Exception {
+ public void fromJsonWithValidJsonStringReturnsLocatorState() {
// given: valid json string
String jsonString = createStatusJson();
@@ -139,10 +138,7 @@ public class LocatorStateTest {
assertThat(value.getWorkingDirectory()).isEqualTo(workingDirectory);
}
- /**
- * NOTE: Must be protected for CatchException.
- */
- protected LocatorState fromJson(final String value) {
+ private LocatorState fromJson(final String value) {
return LocatorState.fromJson(value);
}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/EntryEventSerializationTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/EntryEventSerializationTest.java
index 0594394..c6a441d 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/EntryEventSerializationTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/EntryEventSerializationTest.java
@@ -14,13 +14,12 @@
*/
package org.apache.geode.internal.cache;
-import static com.googlecode.catchexception.CatchException.catchException;
-import static com.googlecode.catchexception.CatchException.caughtException;
import static org.apache.geode.internal.lang.SystemPropertyHelper.EARLY_ENTRY_EVENT_SERIALIZATION;
import static org.apache.geode.internal.lang.SystemPropertyHelper.GEODE_PREFIX;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@@ -175,9 +174,8 @@ public class EntryEventSerializationTest {
Object newValue = new Object();
when(event.basicGetNewValue()).thenReturn(newValue);
- catchException(instance).serializeNewValueIfNeeded(region, event);
+ Throwable thrown = catchThrowable(() -> instance.serializeNewValueIfNeeded(region, event));
- Exception thrown = caughtException();
assertThat(thrown).isInstanceOf(SerializationException.class);
assertThat(thrown.getCause()).isInstanceOf(NotSerializableException.class);
}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/xmlcache/CacheCreationJUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/xmlcache/CacheCreationJUnitTest.java
index 819c5c0..103a4ab 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/xmlcache/CacheCreationJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/xmlcache/CacheCreationJUnitTest.java
@@ -14,9 +14,8 @@
*/
package org.apache.geode.internal.cache.xmlcache;
-import static com.googlecode.catchexception.CatchException.catchException;
-import static com.googlecode.catchexception.CatchException.caughtException;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.inOrder;
@@ -60,10 +59,8 @@ public class CacheCreationJUnitTest {
ServerLauncherParameters.INSTANCE.clear();
}
- @SuppressWarnings("deprecation")
@Test
public void verifyRunInitializerWithInitializerAndNullPropsCallsInitAndInitialize() {
- @SuppressWarnings("resource")
CacheCreation cacheCreation = new CacheCreation();
Declarable initializer = mock(Declarable.class);
Properties props = null;
@@ -75,10 +72,8 @@ public class CacheCreationJUnitTest {
verify(initializer, times(1)).initialize(eq(this.cache), eq(props));
}
- @SuppressWarnings("deprecation")
@Test
public void verifyRunInitializerWithInitializerAndPropsCallsInitAndInitialize() {
- @SuppressWarnings("resource")
CacheCreation cacheCreation = new CacheCreation();
Declarable initializer = mock(Declarable.class);
Properties props = new Properties();
@@ -93,7 +88,6 @@ public class CacheCreationJUnitTest {
@Test
public void verifyInitializeDeclarablesMapWithNoDeclarablesPassesEmptyMap() {
- @SuppressWarnings("resource")
CacheCreation cacheCreation = new CacheCreation();
Map<Declarable, Properties> expected = Collections.emptyMap();
@@ -104,7 +98,6 @@ public class CacheCreationJUnitTest {
@Test
public void verifyInitializeDeclarablesMapWithDeclarablesPassesExpectedMap() {
- @SuppressWarnings("resource")
CacheCreation cacheCreation = new CacheCreation();
Map<Declarable, Properties> expected = new HashMap<>();
Declarable d1 = mock(Declarable.class);
@@ -123,7 +116,6 @@ public class CacheCreationJUnitTest {
@Test
public void verifyInitializeDeclarablesMapWithDeclarableCallInitAndInitialize() {
- @SuppressWarnings("resource")
CacheCreation cacheCreation = new CacheCreation();
Declarable d2 = mock(Declarable.class);
Properties p2 = new Properties();
@@ -138,7 +130,6 @@ public class CacheCreationJUnitTest {
@Test
public void verifyInitializeDeclarablesMapWithDeclarableThatThrowsWillThrowCacheXmlException() {
- @SuppressWarnings("resource")
CacheCreation cacheCreation = new CacheCreation();
Declarable d2 = mock(Declarable.class);
Properties p2 = null;
@@ -146,9 +137,9 @@ public class CacheCreationJUnitTest {
Throwable cause = new RuntimeException("expected");
doThrow(cause).when(d2).initialize(this.cache, null);
- catchException(cacheCreation).initializeDeclarablesMap(this.cache);
+ Throwable thrown = catchThrowable(() -> cacheCreation.initializeDeclarablesMap(this.cache));
- assertThat((Exception) caughtException()).isExactlyInstanceOf(CacheXmlException.class)
+ assertThat(thrown).isExactlyInstanceOf(CacheXmlException.class)
.hasMessageStartingWith("Exception while initializing an instance of").hasCause(cause);
}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/lang/ThrowableUtilsTest.java b/geode-core/src/test/java/org/apache/geode/internal/lang/ThrowableUtilsTest.java
index e1f107a..3f21a47 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/lang/ThrowableUtilsTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/lang/ThrowableUtilsTest.java
@@ -14,13 +14,14 @@
*/
package org.apache.geode.internal.lang;
-import static com.googlecode.catchexception.CatchException.catchException;
-import static com.googlecode.catchexception.CatchException.caughtException;
+import static org.apache.geode.internal.lang.ThrowableUtils.getRootCause;
+import static org.apache.geode.internal.lang.ThrowableUtils.hasCauseMessage;
+import static org.apache.geode.internal.lang.ThrowableUtils.hasCauseType;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.catchThrowable;
import org.junit.Test;
-
/**
* Unit tests for {@link ThrowableUtils}
*/
@@ -28,9 +29,9 @@ public class ThrowableUtilsTest {
@Test
public void getRootCauseOfNullShouldThrowNullPointerException() {
- catchException(this).getRootCause(null);
+ Throwable thrown = catchThrowable(() -> getRootCause(null));
- assertThat((Exception) caughtException()).isExactlyInstanceOf(NullPointerException.class);
+ assertThat(thrown).isExactlyInstanceOf(NullPointerException.class);
}
@Test
@@ -67,16 +68,16 @@ public class ThrowableUtilsTest {
@Test
public void hasCauseTypeOfNullClassShouldThrowNullPointerException() {
- catchException(this).hasCauseType(new Exception(), null);
+ Throwable thrown = catchThrowable(() -> hasCauseType(new Exception(), null));
- assertThat((Exception) caughtException()).isExactlyInstanceOf(NullPointerException.class);
+ assertThat(thrown).isExactlyInstanceOf(NullPointerException.class);
}
@Test
public void hasCauseTypeOfNullThrowableShouldThrowNullPointerException() {
- catchException(this).hasCauseType(null, Exception.class);
+ Throwable thrown = catchThrowable(() -> hasCauseType(null, Exception.class));
- assertThat((Exception) caughtException()).isExactlyInstanceOf(NullPointerException.class);
+ assertThat(thrown).isExactlyInstanceOf(NullPointerException.class);
}
@Test
@@ -117,30 +118,30 @@ public class ThrowableUtilsTest {
@Test
public void hasCauseMessageForNullShouldThrowNullPointerException() {
- catchException(this).hasCauseMessage(null, "message");
+ Throwable thrown = catchThrowable(() -> hasCauseMessage(null, "message"));
- assertThat((Exception) caughtException()).isExactlyInstanceOf(NullPointerException.class);
+ assertThat(thrown).isExactlyInstanceOf(NullPointerException.class);
}
@Test
public void hasCauseMessageOfNullShouldThrowNullPointerException() {
- catchException(this).hasCauseMessage(new OneException(), null);
+ Throwable thrown = catchThrowable(() -> hasCauseMessage(new OneException(), null));
- assertThat((Exception) caughtException()).isExactlyInstanceOf(NullPointerException.class);
+ assertThat(thrown).isExactlyInstanceOf(NullPointerException.class);
}
@Test
public void hasCauseMessageForNullMessageShouldThrowNullPointerException() {
- catchException(this).hasCauseMessage(new OneException((String) null), null);
+ Throwable thrown = catchThrowable(() -> hasCauseMessage(new OneException((String) null), null));
- assertThat((Exception) caughtException()).isExactlyInstanceOf(NullPointerException.class);
+ assertThat(thrown).isExactlyInstanceOf(NullPointerException.class);
}
@Test
public void hasCauseMessageOfNonMatchingNullMessageShouldThrowNullPointerException() {
- catchException(this).hasCauseMessage(new OneException("message"), null);
+ Throwable thrown = catchThrowable(() -> hasCauseMessage(new OneException("message"), null));
- assertThat((Exception) caughtException()).isExactlyInstanceOf(NullPointerException.class);
+ assertThat(thrown).isExactlyInstanceOf(NullPointerException.class);
}
@Test
@@ -168,21 +169,10 @@ public class ThrowableUtilsTest {
assertThat(hasCauseMessage(new OneException("message"), "this is the message")).isFalse();
}
- public Throwable getRootCause(final Throwable throwable) {
- return ThrowableUtils.getRootCause(throwable);
- }
-
- public boolean hasCauseType(final Throwable throwable,
- final Class<? extends Throwable> causeClass) {
- return ThrowableUtils.hasCauseType(throwable, causeClass);
- }
-
- public boolean hasCauseMessage(final Throwable throwable, final String message) {
- return ThrowableUtils.hasCauseMessage(throwable, message);
- }
-
private static class OneException extends Exception {
- public OneException() {}
+ public OneException() {
+ // nothing
+ }
public OneException(String message) {
super(message);
@@ -198,7 +188,9 @@ public class ThrowableUtilsTest {
}
private static class SubException extends OneException {
- public SubException() {}
+ public SubException() {
+ // nothing
+ }
public SubException(String message) {
super(message);
@@ -214,7 +206,9 @@ public class ThrowableUtilsTest {
}
private static class TwoException extends Exception {
- public TwoException() {}
+ public TwoException() {
+ // nothing
+ }
public TwoException(String message) {
super(message);
@@ -230,7 +224,9 @@ public class ThrowableUtilsTest {
}
private static class OtherException extends Exception {
- public OtherException() {}
+ public OtherException() {
+ // nothing
+ }
public OtherException(String message) {
super(message);
diff --git a/geode-core/src/test/java/org/apache/geode/internal/offheap/FreeListManagerTest.java b/geode-core/src/test/java/org/apache/geode/internal/offheap/FreeListManagerTest.java
index 8d1373a..de2e3fc 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/offheap/FreeListManagerTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/offheap/FreeListManagerTest.java
@@ -14,9 +14,8 @@
*/
package org.apache.geode.internal.offheap;
-import static com.googlecode.catchexception.CatchException.catchException;
-import static com.googlecode.catchexception.CatchException.caughtException;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.catchThrowable;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
@@ -32,11 +31,13 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.apache.geode.OutOfOffHeapMemoryException;
import org.apache.geode.distributed.internal.DistributionConfig;
public class FreeListManagerTest {
private final int DEFAULT_SLAB_SIZE = 1024 * 1024 * 5;
+
private final MemoryAllocatorImpl ma = mock(MemoryAllocatorImpl.class);
private final OffHeapMemoryStats stats = mock(OffHeapMemoryStats.class);
private TestableFreeListManager freeListManager;
@@ -483,9 +484,9 @@ public class FreeListManagerTest {
OutOfOffHeapMemoryListener ooohml = mock(OutOfOffHeapMemoryListener.class);
when(this.ma.getOutOfOffHeapMemoryListener()).thenReturn(ooohml);
- catchException(this.freeListManager).allocate(DEFAULT_SLAB_SIZE - 7);
+ Throwable thrown = catchThrowable(() -> this.freeListManager.allocate(DEFAULT_SLAB_SIZE - 7));
- verify(ooohml).outOfOffHeapMemory(caughtException());
+ verify(ooohml).outOfOffHeapMemory((OutOfOffHeapMemoryException) thrown);
}
@Test(expected = AssertionError.class)
@@ -623,11 +624,13 @@ public class FreeListManagerTest {
this.freeListManager = createFreeListManager(ma, new Slab[] {chunk});
assertThat(this.freeListManager.findSlab(address)).isEqualTo(0);
assertThat(this.freeListManager.findSlab(address + 9)).isEqualTo(0);
- catchException(this.freeListManager).findSlab(address - 1);
- assertThat((Exception) caughtException()).isExactlyInstanceOf(IllegalStateException.class)
+
+ Throwable thrown = catchThrowable(() -> this.freeListManager.findSlab(address - 1));
+ assertThat(thrown).isExactlyInstanceOf(IllegalStateException.class)
.hasMessage("could not find a slab for addr " + (address - 1));
- catchException(this.freeListManager).findSlab(address + 10);
- assertThat((Exception) caughtException()).isExactlyInstanceOf(IllegalStateException.class)
+
+ thrown = catchThrowable(() -> this.freeListManager.findSlab(address + 10));
+ assertThat(thrown).isExactlyInstanceOf(IllegalStateException.class)
.hasMessage("could not find a slab for addr " + (address + 10));
}
@@ -639,11 +642,13 @@ public class FreeListManagerTest {
this.freeListManager = createFreeListManager(ma, new Slab[] {slab, chunk});
assertThat(this.freeListManager.findSlab(address)).isEqualTo(1);
assertThat(this.freeListManager.findSlab(address + 9)).isEqualTo(1);
- catchException(this.freeListManager).findSlab(address - 1);
- assertThat((Exception) caughtException()).isExactlyInstanceOf(IllegalStateException.class)
+
+ Throwable thrown = catchThrowable(() -> this.freeListManager.findSlab(address - 1));
+ assertThat(thrown).isExactlyInstanceOf(IllegalStateException.class)
.hasMessage("could not find a slab for addr " + (address - 1));
- catchException(this.freeListManager).findSlab(address + 10);
- assertThat((Exception) caughtException()).isExactlyInstanceOf(IllegalStateException.class)
+
+ thrown = catchThrowable(() -> this.freeListManager.findSlab(address + 10));
+ assertThat(thrown).isExactlyInstanceOf(IllegalStateException.class)
.hasMessage("could not find a slab for addr " + (address + 10));
}
@@ -665,12 +670,16 @@ public class FreeListManagerTest {
this.freeListManager = createFreeListManager(ma, new Slab[] {chunk});
assertThat(this.freeListManager.validateAddressAndSizeWithinSlab(address, 1)).isTrue();
assertThat(this.freeListManager.validateAddressAndSizeWithinSlab(address, 10)).isTrue();
- catchException(this.freeListManager).validateAddressAndSizeWithinSlab(address, 0);
- assertThat((Exception) caughtException()).isExactlyInstanceOf(IllegalStateException.class)
+
+ Throwable thrown =
+ catchThrowable(() -> this.freeListManager.validateAddressAndSizeWithinSlab(address, 0));
+ assertThat(thrown).isExactlyInstanceOf(IllegalStateException.class)
.hasMessage(" address 0x" + Long.toString(address + 0 - 1, 16)
+ " does not address the original slab memory");
- catchException(this.freeListManager).validateAddressAndSizeWithinSlab(address, 11);
- assertThat((Exception) caughtException()).isExactlyInstanceOf(IllegalStateException.class)
+
+ thrown =
+ catchThrowable(() -> this.freeListManager.validateAddressAndSizeWithinSlab(address, 11));
+ assertThat(thrown).isExactlyInstanceOf(IllegalStateException.class)
.hasMessage(" address 0x" + Long.toString(address + 11 - 1, 16)
+ " does not address the original slab memory");
}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/offheap/MemoryAllocatorFillPatternJUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/offheap/MemoryAllocatorFillPatternJUnitTest.java
index 4a3c508..0f9ff0b 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/offheap/MemoryAllocatorFillPatternJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/offheap/MemoryAllocatorFillPatternJUnitTest.java
@@ -14,8 +14,7 @@
*/
package org.apache.geode.internal.offheap;
-import static com.googlecode.catchexception.CatchException.catchException;
-import static com.googlecode.catchexception.CatchException.caughtException;
+import static org.assertj.core.api.Assertions.catchThrowable;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -79,7 +78,7 @@ public class MemoryAllocatorFillPatternJUnitTest {
*
*/
@Test
- public void testFillPatternBasicForTinyAllocations() throws Exception {
+ public void testFillPatternBasicForTinyAllocations() {
doFillPatternBasic(1024);
}
@@ -88,7 +87,7 @@ public class MemoryAllocatorFillPatternJUnitTest {
*
*/
@Test
- public void testFillPatternBasicForHugeAllocations() throws Exception {
+ public void testFillPatternBasicForHugeAllocations() {
doFillPatternBasic(HUGE_CHUNK_SIZE);
}
@@ -96,24 +95,24 @@ public class MemoryAllocatorFillPatternJUnitTest {
/*
* Pull a chunk off the fragment. This will have no fill because it is a "fresh" chunk.
*/
- OffHeapStoredObject chunk = (OffHeapStoredObject) this.allocator.allocate(chunkSize);
+ OffHeapStoredObject chunk1 = (OffHeapStoredObject) this.allocator.allocate(chunkSize);
/*
* Chunk should have valid fill from initial fragment allocation.
*/
- chunk.validateFill();
+ chunk1.validateFill();
// "Dirty" the chunk so the release has something to fill over
- chunk.writeDataBytes(OffHeapStoredObject.MIN_CHUNK_SIZE + 1, WRITE_BYTES);
+ chunk1.writeDataBytes(OffHeapStoredObject.MIN_CHUNK_SIZE + 1, WRITE_BYTES);
// This should free the Chunk (ref count == 1)
- chunk.release();
+ chunk1.release();
/*
* This chunk should have a fill because it was reused from the free list (assuming no
* fragmentation at this point...)
*/
- chunk = (OffHeapStoredObject) this.allocator.allocate(chunkSize);
+ OffHeapStoredObject chunk = (OffHeapStoredObject) this.allocator.allocate(chunkSize);
// Make sure we have a fill this time
chunk.validateFill();
@@ -128,11 +127,11 @@ public class MemoryAllocatorFillPatternJUnitTest {
// "Dirty up" the free chunk
chunk.writeDataBytes(OffHeapStoredObject.MIN_CHUNK_SIZE + 1, WRITE_BYTES);
- catchException(chunk).validateFill();
- assertTrue(caughtException() instanceof IllegalStateException);
+ Throwable thrown = catchThrowable(() -> chunk.validateFill());
+ assertTrue(thrown instanceof IllegalStateException);
assertEquals(
"Fill pattern violated for chunk " + chunk.getAddress() + " with size " + chunk.getSize(),
- caughtException().getMessage());
+ thrown.getMessage());
}
@@ -142,7 +141,7 @@ public class MemoryAllocatorFillPatternJUnitTest {
*
*/
@Test
- public void testFillPatternAfterDefragmentation() throws Exception {
+ public void testFillPatternAfterDefragmentation() {
/*
* Stores our allocated memory.
*/
diff --git a/geode-core/src/test/java/org/apache/geode/security/GemFireSecurityExceptionTest.java b/geode-core/src/test/java/org/apache/geode/security/GemFireSecurityExceptionTest.java
index e42654e..f4b38b3 100644
--- a/geode-core/src/test/java/org/apache/geode/security/GemFireSecurityExceptionTest.java
+++ b/geode-core/src/test/java/org/apache/geode/security/GemFireSecurityExceptionTest.java
@@ -14,9 +14,8 @@
*/
package org.apache.geode.security;
-import static com.googlecode.catchexception.CatchException.catchException;
-import static com.googlecode.catchexception.CatchException.caughtException;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.catchThrowable;
import java.io.NotSerializableException;
import java.io.Serializable;
@@ -35,7 +34,7 @@ import org.apache.geode.test.junit.categories.SecurityTest;
/**
* Unit tests for {@link GemFireSecurityException}.
*/
-@Category({SecurityTest.class})
+@Category(SecurityTest.class)
public class GemFireSecurityExceptionTest {
private String message;
@@ -50,105 +49,102 @@ public class GemFireSecurityExceptionTest {
@Before
public void setUp() throws Exception {
- this.message = testName.getMethodName() + " message";
- this.causeMessage = testName.getMethodName() + " cause message";
+ message = testName.getMethodName() + " message";
+ causeMessage = testName.getMethodName() + " cause message";
- this.nonSerializableResolvedObj = new Object();
- this.nonSerializableNamingException = new NamingException(this.causeMessage);
- this.nonSerializableNamingException.setResolvedObj(this.nonSerializableResolvedObj);
+ nonSerializableResolvedObj = new Object();
+ nonSerializableNamingException = new NamingException(causeMessage);
+ nonSerializableNamingException.setResolvedObj(nonSerializableResolvedObj);
- this.serializableResolvedObj = new SerializableObject(this.testName.getMethodName());
- this.serializableNamingException = new NamingException(this.causeMessage);
- this.serializableNamingException.setResolvedObj(this.serializableResolvedObj);
+ serializableResolvedObj = new SerializableObject(testName.getMethodName());
+ serializableNamingException = new NamingException(causeMessage);
+ serializableNamingException.setResolvedObj(serializableResolvedObj);
assertPreConditions();
}
private void assertPreConditions() {
- catchException(this).clone(this.nonSerializableNamingException);
- assertThat((Throwable) caughtException()).isNotNull();
- assertThat((Throwable) caughtException().getCause())
+ Throwable thrown =
+ catchThrowable(() -> SerializationUtils.clone(nonSerializableNamingException));
+ assertThat(thrown).isNotNull();
+ assertThat(thrown.getCause())
.isInstanceOf(NotSerializableException.class);
- catchException(this).clone(this.serializableNamingException);
- assertThat((Throwable) caughtException()).isNull();
+ thrown = catchThrowable(() -> SerializationUtils.clone(serializableNamingException));
+ assertThat(thrown).isNull();
- assertThat(this.nonSerializableResolvedObj).isNotInstanceOf(Serializable.class);
+ assertThat(nonSerializableResolvedObj).isNotInstanceOf(Serializable.class);
- catchException(this).clone(this.serializableResolvedObj);
- assertThat((Throwable) caughtException()).isNull();
+ thrown = catchThrowable(() -> SerializationUtils.clone(serializableResolvedObj));
+ assertThat(thrown).isNull();
}
@Test
- public void isSerializable() throws Exception {
+ public void isSerializable() {
assertThat(GemFireSecurityException.class).isInstanceOf(Serializable.class);
}
@Test
- public void serializes() throws Exception {
- GemFireSecurityException instance = new GemFireSecurityException(this.message);
+ public void serializes() {
+ GemFireSecurityException instance = new GemFireSecurityException(message);
GemFireSecurityException cloned = (GemFireSecurityException) SerializationUtils.clone(instance);
- assertThat(cloned).hasMessage(this.message);
+ assertThat(cloned).hasMessage(message);
}
@Test
- public void serializesWithThrowable() throws Exception {
- Throwable cause = new Exception(this.causeMessage);
- GemFireSecurityException instance = new GemFireSecurityException(this.message, cause);
+ public void serializesWithThrowable() {
+ Throwable cause = new Exception(causeMessage);
+ GemFireSecurityException instance = new GemFireSecurityException(message, cause);
GemFireSecurityException cloned = (GemFireSecurityException) SerializationUtils.clone(instance);
- assertThat(cloned).hasMessage(this.message).hasCause(cause);
- assertThat(cloned.getCause()).hasMessage(this.causeMessage);
+ assertThat(cloned).hasMessage(message).hasCause(cause);
+ assertThat(cloned.getCause()).hasMessage(causeMessage);
}
@Test
- public void serializesWithNonSerializableNamingException() throws Exception {
+ public void serializesWithNonSerializableNamingException() {
GemFireSecurityException instance =
- new GemFireSecurityException(this.message, this.nonSerializableNamingException);
+ new GemFireSecurityException(message, nonSerializableNamingException);
GemFireSecurityException cloned = (GemFireSecurityException) SerializationUtils.clone(instance);
- assertThat(cloned).hasMessage(this.message).hasCause(this.nonSerializableNamingException);
+ assertThat(cloned).hasMessage(message).hasCause(nonSerializableNamingException);
NamingException cause = (NamingException) cloned.getCause();
- assertThat(cause).hasMessage(this.causeMessage);
+ assertThat(cause).hasMessage(causeMessage);
assertThat(cause.getResolvedObj()).isNull();
}
@Test
- public void serializesWithSerializableNamingException() throws Exception {
+ public void serializesWithSerializableNamingException() {
GemFireSecurityException instance =
- new GemFireSecurityException(this.message, this.serializableNamingException);
+ new GemFireSecurityException(message, serializableNamingException);
GemFireSecurityException cloned = (GemFireSecurityException) SerializationUtils.clone(instance);
- assertThat(cloned).hasMessage(this.message).hasCause(this.serializableNamingException);
+ assertThat(cloned).hasMessage(message).hasCause(serializableNamingException);
NamingException cause = (NamingException) cloned.getCause();
- assertThat(cause).hasMessage(this.causeMessage);
- assertThat(cause.getResolvedObj()).isNotNull().isEqualTo(this.serializableResolvedObj);
+ assertThat(cause).hasMessage(causeMessage);
+ assertThat(cause.getResolvedObj()).isNotNull().isEqualTo(serializableResolvedObj);
}
@Test
- public void isSerializableReturnsTrueForSerializableClass() throws Exception {
- assertThat(new GemFireSecurityException("").isSerializable(this.serializableResolvedObj))
+ public void isSerializableReturnsTrueForSerializableClass() {
+ assertThat(new GemFireSecurityException("").isSerializable(serializableResolvedObj))
.isTrue();
}
@Test
- public void isSerializableReturnsFalseForNonSerializableClass() throws Exception {
- assertThat(new GemFireSecurityException("").isSerializable(this.nonSerializableResolvedObj))
+ public void isSerializableReturnsFalseForNonSerializableClass() {
+ assertThat(new GemFireSecurityException("").isSerializable(nonSerializableResolvedObj))
.isFalse();
}
- public Object clone(final Serializable object) {
- return SerializationUtils.clone(object);
- }
-
- public static class SerializableObject implements Serializable {
+ private static class SerializableObject implements Serializable {
- private String name;
+ private final String name;
SerializableObject(String name) {
this.name = name;
@@ -164,7 +160,6 @@ public class GemFireSecurityExceptionTest {
SerializableObject that = (SerializableObject) o;
return name != null ? name.equals(that.name) : that.name == null;
-
}
@Override
diff --git a/geode-core/src/test/java/org/apache/geode/security/NotAuthorizedExceptionTest.java b/geode-core/src/test/java/org/apache/geode/security/NotAuthorizedExceptionTest.java
index 0d20f90..376b5b1 100644
--- a/geode-core/src/test/java/org/apache/geode/security/NotAuthorizedExceptionTest.java
+++ b/geode-core/src/test/java/org/apache/geode/security/NotAuthorizedExceptionTest.java
@@ -14,9 +14,8 @@
*/
package org.apache.geode.security;
-import static com.googlecode.catchexception.CatchException.catchException;
-import static com.googlecode.catchexception.CatchException.caughtException;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.Mockito.mock;
import java.io.NotSerializableException;
@@ -37,7 +36,7 @@ import org.apache.geode.test.junit.categories.SecurityTest;
/**
* Unit tests for {@link NotAuthorizedException}.
*/
-@Category({SecurityTest.class})
+@Category(SecurityTest.class)
public class NotAuthorizedExceptionTest {
private String message;
@@ -55,99 +54,95 @@ public class NotAuthorizedExceptionTest {
@Before
public void setUp() throws Exception {
- this.message = testName.getMethodName() + " message";
- this.causeMessage = testName.getMethodName() + " cause message";
+ message = testName.getMethodName() + " message";
+ causeMessage = testName.getMethodName() + " cause message";
- this.nonSerializableResolvedObj = new Object();
- this.nonSerializableNamingException = new NamingException(this.causeMessage);
- this.nonSerializableNamingException.setResolvedObj(this.nonSerializableResolvedObj);
+ nonSerializableResolvedObj = new Object();
+ nonSerializableNamingException = new NamingException(causeMessage);
+ nonSerializableNamingException.setResolvedObj(nonSerializableResolvedObj);
- this.serializableResolvedObj = new SerializableObject(this.testName.getMethodName());
- this.serializableNamingException = new NamingException(this.causeMessage);
- this.serializableNamingException.setResolvedObj(this.serializableResolvedObj);
+ serializableResolvedObj = new SerializableObject(testName.getMethodName());
+ serializableNamingException = new NamingException(causeMessage);
+ serializableNamingException.setResolvedObj(serializableResolvedObj);
- this.principalName = "jsmith";
- this.nonSerializablePrincipal = mock(Principal.class);
- this.serializablePrincipal = new SerializablePrincipal(this.principalName);
+ principalName = "jsmith";
+ nonSerializablePrincipal = mock(Principal.class);
+ serializablePrincipal = new SerializablePrincipal(principalName);
assertPreconditions();
}
private void assertPreconditions() {
- catchException(this).clone(this.nonSerializableNamingException);
- assertThat((Throwable) caughtException()).isNotNull();
- assertThat((Throwable) caughtException().getCause())
- .isInstanceOf(NotSerializableException.class);
+ Throwable thrown =
+ catchThrowable(() -> SerializationUtils.clone(nonSerializableNamingException));
+ assertThat(thrown).isNotNull();
+ assertThat(thrown.getCause()).isInstanceOf(NotSerializableException.class);
- catchException(this).clone(this.serializableNamingException);
- assertThat((Throwable) caughtException()).isNull();
+ thrown = catchThrowable(() -> SerializationUtils.clone(serializableNamingException));
+ assertThat(thrown).isNull();
- assertThat(this.nonSerializableResolvedObj).isNotInstanceOf(Serializable.class);
+ assertThat(nonSerializableResolvedObj).isNotInstanceOf(Serializable.class);
- catchException(this).clone(this.serializableResolvedObj);
- assertThat((Throwable) caughtException()).isNull();
+ thrown = catchThrowable(() -> SerializationUtils.clone(serializableResolvedObj));
+ assertThat(thrown).isNull();
- assertThat(this.nonSerializablePrincipal).isNotInstanceOf(Serializable.class);
+ assertThat(nonSerializablePrincipal).isNotInstanceOf(Serializable.class);
- catchException(this).clone(this.serializablePrincipal);
- assertThat((Throwable) caughtException()).isNull();
+ thrown = catchThrowable(() -> SerializationUtils.clone(serializablePrincipal));
+ assertThat(thrown).isNull();
}
@Test
- public void isSerializable() throws Exception {
+ public void isSerializable() {
assertThat(NotAuthorizedException.class).isInstanceOf(Serializable.class);
}
@Test
- public void serializes() throws Exception {
- NotAuthorizedException instance = new NotAuthorizedException(this.message);
+ public void serializes() {
+ NotAuthorizedException instance = new NotAuthorizedException(message);
NotAuthorizedException cloned = (NotAuthorizedException) SerializationUtils.clone(instance);
- assertThat(cloned).hasMessage(this.message);
+ assertThat(cloned).hasMessage(message);
}
@Test
- public void serializesWithThrowable() throws Exception {
- Throwable cause = new Exception(this.causeMessage);
- NotAuthorizedException instance = new NotAuthorizedException(this.message, cause);
+ public void serializesWithThrowable() {
+ Throwable cause = new Exception(causeMessage);
+ NotAuthorizedException instance = new NotAuthorizedException(message, cause);
NotAuthorizedException cloned = (NotAuthorizedException) SerializationUtils.clone(instance);
- assertThat(cloned).hasMessage(this.message);
+ assertThat(cloned).hasMessage(message);
assertThat(cloned).hasCause(cause);
}
@Test
- public void serializesWithNonSerializablePrincipal() throws Exception {
+ public void serializesWithNonSerializablePrincipal() {
NotAuthorizedException instance =
- new NotAuthorizedException(this.message, this.nonSerializablePrincipal);
+ new NotAuthorizedException(message, nonSerializablePrincipal);
assertThat(instance.getPrincipal()).isNotNull();
NotAuthorizedException cloned = (NotAuthorizedException) SerializationUtils.clone(instance);
- assertThat(cloned).hasMessage(this.message);
+ assertThat(cloned).hasMessage(message);
assertThat(cloned.getPrincipal()).isNull();
}
@Test
- public void serializesWithSerializablePrincipal() throws Exception {
+ public void serializesWithSerializablePrincipal() {
NotAuthorizedException instance =
- new NotAuthorizedException(this.message, this.serializablePrincipal);
+ new NotAuthorizedException(message, serializablePrincipal);
NotAuthorizedException cloned = (NotAuthorizedException) SerializationUtils.clone(instance);
- assertThat(cloned).hasMessage(this.message);
- assertThat(cloned.getPrincipal()).isNotNull().isEqualTo(this.serializablePrincipal);
+ assertThat(cloned).hasMessage(message);
+ assertThat(cloned.getPrincipal()).isNotNull().isEqualTo(serializablePrincipal);
}
- public Object clone(final Serializable object) {
- return SerializationUtils.clone(object);
- }
-
- public static class SerializableObject implements Serializable {
+ private static class SerializableObject implements Serializable {
- private String name;
+ private final String name;
SerializableObject(String name) {
this.name = name;
@@ -163,7 +158,6 @@ public class NotAuthorizedExceptionTest {
SerializableObject that = (SerializableObject) o;
return name != null ? name.equals(that.name) : that.name == null;
-
}
@Override
@@ -172,9 +166,9 @@ public class NotAuthorizedExceptionTest {
}
}
- public static class SerializablePrincipal implements Principal, Serializable {
+ private static class SerializablePrincipal implements Principal, Serializable {
- private String name;
+ private final String name;
SerializablePrincipal(String name) {
this.name = name;
@@ -182,7 +176,7 @@ public class NotAuthorizedExceptionTest {
@Override
public String getName() {
- return this.name;
+ return name;
}
@Override
@@ -195,7 +189,6 @@ public class NotAuthorizedExceptionTest {
SerializablePrincipal that = (SerializablePrincipal) o;
return name != null ? name.equals(that.name) : that.name == null;
-
}
@Override
diff --git a/geode-wan/src/distributedTest/java/org/apache/geode/internal/cache/wan/parallel/ParallelGatewaySenderOperationsDUnitTest.java b/geode-wan/src/distributedTest/java/org/apache/geode/internal/cache/wan/parallel/ParallelGatewaySenderOperationsDUnitTest.java
index ce6caaf..b2a1971 100644
--- a/geode-wan/src/distributedTest/java/org/apache/geode/internal/cache/wan/parallel/ParallelGatewaySenderOperationsDUnitTest.java
+++ b/geode-wan/src/distributedTest/java/org/apache/geode/internal/cache/wan/parallel/ParallelGatewaySenderOperationsDUnitTest.java
@@ -14,11 +14,10 @@
*/
package org.apache.geode.internal.cache.wan.parallel;
-import static com.googlecode.catchexception.CatchException.catchException;
-import static com.googlecode.catchexception.CatchException.caughtException;
import static org.apache.geode.internal.cache.tier.sockets.Message.MAX_MESSAGE_SIZE_PROPERTY;
import static org.apache.geode.test.dunit.IgnoredException.addIgnoredException;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.catchThrowable;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
@@ -42,7 +41,7 @@ import org.apache.geode.test.junit.categories.WanTest;
/**
* DUnit test for operations on ParallelGatewaySender
*/
-@Category({WanTest.class})
+@Category(WanTest.class)
@SuppressWarnings("serial")
public class ParallelGatewaySenderOperationsDUnitTest extends WANTestBase {
@@ -569,15 +568,13 @@ public class ParallelGatewaySenderOperationsDUnitTest extends WANTestBase {
vm4.invoke(() -> doPuts(getTestMethodName() + "_PR", 1000));
// try destroying on couple of nodes
- catchException(vm4).invoke(() -> destroySender("ln"));
+ Throwable caughtException = catchThrowable(() -> vm4.invoke(() -> destroySender("ln")));
- Exception caughtException = caughtException();
assertThat(caughtException).isInstanceOf(RMIException.class);
assertThat(caughtException.getCause()).isInstanceOf(GatewaySenderException.class);
- catchException(vm5).invoke(() -> destroySender("ln"));
+ caughtException = catchThrowable(() -> vm5.invoke(() -> destroySender("ln")));
- caughtException = caughtException();
assertThat(caughtException).isInstanceOf(RMIException.class);
assertThat(caughtException.getCause()).isInstanceOf(GatewaySenderException.class);