diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/versions/RegionVersionVectorTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/versions/RegionVersionVectorTest.java index e3e701499091..0647d619ef75 100644 --- a/geode-core/src/test/java/org/apache/geode/internal/cache/versions/RegionVersionVectorTest.java +++ b/geode-core/src/test/java/org/apache/geode/internal/cache/versions/RegionVersionVectorTest.java @@ -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; @@ -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; @@ -57,16 +59,19 @@ @Category(UnitTest.class) public class RegionVersionVectorTest { - private Future 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 @@ -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)); } @@ -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 result = + CompletableFuture.runAsync(() -> rvv.updateLocalVersion(newVersion), executorService); assertThatCode(() -> result.get(2, SECONDS)).doesNotThrowAnyException(); assertThat(rvv.getVersionForMember(ownerId)).isEqualTo(newVersion); @@ -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> { TestableRegionVersionVector(VersionSource ownerId, long version) { @@ -707,7 +713,7 @@ public int getDSFID() { } } - private class VersionRaceConditionRegionVersionVector extends TestableRegionVersionVector { + private static class VersionRaceConditionRegionVersionVector extends TestableRegionVersionVector { VersionRaceConditionRegionVersionVector(VersionSource ownerId, long version) {