Skip to content

Commit

Permalink
GEODE-5639: use AssertJ instead of CatchException
Browse files Browse the repository at this point in the history
* Move PdxAttributesJUnitTest to distributedTest
  • Loading branch information
kirklund committed Aug 28, 2018
1 parent ebe44c2 commit f550cc4
Show file tree
Hide file tree
Showing 21 changed files with 481 additions and 507 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -138,8 +137,8 @@ public void verifyThatPdxFieldNamedSameAsPrimaryKeyIsIgnored() throws Exception
@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -109,9 +108,8 @@ public void bytesValueDataSerializes() {
@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");
Expand All @@ -131,9 +129,8 @@ public void failureToDataSerializeFailsToPropagateInTransaction() {
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");
Expand All @@ -151,9 +148,8 @@ public void failureToDataSerializeFailsToPropagateInTransaction() {
@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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -33,8 +35,10 @@
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
Expand All @@ -43,57 +47,63 @@
* <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);
Expand Down
Loading

0 comments on commit f550cc4

Please sign in to comment.