1279: rename tests with old bug system numbers * Bug34387DUnitTest -> CreateAndLocalDestroyInTXRegressionTest * Bug35214DUnitTest -> EntriesDoNotExpireDuringGIIRegressionTest * Bug38013DUnitTest -> RemotePRValuesAreNotDeserializedRegressionTest * Bug34948DUnitTest -> ValuesAreLazilyDeserializedRegressionTest
Project: http://git-wip-us.apache.org/repos/asf/geode/repo Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/8b731c57 Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/8b731c57 Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/8b731c57 Branch: refs/heads/feature/GEODE-1279 Commit: 8b731c5770b0f1496b1ac93a3f6570fa54f6fd55 Parents: 456ee15 Author: Kirk Lund <kl...@apache.org> Authored: Wed May 24 13:09:11 2017 -0700 Committer: Kirk Lund <kl...@apache.org> Committed: Wed May 24 13:09:11 2017 -0700 ---------------------------------------------------------------------- .../apache/geode/cache30/Bug34387DUnitTest.java | 188 ---------------- .../apache/geode/cache30/Bug34948DUnitTest.java | 157 ------------- .../apache/geode/cache30/Bug35214DUnitTest.java | 220 ------------------- .../apache/geode/cache30/Bug38013DUnitTest.java | 150 ------------- ...CreateAndLocalDestroyInTXRegressionTest.java | 165 ++++++++++++++ ...triesDoNotExpireDuringGIIRegressionTest.java | 206 +++++++++++++++++ ...RValuesAreNotDeserializedRegressionTest.java | 160 ++++++++++++++ ...luesAreLazilyDeserializedRegressionTest.java | 165 ++++++++++++++ .../cache/ConnectDisconnectDUnitTest.java | 148 +++++-------- .../dunit/internal/DistributedTestFixture.java | 16 +- .../internal/JUnit3DistributedTestCase.java | 62 ++---- .../internal/JUnit4DistributedTestCase.java | 123 ++++------- .../SerializableErrorCollector.java | 22 ++ 13 files changed, 845 insertions(+), 937 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/geode/blob/8b731c57/geode-core/src/test/java/org/apache/geode/cache30/Bug34387DUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/cache30/Bug34387DUnitTest.java b/geode-core/src/test/java/org/apache/geode/cache30/Bug34387DUnitTest.java deleted file mode 100644 index d43be83..0000000 --- a/geode-core/src/test/java/org/apache/geode/cache30/Bug34387DUnitTest.java +++ /dev/null @@ -1,188 +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.cache.AttributesFactory; -import org.apache.geode.cache.CacheException; -import org.apache.geode.cache.CacheListener; -import org.apache.geode.cache.CacheTransactionManager; -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.UnsupportedOperationInTransactionException; -import org.apache.geode.cache.util.CacheListenerAdapter; -import org.apache.geode.distributed.DistributedMember; -import org.apache.geode.distributed.internal.InternalDistributedSystem; -import org.apache.geode.internal.i18n.LocalizedStrings; -import org.apache.geode.test.dunit.Host; -import org.apache.geode.test.dunit.VM; - -/** - * Test create + localDestroy for bug 34387 - * - * @since GemFire 5.0 - */ -@Category(DistributedTest.class) -public class Bug34387DUnitTest extends JUnit4CacheTestCase { - - // private transient Region r; - // private transient DistributedMember otherId; - protected transient int invokeCount; - - static volatile boolean callbackFailure; - - public Bug34387DUnitTest() { - super(); - } - - protected static void callbackAssertEquals(String message, Object expected, Object actual) { - if (expected == null && actual == null) - return; - if (expected != null && expected.equals(actual)) - return; - callbackFailure = true; - // Throws an error that is ignored, but... - assertEquals(message, expected, actual); - } - - - private VM getOtherVm() { - Host host = Host.getHost(0); - return host.getVM(0); - } - - private void initOtherId() { - VM vm = getOtherVm(); - vm.invoke(new CacheSerializableRunnable("Connect") { - public void run2() throws CacheException { - getCache(); - } - }); - vm.invoke(() -> Bug34387DUnitTest.getVMDistributedMember()); - } - - private void doCommitOtherVm(final boolean doDestroy) { - VM vm = getOtherVm(); - vm.invoke(new CacheSerializableRunnable("create root") { - public void run2() throws CacheException { - AttributesFactory af = new AttributesFactory(); - af.setScope(Scope.DISTRIBUTED_ACK); - af.setConcurrencyChecksEnabled(true); - Region r1 = createRootRegion("r1", af.create()); - CacheTransactionManager ctm = getCache().getCacheTransactionManager(); - ctm.begin(); - r1.create("createKey", "createValue"); - if (doDestroy) { - try { - r1.localDestroy("createKey"); - fail("expected exception not thrown"); - } catch (UnsupportedOperationInTransactionException e) { - assertEquals(e.getMessage(), - LocalizedStrings.TXStateStub_LOCAL_DESTROY_NOT_ALLOWED_IN_TRANSACTION - .toLocalizedString()); - } - } else { - try { - r1.localInvalidate("createKey"); - fail("expected exception not thrown"); - } catch (UnsupportedOperationInTransactionException e) { - assertEquals(e.getMessage(), - LocalizedStrings.TXStateStub_LOCAL_INVALIDATE_NOT_ALLOWED_IN_TRANSACTION - .toLocalizedString()); - } - } - ctm.commit(); - } - }); - } - - public static DistributedMember getVMDistributedMember() { - return InternalDistributedSystem.getAnyInstance().getDistributedMember(); - } - - ////////////////////// Test Methods ////////////////////// - - /** - * test create followed by localDestroy - */ - @Test - public void testCreateAndLD() throws CacheException { - initOtherId(); - AttributesFactory af = new AttributesFactory(); - af.setDataPolicy(DataPolicy.REPLICATE); - af.setScope(Scope.DISTRIBUTED_ACK); - af.setConcurrencyChecksEnabled(true); - callbackFailure = false; - - CacheListener cl1 = new CacheListenerAdapter() { - public void afterCreate(EntryEvent e) { - callbackAssertEquals("Keys not equal", "createKey", e.getKey()); - callbackAssertEquals("Values not equal", "createValue", e.getNewValue()); - Bug34387DUnitTest.this.invokeCount++; - } - }; - af.addCacheListener(cl1); - Region r1 = createRootRegion("r1", af.create()); - - this.invokeCount = 0; - assertNull(r1.getEntry("createKey")); - doCommitOtherVm(true); - assertNotNull(r1.getEntry("createKey")); - assertEquals("createValue", r1.getEntry("createKey").getValue()); - assertEquals(1, this.invokeCount); - assertFalse("Errors in callbacks; check logs for details", callbackFailure); - } - - /** - * test create followed by localInvalidate - */ - @Test - public void testCreateAndLI() throws CacheException { - initOtherId(); - AttributesFactory af = new AttributesFactory(); - af.setDataPolicy(DataPolicy.REPLICATE); - af.setScope(Scope.DISTRIBUTED_ACK); - af.setConcurrencyChecksEnabled(true); - callbackFailure = false; - - CacheListener cl1 = new CacheListenerAdapter() { - public void afterCreate(EntryEvent e) { - callbackAssertEquals("key not equal", "createKey", e.getKey()); - callbackAssertEquals("value not equal", "createValue", e.getNewValue()); - Bug34387DUnitTest.this.invokeCount++; - } - }; - af.addCacheListener(cl1); - Region r1 = createRootRegion("r1", af.create()); - - this.invokeCount = 0; - assertNull(r1.getEntry("createKey")); - doCommitOtherVm(false); - assertNotNull(r1.getEntry("createKey")); - assertEquals("createValue", r1.getEntry("createKey").getValue()); - assertEquals(1, this.invokeCount); - assertFalse("Errors in callbacks; check logs for details", callbackFailure); - } -} http://git-wip-us.apache.org/repos/asf/geode/blob/8b731c57/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/8b731c57/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/8b731c57/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/8b731c57/geode-core/src/test/java/org/apache/geode/cache30/CreateAndLocalDestroyInTXRegressionTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/cache30/CreateAndLocalDestroyInTXRegressionTest.java b/geode-core/src/test/java/org/apache/geode/cache30/CreateAndLocalDestroyInTXRegressionTest.java new file mode 100644 index 0000000..b978b85 --- /dev/null +++ b/geode-core/src/test/java/org/apache/geode/cache30/CreateAndLocalDestroyInTXRegressionTest.java @@ -0,0 +1,165 @@ +/* + * 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.apache.geode.internal.i18n.LocalizedStrings.TXStateStub_LOCAL_DESTROY_NOT_ALLOWED_IN_TRANSACTION; +import static org.apache.geode.internal.i18n.LocalizedStrings.TXStateStub_LOCAL_INVALIDATE_NOT_ALLOWED_IN_TRANSACTION; +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +import org.apache.geode.cache.AttributesFactory; +import org.apache.geode.cache.CacheException; +import org.apache.geode.cache.CacheListener; +import org.apache.geode.cache.CacheTransactionManager; +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.UnsupportedOperationInTransactionException; +import org.apache.geode.cache.util.CacheListenerAdapter; +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.apache.geode.test.junit.rules.serializable.SerializableErrorCollector; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +/** + * Test create + localDestroy for bug 34387 + * + * #34387: TX in Proxy Regions with create followed by localDestroy on same key results in remote + * VMs receiving create events with null getNewValue(). + * + * Create and LocalDestroy/LocalInvalidate should create event with NewValue + * + * @since GemFire 5.0 + */ +@Category(DistributedTest.class) +public class CreateAndLocalDestroyInTXRegressionTest extends JUnit4CacheTestCase { + + private static final String REGION_NAME = "r1"; + + private int invokeCount; + private VM otherVM; + private transient Region region; + + @Rule + public SerializableErrorCollector errorCollector = new SerializableErrorCollector(); + + @Before + public void setUp() throws Exception { + this.invokeCount = 0; + this.otherVM = Host.getHost(0).getVM(0); + + initOtherVM(this.otherVM); + AttributesFactory af = new AttributesFactory(); + af.setDataPolicy(DataPolicy.REPLICATE); + af.setScope(Scope.DISTRIBUTED_ACK); + af.setConcurrencyChecksEnabled(true); + + CacheListener cl1 = new CacheListenerAdapter() { + @Override + public void afterCreate(EntryEvent e) { + errorCollector.checkThat("Keys not equal", "createKey", equalTo(e.getKey())); + errorCollector.checkThat("Values not equal", "createValue", equalTo(e.getNewValue())); + CreateAndLocalDestroyInTXRegressionTest.this.invokeCount++; + } + }; + + af.addCacheListener(cl1); + this.region = createRootRegion(REGION_NAME, af.create()); + + assertNull(this.region.getEntry("createKey")); + } + + /** + * test create followed by localDestroy + */ + @Test + public void createAndLocalDestroyShouldCreateEventWithNewValue() throws CacheException { + doCommitInOtherVm(otherVM, true); + + assertNotNull(this.region.getEntry("createKey")); + assertEquals("createValue", this.region.getEntry("createKey").getValue()); + assertEquals(1, this.invokeCount); + } + + /** + * test create followed by localInvalidate + */ + @Test + public void createAndLocalInvalidateShouldCreateEventWithNewValue() throws CacheException { + doCommitInOtherVm(this.otherVM, false); + + assertNotNull(this.region.getEntry("createKey")); + assertEquals("createValue", this.region.getEntry("createKey").getValue()); + assertEquals(1, this.invokeCount); + } + + private void initOtherVM(VM otherVM) { + otherVM.invoke(new CacheSerializableRunnable("Connect") { + @Override + public void run2() throws CacheException { + getCache(); + } + }); + } + + private void doCommitInOtherVm(VM otherVM, boolean doDestroy) { + otherVM.invoke(new CacheSerializableRunnable("create root") { + @Override + public void run2() throws CacheException { + AttributesFactory factory = new AttributesFactory(); + factory.setScope(Scope.DISTRIBUTED_ACK); + factory.setConcurrencyChecksEnabled(true); + + Region region = createRootRegion(REGION_NAME, factory.create()); + + CacheTransactionManager transactionManager = getCache().getCacheTransactionManager(); + transactionManager.begin(); + + region.create("createKey", "createValue"); + + if (doDestroy) { + try { + region.localDestroy("createKey"); + fail("expected exception not thrown"); + } catch (UnsupportedOperationInTransactionException e) { + assertEquals(TXStateStub_LOCAL_DESTROY_NOT_ALLOWED_IN_TRANSACTION.toLocalizedString(), + e.getMessage()); + } + } else { + try { + region.localInvalidate("createKey"); + fail("expected exception not thrown"); + } catch (UnsupportedOperationInTransactionException e) { + assertEquals( + TXStateStub_LOCAL_INVALIDATE_NOT_ALLOWED_IN_TRANSACTION.toLocalizedString(), + e.getMessage()); + } + } + + transactionManager.commit(); + } + }); + } + +} http://git-wip-us.apache.org/repos/asf/geode/blob/8b731c57/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..3b78844 --- /dev/null +++ b/geode-core/src/test/java/org/apache/geode/cache30/EntriesDoNotExpireDuringGIIRegressionTest.java @@ -0,0 +1,206 @@ +/* + * 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 + * + * Entries should not expire during GII + * + * @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 AtomicInteger expirationCount; + private AtomicBoolean afterRegionCreateInvoked; + private VM otherVM; + + @Rule + public DistributedRestoreSystemProperties restoreSystemProperties = + new DistributedRestoreSystemProperties(); + + @Rule + public SerializableErrorCollector errorCollector = new SerializableErrorCollector(); + + @Before + public void before() throws Exception { + this.expirationCount = new AtomicInteger(0); + this.afterRegionCreateInvoked = new AtomicBoolean(false); + 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) { + afterRegionCreateInvoked.set(true); + } + + @Override + public void afterInvalidate(EntryEvent event) { + errorCollector.checkThat("afterRegionCreate should have been seen", + afterRegionCreateInvoked.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/8b731c57/geode-core/src/test/java/org/apache/geode/cache30/RemotePRValuesAreNotDeserializedRegressionTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/cache30/RemotePRValuesAreNotDeserializedRegressionTest.java b/geode-core/src/test/java/org/apache/geode/cache30/RemotePRValuesAreNotDeserializedRegressionTest.java new file mode 100644 index 0000000..b8594df --- /dev/null +++ b/geode-core/src/test/java/org/apache/geode/cache30/RemotePRValuesAreNotDeserializedRegressionTest.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 + * + * Remote PartitionedRegion values should not be deserialized + * + * @since GemFire 5.0 + */ +@Category(DistributedTest.class) +public class RemotePRValuesAreNotDeserializedRegressionTest 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 remotePRValuesShouldNotBeDeserialized() 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/8b731c57/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..6aa0820 --- /dev/null +++ b/geode-core/src/test/java/org/apache/geode/cache30/ValuesAreLazilyDeserializedRegressionTest.java @@ -0,0 +1,165 @@ +/* + * 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.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 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 { + + private static final String REGION_NAME = "bug34948"; + + // 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 valueShouldBeLazilyDeserialized() throws CacheException { + AttributesFactory factory = new AttributesFactory(); + factory.setScope(Scope.DISTRIBUTED_ACK); + factory.setDataPolicy(DataPolicy.PRELOADED); + + Region<String, HomeBoy> region = createRootRegion(REGION_NAME, factory.create()); + + // before gii + region.put("key1", new HomeBoy()); + + doCreateOtherVm(this.otherVM); + + // 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 void doCreateOtherVm(VM otherVM) { + otherVM.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(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/8b731c57/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/8b731c57/geode-core/src/test/java/org/apache/geode/test/dunit/internal/DistributedTestFixture.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/internal/DistributedTestFixture.java b/geode-core/src/test/java/org/apache/geode/test/dunit/internal/DistributedTestFixture.java index 4175e81..b372696 100755 --- a/geode-core/src/test/java/org/apache/geode/test/dunit/internal/DistributedTestFixture.java +++ b/geode-core/src/test/java/org/apache/geode/test/dunit/internal/DistributedTestFixture.java @@ -28,7 +28,7 @@ public interface DistributedTestFixture extends Serializable { * <p> * Override this as needed. Default implementation is empty. */ - public void preSetUp() throws Exception; + void preSetUp() throws Exception; /** * {@code postSetUp()} is invoked after {@code DistributedTestCase#setUp()}. @@ -36,7 +36,7 @@ public interface DistributedTestFixture extends Serializable { * <p> * Override this as needed. Default implementation is empty. */ - public void postSetUp() throws Exception; + void postSetUp() throws Exception; /** * {@code preTearDown()} is invoked before {@code DistributedTestCase#tearDown()}. @@ -44,7 +44,7 @@ public interface DistributedTestFixture extends Serializable { * <p> * Override this as needed. Default implementation is empty. */ - public void preTearDown() throws Exception; + void preTearDown() throws Exception; /** * {@code postTearDown()} is invoked after {@code DistributedTestCase#tearDown()}. @@ -52,7 +52,7 @@ public interface DistributedTestFixture extends Serializable { * <p> * Override this as needed. Default implementation is empty. */ - public void postTearDown() throws Exception; + void postTearDown() throws Exception; /** * {@code preTearDownAssertions()} is invoked before any tear down methods have been invoked. If @@ -61,7 +61,7 @@ public interface DistributedTestFixture extends Serializable { * <p> * Override this as needed. Default implementation is empty. */ - public void preTearDownAssertions() throws Exception; + void preTearDownAssertions() throws Exception; /** * {@code postTearDownAssertions()} is invoked after all tear down methods have completed. This @@ -70,7 +70,7 @@ public interface DistributedTestFixture extends Serializable { * <p> * Override this as needed. Default implementation is empty. */ - public void postTearDownAssertions() throws Exception; + void postTearDownAssertions() throws Exception; /** * Returns the {@code Properties} used to define the {@code DistributedSystem}. @@ -79,11 +79,11 @@ public interface DistributedTestFixture extends Serializable { * Override this as needed. This method is called by various {@code getSystem} methods in * {@code DistributedTestCase}. */ - public Properties getDistributedSystemProperties(); + Properties getDistributedSystemProperties(); /** * Returns the {@code name} of the test method being executed. */ - public String getName(); + String getName(); } http://git-wip-us.apache.org/repos/asf/geode/blob/8b731c57/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 } + }