Skip to content

Commit

Permalink
GEODE-4134: use ExecutorService for CompletableFuture (apache#1195)
Browse files Browse the repository at this point in the history
  • Loading branch information
kirklund authored Dec 21, 2017
1 parent d4183f6 commit 0ca3c8c
Showing 1 changed file with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
Expand All @@ -47,7 +50,6 @@
import org.apache.geode.InternalGemFireError;
import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
import org.apache.geode.internal.HeapDataOutputStream;
import org.apache.geode.internal.InternalDataSerializer;
import org.apache.geode.internal.Version;
import org.apache.geode.internal.cache.LocalRegion;
import org.apache.geode.internal.cache.persistence.DiskStoreID;
Expand All @@ -57,16 +59,19 @@
@Category(UnitTest.class)
public class RegionVersionVectorTest {

private Future<Void> result;
private ExecutorService executorService;

@Rule
public ExpectedException expectedException = ExpectedException.none();

@Before
public void setUp() throws Exception {
executorService = Executors.newSingleThreadExecutor();
}

@After
public void tearDown() throws Exception {
if (result != null && !result.isDone()) {
result.cancel(true);
}
assertThat(executorService.shutdownNow()).isEmpty();
}

@Test
Expand Down Expand Up @@ -317,11 +322,11 @@ public void testRVVSerialization() throws Exception {
assertTrue(rvv.sameAs(rvv.getCloneForTransmission()));

HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT);
InternalDataSerializer.writeObject(rvv.getCloneForTransmission(), out);
DataSerializer.writeObject(rvv.getCloneForTransmission(), out);
byte[] bytes = out.toByteArray();

DataInputStream dis = new DataInputStream(new ByteArrayInputStream(bytes));
DiskRegionVersionVector rvv2 = InternalDataSerializer.readObject(dis);
DiskRegionVersionVector rvv2 = DataSerializer.readObject(dis);

assertTrue(rvv.sameAs(rvv2));
}
Expand Down Expand Up @@ -622,7 +627,8 @@ public void doesNotHangIfOtherThreadChangedVersion() throws Exception {
long newVersion = 2;

RegionVersionVector rvv = new VersionRaceConditionRegionVersionVector(ownerId, oldVersion);
result = CompletableFuture.runAsync(() -> rvv.updateLocalVersion(newVersion));
Future<Void> result =
CompletableFuture.runAsync(() -> rvv.updateLocalVersion(newVersion), executorService);

assertThatCode(() -> result.get(2, SECONDS)).doesNotThrowAnyException();
assertThat(rvv.getVersionForMember(ownerId)).isEqualTo(newVersion);
Expand Down Expand Up @@ -676,7 +682,7 @@ private void doExceptionsWithContains(DiskStoreID id, DiskRegionVersionVector rv
assertEquals(0, rvv.getExceptionCount(id));
}

private class TestableRegionVersionVector
private static class TestableRegionVersionVector
extends RegionVersionVector<VersionSource<InternalDistributedMember>> {

TestableRegionVersionVector(VersionSource<InternalDistributedMember> ownerId, long version) {
Expand Down Expand Up @@ -707,7 +713,7 @@ public int getDSFID() {
}
}

private class VersionRaceConditionRegionVersionVector extends TestableRegionVersionVector {
private static class VersionRaceConditionRegionVersionVector extends TestableRegionVersionVector {

VersionRaceConditionRegionVersionVector(VersionSource<InternalDistributedMember> ownerId,
long version) {
Expand Down

0 comments on commit 0ca3c8c

Please sign in to comment.