Repository: geode Updated Branches: refs/heads/feature/GEODE-1279 10bc0d69e -> 9307bd784
Cleanup Bug* dunit tests Project: http://git-wip-us.apache.org/repos/asf/geode/repo Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/9307bd78 Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/9307bd78 Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/9307bd78 Branch: refs/heads/feature/GEODE-1279 Commit: 9307bd784573e5b93c0b4a65bb55082d470da67a Parents: 10bc0d6 Author: Kirk Lund <[email protected]> Authored: Wed May 24 09:35:31 2017 -0700 Committer: Kirk Lund <[email protected]> Committed: Wed May 24 09:35:31 2017 -0700 ---------------------------------------------------------------------- .../apache/geode/cache30/Bug34948DUnitTest.java | 157 ------------- .../apache/geode/cache30/Bug35214DUnitTest.java | 220 ------------------- .../apache/geode/cache30/Bug38013DUnitTest.java | 150 ------------- ...triesDoNotExpireDuringGIIRegressionTest.java | 198 +++++++++++++++++ ...luesAreLazilyDeserializedRegressionTest.java | 161 ++++++++++++++ ...serializedOnRemoteBucketsRegressionTest.java | 160 ++++++++++++++ .../cache/ConnectDisconnectDUnitTest.java | 148 +++++-------- .../internal/JUnit3DistributedTestCase.java | 62 ++---- .../internal/JUnit4DistributedTestCase.java | 123 ++++------- .../SerializableErrorCollector.java | 24 ++ 10 files changed, 660 insertions(+), 743 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/geode/blob/9307bd78/geode-core/src/test/java/org/apache/geode/cache30/Bug34948DUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/cache30/Bug34948DUnitTest.java b/geode-core/src/test/java/org/apache/geode/cache30/Bug34948DUnitTest.java deleted file mode 100644 index 8b98cd3..0000000 --- a/geode-core/src/test/java/org/apache/geode/cache30/Bug34948DUnitTest.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * 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. - */ -package org.apache.geode.cache30; - -import org.junit.experimental.categories.Category; -import org.junit.Test; - -import static org.junit.Assert.*; - -import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase; -import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase; -import org.apache.geode.test.junit.categories.DistributedTest; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; - -import org.apache.geode.DataSerializable; -import org.apache.geode.DataSerializer; -import org.apache.geode.cache.AttributesFactory; -import org.apache.geode.cache.CacheException; -import org.apache.geode.cache.CacheListener; -import org.apache.geode.cache.DataPolicy; -import org.apache.geode.cache.EntryEvent; -import org.apache.geode.cache.Region; -import org.apache.geode.cache.Scope; -import org.apache.geode.cache.util.CacheListenerAdapter; -import org.apache.geode.distributed.DistributedMember; -import org.apache.geode.distributed.DistributedSystem; -import org.apache.geode.distributed.internal.InternalDistributedSystem; -import org.apache.geode.test.dunit.Host; -import org.apache.geode.test.dunit.VM; - -/** - * Test to make sure cache values are lazily deserialized - * - * @since GemFire 5.0 - */ -@Category(DistributedTest.class) -public class Bug34948DUnitTest extends JUnit4CacheTestCase { - - public Bug34948DUnitTest() { - super(); - } - - ////////////////////// Test Methods ////////////////////// - - private VM getOtherVm() { - Host host = Host.getHost(0); - return host.getVM(0); - } - - static protected Object lastCallback = null; - - private void doCreateOtherVm() { - VM vm = getOtherVm(); - vm.invoke(new CacheSerializableRunnable("create root") { - public void run2() throws CacheException { - getSystem(); - AttributesFactory af = new AttributesFactory(); - af.setScope(Scope.DISTRIBUTED_ACK); - af.setDataPolicy(DataPolicy.PRELOADED); - CacheListener cl = new CacheListenerAdapter() { - public void afterCreate(EntryEvent event) { - // getLogWriter().info("afterCreate " + event.getKey()); - if (event.getCallbackArgument() != null) { - lastCallback = event.getCallbackArgument(); - } - } - - public void afterUpdate(EntryEvent event) { - // getLogWriter().info("afterUpdate " + event.getKey()); - if (event.getCallbackArgument() != null) { - lastCallback = event.getCallbackArgument(); - } - } - - public void afterInvalidate(EntryEvent event) { - if (event.getCallbackArgument() != null) { - lastCallback = event.getCallbackArgument(); - } - } - - public void afterDestroy(EntryEvent event) { - if (event.getCallbackArgument() != null) { - lastCallback = event.getCallbackArgument(); - } - } - }; - af.setCacheListener(cl); - createRootRegion("bug34948", af.create()); - } - }); - } - - /** - * Make sure that value is only deserialized in cache whose application asks for the value. - */ - @Test - public void testBug34948() throws CacheException { - final AttributesFactory factory = new AttributesFactory(); - factory.setScope(Scope.DISTRIBUTED_ACK); - factory.setDataPolicy(DataPolicy.PRELOADED); - final Region r = createRootRegion("bug34948", factory.create()); - - // before gii - r.put("key1", new HomeBoy()); - - doCreateOtherVm(); - - // after gii - r.put("key2", new HomeBoy()); - - r.localDestroy("key1"); - r.localDestroy("key2"); - - Object o = r.get("key1"); - assertTrue(r.get("key1") instanceof HomeBoy); - assertTrue(r.get("key2") == null); // preload will not distribute - - // @todo darrel: add putAll test once it does not deserialize - } - - public static class HomeBoy implements DataSerializable { - public HomeBoy() {} - - public void toData(DataOutput out) throws IOException { - DistributedMember me = InternalDistributedSystem.getAnyInstance().getDistributedMember(); - DataSerializer.writeObject(me, out); - } - - public void fromData(DataInput in) throws IOException, ClassNotFoundException { - DistributedSystem ds = InternalDistributedSystem.getAnyInstance(); - DistributedMember me = ds.getDistributedMember(); - DistributedMember hb = (DistributedMember) DataSerializer.readObject(in); - if (me.equals(hb)) { - ds.getLogWriter().info("HomeBoy was deserialized on his home"); - } else { - String msg = "HomeBoy was deserialized on " + me + " instead of his home " + hb; - ds.getLogWriter().error(msg); - throw new IllegalStateException(msg); - } - } - } -} http://git-wip-us.apache.org/repos/asf/geode/blob/9307bd78/geode-core/src/test/java/org/apache/geode/cache30/Bug35214DUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/cache30/Bug35214DUnitTest.java b/geode-core/src/test/java/org/apache/geode/cache30/Bug35214DUnitTest.java deleted file mode 100644 index ed25b26..0000000 --- a/geode-core/src/test/java/org/apache/geode/cache30/Bug35214DUnitTest.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * 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. - */ -package org.apache.geode.cache30; - -import org.junit.experimental.categories.Category; -import org.junit.Test; - -import static org.junit.Assert.*; - -import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase; -import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase; -import org.apache.geode.test.junit.categories.DistributedTest; - -import org.apache.geode.SystemFailure; -import org.apache.geode.cache.AttributesFactory; -import org.apache.geode.cache.CacheException; -import org.apache.geode.cache.CacheListener; -import org.apache.geode.cache.DataPolicy; -import org.apache.geode.cache.EntryEvent; -import org.apache.geode.cache.ExpirationAction; -import org.apache.geode.cache.ExpirationAttributes; -import org.apache.geode.cache.Region; -import org.apache.geode.cache.RegionEvent; -import org.apache.geode.cache.Scope; -import org.apache.geode.cache.util.CacheListenerAdapter; -import org.apache.geode.internal.cache.LocalRegion; -import org.apache.geode.test.dunit.Assert; -import org.apache.geode.test.dunit.AsyncInvocation; -import org.apache.geode.test.dunit.Host; -import org.apache.geode.test.dunit.LogWriterUtils; -import org.apache.geode.test.dunit.ThreadUtils; -import org.apache.geode.test.dunit.VM; -import org.apache.geode.test.dunit.Wait; -import org.apache.geode.test.dunit.WaitCriterion; - -/** - * Make sure entry expiration does not happen during gii for bug 35214 - * - * @since GemFire 5.0 - */ -@Category(DistributedTest.class) -public class Bug35214DUnitTest extends JUnit4CacheTestCase { - - protected volatile int expirationCount = 0; - - private final static int ENTRY_COUNT = 100; - - protected static volatile boolean callbackFailure; - - public Bug35214DUnitTest() { - super(); - } - - private VM getOtherVm() { - Host host = Host.getHost(0); - return host.getVM(0); - } - - private void initOtherVm() { - VM vm = getOtherVm(); - vm.invoke(new CacheSerializableRunnable("init") { - public void run2() throws CacheException { - getCache(); - AttributesFactory af = new AttributesFactory(); - af.setScope(Scope.DISTRIBUTED_ACK); - Region r1 = createRootRegion("r1", af.create()); - for (int i = 1; i <= ENTRY_COUNT; i++) { - r1.put("key" + i, "value" + i); - } - } - }); - } - - private AsyncInvocation updateOtherVm() throws Throwable { - VM vm = getOtherVm(); - AsyncInvocation otherUpdater = vm.invokeAsync(new CacheSerializableRunnable("update") { - public void run2() throws CacheException { - Region r1 = getRootRegion("r1"); - // let the main guys gii get started; we want to do updates - // during his gii - { - // wait for profile of getInitialImage cache to show up - org.apache.geode.internal.cache.CacheDistributionAdvisor adv = - ((org.apache.geode.internal.cache.DistributedRegion) r1) - .getCacheDistributionAdvisor(); - int numProfiles; - int expectedProfiles = 1; - for (;;) { - numProfiles = adv.adviseInitialImage(null).getReplicates().size(); - if (numProfiles < expectedProfiles) { - // getLogWriter().info("PROFILE CHECK: Found " + numProfiles + - // " getInitialImage Profiles (waiting for " + expectedProfiles + ")"); - // pause(5); - } else { - LogWriterUtils.getLogWriter() - .info("PROFILE CHECK: Found " + numProfiles + " getInitialImage Profiles (OK)"); - break; - } - } - } - // start doing updates of the keys to see if we can get deadlocked - int updateCount = 1; - do { - for (int i = 1; i <= ENTRY_COUNT; i++) { - String key = "key" + i; - if (r1.containsKey(key)) { - r1.destroy(key); - } else { - r1.put(key, "value" + i + "uc" + updateCount); - } - } - } while (updateCount++ < 20); - // do one more loop with no destroys - for (int i = 1; i <= ENTRY_COUNT; i++) { - String key = "key" + i; - if (!r1.containsKey(key)) { - r1.put(key, "value" + i + "uc" + updateCount); - } - } - } - }); - - // FIXME this thread does not terminate - // DistributedTestCase.join(otherUpdater, 5 * 60 * 1000, getLogWriter()); - // if(otherUpdater.exceptionOccurred()){ - // fail("otherUpdater failed", otherUpdater.getException()); - // } - - return otherUpdater; - } - - ////////////////////// Test Methods ////////////////////// - - protected boolean afterRegionCreateSeen = false; - - protected static void callbackAssertTrue(String msg, boolean cond) { - if (cond) - return; - callbackFailure = true; - // Throws ignored error, but... - assertTrue(msg, cond); - } - - - /** - * make sure entries do not expire during a GII - */ - @Test - public void testNoEntryExpireDuringGII() throws Exception { - initOtherVm(); - AsyncInvocation updater = null; - try { - updater = updateOtherVm(); - } catch (VirtualMachineError e) { - SystemFailure.initiateFailure(e); - throw e; - } catch (Throwable e1) { - Assert.fail("failed due to " + e1, e1); - } - System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true"); - org.apache.geode.internal.cache.InitialImageOperation.slowImageProcessing = 30; - callbackFailure = false; - - try { - AttributesFactory af = new AttributesFactory(); - af.setDataPolicy(DataPolicy.REPLICATE); - af.setScope(Scope.DISTRIBUTED_ACK); - af.setStatisticsEnabled(true); - af.setEntryIdleTimeout(new ExpirationAttributes(1, ExpirationAction.INVALIDATE)); - CacheListener cl1 = new CacheListenerAdapter() { - public void afterRegionCreate(RegionEvent re) { - afterRegionCreateSeen = true; - } - - public void afterInvalidate(EntryEvent e) { - callbackAssertTrue("afterregionCreate not seen", afterRegionCreateSeen); - // make sure region is initialized - callbackAssertTrue("not initialized", ((LocalRegion) e.getRegion()).isInitialized()); - expirationCount++; - org.apache.geode.internal.cache.InitialImageOperation.slowImageProcessing = 0; - } - }; - af.addCacheListener(cl1); - final Region r1 = createRootRegion("r1", af.create()); - ThreadUtils.join(updater, 60 * 1000); - WaitCriterion ev = new WaitCriterion() { - public boolean done() { - return r1.values().size() == 0; - } - - public String description() { - return "region never became empty"; - } - }; - Wait.waitForCriterion(ev, 2 * 1000, 200, true); - { - assertEquals(0, r1.values().size()); - assertEquals(ENTRY_COUNT, r1.keySet().size()); - } - - } finally { - org.apache.geode.internal.cache.InitialImageOperation.slowImageProcessing = 0; - System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY); - assertEquals(null, System.getProperty(LocalRegion.EXPIRY_MS_PROPERTY)); - } - assertFalse("Errors in callbacks; check logs for details", callbackFailure); - } -} http://git-wip-us.apache.org/repos/asf/geode/blob/9307bd78/geode-core/src/test/java/org/apache/geode/cache30/Bug38013DUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/cache30/Bug38013DUnitTest.java b/geode-core/src/test/java/org/apache/geode/cache30/Bug38013DUnitTest.java deleted file mode 100644 index a0e8021..0000000 --- a/geode-core/src/test/java/org/apache/geode/cache30/Bug38013DUnitTest.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * 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. - */ -package org.apache.geode.cache30; - -import org.junit.experimental.categories.Category; -import org.junit.Test; - -import static org.junit.Assert.*; - -import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase; -import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase; -import org.apache.geode.test.junit.categories.DistributedTest; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; - -import org.apache.geode.DataSerializable; -import org.apache.geode.DataSerializer; -import org.apache.geode.cache.AttributesFactory; -import org.apache.geode.cache.CacheException; -import org.apache.geode.cache.CacheListener; -import org.apache.geode.cache.EntryEvent; -import org.apache.geode.cache.PartitionAttributesFactory; -import org.apache.geode.cache.Region; -import org.apache.geode.cache.util.CacheListenerAdapter; -import org.apache.geode.distributed.DistributedMember; -import org.apache.geode.distributed.DistributedSystem; -import org.apache.geode.distributed.internal.InternalDistributedSystem; -import org.apache.geode.test.dunit.Host; -import org.apache.geode.test.dunit.VM; - -/** - * Test to make sure PR cache values are lazily deserialized - * - * @since GemFire 5.0 - */ -@Category(DistributedTest.class) -public class Bug38013DUnitTest extends JUnit4CacheTestCase { - - public Bug38013DUnitTest() { - super(); - } - - ////////////////////// Test Methods ////////////////////// - - private VM getOtherVm() { - Host host = Host.getHost(0); - return host.getVM(0); - } - - static protected Object lastCallback = null; - - private void doCreateOtherVm() { - VM vm = getOtherVm(); - vm.invoke(new CacheSerializableRunnable("create root") { - public void run2() throws CacheException { - getSystem(); - AttributesFactory af = new AttributesFactory(); - CacheListener cl = new CacheListenerAdapter() { - public void afterCreate(EntryEvent event) { - // getLogWriter().info("afterCreate " + event.getKey()); - if (event.getCallbackArgument() != null) { - lastCallback = event.getCallbackArgument(); - } - } - - public void afterUpdate(EntryEvent event) { - // getLogWriter().info("afterUpdate " + event.getKey()); - if (event.getCallbackArgument() != null) { - lastCallback = event.getCallbackArgument(); - } - } - - public void afterInvalidate(EntryEvent event) { - if (event.getCallbackArgument() != null) { - lastCallback = event.getCallbackArgument(); - } - } - - public void afterDestroy(EntryEvent event) { - if (event.getCallbackArgument() != null) { - lastCallback = event.getCallbackArgument(); - } - } - }; - af.setCacheListener(cl); - // create a pr with a data store - PartitionAttributesFactory paf = new PartitionAttributesFactory(); - paf.setRedundantCopies(0); - // use defaults so this is a data store - af.setPartitionAttributes(paf.create()); - createRootRegion("bug38013", af.create()); - } - }); - } - - /** - * Make sure that value is only deserialized in cache whose application asks for the value. - */ - @Test - public void testBug38013() throws CacheException { - final AttributesFactory factory = new AttributesFactory(); - PartitionAttributesFactory paf = new PartitionAttributesFactory(); - paf.setRedundantCopies(0); - paf.setLocalMaxMemory(0); // make it an accessor - factory.setPartitionAttributes(paf.create()); - final Region r = createRootRegion("bug38013", factory.create()); - - doCreateOtherVm(); - - r.put("key1", new HomeBoy()); - - assertTrue(r.get("key1") instanceof HomeBoy); - } - - public static class HomeBoy implements DataSerializable { - public HomeBoy() {} - - public void toData(DataOutput out) throws IOException { - DistributedMember me = InternalDistributedSystem.getAnyInstance().getDistributedMember(); - DataSerializer.writeObject(me, out); - } - - public void fromData(DataInput in) throws IOException, ClassNotFoundException { - DistributedSystem ds = InternalDistributedSystem.getAnyInstance(); - DistributedMember me = ds.getDistributedMember(); - DistributedMember hb = (DistributedMember) DataSerializer.readObject(in); - if (me.equals(hb)) { - ds.getLogWriter().info("HomeBoy was deserialized on his home"); - } else { - String msg = "HomeBoy was deserialized on " + me + " instead of his home " + hb; - ds.getLogWriter().error(msg); - throw new IllegalStateException(msg); - } - } - } -} http://git-wip-us.apache.org/repos/asf/geode/blob/9307bd78/geode-core/src/test/java/org/apache/geode/cache30/EntriesDoNotExpireDuringGIIRegressionTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/cache30/EntriesDoNotExpireDuringGIIRegressionTest.java b/geode-core/src/test/java/org/apache/geode/cache30/EntriesDoNotExpireDuringGIIRegressionTest.java new file mode 100644 index 0000000..72be29b --- /dev/null +++ b/geode-core/src/test/java/org/apache/geode/cache30/EntriesDoNotExpireDuringGIIRegressionTest.java @@ -0,0 +1,198 @@ +/* + * 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. + */ +package org.apache.geode.cache30; + +import static java.util.concurrent.TimeUnit.MINUTES; +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.core.Is.is; + +import org.apache.geode.cache.AttributesFactory; +import org.apache.geode.cache.CacheException; +import org.apache.geode.cache.CacheListener; +import org.apache.geode.cache.DataPolicy; +import org.apache.geode.cache.EntryEvent; +import org.apache.geode.cache.ExpirationAction; +import org.apache.geode.cache.ExpirationAttributes; +import org.apache.geode.cache.Region; +import org.apache.geode.cache.RegionEvent; +import org.apache.geode.cache.Scope; +import org.apache.geode.cache.util.CacheListenerAdapter; +import org.apache.geode.internal.cache.CacheDistributionAdvisor; +import org.apache.geode.internal.cache.DistributedRegion; +import org.apache.geode.internal.cache.InitialImageOperation; +import org.apache.geode.internal.cache.LocalRegion; +import org.apache.geode.test.dunit.AsyncInvocation; +import org.apache.geode.test.dunit.Host; +import org.apache.geode.test.dunit.VM; +import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase; +import org.apache.geode.test.dunit.rules.DistributedRestoreSystemProperties; +import org.apache.geode.test.junit.categories.DistributedTest; +import org.apache.geode.test.junit.rules.serializable.SerializableErrorCollector; +import org.awaitility.Awaitility; +import org.awaitility.core.ConditionFactory; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * Make sure entry expiration does not happen during gii for bug 35214 + * + * #35214: hang during getInitialImage due to entry expiration + * + * @since GemFire 5.0 + */ +@Category(DistributedTest.class) +public class EntriesDoNotExpireDuringGIIRegressionTest extends JUnit4CacheTestCase { + + private static final int ENTRY_COUNT = 100; + private static final String REGION_NAME = "r1"; + + // TODO: value of expirationCount is not validated + private final AtomicInteger expirationCount = new AtomicInteger(0); + + private final AtomicBoolean afterRegionCreateSeen = new AtomicBoolean(false); + + private VM otherVM; + + @Rule + public DistributedRestoreSystemProperties restoreSystemProperties = new DistributedRestoreSystemProperties(); + + @Rule + public SerializableErrorCollector errorCollector = new SerializableErrorCollector(); + + @Before + public void before() throws Exception { + this.otherVM = Host.getHost(0).getVM(0); + initOtherVm(this.otherVM); + + System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true"); + InitialImageOperation.slowImageProcessing = 30; + } + + @After + public void after() throws Exception { + InitialImageOperation.slowImageProcessing = 0; + } + + /** + * make sure entries do not expire during a GII + */ + @Test + public void entriesShouldNotExpireDuringGII() throws Exception { + AsyncInvocation updater = updateOtherVm(this.otherVM); + + AttributesFactory factory = new AttributesFactory(); + factory.setDataPolicy(DataPolicy.REPLICATE); + factory.setScope(Scope.DISTRIBUTED_ACK); + factory.setStatisticsEnabled(true); + factory.setEntryIdleTimeout(new ExpirationAttributes(1, ExpirationAction.INVALIDATE)); + factory.addCacheListener(createCacheListener()); + + Region region = createRootRegion(REGION_NAME, factory.create()); + + updater.await(); + + await().until(() -> region.values().size() == 0); + + assertThat(region.values().size()).isEqualTo(0); + assertThat(region.keySet().size()).isEqualTo(ENTRY_COUNT); + } + + private void initOtherVm(VM otherVM) { + otherVM.invoke(new CacheSerializableRunnable("init") { + @Override + public void run2() throws CacheException { + getCache(); + + AttributesFactory factory = new AttributesFactory(); + factory.setScope(Scope.DISTRIBUTED_ACK); + + Region region = createRootRegion(REGION_NAME, factory.create()); + + for (int i = 1; i <= ENTRY_COUNT; i++) { + region.put("key" + i, "value" + i); + } + } + }); + } + + private AsyncInvocation updateOtherVm(VM otherVM) { + return otherVM.invokeAsync(new CacheSerializableRunnable("update") { + @Override + public void run2() throws CacheException { + Region region = getRootRegion(REGION_NAME); + // let the main guys gii get started; we want to do updates during his gii + + // wait for profile of getInitialImage cache to show up + CacheDistributionAdvisor advisor = ((DistributedRegion) region).getCacheDistributionAdvisor(); + int expectedProfiles = 1; + await().until(() -> assertThat(numberProfiles(advisor)).isGreaterThanOrEqualTo(expectedProfiles)); + + // start doing updates of the keys to see if we can get deadlocked + int updateCount = 1; + do { + for (int i = 1; i <= ENTRY_COUNT; i++) { + String key = "key" + i; + if (region.containsKey(key)) { + region.destroy(key); + } else { + region.put(key, "value" + i + "uc" + updateCount); + } + } + } while (updateCount++ < 20); + + // do one more loop with no destroys + for (int i = 1; i <= ENTRY_COUNT; i++) { + String key = "key" + i; + if (!region.containsKey(key)) { + region.put(key, "value" + i + "uc" + updateCount); + } + } + } + }); + } + + private int numberProfiles(CacheDistributionAdvisor advisor) { + return advisor.adviseInitialImage(null).getReplicates().size(); + } + + private CacheListener createCacheListener() { + return new CacheListenerAdapter() { + @Override + public void afterRegionCreate(RegionEvent event) { + afterRegionCreateSeen.set(true); + } + @Override + public void afterInvalidate(EntryEvent event) { + errorCollector.checkThat("afterRegionCreate should have been seen", afterRegionCreateSeen.get(), is(true)); + errorCollector.checkThat("Region should have been initialized", ((LocalRegion) event.getRegion()).isInitialized(), is(true)); + + expirationCount.incrementAndGet(); + + InitialImageOperation.slowImageProcessing = 0; + } + }; + } + + private ConditionFactory await() { + return Awaitility.await().atMost(2, MINUTES); + } + +} http://git-wip-us.apache.org/repos/asf/geode/blob/9307bd78/geode-core/src/test/java/org/apache/geode/cache30/ValuesAreLazilyDeserializedRegressionTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/cache30/ValuesAreLazilyDeserializedRegressionTest.java b/geode-core/src/test/java/org/apache/geode/cache30/ValuesAreLazilyDeserializedRegressionTest.java new file mode 100644 index 0000000..329cf47 --- /dev/null +++ b/geode-core/src/test/java/org/apache/geode/cache30/ValuesAreLazilyDeserializedRegressionTest.java @@ -0,0 +1,161 @@ +/* + * 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. + */ +package org.apache.geode.cache30; + +import static org.junit.Assert.assertTrue; + +import org.apache.geode.DataSerializable; +import org.apache.geode.DataSerializer; +import org.apache.geode.cache.AttributesFactory; +import org.apache.geode.cache.CacheException; +import org.apache.geode.cache.CacheListener; +import org.apache.geode.cache.DataPolicy; +import org.apache.geode.cache.EntryEvent; +import org.apache.geode.cache.Region; +import org.apache.geode.cache.Scope; +import org.apache.geode.cache.util.CacheListenerAdapter; +import org.apache.geode.distributed.DistributedMember; +import org.apache.geode.distributed.DistributedSystem; +import org.apache.geode.distributed.internal.InternalDistributedSystem; +import org.apache.geode.test.dunit.Host; +import org.apache.geode.test.dunit.VM; +import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase; +import org.apache.geode.test.junit.categories.DistributedTest; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; + +/** + * Test to make sure cache values are lazily deserialized + * + * #34948: distributed cache values are always getting deserialized + * + * @since GemFire 5.0 + */ +@Category(DistributedTest.class) +public class ValuesAreLazilyDeserializedRegressionTest extends JUnit4CacheTestCase { + + // TODO: value of lastCallback is not validated + private static Object lastCallback = null; + + /** + * Make sure that value is only deserialized in cache whose application asks for the value. + */ + @Test + public void valueShouldBeDeserializedLazily() throws CacheException { + AttributesFactory factory = new AttributesFactory(); + factory.setScope(Scope.DISTRIBUTED_ACK); + factory.setDataPolicy(DataPolicy.PRELOADED); + + Region<String, HomeBoy> region = createRootRegion("bug34948", factory.create()); + + // before gii + region.put("key1", new HomeBoy()); + + doCreateOtherVm(); + + // after gii + region.put("key2", new HomeBoy()); + + region.localDestroy("key1"); + region.localDestroy("key2"); + + Object value = region.get("key1"); + assertTrue(region.get("key1") instanceof HomeBoy); + assertTrue(region.get("key2") == null); // preload will not distribute + + // TODO: add putAll test once it does not deserialize + } + + private VM getOtherVm() { + Host host = Host.getHost(0); + return host.getVM(0); + } + + private void doCreateOtherVm() { + VM vm = getOtherVm(); + vm.invoke(new CacheSerializableRunnable("create root") { + + @Override + public void run2() throws CacheException { + getSystem(); + + CacheListener<String, HomeBoy> listener = new CacheListenerAdapter<String, HomeBoy>() { + @Override + public void afterCreate(EntryEvent event) { + if (event.getCallbackArgument() != null) { + lastCallback = event.getCallbackArgument(); + } + } + + @Override + public void afterUpdate(EntryEvent event) { + if (event.getCallbackArgument() != null) { + lastCallback = event.getCallbackArgument(); + } + } + + @Override + public void afterInvalidate(EntryEvent event) { + if (event.getCallbackArgument() != null) { + lastCallback = event.getCallbackArgument(); + } + } + + @Override + public void afterDestroy(EntryEvent event) { + if (event.getCallbackArgument() != null) { + lastCallback = event.getCallbackArgument(); + } + } + }; + + AttributesFactory<String, HomeBoy> factory = new AttributesFactory<>(); + factory.setScope(Scope.DISTRIBUTED_ACK); + factory.setDataPolicy(DataPolicy.PRELOADED); + factory.setCacheListener(listener); + + createRootRegion("bug34948", factory.create()); + } + }); + } + + private static class HomeBoy implements DataSerializable { + public HomeBoy() {} + + @Override + public void toData(DataOutput out) throws IOException { + DistributedMember me = InternalDistributedSystem.getAnyInstance().getDistributedMember(); + DataSerializer.writeObject(me, out); + } + + @Override + public void fromData(DataInput in) throws IOException, ClassNotFoundException { + DistributedSystem ds = InternalDistributedSystem.getAnyInstance(); + DistributedMember me = ds.getDistributedMember(); + DistributedMember hb = DataSerializer.readObject(in); + if (me.equals(hb)) { + ds.getLogWriter().info("HomeBoy was deserialized on his home"); + } else { + String msg = "HomeBoy was deserialized on " + me + " instead of his home " + hb; + ds.getLogWriter().error(msg); + throw new IllegalStateException(msg); + } + } + } +} http://git-wip-us.apache.org/repos/asf/geode/blob/9307bd78/geode-core/src/test/java/org/apache/geode/cache30/ValuesAreNotDeserializedOnRemoteBucketsRegressionTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/cache30/ValuesAreNotDeserializedOnRemoteBucketsRegressionTest.java b/geode-core/src/test/java/org/apache/geode/cache30/ValuesAreNotDeserializedOnRemoteBucketsRegressionTest.java new file mode 100644 index 0000000..1aae322 --- /dev/null +++ b/geode-core/src/test/java/org/apache/geode/cache30/ValuesAreNotDeserializedOnRemoteBucketsRegressionTest.java @@ -0,0 +1,160 @@ +/* + * 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. + */ +package org.apache.geode.cache30; + +import static org.junit.Assert.assertTrue; + +import org.apache.geode.DataSerializable; +import org.apache.geode.DataSerializer; +import org.apache.geode.cache.AttributesFactory; +import org.apache.geode.cache.CacheException; +import org.apache.geode.cache.CacheListener; +import org.apache.geode.cache.EntryEvent; +import org.apache.geode.cache.PartitionAttributesFactory; +import org.apache.geode.cache.Region; +import org.apache.geode.cache.util.CacheListenerAdapter; +import org.apache.geode.distributed.DistributedMember; +import org.apache.geode.distributed.DistributedSystem; +import org.apache.geode.distributed.internal.InternalDistributedSystem; +import org.apache.geode.test.dunit.Host; +import org.apache.geode.test.dunit.VM; +import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase; +import org.apache.geode.test.junit.categories.DistributedTest; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; + +/** + * Test to make sure PR cache values are lazily deserialized + * + * #38013: PR regions do deserialization on remote bucket during get causing NoClassDefFoundError + * + * Values should not be deserialized on remote bucket + * + * @since GemFire 5.0 + */ +@Category(DistributedTest.class) +public class ValuesAreNotDeserializedOnRemoteBucketsRegressionTest extends JUnit4CacheTestCase { + + private static final String REGION_NAME = "bug38013"; + + // TODO: value of lastCallback is not validated + private static Object lastCallback = null; + + private VM otherVM; + + @Before + public void before() throws Exception { + this.otherVM = Host.getHost(0).getVM(0); + } + + /** + * Make sure that value is only deserialized in cache whose application asks for the value. + */ + @Test + public void testBug38013() throws Exception { + PartitionAttributesFactory partitionAttributesFactory = new PartitionAttributesFactory(); + partitionAttributesFactory.setRedundantCopies(0); + partitionAttributesFactory.setLocalMaxMemory(0); // make it an accessor + + AttributesFactory factory = new AttributesFactory(); + factory.setPartitionAttributes(partitionAttributesFactory.create()); + + Region<String, HomeBoy> region = createRootRegion(REGION_NAME, factory.create()); + + doCreateOtherVm(this.otherVM); + + region.put("key1", new HomeBoy()); + + assertTrue(region.get("key1") instanceof HomeBoy); + } + + private void doCreateOtherVm(VM otherVM) { + otherVM.invoke(new CacheSerializableRunnable("create root") { + public void run2() throws CacheException { + getSystem(); + + CacheListener listener = new CacheListenerAdapter() { + @Override + public void afterCreate(EntryEvent event) { + if (event.getCallbackArgument() != null) { + lastCallback = event.getCallbackArgument(); + } + } + + @Override + public void afterUpdate(EntryEvent event) { + if (event.getCallbackArgument() != null) { + lastCallback = event.getCallbackArgument(); + } + } + + @Override + public void afterInvalidate(EntryEvent event) { + if (event.getCallbackArgument() != null) { + lastCallback = event.getCallbackArgument(); + } + } + + @Override + public void afterDestroy(EntryEvent event) { + if (event.getCallbackArgument() != null) { + lastCallback = event.getCallbackArgument(); + } + } + }; + + AttributesFactory factory = new AttributesFactory(); + factory.setCacheListener(listener); + + // create a pr with a data store + PartitionAttributesFactory partitionAttributesFactory = new PartitionAttributesFactory(); + partitionAttributesFactory.setRedundantCopies(0); + + // use defaults so this is a data store + factory.setPartitionAttributes(partitionAttributesFactory.create()); + createRootRegion(REGION_NAME, factory.create()); + } + }); + } + + private static class HomeBoy implements DataSerializable { + public HomeBoy() {} + + @Override + public void toData(DataOutput out) throws IOException { + DistributedMember me = InternalDistributedSystem.getAnyInstance().getDistributedMember(); + DataSerializer.writeObject(me, out); + } + + @Override + public void fromData(DataInput in) throws IOException, ClassNotFoundException { + DistributedSystem ds = InternalDistributedSystem.getAnyInstance(); + DistributedMember me = ds.getDistributedMember(); + DistributedMember hb = DataSerializer.readObject(in); + if (me.equals(hb)) { + ds.getLogWriter().info("HomeBoy was deserialized on his home"); + } else { + String msg = "HomeBoy was deserialized on " + me + " instead of his home " + hb; + ds.getLogWriter().error(msg); + throw new IllegalStateException(msg); + } + } + } +} http://git-wip-us.apache.org/repos/asf/geode/blob/9307bd78/geode-core/src/test/java/org/apache/geode/internal/cache/ConnectDisconnectDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/ConnectDisconnectDUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/ConnectDisconnectDUnitTest.java index de63433..b52fe4d 100755 --- a/geode-core/src/test/java/org/apache/geode/internal/cache/ConnectDisconnectDUnitTest.java +++ b/geode-core/src/test/java/org/apache/geode/internal/cache/ConnectDisconnectDUnitTest.java @@ -14,105 +14,87 @@ */ package org.apache.geode.internal.cache; -import static org.apache.geode.distributed.ConfigurationProperties.*; - -import java.util.Properties; - -import org.junit.Test; -import org.junit.experimental.categories.Category; +import static org.apache.geode.distributed.ConfigurationProperties.CONSERVE_SOCKETS; +import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL; +import static org.assertj.core.api.Assertions.assertThat; +import org.apache.geode.internal.logging.LogService; import org.apache.geode.test.dunit.AsyncInvocation; -import org.apache.geode.test.dunit.DistributedTestUtils; import org.apache.geode.test.dunit.Host; -import org.apache.geode.test.dunit.IgnoredException; -import org.apache.geode.test.dunit.LogWriterUtils; import org.apache.geode.test.dunit.SerializableRunnable; import org.apache.geode.test.dunit.VM; import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase; +import org.apache.geode.test.junit.Repeat; import org.apache.geode.test.junit.categories.DistributedTest; +import org.apache.geode.test.junit.rules.RepeatRule; +import org.apache.logging.log4j.Logger; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.util.Properties; -/** A test of 46438 - missing response to an update attributes message */ +/** + * A test of 46438 - missing response to an update attributes message + * + * see bugs #50785 and #46438 + */ @Category(DistributedTest.class) public class ConnectDisconnectDUnitTest extends JUnit4CacheTestCase { + private static final Logger logger = LogService.getLogger(); - private IgnoredException ex; + private static int count; - // see bugs #50785 and #46438 - @Test - public void testManyConnectsAndDisconnects() throws Throwable { - // invokeInEveryVM(new SerializableRunnable() { - // - // @Override - // public void run() { - // Log.setLogWriterLevel("info"); - // } - // }); - - // uncomment these lines to use stand-alone locators - // int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(4); - // setLocatorPorts(ports); - - for (int i = 0; i < 20; i++) { - LogWriterUtils.getLogWriter().info("Test run: " + i); - runOnce(); - tearDown(); - setUp(); - } + @Rule + public RepeatRule repeat = new RepeatRule(); + + @BeforeClass + public static void beforeClass() { + count = 0; } + @Before + public void before() { + count++; + } - static int LOCATOR_PORT; - static String LOCATORS_STRING; + @After + public void after() { + disconnectAllFromDS(); - static int[] locatorPorts; + } - public void setLocatorPorts(int[] ports) { - DistributedTestUtils.deleteLocatorStateFile(ports); - String locators = ""; - for (int i = 0; i < ports.length; i++) { - if (i > 0) { - locators += ","; - } - locators += "localhost[" + ports[i] + "]"; - } - final String locators_string = locators; - for (int i = 0; i < ports.length; i++) { - final int port = ports[i]; - Host.getHost(0).getVM(i).invoke(new SerializableRunnable("set locator port") { - public void run() { - LOCATOR_PORT = port; - LOCATORS_STRING = locators_string; - } - }); - } - locatorPorts = ports; + @AfterClass + public static void afterClass() { + assertThat(count).isEqualTo(20); } @Override - public final void postTearDownCacheTestCase() throws Exception { - if (locatorPorts != null) { - DistributedTestUtils.deleteLocatorStateFile(locatorPorts); - } + public Properties getDistributedSystemProperties() { + Properties props = super.getDistributedSystemProperties(); + props.setProperty(LOG_LEVEL, "info"); + props.setProperty(CONSERVE_SOCKETS, "false"); + return props; } /** * This test creates 4 vms and starts a cache in each VM. If that doesn't hang, it destroys the DS * in all vms and recreates the cache. - * - * @throws Throwable */ - public void runOnce() throws Throwable { + @Test + @Repeat(20) + public void testManyConnectsAndDisconnects() throws Exception { + logger.info("Test run: {}", count); int numVMs = 4; - VM[] vms = new VM[numVMs]; for (int i = 0; i < numVMs; i++) { - // if(i == 0) { - // vms[i] = Host.getHost(0).getVM(4); - // } else { vms[i] = Host.getHost(0).getVM(i); - // } } AsyncInvocation[] asyncs = new AsyncInvocation[numVMs]; @@ -120,44 +102,14 @@ public class ConnectDisconnectDUnitTest extends JUnit4CacheTestCase { asyncs[i] = vms[i].invokeAsync(new SerializableRunnable("Create a cache") { @Override public void run() { - // try { - // JGroupMembershipManager.setDebugJGroups(true); getCache(); - // } finally { - // JGroupMembershipManager.setDebugJGroups(false); - // } } }); } - for (int i = 0; i < numVMs; i++) { - asyncs[i].getResult(); - // try { - // asyncs[i].getResult(30 * 1000); - // } catch(TimeoutException e) { - // getLogWriter().severe("DAN DEBUG - we have a hang"); - // dumpAllStacks(); - // fail("DAN - WE HIT THE ISSUE",e); - // throw e; - // } - } - - disconnectAllFromDS(); - } - - - @Override - public Properties getDistributedSystemProperties() { - Properties props = super.getDistributedSystemProperties(); - props.setProperty(LOG_LEVEL, "info"); - props.setProperty(CONSERVE_SOCKETS, "false"); - if (LOCATOR_PORT > 0) { - props.setProperty(START_LOCATOR, "localhost[" + LOCATOR_PORT + "]"); - props.setProperty(LOCATORS, LOCATORS_STRING); + asyncs[i].await(); } - return props; } - } http://git-wip-us.apache.org/repos/asf/geode/blob/9307bd78/geode-core/src/test/java/org/apache/geode/test/dunit/internal/JUnit3DistributedTestCase.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/internal/JUnit3DistributedTestCase.java b/geode-core/src/test/java/org/apache/geode/test/dunit/internal/JUnit3DistributedTestCase.java index abdac89..fc0f2f6 100755 --- a/geode-core/src/test/java/org/apache/geode/test/dunit/internal/JUnit3DistributedTestCase.java +++ b/geode-core/src/test/java/org/apache/geode/test/dunit/internal/JUnit3DistributedTestCase.java @@ -18,13 +18,10 @@ import java.io.Serializable; import java.util.Properties; import junit.framework.TestCase; -import org.apache.logging.log4j.Logger; import org.junit.experimental.categories.Category; -import org.apache.geode.cache.Cache; import org.apache.geode.distributed.DistributedSystem; import org.apache.geode.distributed.internal.InternalDistributedSystem; -import org.apache.geode.internal.logging.LogService; import org.apache.geode.test.junit.categories.DistributedTest; /** @@ -34,8 +31,6 @@ import org.apache.geode.test.junit.categories.DistributedTest; public abstract class JUnit3DistributedTestCase extends TestCase implements DistributedTestFixture, Serializable { - private static final Logger logger = LogService.getLogger(); - private final JUnit4DistributedTestCase delegate = new JUnit4DistributedTestCase(this) {}; /** @@ -47,19 +42,12 @@ public abstract class JUnit3DistributedTestCase extends TestCase JUnit4DistributedTestCase.initializeDistributedTestCase(); } - // --------------------------------------------------------------------------- - // methods for tests - // --------------------------------------------------------------------------- - /** * @deprecated Please override {@link #getDistributedSystemProperties()} instead. */ @Deprecated - public final void setSystem(final Properties props, final DistributedSystem ds) { // TODO: - // override - // getDistributedSystemProperties - // and then - // delete + public final void setSystem(final Properties props, final DistributedSystem ds) { + // TODO: override getDistributedSystemProperties and then delete delegate.setSystem(props, ds); } @@ -100,10 +88,6 @@ public abstract class JUnit3DistributedTestCase extends TestCase return delegate.basicGetSystem(); } - public final void nullSystem() { // TODO: delete - delegate.nullSystem(); - } - public static final InternalDistributedSystem getSystemStatic() { return JUnit4DistributedTestCase.getSystemStatic(); } @@ -146,10 +130,6 @@ public abstract class JUnit3DistributedTestCase extends TestCase JUnit4DistributedTestCase.disconnectFromDS(); } - // --------------------------------------------------------------------------- - // name methods - // --------------------------------------------------------------------------- - public static final String getTestMethodName() { return JUnit4DistributedTestCase.getTestMethodName(); } @@ -162,10 +142,6 @@ public abstract class JUnit3DistributedTestCase extends TestCase return delegate.getUniqueName(); } - // --------------------------------------------------------------------------- - // setup methods - // --------------------------------------------------------------------------- - /** * Sets up the DistributedTestCase. * <p> @@ -174,7 +150,7 @@ public abstract class JUnit3DistributedTestCase extends TestCase */ @Override public final void setUp() throws Exception { - delegate.setUp(); + delegate.setUpJUnit4DistributedTestCase(); } /** @@ -184,7 +160,9 @@ public abstract class JUnit3DistributedTestCase extends TestCase * <p> * Override this as needed. Default implementation is empty. */ - public void preSetUp() throws Exception {} + public void preSetUp() throws Exception { + // nothing by default + } /** * {@code postSetUp()} is invoked after @@ -193,11 +171,9 @@ public abstract class JUnit3DistributedTestCase extends TestCase * <p> * Override this as needed. Default implementation is empty. */ - public void postSetUp() throws Exception {} - - // --------------------------------------------------------------------------- - // teardown methods - // --------------------------------------------------------------------------- + public void postSetUp() throws Exception { + // nothing by default + } /** * Tears down the DistributedTestCase. @@ -219,7 +195,9 @@ public abstract class JUnit3DistributedTestCase extends TestCase * <p> * Override this as needed. Default implementation is empty. */ - public void preTearDown() throws Exception {} + public void preTearDown() throws Exception { + // nothing by default + } /** * {@code postTearDown()} is invoked after @@ -228,7 +206,9 @@ public abstract class JUnit3DistributedTestCase extends TestCase * <p> * Override this as needed. Default implementation is empty. */ - public void postTearDown() throws Exception {} + public void postTearDown() throws Exception { + // nothing by default + } /** * {@code preTearDownAssertions()} is invoked before any tear down methods have been invoked. If @@ -237,7 +217,9 @@ public abstract class JUnit3DistributedTestCase extends TestCase * <p> * Override this as needed. Default implementation is empty. */ - public void preTearDownAssertions() throws Exception {} + public void preTearDownAssertions() throws Exception { + // nothing by default + } /** * {@code postTearDownAssertions()} is invoked after all tear down methods have completed. This @@ -246,10 +228,8 @@ public abstract class JUnit3DistributedTestCase extends TestCase * <p> * Override this as needed. Default implementation is empty. */ - public void postTearDownAssertions() throws Exception {} - - protected static final void destroyRegions(final Cache cache) { // TODO: this should move to - // CacheTestCase - JUnit4DistributedTestCase.destroyRegions(cache); + public void postTearDownAssertions() throws Exception { + // nothing by default } + } http://git-wip-us.apache.org/repos/asf/geode/blob/9307bd78/geode-core/src/test/java/org/apache/geode/test/dunit/internal/JUnit4DistributedTestCase.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/internal/JUnit4DistributedTestCase.java b/geode-core/src/test/java/org/apache/geode/test/dunit/internal/JUnit4DistributedTestCase.java index 80fb92a..8a444a4 100644 --- a/geode-core/src/test/java/org/apache/geode/test/dunit/internal/JUnit4DistributedTestCase.java +++ b/geode-core/src/test/java/org/apache/geode/test/dunit/internal/JUnit4DistributedTestCase.java @@ -18,6 +18,11 @@ import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS; import static org.apache.geode.distributed.ConfigurationProperties.LOG_FILE; import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT; import static org.apache.geode.distributed.ConfigurationProperties.STATISTIC_ARCHIVE_FILE; +import static org.apache.geode.test.dunit.DistributedTestUtils.getAllDistributedSystemProperties; +import static org.apache.geode.test.dunit.DistributedTestUtils.unregisterInstantiatorsInThisVM; +import static org.apache.geode.test.dunit.Invoke.invokeInEveryVM; +import static org.apache.geode.test.dunit.Invoke.invokeInLocator; +import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter; import static org.junit.Assert.assertNotNull; import org.apache.geode.admin.internal.AdminDistributedSystemImpl; @@ -50,11 +55,8 @@ import org.apache.geode.internal.net.SocketCreator; import org.apache.geode.internal.net.SocketCreatorFactory; import org.apache.geode.management.internal.cli.LogWrapper; import org.apache.geode.test.dunit.DUnitBlackboard; -import org.apache.geode.test.dunit.DistributedTestUtils; import org.apache.geode.test.dunit.Host; import org.apache.geode.test.dunit.IgnoredException; -import org.apache.geode.test.dunit.Invoke; -import org.apache.geode.test.dunit.LogWriterUtils; import org.apache.geode.test.dunit.standalone.DUnitLauncher; import org.apache.geode.test.junit.rules.serializable.SerializableTestName; import org.apache.logging.log4j.Logger; @@ -64,10 +66,8 @@ import org.junit.BeforeClass; import org.junit.Rule; import java.io.Serializable; -import java.text.DecimalFormat; -import java.util.Iterator; import java.util.LinkedHashSet; -import java.util.Map; +import java.util.Map.Entry; import java.util.Properties; import java.util.Set; @@ -75,10 +75,9 @@ import java.util.Set; * This class is the base class for all distributed tests using JUnit 4. */ public abstract class JUnit4DistributedTestCase implements DistributedTestFixture, Serializable { - private static final Logger logger = LogService.getLogger(); - private static final Set<String> testHistory = new LinkedHashSet<String>(); + private static final Set<String> testHistory = new LinkedHashSet<>(); /** This VM's connection to the distributed system */ private static InternalDistributedSystem system; @@ -86,10 +85,7 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur private static Properties lastSystemProperties; private static volatile String testMethodName; - /** For formatting timing info */ - private static final DecimalFormat format = new DecimalFormat("###.###"); - - private static boolean reconnect = false; + private static DUnitBlackboard blackboard; private static final boolean logPerTest = Boolean.getBoolean("dunitLogPerTest"); @@ -116,17 +112,6 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur @Rule public SerializableTestName testNameForDistributedTestCase = new SerializableTestName(); - private static DUnitBlackboard blackboard; - - /** - * Returns a DUnitBlackboard that can be used to pass data between VMs and synchronize actions. - * - * @return the blackboard - */ - public DUnitBlackboard getBlackboard() { - return blackboard; - } - @BeforeClass public static final void initializeDistributedTestCase() { DUnitLauncher.launchIfNeeded(); @@ -147,19 +132,12 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur return this.distributedTestFixture.getClass(); } - // --------------------------------------------------------------------------- - // methods for tests - // --------------------------------------------------------------------------- - /** * @deprecated Please override {@link #getDistributedSystemProperties()} instead. */ @Deprecated - public final void setSystem(final Properties props, final DistributedSystem ds) { // TODO: - // override - // getDistributedSystemProperties - // and then - // delete + public final void setSystem(final Properties props, final DistributedSystem ds) { + // TODO: override getDistributedSystemProperties and then delete system = (InternalDistributedSystem) ds; lastSystemProperties = props; lastSystemCreatedInTest = getTestClass(); // used to be getDeclaringClass() @@ -183,9 +161,10 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur if (system == null) { system = InternalDistributedSystem.getAnyInstance(); } + if (system == null || !system.isConnected()) { // Figure out our distributed system properties - Properties p = DistributedTestUtils.getAllDistributedSystemProperties(props); + Properties p = getAllDistributedSystemProperties(props); lastSystemCreatedInTest = getTestClass(); // used to be getDeclaringClass() if (logPerTest) { String testMethod = getTestMethodName(); @@ -197,36 +176,33 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur } system = (InternalDistributedSystem) DistributedSystem.connect(p); lastSystemProperties = p; + } else { boolean needNewSystem = false; if (!getTestClass().equals(lastSystemCreatedInTest)) { // used to be getDeclaringClass() - Properties newProps = DistributedTestUtils.getAllDistributedSystemProperties(props); + Properties newProps = getAllDistributedSystemProperties(props); needNewSystem = !newProps.equals(lastSystemProperties); if (needNewSystem) { - LogWriterUtils.getLogWriter() - .info("Test class has changed and the new DS properties are not an exact match. " - + "Forcing DS disconnect. Old props = " + lastSystemProperties + "new props=" - + newProps); + getLogWriter().info("Test class has changed and the new DS properties are not an exact match. " + "Forcing DS disconnect. Old props = " + lastSystemProperties + "new props=" + newProps); } + } else { Properties activeProps = system.getProperties(); - for (Iterator iter = props.entrySet().iterator(); iter.hasNext();) { - Map.Entry entry = (Map.Entry) iter.next(); + for (Entry<Object, Object> entry : props.entrySet()) { String key = (String) entry.getKey(); String value = (String) entry.getValue(); if (!value.equals(activeProps.getProperty(key))) { needNewSystem = true; - LogWriterUtils.getLogWriter().info("Forcing DS disconnect. For property " + key - + " old value = " + activeProps.getProperty(key) + " new value = " + value); + getLogWriter().info("Forcing DS disconnect. For property " + key + " old value = " + activeProps.getProperty(key) + " new value = " + value); break; } } } + if (needNewSystem) { // the current system does not meet our needs to disconnect and // call recursively to get a new system. - LogWriterUtils.getLogWriter() - .info("Disconnecting from current DS in order to make a new one"); + getLogWriter().info("Disconnecting from current DS in order to make a new one"); disconnectFromDS(); getSystem(props); } @@ -305,14 +281,13 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur public static final void disconnectAllFromDS() { disconnectFromDS(); - Invoke.invokeInEveryVM("disconnectFromDS", () -> disconnectFromDS()); + invokeInEveryVM("disconnectFromDS", () -> disconnectFromDS()); } /** * Disconnects this VM from the distributed system */ public static final void disconnectFromDS() { - // setTestMethodName(null); GemFireCacheImpl.testCacheXml = null; if (system != null) { system.disconnect(); @@ -326,20 +301,24 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur } try { ds.disconnect(); - } catch (Exception e) { - // ignore + } catch (Exception ignore) { } } AdminDistributedSystemImpl ads = AdminDistributedSystemImpl.getConnectedInstance(); - if (ads != null) {// && ads.isConnected()) { + if (ads != null) { ads.disconnect(); } } - // --------------------------------------------------------------------------- - // name methods - // --------------------------------------------------------------------------- + /** + * Returns a DUnitBlackboard that can be used to pass data between VMs and synchronize actions. + * + * @return the blackboard + */ + public DUnitBlackboard getBlackboard() { + return blackboard; + } public static final String getTestMethodName() { return testMethodName; @@ -358,10 +337,6 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur return getTestClass().getSimpleName() + "_" + getName(); } - // --------------------------------------------------------------------------- - // setup methods - // --------------------------------------------------------------------------- - /** * Sets up the DistributedTestCase. * @@ -455,11 +430,10 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur .set(new InternalDistributedSystem.CreationStackGenerator() { @Override public Throwable generateCreationStack(final DistributionConfig config) { - final StringBuilder sb = new StringBuilder(); - final String[] validAttributeNames = config.getAttributeNames(); - for (int i = 0; i < validAttributeNames.length; i++) { - final String attName = validAttributeNames[i]; - final Object actualAtt = config.getAttributeObject(attName); + StringBuilder sb = new StringBuilder(); + String[] validAttributeNames = config.getAttributeNames(); + for (String attName : validAttributeNames) { + Object actualAtt = config.getAttributeObject(attName); String actualAttStr = actualAtt.toString(); sb.append(" "); sb.append(attName); @@ -487,10 +461,6 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur System.out.println("Previously run tests: " + testHistory); } - // --------------------------------------------------------------------------- - // teardown methods - // --------------------------------------------------------------------------- - /** * Tears down the DistributedTestCase. * @@ -515,8 +485,7 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur } private final void tearDownDistributedTestCase() throws Exception { - Invoke.invokeInEveryVM("tearDownCreationStackGenerator", - () -> tearDownCreationStackGenerator()); + invokeInEveryVM("tearDownCreationStackGenerator", () -> tearDownCreationStackGenerator()); if (logPerTest) { disconnectAllFromDS(); } @@ -524,7 +493,6 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur if (!getDistributedSystemProperties().isEmpty()) { disconnectAllFromDS(); } - } /** @@ -569,10 +537,10 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur private static final void cleanupAllVms() { tearDownVM(); - Invoke.invokeInEveryVM("tearDownVM", () -> tearDownVM()); - Invoke.invokeInLocator(() -> { + invokeInEveryVM("tearDownVM", () -> tearDownVM()); + invokeInLocator(() -> { DistributionMessageObserver.setInstance(null); - DistributedTestUtils.unregisterInstantiatorsInThisVM(); + unregisterInstantiatorsInThisVM(); }); DUnitLauncher.closeAndCheckForSuspects(); } @@ -580,6 +548,7 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur private static final void tearDownVM() { closeCache(); disconnectFromDS(); + // keep alphabetized to detect duplicate lines CacheCreation.clearThreadLocals(); CacheServerLauncher.clearStatics(); @@ -588,7 +557,7 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur ClientServerTestCase.AUTO_LOAD_BALANCE = false; ClientStatsManager.cleanupForTests(); DiskStoreObserver.setInstance(null); - DistributedTestUtils.unregisterInstantiatorsInThisVM(); + unregisterInstantiatorsInThisVM(); DistributionMessageObserver.setInstance(null); GlobalLockingDUnitTest.region_testBug32356 = null; InitialImageOperation.slowImageProcessing = 0; @@ -614,7 +583,8 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur SocketCreatorFactory.close(); } - private static final void closeCache() { // TODO: this should move to CacheTestCase + // TODO: this should move to CacheTestCase + private static final void closeCache() { GemFireCacheImpl cache = GemFireCacheImpl.getInstance(); if (cache != null && !cache.isClosed()) { destroyRegions(cache); @@ -622,12 +592,11 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur } } - protected static final void destroyRegions(final Cache cache) { // TODO: this should move to - // CacheTestCase + // TODO: this should move to CacheTestCase + protected static final void destroyRegions(final Cache cache) { if (cache != null && !cache.isClosed()) { // try to destroy the root regions first so that we clean up any persistent files. - for (Iterator itr = cache.rootRegions().iterator(); itr.hasNext();) { - Region root = (Region) itr.next(); + for (Region<?, ?> root : cache.rootRegions()) { String regionFullPath = root == null ? null : root.getFullPath(); // for colocated regions you can't locally destroy a partitioned region. if (root.isDestroyed() || root instanceof HARegion || root instanceof PartitionedRegion) { http://git-wip-us.apache.org/repos/asf/geode/blob/9307bd78/geode-junit/src/main/java/org/apache/geode/test/junit/rules/serializable/SerializableErrorCollector.java ---------------------------------------------------------------------- diff --git a/geode-junit/src/main/java/org/apache/geode/test/junit/rules/serializable/SerializableErrorCollector.java b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/serializable/SerializableErrorCollector.java new file mode 100644 index 0000000..0abfdaf --- /dev/null +++ b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/serializable/SerializableErrorCollector.java @@ -0,0 +1,24 @@ +/* + * 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. + */ +package org.apache.geode.test.junit.rules.serializable; + +import org.junit.rules.ErrorCollector; + +import java.io.Serializable; + +public class SerializableErrorCollector extends ErrorCollector implements Serializable { +}
