Revert "GEODE-714: Modify all tests to use JUnit Categories" This reverts commit ca6148aa99faf8fcb278fd7a840f69f622e6fc3f.
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/cb7dbd0b Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/cb7dbd0b Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/cb7dbd0b Branch: refs/heads/feature/GEODE-714 Commit: cb7dbd0b77507ed383e37eb7dd0925533d6dcbcf Parents: dfba327 Author: Kirk Lund <kl...@pivotal.io> Authored: Mon Jan 4 16:28:38 2016 -0800 Committer: Kirk Lund <kl...@pivotal.io> Committed: Mon Jan 4 16:28:38 2016 -0800 ---------------------------------------------------------------------- build.gradle | 21 +- .../test/java/com/gemstone/gemfire/BadTest.java | 42 + .../cache30/Bug40255JUnitDisabledTest.java | 139 +++ .../gemfire/cache30/Bug40255JUnitTest.java | 143 --- .../cache30/Bug40662JUnitDisabledTest.java | 92 ++ .../gemfire/cache30/Bug40662JUnitTest.java | 93 -- .../locks/CollaborationJUnitDisabledTest.java | 562 ++++++++++ .../internal/locks/CollaborationJUnitTest.java | 617 ----------- .../DiskRegionPerfJUnitPerformanceTest.java | 6 +- ...HARegionQueueStartStopJUnitDisabledTest.java | 123 +++ .../cache/tier/sockets/HAInterestBaseTest.java | 1015 +++++++++++++++++ .../tier/sockets/HAInterestPart1DUnitTest.java | 102 +- .../tier/sockets/HAInterestPart2DUnitTest.java | 116 +- .../cache/tier/sockets/HAInterestTestCase.java | 1018 ------------------ .../tier/sockets/command/CommitCommandTest.java | 6 - .../logging/LogWriterPerformanceTest.java | 6 - .../log4j/Log4J2DisabledPerformanceTest.java | 6 - .../logging/log4j/Log4J2PerformanceTest.java | 9 +- .../LogWriterLoggerDisabledPerformanceTest.java | 6 - .../log4j/LogWriterLoggerPerformanceTest.java | 9 +- .../test/java/dunit/DistributedTestCase.java | 3 - ...IndexRepositoryImplJUnitPerformanceTest.java | 437 ++++++++ .../IndexRepositoryImplPerformanceTest.java | 439 -------- 23 files changed, 2537 insertions(+), 2473 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cb7dbd0b/build.gradle ---------------------------------------------------------------------- diff --git a/build.gradle b/build.gradle index 4563590..f464dc3 100755 --- a/build.gradle +++ b/build.gradle @@ -345,7 +345,7 @@ subprojects { } test { - include '**/*Test.class' + include '**/*JUnitTest.class' useJUnit { includeCategories 'com.gemstone.gemfire.test.junit.categories.UnitTest' excludeCategories 'com.gemstone.gemfire.test.junit.categories.IntegrationTest' @@ -364,12 +364,10 @@ subprojects { //This target does not run any tests. Rather, it validates that there are no //tests that are missing a category annotation task checkMissedTests(type: Test) { - include '**/*Test.class' + include '**/*JUnitTest.class' useJUnit { excludeCategories 'com.gemstone.gemfire.test.junit.categories.UnitTest' excludeCategories 'com.gemstone.gemfire.test.junit.categories.IntegrationTest' - excludeCategories 'com.gemstone.gemfire.test.junit.categories.DistributedTest' - excludeCategories 'com.gemstone.gemfire.test.junit.categories.PerformanceTest' } beforeTest { descriptor -> @@ -379,7 +377,7 @@ subprojects { } task integrationTest(type:Test) { - include '**/*Test.class' + include '**/*JUnitTest.class' useJUnit { excludeCategories 'com.gemstone.gemfire.test.junit.categories.UnitTest' includeCategories 'com.gemstone.gemfire.test.junit.categories.IntegrationTest' @@ -394,16 +392,17 @@ subprojects { } task distributedTest(type:Test) { - include '**/*Test.class' + include '**/*DUnitTest.class' // maxParallelForks = 2 // maxParallelForks = Runtime.runtime.availableProcessors() - useJUnit { - excludeCategories 'com.gemstone.gemfire.test.junit.categories.UnitTest' - excludeCategories 'com.gemstone.gemfire.test.junit.categories.IntegrationTest' - includeCategories 'com.gemstone.gemfire.test.junit.categories.DistributedTest' - } +// TODO add @Category(DistributedTest.class) to dunit tests +// useJUnit { +// excludeCategories 'com.gemstone.gemfire.test.junit.categories.UnitTest' +// excludeCategories 'com.gemstone.gemfire.test.junit.categories.IntegrationTest' +// includeCategories 'com.gemstone.gemfire.test.junit.categories.DistributedTest' +// } //I'm hoping this might deal with SOME OOMEs I've seen forkEvery 30 http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cb7dbd0b/gemfire-core/src/test/java/com/gemstone/gemfire/BadTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/BadTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/BadTest.java new file mode 100644 index 0000000..46dc799 --- /dev/null +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/BadTest.java @@ -0,0 +1,42 @@ +/* + * 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 com.gemstone.gemfire; + +import junit.framework.*; + +/** + * This test provides examples of a test failing and a test getting an + * error. We use it to test JUnit failure reporting. + */ +public class BadTest extends TestCase { + + public BadTest(String name) { + super(name); + } + + //////// Test Methods + + public void testFailure() { + fail("I'm failing away..."); + } + + public void testError() { + String s = "I've failed"; + throw new RuntimeException(s); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cb7dbd0b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/Bug40255JUnitDisabledTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/Bug40255JUnitDisabledTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/Bug40255JUnitDisabledTest.java new file mode 100644 index 0000000..4fe8a49 --- /dev/null +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/Bug40255JUnitDisabledTest.java @@ -0,0 +1,139 @@ +/* + * 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 com.gemstone.gemfire.cache30; + +import java.io.File; +import java.util.Properties; + +import junit.framework.TestCase; + +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.CacheFactory; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.RegionAttributes; +import com.gemstone.gemfire.distributed.DistributedSystem; +import com.gemstone.gemfire.distributed.internal.DistributionConfig; + +/** + * @author Shobhit Agarwal + * + */ +public class Bug40255JUnitDisabledTest extends TestCase{ + + private static final String BUG_40255_XML = Bug40255JUnitDisabledTest.class.getResource("bug40255xmlparameterization.xml").getFile(); + private static final String BUG_40255_PROPS = Bug40255JUnitDisabledTest.class.getResource("bug40255_gemfire.properties").getFile(); + + private static final String ATTR_PROPERTY_STRING = "region.disk.store"; + + private static final String ATTR_PROPERTY_VALUE = "teststore"; + + private static final String NESTED_ATTR_PROPERTY_STRING = "custom-nested.test"; + + private static final String NESTED_ATTR_PROPERTY_VALUE = "disk"; + + private static final String ELEMENT_PROPERTY_STRING = "custom-string.element"; + + private static final String ELEMENT_PROPERTY_VALUE = "example-string"; + + private static final String CONCAT_ELEMENT_PROPERTY_STRING = "concat.test"; + + private static final String CONCAT_ELEMENT_PROPERTY_VALUE = "-name"; + + private static final String ELEMENT_KEY_VALUE = "example-value"; + + DistributedSystem ds; + Cache cache; + + @Override + public void setName(String name) { + super.setName(name); + } + + public void testResolveReplacePropertyStringForLonerCache(){ + Properties props = new Properties(); + props.setProperty("mcast-port", "0"); + props.setProperty("locators", ""); + System.setProperty("gemfirePropertyFile", BUG_40255_PROPS); + props.setProperty(DistributionConfig.CACHE_XML_FILE_NAME, BUG_40255_XML); + System.setProperty(NESTED_ATTR_PROPERTY_STRING, NESTED_ATTR_PROPERTY_VALUE); + System.setProperty(ATTR_PROPERTY_STRING, ATTR_PROPERTY_VALUE); + System.setProperty(ELEMENT_PROPERTY_STRING, ELEMENT_PROPERTY_VALUE); + System.setProperty(CONCAT_ELEMENT_PROPERTY_STRING, CONCAT_ELEMENT_PROPERTY_VALUE); + + // create the directory where data is going to be stored + File dir = new File("persistData1"); + dir.mkdir(); + + this.ds = DistributedSystem.connect(props); + this.cache = CacheFactory.create(this.ds); + + Region exampleRegion = this.cache.getRegion("example-region"); + RegionAttributes<Object, Object> attrs = exampleRegion.getAttributes(); + + //Check if disk store got same name as passed in system properties in setup(). + assertEquals(attrs.getDiskStoreName(), System.getProperty(ATTR_PROPERTY_STRING)); + assertNotNull(exampleRegion.get(ELEMENT_PROPERTY_VALUE+CONCAT_ELEMENT_PROPERTY_VALUE)); + assertEquals(exampleRegion.get(ELEMENT_PROPERTY_VALUE+CONCAT_ELEMENT_PROPERTY_VALUE), ELEMENT_KEY_VALUE); + assertNotNull(exampleRegion.get(ELEMENT_PROPERTY_VALUE)); + assertEquals(exampleRegion.get(ELEMENT_PROPERTY_VALUE), CONCAT_ELEMENT_PROPERTY_VALUE); + } + + public void testResolveReplacePropertyStringForNonLonerCache(){ + Properties props = new Properties(); + props.setProperty("mcast-port", "10333"); + props.setProperty("locators", ""); + System.setProperty("gemfirePropertyFile", BUG_40255_PROPS); + props.setProperty(DistributionConfig.CACHE_XML_FILE_NAME, BUG_40255_XML); + System.setProperty(NESTED_ATTR_PROPERTY_STRING, NESTED_ATTR_PROPERTY_VALUE); + System.setProperty(ATTR_PROPERTY_STRING, ATTR_PROPERTY_VALUE); + System.setProperty(ELEMENT_PROPERTY_STRING, ELEMENT_PROPERTY_VALUE); + System.setProperty(CONCAT_ELEMENT_PROPERTY_STRING, CONCAT_ELEMENT_PROPERTY_VALUE); + + // create the directory where data is going to be stored + File dir = new File("persistData1"); + dir.mkdir(); + + this.ds = DistributedSystem.connect(props); + this.cache = CacheFactory.create(this.ds); + + Region exampleRegion = this.cache.getRegion("example-region"); + RegionAttributes<Object, Object> attrs = exampleRegion.getAttributes(); + + //Check if disk store got same name as passed in system properties in setup(). + assertEquals(attrs.getDiskStoreName(), System.getProperty(ATTR_PROPERTY_STRING)); + assertNotNull(exampleRegion.get(ELEMENT_PROPERTY_VALUE+CONCAT_ELEMENT_PROPERTY_VALUE)); + assertEquals(exampleRegion.get(ELEMENT_PROPERTY_VALUE+CONCAT_ELEMENT_PROPERTY_VALUE), ELEMENT_KEY_VALUE); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + if (this.cache != null) { + this.cache.close(); + this.cache = null; + } + if (this.ds != null) { + this.ds.disconnect(); + this.ds = null; + } + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cb7dbd0b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/Bug40255JUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/Bug40255JUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/Bug40255JUnitTest.java deleted file mode 100644 index 92bfbe7..0000000 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/Bug40255JUnitTest.java +++ /dev/null @@ -1,143 +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 com.gemstone.gemfire.cache30; - -import static org.junit.Assert.*; - -import java.io.File; -import java.util.Properties; - -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.CacheFactory; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.cache.RegionAttributes; -import com.gemstone.gemfire.distributed.DistributedSystem; -import com.gemstone.gemfire.distributed.internal.DistributionConfig; -import com.gemstone.gemfire.test.junit.categories.IntegrationTest; - -/** - * @author Shobhit Agarwal - * - */ -@Category(IntegrationTest.class) -@Ignore("Test is broken and was named Bug40255JUnitDisabledTest") -public class Bug40255JUnitTest { - - private static final String BUG_40255_XML = Bug40255JUnitTest.class.getResource("bug40255xmlparameterization.xml").getFile(); - private static final String BUG_40255_PROPS = Bug40255JUnitTest.class.getResource("bug40255_gemfire.properties").getFile(); - - private static final String ATTR_PROPERTY_STRING = "region.disk.store"; - - private static final String ATTR_PROPERTY_VALUE = "teststore"; - - private static final String NESTED_ATTR_PROPERTY_STRING = "custom-nested.test"; - - private static final String NESTED_ATTR_PROPERTY_VALUE = "disk"; - - private static final String ELEMENT_PROPERTY_STRING = "custom-string.element"; - - private static final String ELEMENT_PROPERTY_VALUE = "example-string"; - - private static final String CONCAT_ELEMENT_PROPERTY_STRING = "concat.test"; - - private static final String CONCAT_ELEMENT_PROPERTY_VALUE = "-name"; - - private static final String ELEMENT_KEY_VALUE = "example-value"; - - DistributedSystem ds; - Cache cache; - - @Test - public void testResolveReplacePropertyStringForLonerCache(){ - Properties props = new Properties(); - props.setProperty("mcast-port", "0"); - props.setProperty("locators", ""); - System.setProperty("gemfirePropertyFile", BUG_40255_PROPS); - props.setProperty(DistributionConfig.CACHE_XML_FILE_NAME, BUG_40255_XML); - System.setProperty(NESTED_ATTR_PROPERTY_STRING, NESTED_ATTR_PROPERTY_VALUE); - System.setProperty(ATTR_PROPERTY_STRING, ATTR_PROPERTY_VALUE); - System.setProperty(ELEMENT_PROPERTY_STRING, ELEMENT_PROPERTY_VALUE); - System.setProperty(CONCAT_ELEMENT_PROPERTY_STRING, CONCAT_ELEMENT_PROPERTY_VALUE); - - // create the directory where data is going to be stored - File dir = new File("persistData1"); - dir.mkdir(); - - this.ds = DistributedSystem.connect(props); - this.cache = CacheFactory.create(this.ds); - - Region exampleRegion = this.cache.getRegion("example-region"); - RegionAttributes<Object, Object> attrs = exampleRegion.getAttributes(); - - //Check if disk store got same name as passed in system properties in setup(). - assertEquals(attrs.getDiskStoreName(), System.getProperty(ATTR_PROPERTY_STRING)); - assertNotNull(exampleRegion.get(ELEMENT_PROPERTY_VALUE+CONCAT_ELEMENT_PROPERTY_VALUE)); - assertEquals(exampleRegion.get(ELEMENT_PROPERTY_VALUE+CONCAT_ELEMENT_PROPERTY_VALUE), ELEMENT_KEY_VALUE); - assertNotNull(exampleRegion.get(ELEMENT_PROPERTY_VALUE)); - assertEquals(exampleRegion.get(ELEMENT_PROPERTY_VALUE), CONCAT_ELEMENT_PROPERTY_VALUE); - } - - @Test - public void testResolveReplacePropertyStringForNonLonerCache(){ - Properties props = new Properties(); - props.setProperty("mcast-port", "10333"); - props.setProperty("locators", ""); - System.setProperty("gemfirePropertyFile", BUG_40255_PROPS); - props.setProperty(DistributionConfig.CACHE_XML_FILE_NAME, BUG_40255_XML); - System.setProperty(NESTED_ATTR_PROPERTY_STRING, NESTED_ATTR_PROPERTY_VALUE); - System.setProperty(ATTR_PROPERTY_STRING, ATTR_PROPERTY_VALUE); - System.setProperty(ELEMENT_PROPERTY_STRING, ELEMENT_PROPERTY_VALUE); - System.setProperty(CONCAT_ELEMENT_PROPERTY_STRING, CONCAT_ELEMENT_PROPERTY_VALUE); - - // create the directory where data is going to be stored - File dir = new File("persistData1"); - dir.mkdir(); - - this.ds = DistributedSystem.connect(props); - this.cache = CacheFactory.create(this.ds); - - Region exampleRegion = this.cache.getRegion("example-region"); - RegionAttributes<Object, Object> attrs = exampleRegion.getAttributes(); - - //Check if disk store got same name as passed in system properties in setup(). - assertEquals(attrs.getDiskStoreName(), System.getProperty(ATTR_PROPERTY_STRING)); - assertNotNull(exampleRegion.get(ELEMENT_PROPERTY_VALUE+CONCAT_ELEMENT_PROPERTY_VALUE)); - assertEquals(exampleRegion.get(ELEMENT_PROPERTY_VALUE+CONCAT_ELEMENT_PROPERTY_VALUE), ELEMENT_KEY_VALUE); - } - - @After - public void tearDown() throws Exception { - if (this.cache != null) { - this.cache.close(); - this.cache = null; - } - if (this.ds != null) { - this.ds.disconnect(); - this.ds = null; - } - } - - @Before - public void setUp() throws Exception { - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cb7dbd0b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/Bug40662JUnitDisabledTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/Bug40662JUnitDisabledTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/Bug40662JUnitDisabledTest.java new file mode 100644 index 0000000..9455641 --- /dev/null +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/Bug40662JUnitDisabledTest.java @@ -0,0 +1,92 @@ +/* + * 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 com.gemstone.gemfire.cache30; + +import java.util.Properties; + +import junit.framework.TestCase; + +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.CacheFactory; +import com.gemstone.gemfire.cache.EvictionAction; +import com.gemstone.gemfire.cache.EvictionAttributes; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.RegionAttributes; +import com.gemstone.gemfire.distributed.DistributedSystem; +import com.gemstone.gemfire.distributed.internal.DistributionConfig; + +/** + * Test for Bug no. 40662. To verify the default action being set in eviction + * attributes by CacheXmlParser when cache.xml has eviction attributes with no + * eviction action specified. which was being set to EvictionAction.NONE + * + * @author shoagarwal + * @since 6.6 + */ +public class Bug40662JUnitDisabledTest extends TestCase { + + private static final String BUG_40662_XML = Bug40662JUnitDisabledTest.class.getResource("bug40662noevictionaction.xml").getFile(); + + DistributedSystem ds; + Cache cache; + + @Override + public void setName(String name) { + super.setName(name); + } + + /** + * Test for checking eviction action in eviction attributes if no evicition + * action is specified in cache.xml + */ + public void testEvictionActionSetLocalDestroyPass() { + Region exampleRegion = this.cache.getRegion("example-region"); + RegionAttributes<Object, Object> attrs = exampleRegion.getAttributes(); + EvictionAttributes evicAttrs = attrs.getEvictionAttributes(); + + //Default eviction action is LOCAL_DESTROY always. + assertEquals(EvictionAction.LOCAL_DESTROY, evicAttrs.getAction()); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + if (this.cache != null) { + this.cache.close(); + this.cache = null; + } + if (this.ds != null) { + this.ds.disconnect(); + this.ds = null; + } + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + Properties props = new Properties(); + props.setProperty("mcast-port", "0"); + props.setProperty("locators", ""); + props.setProperty(DistributionConfig.CACHE_XML_FILE_NAME, BUG_40662_XML); + this.ds = DistributedSystem.connect(props); + this.cache = CacheFactory.create(this.ds); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cb7dbd0b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/Bug40662JUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/Bug40662JUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/Bug40662JUnitTest.java deleted file mode 100644 index 0d62127..0000000 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/Bug40662JUnitTest.java +++ /dev/null @@ -1,93 +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 com.gemstone.gemfire.cache30; - -import static org.junit.Assert.*; - -import java.util.Properties; - -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.experimental.categories.Category; - -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.CacheFactory; -import com.gemstone.gemfire.cache.EvictionAction; -import com.gemstone.gemfire.cache.EvictionAttributes; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.cache.RegionAttributes; -import com.gemstone.gemfire.distributed.DistributedSystem; -import com.gemstone.gemfire.distributed.internal.DistributionConfig; -import com.gemstone.gemfire.test.junit.categories.IntegrationTest; - -/** - * Test for Bug no. 40662. To verify the default action being set in eviction - * attributes by CacheXmlParser when cache.xml has eviction attributes with no - * eviction action specified. which was being set to EvictionAction.NONE - * - * @author shoagarwal - * @since 6.6 - */ -@Category(IntegrationTest.class) -@Ignore("Test is broken and was named Bug40662JUnitDisabledTest") -public class Bug40662JUnitTest { - - private static final String BUG_40662_XML = Bug40662JUnitTest.class.getResource("bug40662noevictionaction.xml").getFile(); - - DistributedSystem ds; - Cache cache; - - /** - * Test for checking eviction action in eviction attributes if no evicition - * action is specified in cache.xml - */ - public void testEvictionActionSetLocalDestroyPass() { - Region exampleRegion = this.cache.getRegion("example-region"); - RegionAttributes<Object, Object> attrs = exampleRegion.getAttributes(); - EvictionAttributes evicAttrs = attrs.getEvictionAttributes(); - - //Default eviction action is LOCAL_DESTROY always. - assertEquals(EvictionAction.LOCAL_DESTROY, evicAttrs.getAction()); - } - - @After - protected void tearDown() throws Exception { - if (this.cache != null) { - this.cache.close(); - this.cache = null; - } - if (this.ds != null) { - this.ds.disconnect(); - this.ds = null; - } - } - - @Before - protected void setUp() throws Exception { - Properties props = new Properties(); - props.setProperty("mcast-port", "0"); - props.setProperty("locators", ""); - props.setProperty(DistributionConfig.CACHE_XML_FILE_NAME, BUG_40662_XML); - this.ds = DistributedSystem.connect(props); - this.cache = CacheFactory.create(this.ds); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cb7dbd0b/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/locks/CollaborationJUnitDisabledTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/locks/CollaborationJUnitDisabledTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/locks/CollaborationJUnitDisabledTest.java new file mode 100755 index 0000000..7b93a36 --- /dev/null +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/locks/CollaborationJUnitDisabledTest.java @@ -0,0 +1,562 @@ +/* + * 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 com.gemstone.gemfire.distributed.internal.locks; + +import junit.framework.*; +import java.util.*; + +import com.gemstone.gemfire.CancelCriterion; +import com.gemstone.gemfire.LogWriter; +import com.gemstone.gemfire.SystemFailure; +import com.gemstone.gemfire.internal.logging.LocalLogWriter; +import com.gemstone.gemfire.internal.logging.InternalLogWriter; + +import dunit.DistributedTestCase; +import dunit.DistributedTestCase.WaitCriterion; + +/** + * Tests the Collaboration Lock used internally by dlock service. + * + * @author Kirk Lund + * @since 4.1.1 + */ +public class CollaborationJUnitDisabledTest extends TestCase { + + protected LogWriter log = new LocalLogWriter(InternalLogWriter.INFO_LEVEL); + protected Collaboration collaboration; + + public CollaborationJUnitDisabledTest(String name) { + super(name); + } + + public void setUp() throws Exception { + this.collaboration = new Collaboration(new CancelCriterion() { + + public String cancelInProgress() { + // TODO Auto-generated method stub + return null; + } + + public RuntimeException generateCancelledException(Throwable e) { + // TODO Auto-generated method stub + return null; + } + + }); + } + + public void tearDown() throws Exception { + this.collaboration = null; + } + + protected volatile boolean flagTestBlocksUntilRelease = false; + protected volatile boolean threadBStartedTestBlocksUntilRelease = false; + public void testBlocksUntilRelease() throws Exception { + this.log.info("[testBlocksUntilRelease]"); + Thread threadA = new Thread(group, new Runnable() { + public void run() { + collaboration.acquireUninterruptibly("topicA"); + try { + flagTestBlocksUntilRelease = true; + while(flagTestBlocksUntilRelease) { + try { + Thread.sleep(10); + } + catch (InterruptedException ignore) {fail("interrupted");} + } + } + finally { + collaboration.release(); + } + } + }); + + // thread one acquires + threadA.start(); + WaitCriterion ev = new WaitCriterion() { + public boolean done() { + return CollaborationJUnitDisabledTest.this.flagTestBlocksUntilRelease; + } + public String description() { + return "waiting for thread"; + } + }; + DistributedTestCase.waitForCriterion(ev, 5 * 1000, 200, true); + assertTrue(this.collaboration.hasCurrentTopic(threadA)); + + // thread two blocks until one releeases + Thread threadB = new Thread(group, new Runnable() { + public void run() { + threadBStartedTestBlocksUntilRelease = true; + collaboration.acquireUninterruptibly("topicB"); + try { + flagTestBlocksUntilRelease = true; + WaitCriterion ev2 = new WaitCriterion() { + public boolean done() { + return !flagTestBlocksUntilRelease; + } + public String description() { + return "waiting for release"; + } + }; + DistributedTestCase.waitForCriterion(ev2, 20 * 1000, 200, true); + } + finally { + collaboration.release(); + } + } + }); + + // start up threadB + threadB.start(); + ev = new WaitCriterion() { + public boolean done() { + return threadBStartedTestBlocksUntilRelease; + } + public String description() { + return "waiting for thread b"; + } + }; + DistributedTestCase.waitForCriterion(ev, 5 * 1000, 200, true); + + // threadA holds topic and threadB is waiting... + assertTrue(this.collaboration.hasCurrentTopic(threadA)); + assertFalse(this.collaboration.hasCurrentTopic(threadB)); + + // let threadA release so that threadB gets lock + this.flagTestBlocksUntilRelease = false; + DistributedTestCase.join(threadA, 30 * 1000, null); + + // make sure threadB is doing what it's supposed to do... + ev = new WaitCriterion() { + public boolean done() { + return flagTestBlocksUntilRelease; + } + public String description() { + return "threadB"; + } + }; + DistributedTestCase.waitForCriterion(ev, 5 * 1000, 200, true); + // threadB must have lock now... let threadB release + assertTrue(this.collaboration.hasCurrentTopic(threadB)); + this.flagTestBlocksUntilRelease = false; + DistributedTestCase.join(threadB, 30 * 1000, null); + + // collaboration should be free now + assertFalse(this.collaboration.hasCurrentTopic(threadA)); + assertFalse(this.collaboration.hasCurrentTopic(threadB)); + assertFalse(this.collaboration.hasCurrentTopic()); + } + + protected volatile boolean threadAFlag_TestLateComerJoinsIn = false; + protected volatile boolean threadBFlag_TestLateComerJoinsIn = false; + protected volatile boolean threadCFlag_TestLateComerJoinsIn = true; + protected volatile boolean threadDFlag_TestLateComerJoinsIn = false; + public void testLateComerJoinsIn() throws Exception { + this.log.info("[testLateComerJoinsIn]"); + + final Object topicA = "topicA"; + final Object topicB = "topicB"; + + // threads one and two acquire + Thread threadA = new Thread(group, new Runnable() { + public void run() { + collaboration.acquireUninterruptibly(topicA); + try { + threadAFlag_TestLateComerJoinsIn = true; + WaitCriterion ev = new WaitCriterion() { + public boolean done() { + return !threadAFlag_TestLateComerJoinsIn; + } + public String description() { + return null; + } + }; + DistributedTestCase.waitForCriterion(ev, 60 * 1000, 200, true); + } + finally { + collaboration.release(); + } + } + }); + threadA.start(); + WaitCriterion ev = new WaitCriterion() { + public boolean done() { + return threadAFlag_TestLateComerJoinsIn; + } + public String description() { + return "wait for ThreadA"; + } + }; + DistributedTestCase.waitForCriterion(ev, 30 * 1000, 200, true); + assertTrue(this.collaboration.hasCurrentTopic(threadA)); + assertTrue(this.collaboration.isCurrentTopic(topicA)); + + Thread threadB = new Thread(group, new Runnable() { + public void run() { + collaboration.acquireUninterruptibly(topicA); + try { + threadBFlag_TestLateComerJoinsIn = true; + WaitCriterion ev2 = new WaitCriterion() { + public boolean done() { + return !threadBFlag_TestLateComerJoinsIn; + } + public String description() { + return null; + } + }; + DistributedTestCase.waitForCriterion(ev2, 60 * 1000, 200, true); + } + finally { + collaboration.release(); + } + } + }); + threadB.start(); + ev = new WaitCriterion() { + public boolean done() { + return threadBFlag_TestLateComerJoinsIn; + } + public String description() { + return ""; + } + }; + DistributedTestCase.waitForCriterion(ev, 60 * 1000, 200, true); + assertTrue(this.collaboration.hasCurrentTopic(threadB)); + + // thread three blocks for new topic + Thread threadC = new Thread(group, new Runnable() { + public void run() { + threadCFlag_TestLateComerJoinsIn = false; + collaboration.acquireUninterruptibly(topicB); + try { + threadCFlag_TestLateComerJoinsIn = true; + WaitCriterion ev2 = new WaitCriterion() { + public boolean done() { + return !threadCFlag_TestLateComerJoinsIn; + } + public String description() { + return null; + } + }; + DistributedTestCase.waitForCriterion(ev2, 60 * 1000, 200, true); + } + finally { + collaboration.release(); + } + } + }); + threadC.start(); + ev = new WaitCriterion() { + public boolean done() { + return threadCFlag_TestLateComerJoinsIn; + } + public String description() { + return null; + } + }; + DistributedTestCase.waitForCriterion(ev, 60 * 1000, 200, true); + assertFalse(this.collaboration.hasCurrentTopic(threadC)); + assertFalse(this.collaboration.isCurrentTopic(topicB)); + + // thread four (lateComer) acquires current topic immediately + Thread threadD = new Thread(group, new Runnable() { + public void run() { + collaboration.acquireUninterruptibly(topicA); + try { + threadDFlag_TestLateComerJoinsIn = true; + while(threadDFlag_TestLateComerJoinsIn) { + try { + Thread.sleep(10); + } + catch (InterruptedException ignore) {fail("interrupted");} + } + } + finally { + collaboration.release(); + } + } + }); + threadD.start(); + ev = new WaitCriterion() { + public boolean done() { + return threadDFlag_TestLateComerJoinsIn; + } + public String description() { + return null; + } + }; + DistributedTestCase.waitForCriterion(ev, 60 * 1000, 200, true); + assertTrue(this.collaboration.hasCurrentTopic(threadD)); + + // release threadA + this.threadAFlag_TestLateComerJoinsIn = false; + DistributedTestCase.join(threadA, 30 * 1000, null); + assertFalse(this.collaboration.hasCurrentTopic(threadA)); + assertTrue(this.collaboration.hasCurrentTopic(threadB)); + assertFalse(this.collaboration.hasCurrentTopic(threadC)); + assertTrue(this.collaboration.hasCurrentTopic(threadD)); + assertTrue(this.collaboration.isCurrentTopic(topicA)); + assertFalse(this.collaboration.isCurrentTopic(topicB)); + + // release threadB + this.threadBFlag_TestLateComerJoinsIn = false; + DistributedTestCase.join(threadB, 30 * 1000, null); + assertFalse(this.collaboration.hasCurrentTopic(threadB)); + assertFalse(this.collaboration.hasCurrentTopic(threadC)); + assertTrue(this.collaboration.hasCurrentTopic(threadD)); + assertTrue(this.collaboration.isCurrentTopic(topicA)); + assertFalse(this.collaboration.isCurrentTopic(topicB)); + + // release threadD + this.threadDFlag_TestLateComerJoinsIn = false; + DistributedTestCase.join(threadD, 30 * 1000, null); + ev = new WaitCriterion() { + public boolean done() { + return threadCFlag_TestLateComerJoinsIn; + } + public String description() { + return null; + } + }; + DistributedTestCase.waitForCriterion(ev, 60 * 1000, 200, true); + assertTrue(this.collaboration.hasCurrentTopic(threadC)); + assertFalse(this.collaboration.hasCurrentTopic(threadD)); + assertFalse(this.collaboration.isCurrentTopic(topicA)); + assertTrue(this.collaboration.isCurrentTopic(topicB)); + + // release threadC + this.threadCFlag_TestLateComerJoinsIn = false; + DistributedTestCase.join(threadC, 30 * 1000, null); + assertFalse(this.collaboration.hasCurrentTopic(threadC)); + assertFalse(this.collaboration.isCurrentTopic(topicA)); + assertFalse(this.collaboration.isCurrentTopic(topicB)); + } + + protected List waitingList = Collections.synchronizedList(new ArrayList()); + protected List fairnessList = Collections.synchronizedList(new ArrayList()); + protected volatile boolean runTestFairnessStressfully = true; + public void testFairnessStressfully() throws Exception { + this.log.info("[testFairnessStressfully]"); + final int numThreads = 20; + Thread threads[] = new Thread[numThreads]; + + Runnable run = new Runnable() { + public void run() { + boolean released = false; + try { + String uniqueTopic = Thread.currentThread().getName(); + while(runTestFairnessStressfully) { + waitingList.add(uniqueTopic); + collaboration.acquireUninterruptibly(uniqueTopic); + try { + released = false; + fairnessList.add(uniqueTopic); + waitingList.remove(uniqueTopic); + } + finally { + // wait for the other threads to line up... + WaitCriterion ev = new WaitCriterion() { + public boolean done() { + return !runTestFairnessStressfully || waitingList.size() >= numThreads - 1; + } + public String description() { + return "other threads lining up"; + } + }; + DistributedTestCase.waitForCriterion(ev, 60 * 1000, 200, true); + collaboration.release(); + released = true; + } + } + } + finally { + if (!released) { + collaboration.release(); + } + } + } + }; + + try { + // many threads loop: acquire and release with unique topic + for (int t = 0; t < threads.length; t++) { + threads[t] = new Thread(group, run, String.valueOf(t)); + threads[t].start(); + } + + log.info("Started all threads... waiting for test to complete."); + + // wait for numThreads * 10 + WaitCriterion ev = new WaitCriterion() { + public boolean done() { + return fairnessList.size() >= numThreads * 20; + } + public String description() { + return "waiting for numThreads * 10"; + } + }; + DistributedTestCase.waitForCriterion(ev, 5 * 60 * 1000, 200, true); + } + finally { + if (this.runTestFairnessStressfully) { + this.runTestFairnessStressfully = false; + } + } + + for (int t = 0; t < threads.length; t++) { + DistributedTestCase.join(threads[t], 30 * 1000, null); + } + + // assert that all topics are acquired in order + // count number of occurrences of each thread + int count[] = new int[numThreads]; + for (int i = 0; i < count.length; i++) { // shouldn't be necessary + count[i] = 0; + } + synchronized(this.fairnessList) { + for (Iterator iter = this.fairnessList.iterator(); iter.hasNext();) { + int id = Integer.valueOf((String)iter.next()).intValue(); + count[id] = count[id]+1; + } + } + + int totalLocks = 0; + int minLocks = Integer.MAX_VALUE; + int maxLocks = 0; + for (int i = 0; i < count.length; i++) { + int locks = count[i]; + this.log.fine("testFairnessStressfully thread-" + i + " acquired topic " + + locks + " times."); + if (locks < minLocks) minLocks = locks; + if (locks > maxLocks) maxLocks = locks; + totalLocks = totalLocks + locks; + } + + this.log.info("[testFairnessStressfully] totalLocks=" + totalLocks + + " minLocks=" + minLocks + + " maxLocks=" + maxLocks); + + int expectedLocks = (totalLocks / numThreads) + 1; + + // NOTE: if you turn on fine logs, this deviation may be too small... + // slower machines may also fail depending on thread scheduling + int deviation = (int)(expectedLocks * 0.25); + int lowThreshold = expectedLocks - deviation; + int highThreshold = expectedLocks + deviation; + + this.log.info("[testFairnessStressfully] deviation=" + deviation + + " expectedLocks=" + expectedLocks + + " lowThreshold=" + lowThreshold + + " highThreshold=" + highThreshold); + + // if these assertions keep failing we'll have to rewrite the test + // to handle scheduling of the threads... + + assertTrue("minLocks is less than lowThreshold", + minLocks >= lowThreshold); + assertTrue("maxLocks is greater than highThreshold", + maxLocks <= highThreshold); + } + + public void testHasCurrentTopic() throws Exception { + this.log.info("[testHasCurrentTopic]"); + assertTrue(!this.collaboration.hasCurrentTopic()); + this.collaboration.acquireUninterruptibly("testHasCurrentTopic"); + try { + assertTrue(this.collaboration.hasCurrentTopic()); + } + finally { + this.collaboration.release(); + } + assertTrue(!this.collaboration.hasCurrentTopic()); + } + + protected volatile boolean flagTestThreadHasCurrentTopic = false; + public void testThreadHasCurrentTopic() throws Exception { + this.log.info("[testThreadHasCurrentTopic]"); + Thread thread = new Thread(group, new Runnable() { + public void run() { + collaboration.acquireUninterruptibly("testThreadHasCurrentTopic"); + try { + flagTestThreadHasCurrentTopic = true; + WaitCriterion ev = new WaitCriterion() { + public boolean done() { + return !flagTestThreadHasCurrentTopic; + } + public String description() { + return null; + } + }; + DistributedTestCase.waitForCriterion(ev, 60 * 1000, 200, true); + } + finally { + collaboration.release(); + } + } + }); + + // before starting thread, hasCurrentTopic(thread) returns false + assertTrue(!this.collaboration.hasCurrentTopic(thread)); + thread.start(); + WaitCriterion ev = new WaitCriterion() { + public boolean done() { + return flagTestThreadHasCurrentTopic; + } + public String description() { + return null; + } + }; + DistributedTestCase.waitForCriterion(ev, 60 * 1000, 200, true); + + // after starting thread, hasCurrentTopic(thread) returns true + assertTrue(this.collaboration.hasCurrentTopic(thread)); + this.flagTestThreadHasCurrentTopic = false; + DistributedTestCase.join(thread, 30 * 1000, null); + + // after thread finishes, hasCurrentTopic(thread) returns false + assertTrue(!this.collaboration.hasCurrentTopic(thread)); + } + + public void testIsCurrentTopic() throws Exception { + this.log.info("[testIsCurrentTopic]"); + Object topic = "testIsCurrentTopic"; + assertTrue(!this.collaboration.isCurrentTopic(topic)); + this.collaboration.acquireUninterruptibly(topic); + try { + assertTrue(this.collaboration.isCurrentTopic(topic)); + } + finally { + this.collaboration.release(); + } + assertTrue(!this.collaboration.isCurrentTopic(topic)); + } + + protected final ThreadGroup group = + new ThreadGroup("CollaborationJUnitTest Threads") { + public void uncaughtException(Thread t, Throwable e) + { + if (e instanceof VirtualMachineError) { + SystemFailure.setFailure((VirtualMachineError)e); // don't throw + } + String s = "Uncaught exception in thread " + t; + log.error(s, e); + fail(s); + } + }; +} + http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cb7dbd0b/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/locks/CollaborationJUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/locks/CollaborationJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/locks/CollaborationJUnitTest.java deleted file mode 100755 index 711500e..0000000 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/locks/CollaborationJUnitTest.java +++ /dev/null @@ -1,617 +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 com.gemstone.gemfire.distributed.internal.locks; - -import static org.junit.Assert.*; - -import java.util.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import com.gemstone.gemfire.CancelCriterion; -import com.gemstone.gemfire.LogWriter; -import com.gemstone.gemfire.SystemFailure; -import com.gemstone.gemfire.internal.logging.LocalLogWriter; -import com.gemstone.gemfire.test.junit.categories.IntegrationTest; -import com.gemstone.gemfire.internal.logging.InternalLogWriter; - -import dunit.DistributedTestCase; -import dunit.DistributedTestCase.WaitCriterion; - -/** - * Tests the Collaboration Lock used internally by dlock service. - * - * @author Kirk Lund - * @since 4.1.1 - */ -@Category(IntegrationTest.class) -@Ignore("Test is broken and was named CollaborationJUnitDisabledTest") -public class CollaborationJUnitTest { - - protected LogWriter log = new LocalLogWriter(InternalLogWriter.INFO_LEVEL); - protected Collaboration collaboration; - - @Before - public void setUp() throws Exception { - this.collaboration = new Collaboration(new CancelCriterion() { - @Override - public String cancelInProgress() { - return null; - } - @Override - public RuntimeException generateCancelledException(Throwable e) { - return null; - } - }); - } - - @After - public void tearDown() throws Exception { - this.collaboration = null; - } - - protected volatile boolean flagTestBlocksUntilRelease = false; - protected volatile boolean threadBStartedTestBlocksUntilRelease = false; - - @Test - public void testBlocksUntilRelease() throws Exception { - this.log.info("[testBlocksUntilRelease]"); - Thread threadA = new Thread(group, new Runnable() { - @Override - public void run() { - collaboration.acquireUninterruptibly("topicA"); - try { - flagTestBlocksUntilRelease = true; - while(flagTestBlocksUntilRelease) { - try { - Thread.sleep(10); - } - catch (InterruptedException ignore) {fail("interrupted");} - } - } - finally { - collaboration.release(); - } - } - }); - - // thread one acquires - threadA.start(); - WaitCriterion ev = new WaitCriterion() { - @Override - public boolean done() { - return CollaborationJUnitTest.this.flagTestBlocksUntilRelease; - } - @Override - public String description() { - return "waiting for thread"; - } - }; - DistributedTestCase.waitForCriterion(ev, 5 * 1000, 200, true); - assertTrue(this.collaboration.hasCurrentTopic(threadA)); - - // thread two blocks until one releeases - Thread threadB = new Thread(group, new Runnable() { - @Override - public void run() { - threadBStartedTestBlocksUntilRelease = true; - collaboration.acquireUninterruptibly("topicB"); - try { - flagTestBlocksUntilRelease = true; - WaitCriterion ev2 = new WaitCriterion() { - @Override - public boolean done() { - return !flagTestBlocksUntilRelease; - } - @Override - public String description() { - return "waiting for release"; - } - }; - DistributedTestCase.waitForCriterion(ev2, 20 * 1000, 200, true); - } - finally { - collaboration.release(); - } - } - }); - - // start up threadB - threadB.start(); - ev = new WaitCriterion() { - @Override - public boolean done() { - return threadBStartedTestBlocksUntilRelease; - } - @Override - public String description() { - return "waiting for thread b"; - } - }; - DistributedTestCase.waitForCriterion(ev, 5 * 1000, 200, true); - - // threadA holds topic and threadB is waiting... - assertTrue(this.collaboration.hasCurrentTopic(threadA)); - assertFalse(this.collaboration.hasCurrentTopic(threadB)); - - // let threadA release so that threadB gets lock - this.flagTestBlocksUntilRelease = false; - DistributedTestCase.join(threadA, 30 * 1000, null); - - // make sure threadB is doing what it's supposed to do... - ev = new WaitCriterion() { - @Override - public boolean done() { - return flagTestBlocksUntilRelease; - } - @Override - public String description() { - return "threadB"; - } - }; - DistributedTestCase.waitForCriterion(ev, 5 * 1000, 200, true); - // threadB must have lock now... let threadB release - assertTrue(this.collaboration.hasCurrentTopic(threadB)); - this.flagTestBlocksUntilRelease = false; - DistributedTestCase.join(threadB, 30 * 1000, null); - - // collaboration should be free now - assertFalse(this.collaboration.hasCurrentTopic(threadA)); - assertFalse(this.collaboration.hasCurrentTopic(threadB)); - assertFalse(this.collaboration.hasCurrentTopic()); - } - - protected volatile boolean threadAFlag_TestLateComerJoinsIn = false; - protected volatile boolean threadBFlag_TestLateComerJoinsIn = false; - protected volatile boolean threadCFlag_TestLateComerJoinsIn = true; - protected volatile boolean threadDFlag_TestLateComerJoinsIn = false; - - @Test - public void testLateComerJoinsIn() throws Exception { - this.log.info("[testLateComerJoinsIn]"); - - final Object topicA = "topicA"; - final Object topicB = "topicB"; - - // threads one and two acquire - Thread threadA = new Thread(group, new Runnable() { - @Override - public void run() { - collaboration.acquireUninterruptibly(topicA); - try { - threadAFlag_TestLateComerJoinsIn = true; - WaitCriterion ev = new WaitCriterion() { - @Override - public boolean done() { - return !threadAFlag_TestLateComerJoinsIn; - } - @Override - public String description() { - return null; - } - }; - DistributedTestCase.waitForCriterion(ev, 60 * 1000, 200, true); - } - finally { - collaboration.release(); - } - } - }); - threadA.start(); - WaitCriterion ev = new WaitCriterion() { - @Override - public boolean done() { - return threadAFlag_TestLateComerJoinsIn; - } - @Override - public String description() { - return "wait for ThreadA"; - } - }; - DistributedTestCase.waitForCriterion(ev, 30 * 1000, 200, true); - assertTrue(this.collaboration.hasCurrentTopic(threadA)); - assertTrue(this.collaboration.isCurrentTopic(topicA)); - - Thread threadB = new Thread(group, new Runnable() { - @Override - public void run() { - collaboration.acquireUninterruptibly(topicA); - try { - threadBFlag_TestLateComerJoinsIn = true; - WaitCriterion ev2 = new WaitCriterion() { - @Override - public boolean done() { - return !threadBFlag_TestLateComerJoinsIn; - } - @Override - public String description() { - return null; - } - }; - DistributedTestCase.waitForCriterion(ev2, 60 * 1000, 200, true); - } - finally { - collaboration.release(); - } - } - }); - threadB.start(); - ev = new WaitCriterion() { - @Override - public boolean done() { - return threadBFlag_TestLateComerJoinsIn; - } - @Override - public String description() { - return ""; - } - }; - DistributedTestCase.waitForCriterion(ev, 60 * 1000, 200, true); - assertTrue(this.collaboration.hasCurrentTopic(threadB)); - - // thread three blocks for new topic - Thread threadC = new Thread(group, new Runnable() { - @Override - public void run() { - threadCFlag_TestLateComerJoinsIn = false; - collaboration.acquireUninterruptibly(topicB); - try { - threadCFlag_TestLateComerJoinsIn = true; - WaitCriterion ev2 = new WaitCriterion() { - @Override - public boolean done() { - return !threadCFlag_TestLateComerJoinsIn; - } - @Override - public String description() { - return null; - } - }; - DistributedTestCase.waitForCriterion(ev2, 60 * 1000, 200, true); - } - finally { - collaboration.release(); - } - } - }); - threadC.start(); - ev = new WaitCriterion() { - @Override - public boolean done() { - return threadCFlag_TestLateComerJoinsIn; - } - @Override - public String description() { - return null; - } - }; - DistributedTestCase.waitForCriterion(ev, 60 * 1000, 200, true); - assertFalse(this.collaboration.hasCurrentTopic(threadC)); - assertFalse(this.collaboration.isCurrentTopic(topicB)); - - // thread four (lateComer) acquires current topic immediately - Thread threadD = new Thread(group, new Runnable() { - @Override - public void run() { - collaboration.acquireUninterruptibly(topicA); - try { - threadDFlag_TestLateComerJoinsIn = true; - while(threadDFlag_TestLateComerJoinsIn) { - try { - Thread.sleep(10); - } - catch (InterruptedException ignore) {fail("interrupted");} - } - } - finally { - collaboration.release(); - } - } - }); - threadD.start(); - ev = new WaitCriterion() { - @Override - public boolean done() { - return threadDFlag_TestLateComerJoinsIn; - } - @Override - public String description() { - return null; - } - }; - DistributedTestCase.waitForCriterion(ev, 60 * 1000, 200, true); - assertTrue(this.collaboration.hasCurrentTopic(threadD)); - - // release threadA - this.threadAFlag_TestLateComerJoinsIn = false; - DistributedTestCase.join(threadA, 30 * 1000, null); - assertFalse(this.collaboration.hasCurrentTopic(threadA)); - assertTrue(this.collaboration.hasCurrentTopic(threadB)); - assertFalse(this.collaboration.hasCurrentTopic(threadC)); - assertTrue(this.collaboration.hasCurrentTopic(threadD)); - assertTrue(this.collaboration.isCurrentTopic(topicA)); - assertFalse(this.collaboration.isCurrentTopic(topicB)); - - // release threadB - this.threadBFlag_TestLateComerJoinsIn = false; - DistributedTestCase.join(threadB, 30 * 1000, null); - assertFalse(this.collaboration.hasCurrentTopic(threadB)); - assertFalse(this.collaboration.hasCurrentTopic(threadC)); - assertTrue(this.collaboration.hasCurrentTopic(threadD)); - assertTrue(this.collaboration.isCurrentTopic(topicA)); - assertFalse(this.collaboration.isCurrentTopic(topicB)); - - // release threadD - this.threadDFlag_TestLateComerJoinsIn = false; - DistributedTestCase.join(threadD, 30 * 1000, null); - ev = new WaitCriterion() { - @Override - public boolean done() { - return threadCFlag_TestLateComerJoinsIn; - } - @Override - public String description() { - return null; - } - }; - DistributedTestCase.waitForCriterion(ev, 60 * 1000, 200, true); - assertTrue(this.collaboration.hasCurrentTopic(threadC)); - assertFalse(this.collaboration.hasCurrentTopic(threadD)); - assertFalse(this.collaboration.isCurrentTopic(topicA)); - assertTrue(this.collaboration.isCurrentTopic(topicB)); - - // release threadC - this.threadCFlag_TestLateComerJoinsIn = false; - DistributedTestCase.join(threadC, 30 * 1000, null); - assertFalse(this.collaboration.hasCurrentTopic(threadC)); - assertFalse(this.collaboration.isCurrentTopic(topicA)); - assertFalse(this.collaboration.isCurrentTopic(topicB)); - } - - protected List waitingList = Collections.synchronizedList(new ArrayList()); - protected List fairnessList = Collections.synchronizedList(new ArrayList()); - protected volatile boolean runTestFairnessStressfully = true; - - @Test - public void testFairnessStressfully() throws Exception { - this.log.info("[testFairnessStressfully]"); - final int numThreads = 20; - Thread threads[] = new Thread[numThreads]; - - Runnable run = new Runnable() { - public void run() { - boolean released = false; - try { - String uniqueTopic = Thread.currentThread().getName(); - while(runTestFairnessStressfully) { - waitingList.add(uniqueTopic); - collaboration.acquireUninterruptibly(uniqueTopic); - try { - released = false; - fairnessList.add(uniqueTopic); - waitingList.remove(uniqueTopic); - } - finally { - // wait for the other threads to line up... - WaitCriterion ev = new WaitCriterion() { - @Override - public boolean done() { - return !runTestFairnessStressfully || waitingList.size() >= numThreads - 1; - } - @Override - public String description() { - return "other threads lining up"; - } - }; - DistributedTestCase.waitForCriterion(ev, 60 * 1000, 200, true); - collaboration.release(); - released = true; - } - } - } - finally { - if (!released) { - collaboration.release(); - } - } - } - }; - - try { - // many threads loop: acquire and release with unique topic - for (int t = 0; t < threads.length; t++) { - threads[t] = new Thread(group, run, String.valueOf(t)); - threads[t].start(); - } - - log.info("Started all threads... waiting for test to complete."); - - // wait for numThreads * 10 - WaitCriterion ev = new WaitCriterion() { - @Override - public boolean done() { - return fairnessList.size() >= numThreads * 20; - } - @Override - public String description() { - return "waiting for numThreads * 10"; - } - }; - DistributedTestCase.waitForCriterion(ev, 5 * 60 * 1000, 200, true); - } - finally { - if (this.runTestFairnessStressfully) { - this.runTestFairnessStressfully = false; - } - } - - for (int t = 0; t < threads.length; t++) { - DistributedTestCase.join(threads[t], 30 * 1000, null); - } - - // assert that all topics are acquired in order - // count number of occurrences of each thread - int count[] = new int[numThreads]; - for (int i = 0; i < count.length; i++) { // shouldn't be necessary - count[i] = 0; - } - synchronized(this.fairnessList) { - for (Iterator iter = this.fairnessList.iterator(); iter.hasNext();) { - int id = Integer.valueOf((String)iter.next()).intValue(); - count[id] = count[id]+1; - } - } - - int totalLocks = 0; - int minLocks = Integer.MAX_VALUE; - int maxLocks = 0; - for (int i = 0; i < count.length; i++) { - int locks = count[i]; - this.log.fine("testFairnessStressfully thread-" + i + " acquired topic " + - locks + " times."); - if (locks < minLocks) minLocks = locks; - if (locks > maxLocks) maxLocks = locks; - totalLocks = totalLocks + locks; - } - - this.log.info("[testFairnessStressfully] totalLocks=" + totalLocks + - " minLocks=" + minLocks + - " maxLocks=" + maxLocks); - - int expectedLocks = (totalLocks / numThreads) + 1; - - // NOTE: if you turn on fine logs, this deviation may be too small... - // slower machines may also fail depending on thread scheduling - int deviation = (int)(expectedLocks * 0.25); - int lowThreshold = expectedLocks - deviation; - int highThreshold = expectedLocks + deviation; - - this.log.info("[testFairnessStressfully] deviation=" + deviation + - " expectedLocks=" + expectedLocks + - " lowThreshold=" + lowThreshold + - " highThreshold=" + highThreshold); - - // if these assertions keep failing we'll have to rewrite the test - // to handle scheduling of the threads... - - assertTrue("minLocks is less than lowThreshold", - minLocks >= lowThreshold); - assertTrue("maxLocks is greater than highThreshold", - maxLocks <= highThreshold); - } - - @Test - public void testHasCurrentTopic() throws Exception { - this.log.info("[testHasCurrentTopic]"); - assertTrue(!this.collaboration.hasCurrentTopic()); - this.collaboration.acquireUninterruptibly("testHasCurrentTopic"); - try { - assertTrue(this.collaboration.hasCurrentTopic()); - } - finally { - this.collaboration.release(); - } - assertTrue(!this.collaboration.hasCurrentTopic()); - } - - protected volatile boolean flagTestThreadHasCurrentTopic = false; - - @Test - public void testThreadHasCurrentTopic() throws Exception { - this.log.info("[testThreadHasCurrentTopic]"); - Thread thread = new Thread(group, new Runnable() { - @Override - public void run() { - collaboration.acquireUninterruptibly("testThreadHasCurrentTopic"); - try { - flagTestThreadHasCurrentTopic = true; - WaitCriterion ev = new WaitCriterion() { - @Override - public boolean done() { - return !flagTestThreadHasCurrentTopic; - } - @Override - public String description() { - return null; - } - }; - DistributedTestCase.waitForCriterion(ev, 60 * 1000, 200, true); - } - finally { - collaboration.release(); - } - } - }); - - // before starting thread, hasCurrentTopic(thread) returns false - assertTrue(!this.collaboration.hasCurrentTopic(thread)); - thread.start(); - WaitCriterion ev = new WaitCriterion() { - @Override - public boolean done() { - return flagTestThreadHasCurrentTopic; - } - @Override - public String description() { - return null; - } - }; - DistributedTestCase.waitForCriterion(ev, 60 * 1000, 200, true); - - // after starting thread, hasCurrentTopic(thread) returns true - assertTrue(this.collaboration.hasCurrentTopic(thread)); - this.flagTestThreadHasCurrentTopic = false; - DistributedTestCase.join(thread, 30 * 1000, null); - - // after thread finishes, hasCurrentTopic(thread) returns false - assertTrue(!this.collaboration.hasCurrentTopic(thread)); - } - - @Test - public void testIsCurrentTopic() throws Exception { - this.log.info("[testIsCurrentTopic]"); - Object topic = "testIsCurrentTopic"; - assertTrue(!this.collaboration.isCurrentTopic(topic)); - this.collaboration.acquireUninterruptibly(topic); - try { - assertTrue(this.collaboration.isCurrentTopic(topic)); - } - finally { - this.collaboration.release(); - } - assertTrue(!this.collaboration.isCurrentTopic(topic)); - } - - protected final ThreadGroup group = - new ThreadGroup("CollaborationJUnitTest Threads") { - @Override - public void uncaughtException(Thread t, Throwable e) - { - if (e instanceof VirtualMachineError) { - SystemFailure.setFailure((VirtualMachineError)e); // don't throw - } - String s = "Uncaught exception in thread " + t; - log.error(s, e); - fail(s); - } - }; -} - http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cb7dbd0b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/diskPerf/DiskRegionPerfJUnitPerformanceTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/diskPerf/DiskRegionPerfJUnitPerformanceTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/diskPerf/DiskRegionPerfJUnitPerformanceTest.java index 5ec4af8..0ee9d4f 100755 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/diskPerf/DiskRegionPerfJUnitPerformanceTest.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/diskPerf/DiskRegionPerfJUnitPerformanceTest.java @@ -21,7 +21,6 @@ import java.util.Arrays; import org.junit.After; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -32,15 +31,14 @@ import com.gemstone.gemfire.cache.Scope; import com.gemstone.gemfire.internal.cache.DiskRegionHelperFactory; import com.gemstone.gemfire.internal.cache.DiskRegionProperties; import com.gemstone.gemfire.internal.cache.DiskRegionTestingBase; -import com.gemstone.gemfire.test.junit.categories.PerformanceTest; +import com.gemstone.gemfire.test.junit.categories.IntegrationTest; /** * Consolidated Disk Region Perftest. Overflow, Persist, OverflowWithPersist * modes are tested for Sync, AsyncWithBuffer and AsyncWithoutBufer writes. * */ -@Category(PerformanceTest.class) -@Ignore("Tests have no assertions") +@Category(IntegrationTest.class) public class DiskRegionPerfJUnitPerformanceTest extends DiskRegionTestingBase { LogWriter log = null; http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cb7dbd0b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HARegionQueueStartStopJUnitDisabledTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HARegionQueueStartStopJUnitDisabledTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HARegionQueueStartStopJUnitDisabledTest.java new file mode 100755 index 0000000..4cfc9ba --- /dev/null +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HARegionQueueStartStopJUnitDisabledTest.java @@ -0,0 +1,123 @@ +/* + * 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 com.gemstone.gemfire.internal.cache.ha; + +import java.io.IOException; +import java.util.Properties; + +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.CacheException; +import com.gemstone.gemfire.cache.CacheFactory; +import com.gemstone.gemfire.internal.cache.GemFireCacheImpl; +import com.gemstone.gemfire.internal.cache.RegionQueue; +import com.gemstone.gemfire.distributed.DistributedSystem; +import com.gemstone.gemfire.internal.Assert; + +import junit.framework.TestCase; + +/** + * @author Mitul Bid + * + */ +public class HARegionQueueStartStopJUnitDisabledTest extends TestCase +{ + + /** + * Creates the cache instance for the test + * + * @return the cache instance + * @throws CacheException - + * thrown if any exception occurs in cache creation + */ + private Cache createCache() throws CacheException + { + return CacheFactory.create(DistributedSystem.connect(new Properties())); + } + + /** + * Creates HA region-queue object + * + * @return HA region-queue object + * @throws IOException + * @throws ClassNotFoundException + * @throws CacheException + * @throws InterruptedException + */ + private RegionQueue createHARegionQueue(String name, Cache cache) + throws IOException, ClassNotFoundException, CacheException, InterruptedException + { + RegionQueue regionqueue =HARegionQueue.getHARegionQueueInstance(name, cache,HARegionQueue.NON_BLOCKING_HA_QUEUE, false); + return regionqueue; + } + + public void testStartStop() + { + try { + boolean exceptionOccured = false; + Cache cache = createCache(); + createHARegionQueue("test", cache); + Assert + .assertTrue(HARegionQueue.getDispatchedMessagesMapForTesting() != null); + HARegionQueue.stopHAServices(); + try { + HARegionQueue.getDispatchedMessagesMapForTesting(); + } + catch (NullPointerException e) { + exceptionOccured = true; + } + if (!exceptionOccured) { + fail("Expected exception to occur but did not occur"); + } + HARegionQueue.startHAServices((GemFireCacheImpl)cache); + Assert + .assertTrue(HARegionQueue.getDispatchedMessagesMapForTesting() != null); + cache.close(); + try { + HARegionQueue.getDispatchedMessagesMapForTesting(); + } + catch (NullPointerException e) { + exceptionOccured = true; + } + if (!exceptionOccured) { + fail("Expected exception to occur but did not occur"); + } + + cache = createCache(); + + try { + HARegionQueue.getDispatchedMessagesMapForTesting(); + } + catch (NullPointerException e) { + exceptionOccured = true; + } + if (!exceptionOccured) { + fail("Expected exception to occur but did not occur"); + } + + } + catch (Exception e) { + e.printStackTrace(); + fail("Test failed due to " + e); + } + + } + + +}