Repository: geode Updated Branches: refs/heads/feature/GEODE-1279 456ee1576 -> 10bc0d69e
Start 1279 Project: http://git-wip-us.apache.org/repos/asf/geode/repo Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/10bc0d69 Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/10bc0d69 Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/10bc0d69 Branch: refs/heads/feature/GEODE-1279 Commit: 10bc0d69e93a399e95c11db71d22401a4d097a2f Parents: 456ee15 Author: Kirk Lund <kl...@apache.org> Authored: Tue May 23 15:45:12 2017 -0700 Committer: Kirk Lund <kl...@apache.org> Committed: Tue May 23 15:46:22 2017 -0700 ---------------------------------------------------------------------- .../apache/geode/cache30/Bug34387DUnitTest.java | 188 ------------------- .../CreateAndDestroyKeyTXRegressionTest.java | 186 ++++++++++++++++++ .../dunit/internal/DistributedTestFixture.java | 16 +- .../internal/JUnit4DistributedTestCase.java | 2 +- 4 files changed, 195 insertions(+), 197 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/geode/blob/10bc0d69/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/10bc0d69/geode-core/src/test/java/org/apache/geode/cache30/CreateAndDestroyKeyTXRegressionTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/cache30/CreateAndDestroyKeyTXRegressionTest.java b/geode-core/src/test/java/org/apache/geode/cache30/CreateAndDestroyKeyTXRegressionTest.java new file mode 100644 index 0000000..8a657c0 --- /dev/null +++ b/geode-core/src/test/java/org/apache/geode/cache30/CreateAndDestroyKeyTXRegressionTest.java @@ -0,0 +1,186 @@ +/* + * 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.assertEquals; +import static org.junit.Assert.assertFalse; +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.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; +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; + +/** + * CreateAndDestroyKeyTXRegressionTest + * + * Test create + localDestroy for bug 34387 + * + * TX in Proxy Regions with create followed by localDestroy on same key results in remote VMs receiving create events with null getNewValue(). + * + * @since GemFire 5.0 + */ +@Category(DistributedTest.class) +public class CreateAndDestroyKeyTXRegressionTest extends JUnit4CacheTestCase { + + private static volatile boolean callbackFailure; + + private int invokeCount; + private Region region; + + @Before + public void setUp() throws Exception { + callbackFailure = false; + this.invokeCount = 0; + + initOtherId(); + 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) { + callbackAssertEquals("Keys not equal", "createKey", e.getKey()); + callbackAssertEquals("Values not equal", "createValue", e.getNewValue()); + CreateAndDestroyKeyTXRegressionTest.this.invokeCount++; + } + }; + + af.addCacheListener(cl1); + this.region = createRootRegion("r1", af.create()); + + assertNull(this.region.getEntry("createKey")); + } + + /** + * test create followed by localDestroy + */ + @Test + public void testCreateAndLD() throws CacheException { + doCommitOtherVm(true); + + assertNotNull(this.region.getEntry("createKey")); + assertEquals("createValue", this.region.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 { + doCommitOtherVm(false); + + assertNotNull(this.region.getEntry("createKey")); + assertEquals("createValue", this.region.getEntry("createKey").getValue()); + assertEquals(1, this.invokeCount); + assertFalse("Errors in callbacks; check logs for details", callbackFailure); + } + + private 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") { + @Override + public void run2() throws CacheException { + getCache(); + } + }); + vm.invoke(() -> getVMDistributedMember()); + } + + private void doCommitOtherVm(final boolean doDestroy) { + VM vm = getOtherVm(); + vm.invoke(new CacheSerializableRunnable("create root") { + @Override + public void run2() throws CacheException { + AttributesFactory af = new AttributesFactory(); + af.setScope(Scope.DISTRIBUTED_ACK); + af.setConcurrencyChecksEnabled(true); + + Region region = createRootRegion("r1", af.create()); + + CacheTransactionManager ctm = getCache().getCacheTransactionManager(); + ctm.begin(); + + region.create("createKey", "createValue"); + + if (doDestroy) { + try { + region.localDestroy("createKey"); + fail("expected exception not thrown"); + } catch (UnsupportedOperationInTransactionException e) { + assertEquals(e.getMessage(), + LocalizedStrings.TXStateStub_LOCAL_DESTROY_NOT_ALLOWED_IN_TRANSACTION + .toLocalizedString()); + } + } else { + try { + region.localInvalidate("createKey"); + fail("expected exception not thrown"); + } catch (UnsupportedOperationInTransactionException e) { + assertEquals(e.getMessage(), + LocalizedStrings.TXStateStub_LOCAL_INVALIDATE_NOT_ALLOWED_IN_TRANSACTION + .toLocalizedString()); + } + } + + ctm.commit(); + } + }); + } + + private static DistributedMember getVMDistributedMember() { + return InternalDistributedSystem.getAnyInstance().getDistributedMember(); + } + +} http://git-wip-us.apache.org/repos/asf/geode/blob/10bc0d69/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/10bc0d69/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 5a679bb..80fb92a 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 @@ -370,7 +370,7 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur * setUp() or override {@link #postSetUp()} with work that needs to occur after setUp(). */ @Before - public final void setUp() throws Exception { + public final void setUpJUnit4DistributedTestCase() throws Exception { preSetUp(); setUpDistributedTestCase(); postSetUp();